java 如何设置 JAX-WS 客户端超时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14021072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set JAX-WS client timeout?
提问by mariami
I'm developing Jax-ws client on Jboss 5.1.0 GA. I want to set web service client timeout.
我正在 Jboss 5.1.0 GA 上开发 Jax-ws 客户端。我想设置 Web 服务客户端超时。
I've tried StubExt.PROPERTY_CLIENT_TIMEOUT.
我试过StubExt.PROPERTY_CLIENT_TIMEOUT。
int timeoutMillisecond=3000;
bp.getRequestContext().put(StubExt.PROPERTY_CLIENT_TIMEOUT, timeoutMillisecond);
It works but exception is thrown only after 3*timeoutMillisecond(after 9000 millisecond), but 3000ms is written in log file.
它可以工作,但仅在3*timeoutMillisecond之后(9000 毫秒之后)才会抛出异常,但3000毫秒被写入日志文件。
2012-12-24 15:42:40,053 DEBUG Sending request
2012-12-24 15:42:49,057 ERROR WebServiceException returned:
javax.xml.ws.WebServiceException: org.jboss.ws.core.WSTimeoutException: Timeout after: 3000ms
I've rtied also many other ways
我也有很多其他的方式
bp.getRequestContext().put("com.sun.xml.ws.connect.timeout", 100);
bp.getRequestContext().put("com.sun.xml.ws.request.timeout", 100);
// from com.sun.xml.ws.developer.JAXWSProperties
bp.getRequestContext().put(JAXWSProperties.CONNECT_TIMEOUT, 100);
bp.getRequestContext().put(JAXWSProperties.REQUEST_TIMEOUT, 100);
But nothing worked on Jboss 5.1
但在 Jboss 5.1 上没有任何效果
Could you tell me how to set client timeout correctly ?
你能告诉我如何正确设置客户端超时吗?
采纳答案by mariami
I did the following steps and fixed the problem:
我执行了以下步骤并解决了问题:
Upgraded jbossws-nativelibrary, follow this link.
jbossws-native-3.4.0 is the latest supported version for Jboss 5.1.0GA. You can see JBossWS - Supported Target ContainersUsed
StubExt.PROPERTY_CLIENT_TIMEOUT
int timeoutMillisecond=3000; bp.getRequestContext().put(StubExt.PROPERTY_CLIENT_TIMEOUT, timeoutMillisecond);
升级了jbossws-native库,点击这个链接。
jbossws-native-3.4.0 是 Jboss 5.1.0GA 的最新支持版本。你可以看到JBossWS - 支持的目标容器用过的
StubExt.PROPERTY_CLIENT_TIMEOUT
int timeoutMillisecond=3000; bp.getRequestContext().put(StubExt.PROPERTY_CLIENT_TIMEOUT, timeoutMillisecond);
By the way, in this version StubExt.PROPERTY_CONNECTION_TIMEOUT
also works correctly.
顺便说一句,在这个版本中StubExt.PROPERTY_CONNECTION_TIMEOUT
也能正常工作。
回答by pet
you're complete missing the point check out code:
你完全错过了点检出代码:
URL url = new URL("http://tst.com:9990/ws/hello?wsdl");
URL url = new URL(" http://tst.com:9990/ws/hello?wsdl");
//1st argument service URI, refer to wsdl document above
//2nd argument is service name, refer to wsdl document above
QName qname = new QName("http://tstsoap/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
As you can see, you cannot get a port without creating a service first.
So the timeout always occurs at the service creation.
So setting a time for the port is pointless.......
Somebody needs to post something about service timeouts....not port timeouts....
Unless somebody can prove me wrong....
如您所见,如果不先创建服务,就无法获得端口。
所以超时总是发生在服务创建时。所以为端口设置时间是没有意义的....... 有人需要发布一些关于服务超时的信息......不是端口超时......除非有人能证明我是错的......
回答by Naveenkumar K
You can use thesesettings for your service port.
您可以将这些设置用于您的服务端口。
BindingProvider bindingProvider = (BindingProvider) YOUR_SERVICE_PORT;
Map<String, Object> context = bindingProvider.getRequestContext();
context.put(BindingProviderProperties.CONNECT_TIMEOUT, 3*1000);
context.put(BindingProviderProperties.REQUEST_TIMEOUT,3*1000);