【发布时间】:2018-02-18 08:23:46
【问题描述】:
我正在尝试从 java 调用两个soap ws。当我从两个不同的 java 线程调用这些 ws 时,它被成功调用,但是当尝试在同一个线程中调用时,第一次调用成功,第二次调用卡住。我可以在我的日志中看到这两个请求。
我检查了服务器上的 tcp 转储,可以看到第一个请求,所有标头参数都设置正确,但在第二次调用中,而不是 content-length 得到 transfer-encoding = chunked。
第一个 ws 调用标头 - 2018 年 2 月 15 日上午 9:59:40 [8]
Content-Length=639 Content-Type=text/ xml; charset=UTF-8 Accept=/ Host=test102.com User-Agent=Apache CXF 2.7.11 SOAPAction="Trackem.Web.Services/ReserveServiceTime" Proxy-Connection=Keep-Alive第二个 ws 调用标头 - 2018 年 2 月 15 日上午 10:01:11 [9]
Transfer-Encoding=chunked Content-Type=text/ xml;字符集=UTF-8 Accept=/ Host=test102.com
用户代理=Apache CXF 2.7.11 SOAPAction="Trackem.Web.Services/CreateOrUpdateTask" Proxy-Connection=Keep-Alive5:05 PM
请帮助我理解为什么第二次通话不能正常工作?
这是我的 java ws 方法 -
public P getPort(final Class<P> serviceEndpointInterface, final String ascNode) throws MalformedURLException{
final Bus currThreadBus = BusFactory.getThreadDefaultBus();
ClassLoader originalThreadClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader busFactoryClassLoader = BusFactory.class.getClassLoader();
try {
Thread.currentThread().setContextClassLoader(busFactoryClassLoader);
BusFactory.setThreadDefaultBus(BusFactory.newInstance().createBus());
QName qname = new QName(nameSpace, strQName);
Service service = Service.create(qname);
P port = null;
if (CommonUtil.isEmpty(portName)) {
port = service.getPort(serviceEndpointInterface);
} else {
QName portQname = new QName(nameSpace, portName);
port = service.getPort(portQname, serviceEndpointInterface);
}
BindingProvider bp = (BindingProvider) port;
// Timeout in millis
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL);
bp.getRequestContext().put(Message.CONNECTION_TIMEOUT, Integer.parseInt(connectTimeout));
bp.getRequestContext().put(Message.RECEIVE_TIMEOUT, Integer.parseInt(requestTimeout));
final Client client = ClientProxy.getClient(port);
client.getOutInterceptors().add(new LoggingOutInterceptor());
client.getInInterceptors().add(new LoggingInInterceptor());
//Add proxy server details if configured in ASC
if(!CommonMethods.isEmpty(proxyHost) && !CommonMethods.isEmpty(proxyPort))
{
HTTPConduit http = (HTTPConduit) ClientProxy.getClient(port).getConduit();
http.getClient().setProxyServer(proxyHost);
http.getClient().setProxyServerPort(Integer.parseInt(proxyPort));
if(!CommonMethods.isEmpty(proxyUsername) && !CommonMethods.isEmpty(proxyPassword))
{
http.getProxyAuthorization().setUserName(proxyUsername);
http.getProxyAuthorization().setPassword(proxyPassword);
}
}
return port;
}finally {
BusFactory.setThreadDefaultBus(currThreadBus);
Thread.currentThread().setContextClassLoader(originalThreadClassLoader);
}}
【问题讨论】:
标签: java web-services http soap