Hello! I have a simple client to connect a web service destination:
//Obtengo el acceso al servicio.
final WsTransaccionOnlineReceptorImplService
wsTOLReceptorImplService = new WsTransaccionOnlineReceptorImplService(wsdlURL,
SERVICE_NAME);
//Obtengo el port donde estan definidas las operaciones.
final WsTransaccionOnlineReceptor port =
wsTOLReceptorImplService.getWsTransaccionOnlineReceptorPort();
//Asigno los timeouts correspondientes.
final Client cliente = ClientProxy.getClient(port);
final HTTPConduit http = (HTTPConduit) cliente.getConduit();
final HTTPClientPolicy httpClientPolicy = new
HTTPClientPolicy();
//Timeout para la conexion (milisegundos).
httpClientPolicy.setConnectionTimeout(3000);
//Timeout de recepcion de datos(milisegundos).
httpClientPolicy.setReceiveTimeout(10000);
http.setClient(httpClientPolicy);
final RespuestaType resp=port.aprobacionTransaccion(tol);
The ReceiveTimeout works as expected, when no data arrives in the specified
ReceiveTimeout a java.net.SocketTimeoutException: Read timed out arises.
In some cases when there is network problems or may be the response is in
"chunked transfer encoding" and there is delay between chunks, the response
takes minutes to arrive and no exception is thrown (because data is incoming,
but slowly).
This client is embedded in a JAX-WS web service and must return a response to
the caller in certain amount of time and obviously I need an extra timeout,
let's say a "ResponseTimeout".
I tried to start a thread and sleep "ResponseTimeout", after that, call a
cliente.close() if response not arrived completely but has no effect in
blocking mode and i think is not the adequate solution.
Should I use asynchronous web services to achieve this?
Any suggestion will be appreciated!!
Thanks!