1


我们的 Jersey 客户端从服务器获取以下异常。

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)

这是客户端创建代码:

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);

因此,我们正在尝试为客户端设置最大超时但无济于事。

任何人都知道如何配置客户端超时?
处理Tomcat超时可能更好?(如何?)虽然我认为它落后于一些负载均衡器。

4

1 回答 1

2

尝试下面的代码来设置客户端读取超时。

clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT,30000);//30 seconds read timeout

尝试下面的代码来设置客户端连接超时。

clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT,30000);//30 seconds for connection timeout
于 2012-12-13T12:31:58.747 回答