在soap ws调用中获取Transfer-Encoding = chunked而不是内容长度

时间:2018-02-18 08:23:46

标签: java web-services http soap

我试图用两个肥皂和java调用。当我从两个不同的java线程调用这些ws时,它已被成功调用,但是当试图在同一个线程中调用时,首先调用成功,第二个调用被卡住。我可以在日志中看到这两个请求。

我检查了服务器上的tcp dump并且可以看到第一个请求,所有头参数都设置正确,但是在第二次调用中而不是content-length得到transfer-encoding = chunked。

  

首先打电话标题 - 2/15/2018 9:59:40 AM [ 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" - 代理连接=保活

     

秒ws call header - 2/15/2018 10:01:11 AM [ 9 ]
   Transfer-Encoding = chunked Content-Type = text / xml; charset = UTF-8 Accept = / Host = test102.com
  User-Agent = Apache CXF 2.7.11   的SOAPAction =" Trackem.Web.Services/CreateOrUpdateTask"   代理连接= 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);
}}

1 个答案:

答案 0 :(得分:-2)

  

我通过禁用HTTP客户端中的块传输解决了这个问题。   。http.getClient()setAllowChunking(假);

我想,问题出在我的代理服务器上,请看link