[Java]
<Strong> </strong> <pre class = "java" name = "code"> recently, the problem of "premature file termination" often occurs when calling webservice interfaces with cxf. After various tests, the problem lies in cookie settings. cookie information must be encapsulated before an interface is called. The following is the DEMO code. </Pre> <pre class = "java" name = "code"> </pre> <pre class = "java" name = "code"> package com. toft. webservice. client. domino;
Import java. io. BufferedWriter;
Import java. io. File;
Import java. io. FileWriter;
Import java. io. IOException;
Import java.net. URL;
Import java. text. SimpleDateFormat;
Import java. util. Date;
Import java. util. List;
Import java. util. Map;
Import javax. xml. namespace. QName;
Import org. apache. cxf. endpoint. Client;
Import org. apache. cxf. frontend. ClientProxy;
Import org. apache. cxf. jaxws. JaxWsProxyFactoryBean;
Import org. apache. cxf. transport. http. HTTPConduit;
Import org. apache. cxf. transports. http. configuration. HTTPClientPolicy;
Import org. apache. log4j. Logger;
Import com. toft. core2.ToftException;
Import com. toft. webservice. core. CoreWebService;
Import com. toft. webservice. core. JaxbBinder;
Import com. toft. webservice. utils. WebServicePropertiesUtils;
Import com. toft. webservice. wsdl. client. domino. CreateDocByOwnership;
Import com. toft. webservice. wsdl. client. domino. CreateDocByResult;
Import com. toft. webservice. wsdl. client. domino. GETTODOReturn;
Import com. toft. widgets. rent. util. Constant;
Import com. toft. widgets. rent. util. Tools;
/**
* Create a Domino document interface.
*
* @ Author sunzuqiang
*/
Public final class DominoInterface extends CoreWebService {
/**
*
* @ Param Map object, corresponding to a row in Result
* @ Param List object, corresponding to Result
*/
Public boolean create (String projectno, String WORKFLOW_INSTANCES) throws ToftException {
WebServicePropertiesUtils properties = new WebServicePropertiesUtils ();
// CreateDocByResultService ss = new CreateDocByResultService (wsdlURL, SERVICE_NAME );
// CreateDocByResult port = ss. getDomino ();
Try {
String wsdl = "<a href =" http: // ***** domino. wsdl "> http: // ***** domino. wsdl </a> "; </pre> <pre class =" java "name =" code "> URL wsdlURL = new URL (wsdl );
// Cxf calls webservice factory class
JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean ();
// Set the request's wsdl address
Svr. setAddress (wsdlURL. toString ());
// Set the implementation class of the wsdl Interface
Svr. setServiceClass (CreateDocByResult. class );
/*
* ------- Gorgeous split line -----
* Start setting cookie Information
*/
// Obtain the method of the interface implementation class through the factory class
CreateDocByResult hw = (CreateDocByResult) svr. create ();
// Set the client information to the interface class
Client client = ClientProxy. getClient (hw );
// The client encapsulates http Information
HTTPConduit http = (HTTPConduit) client. getConduit ();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy ();
// It is very important to set the cookie for this row. If the interface permits anonymous access, set it to "". If you want to verify the single sign-on user information, you need to set the following settings:
HttpClientPolicy. setCookie (String) this. getContext (). getRequest (). getHeader ("Cookie "));
HttpClientPolicy. setAllowChunking (false );
Http. setClient (httpClientPolicy );
Logger. debug ("Invoking createdoc ...");
Logger. debug ("START domino interface ");
Result = hw. createdoc (xml );
Logger. debug ("domino interface started ");
Logger. debug ("Invoking createdoc success! ");
Return result;
} Catch (Exception f ){
F. printStackTrace ();
Throw ToftException. ThrowToftException ("An error occurred while calling the Domino interface! ");
} Catch (Throwable e ){
E. printStackTrace ();
Throw ToftException. ThrowToftException ("An error occurred while calling the Domino interface! ");
} Finally {
Logger. debug ("An error occurred while calling the Domino interface! ");
}
}
} </Pre> <br>
Recently, calling webservice interfaces with cxf often causes the "premature termination of Files" issue. After various tests, the problem lies in cookie settings. cookie information must be encapsulated before an interface is called. The following is the DEMO code.
<Pre> </pre>
<Pre class = "java" name = "code"> </pre> <br>
<Pre> </pre>
Author: sunzuqiang