Soap:使用 WSDL2Java 设置超时 [英] Soap: Set TimeOut using WSDL2Java

查看:55
本文介绍了Soap:使用 WSDL2Java 设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 SOAP 服务发送一些数据.现在我们已经使用基于 WSDL 的 WSDL2Java 创建了一些类.现在通话时间超过 1 分钟,而超时设置(我认为)为 1 分钟.如何更改超时时间?

I'm trying to send some data to a SOAP service. Now we have created some classes with WSDL2Java based on a WSDL. Now the call is taking more than 1 minute, while the time out is set (I think) on 1 minute. How can I change the timeout?

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

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

I already tried the following, but it seems like that hasn't any effect

    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

推荐答案

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

I solved the issue by using the following code:

导入:

    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

这篇关于Soap:使用 WSDL2Java 设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆