gpt4 book ai didi

java - Soap:使用 WSDL2Java 设置超时

转载 作者:行者123 更新时间:2023-12-01 22:43:14 25 4
gpt4 key购买 nike

我正在尝试将一些数据发送到 SOAP 服务。现在我们已经使用 WSDL2Java 基于 WSDL 创建了一些类。现在通话时间超过 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

最佳答案

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

导入:

    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

关于java - Soap:使用 WSDL2Java 设置超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25784402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com