Reputation: 17
We are on apache CXF v3.1. I'm making API calls to a SOAP based server. I used to make synchronous calls and the following logic worked just fine for timeouts:
URL url = MyClient.class.getClassLoader().getResource("service.wsdl");
// create service
PaymentPortTypeService service = new PaymentPortTypeService(url);
// Set executor for async response
service.setExecutor(threadPoolExecutor);
/*
* Handlers are used to set the security headers on the SOAP envelope.
*/
PaymentsHeaderHandlerResolver hResolver = new PaymentsHeaderHandlerResolver(userId, password);
service.setHandlerResolver(hResolver);
// create client
client = service.getPaymentPortTypeSoap11();
BindingProvider bp = ((BindingProvider) client);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vBaseUrl);
org.apache.cxf.endpoint.Client c = ClientProxy.getClient(client);
((ClientImpl)c).setSynchronousTimeout(30000);
AsyncHTTPConduit httpConduit = (AsyncHTTPConduit) c.getConduit();
httpConduit.getClient().setConnectionTimeout(1000);
httpConduit.getClient().setReceiveTimeout(30000);
httpConduit.getClient().setAllowChunking(false);
After we have moved to asynchronous HTTP, the timeouts don't seem to work anymore. Can you spot what I might be doing wrong?
Please note that we have the following in pom.xml to help generate the async interfaces:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/service.wsdl</wsdl>
<extraargs>
<extraarg>-asyncMethods</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</plugin>
Upvotes: 0
Views: 1425
Reputation: 1955
I believe you don't need to use CXF specific code, you can set timeout via binding properties:
bp.getRequestContext().put("javax.xml.ws.client.receiveTimeout", 30000);
bp.getRequestContext().put("javax.xml.ws.client.connectionTimeout", 10000);
Please note, the javax.xml.ws.client.receiveTimeout
and javax.xml.ws.client.connectionTimeout
are different to BindingProviderProperties.REQUEST_TIMEOUT
and BindingProviderProperties.CONNECT_TIMEOUT
Upvotes: 1