I have generated the client stubs using WSDLToJava. After that I have created the client as mentioned here http://cxf.apache.org/docs/developing-a-consumer.
this.testService = new TestService(wsdlURL, SERVICE_NAME); //line #1
this.port = testService.getTestPort(); //line #2
Client client = ClientProxy.getClient(port); //line #3
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
HTTPConduit conduit = (HTTPConduit)client.getConduit();
// setting timeouts for connection
String timeOutSecond = CoreProperty.getProp(CORE_SERVICE_TIME_OUT_MILLISECONDS);
int timeout =0;
try{
if(Utils.isNotNullOrBlank(timeOutSecond))
timeout = Integer.parseInt(timeOutSecond.trim());
else
timeout = Constants.DEFAULT_SERVICE_TIME_OUT_MILLISECONDS;
}catch (NumberFormatException e) {
timeout = Constants.DEFAULT_SERVICE_TIME_OUT_MILLISECONDS;
}
conduit.getClient().setReceiveTimeout(timeout);
The issue is that line #1 is taking almost 5 minutes to throw error if the server is down – specified in the wsdlURL .
I want to set a time out of 30 seconds to establish the client connection.
If the service is up everything is working fine and the receivetimeout I have set working fine. How can I set the timeout for establishing the connection.
THE PROGRAM IS WAITING AT LINE #1 IF THE SERVER IS DOWN, IT IS WAITING FOR MORE THAN 4 MINUTES THERE AND I WANT TO AVOID THAT.
Thanks for your time. Please help
I think the only option is to create a spring configuration file that configures an http:conduit with a name of “http://servername.com/.*” that sets a shorter timeout. Create the bus from that config file. See:
http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html