Soap:使用WSDL2Java设置TimeOut

时间:2014-09-11 09:55:59

标签: java soap wsdl wsdl2java

我试图将一些数据发送到SOAP服务。现在我们已经使用基于WSDL的WSDL2Java创建了一些类。现在呼叫超过1分钟,而超时是在1分钟设置(我认为)。如何更改超时?

Caused by: javax.xml.ws.WebServiceException: Could not send Message.
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
    at com.sun.proxy.$Proxy164.salesOrderProcess(Unknown Source)
    at com.project.b2b.cq.shimanoexportorder.SalesOrderPrepareInterceptor.onPrepare(SalesOrderPrepareInterceptor.java:133)
    at com.project.b2b.cq.shimanoexportorder.SalesOrderPrepareInterceptor.onPrepare(SalesOrderPrepareInterceptor.java:1)
    at de.cq.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokePrepareInterceptors(ModelWrapper.java:251)
    ... 124 more
Caused by: java.net.SocketTimeoutException: SocketTimeoutException invoking {URL}: Read timed out
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1422)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1407)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:640)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:519)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:449)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:352)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:304)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
    ... 128 more
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:152)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1527)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1485)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1393)
    ... 138 more

我已经尝试了以下内容,但似乎没有任何效果

    final SalesOrderServiceSoap salesOrderServiceSoap = new SalesOrderService(url).getSalesOrderServiceSoap();
    final Map<String, Object> requestContext = ((BindingProvider) salesOrderServiceSoap).getRequestContext();
    requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, Integer.valueOf(120000)); // Timeout in millis
    requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, Integer.valueOf(120000)); // Timeout in millis

2 个答案:

答案 0 :(得分:2)

我使用以下代码解决了这个问题:

导入:

    import org.apache.cxf.endpoint.Client;
    import org.apache.cxf.frontend.ClientProxy;
    import org.apache.cxf.transport.http.HTTPConduit;
    import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

代码:

    final SalesOrderServiceSoap salesOrderServiceSoap = new SalesOrderService(url).getSalesOrderServiceSoap(); //The service you need to use
    final Client cl = ClientProxy.getClient(salesOrderServiceSoap);
    final HTTPConduit httpConduit = (HTTPConduit) cl.getConduit();
    final HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

    httpClientPolicy.setConnectionTimeout(CONNECTION_TIMEOUT); //Time in milliseconds
    httpClientPolicy.setReceiveTimeout(RECEIVE_TIMEOUT); //Time in milliseconds
    httpConduit.setClient(httpClientPolicy);

您需要以下库:

    cxf-core-3.0.1.jar
    cxf-rt-frontend-simple-3.0.1.jar
    cxf-rt-transports-http.3.0.1.jar

答案 1 :(得分:1)

对于具有以下例外情况的人:

SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy

只需更改

的依赖项
cxf-rt-frontend-simple

cxf-rt-frontend-jaxws