Reputation: 2015
Our Jersey client gets the exception below from the server.
Got exception from API:POST http://my-host.com/api/x/y returned a response status of 504 Gateway Timeout, Stack trace: com.sun.jersey.api.client.UniformInterfaceException: POST http://my-host.com/api/x/y returned a response status of 504 Gateway Timeout
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:698)
at com.sun.jersey.api.client.WebResource.access$300(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:574)
at com.g.e.s.i.t.XYZ.callResource(ABC.java:84)
at ...
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
This is the client creation code:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(mapper);
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getSingletons().add(provider);
Client client = Client.create(clientConfig);
client.setConnectTimeout(Integer.MAX_VALUE);
client.setReadTimeout(Integer.MAX_VALUE);
return client.resource(url);
So, we're trying to setup the maximum timeout for the client but does not help.
Any one knows how to configure the client for the timeout?
May be is better to handle the Tomcat timeout? (how?) although I think it is behind some load balancer.
Upvotes: 1
Views: 3718
Reputation: 953
Try below code for setting client read time out.
clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT,30000);//30 seconds read timeout
Try below code for setting client connection time out.
clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT,30000);//30 seconds for connection timeout
Upvotes: 2