Java调用Domino接口报文件过早结束问题
[java]<strong></strong><pre class="java" name="code">最近用cxf调用webservice接口经常出现“文件过早结束”问题。经各种测试,问题在于cookie设置问题,调用接口之前必须封装cookie信息。以下是DEMO代码。</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;
/**
*创建Domino文档接口.
*
* @author sunzuqiang
*/
public final class DominoInte易做图ce extends CoreWebService {
/**
*
* @param Map对象,对应Result中的一行
* @param List对象,对应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调用webservice工厂类
JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean();
//设置请求的wsdl地址
svr.setAddress(wsdlURL.toString());
//设置wsdl接口实现类
svr.setServiceClass(CreateDocByResult.class);
/*
*-------华丽的分割线-----
*开始设置cookie信息
*/
//通过工厂类来获得接口实现类的方法
CreateDocByResult hw = (CreateDocByResult) svr.create();
//把客户端的信息设置到接口类里
Client client = ClientProxy.getClient(hw);
//客户端封装http信息
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
//此行设置cookie非常重要,如果接口允许匿名访问就设置为""就好,如果要验证单点登录用户信息就得如下设置
httpClientPolicy.setCookie((String)this.getContext().getRequest().getHeader("Cookie"));
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
logger.debug("Invoking createdoc...");
logger.debug("开始启动domino接口");
result = hw.createdoc(xml);
logger.debug("已经启动domino接口");
logger.debug("Invoking createdoc success!");
return result;
} catch(Exception f){
f.printStackTrace();
throw ToftException.ThrowToftException("调用Domino接口异常!");
}catch (Throwable e) {
e.printStackTrace();
throw ToftException.ThrowToftException("调用Domino接口异常!");
}finally{
logger.debug("调用Domino接口异常!");
}
}
}</pre><br>
最近用cxf调用webservice接口经常出现“文件过早结束”问题。经各种测试,问题在于cookie设置问题,调用接口之前必须封装cookie信息。以下是DEMO代码。
<pre></pre>
<pre class="java" name="code"> </pre><br>
<pre></pre&g
补充:软件开发 , Java ,