我可以全局设置HTTP连接的超时吗?

我有一个程序,它使用javax.xml.ws.Service来调用由WSDL定义的远程服务。 此程序在Google App Engine上运行,默认情况下,将HTTP连接超时设置为5秒{1}。 我需要增加此超时值,因为此服务通常需要很长时间才能响应,但由于此请求不是通过URLConnection ,我无法弄清楚如何调用URLConnection.setReadTimeout(int) {2},或以其他方式更改超时。

有没有办法在App Engine上全局设置HTTP连接超时? 而且,为了分享知识,人们将如何解决这类问题呢?

{1}: https : //developers.google.com/appengine/docs/java/urlfetch/overview#Requests

{2}: http : //docs.oracle.com/javase/1.5.0/docs/api/java/net/URLConnection.html#setReadTimeout(int)

您可以尝试设置此处记录的sun.net.client.defaultConnectTimeoutsun.net.client.defaultReadTimeout系统属性,例如

 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); System.setProperty("sun.net.client.defaultConnectTimeout", "30000"); 

编辑

很抱歉,只需重新阅读并注意到这是在Google App Engine上。 我不确定,但考虑到Google和Oracle最近的诉讼关系,我猜测GAE没有运行Oracle JVM。 我会留下这个,以防其他人遇到类似的问题。

尝试这个:

 Port port = service.getPort(endPointInterface); //or another "getPort(...)" ((BindingProvider) port).getRequestContext() .put(BindingProviderProperties.REQUEST_TIMEOUT, 30); 

请参阅https://developers.google.com/appengine/docs/java/urlfetch/usingjavanet

您可以执行以下操作来获取URLConnection:

  URL url = new URL("http://www.example.com/atom.xml"); URLConnection tempConnection = url.openConnection(); tempConnection.setReadTimeout(10); 

对于使用JAX-WS的App Engine,您必须设置请求上下文(今天使用SDK 1.9.15进行测试)。 对于普通机器,您不能超过60秒,并且必须切换到更大的机器(Bx)以更好地使用任务队列。

对于本地测试,您通常会使用BindingProviderProperties.CONNECT_TIMEOUT和BindingProviderProperties.REQUEST_TIMEOUT,但它们不在App Engine JRE白名单上,您的代码检查可能会不断警告您。 但是可以使用等效的字符串:

 com.sun.xml.internal.ws.connect.timeout com.sun.xml.internal.ws.connect.timeout 

要部署到App Engine:

 com.sun.xml.ws.connect.timeout com.sun.xml.ws.request.timeout 

如何将其应用于JAX-WS 2.x中自动生成的代码的完整示例,必须以毫秒为单位提供值:

 @WebEndpoint(name = "Your.RandomServicePort") public YourServiceInterface getYourRandomServicePort() { YourRandomServiceInterface port = super.getPort(YOURRANDOMSERVICE_QNAME_PORT, YourRandomServiceInterface.class); Map requestContext = ((BindingProvider)port).getRequestContext(); requestContext.put("com.sun.xml.ws.connect.timeout", 10000); requestContext.put("com.sun.xml.ws.request.timeout", 10000); return port; }