如果在特定时间内没有来自服务器的响应,如何从客户端程序(Java)停止调用的webservice。 如果在指定时间内没有来自服务器的响应,我需要准备错误消息并将消息发送到UI。
try { applicationProcessRs = service.processApplication(applicationProcessRq); } catch ( ApplicationProcessFaultMsg e ) { log.error( e.getMessage(), e ); }谢谢, Ramakrishna K.
How do i stop invoked webservice from client program(Java) if there is no response from server within specific time. If there is no response from server within specified time, I need to prepare error message and send the message to UI.
try { applicationProcessRs = service.processApplication(applicationProcessRq); } catch ( ApplicationProcessFaultMsg e ) { log.error( e.getMessage(), e ); }Thanks, Ramakrishna K
最满意答案
如果要为特定服务设置超时,一旦创建了代理,就需要将其转换为BindingProvider(您已知道),获取请求上下文并设置属性。 在线JAX-WS文档是错误的,这些是正确的属性名称
MyInterface myInterface = new MyInterfaceService().getMyInterfaceSOAP(); Map<String, Object> requestContext = ((BindingProvider)myInterface).getRequestContext(); requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 3000); // Timeout in millis requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 1000); // Timeout in millis myInterface.callMyRemoteMethodWith(myParameter);
当然,这是一种可怕的做事方式,我会创建一个很好的工厂来生产这些绑定提供程序,可以注入你想要的超时。
请注意,REQUEST_TIMEOUT / CONNECT_TIMEOUT属性实际上是从SUN内部类com.sun.xml.internal.ws.developer.JAXWSProperties继承的,并且(至少在32位Linux上)javac 1.6.0_27和javac 1.7.0_03未能编译此代码(类似于bugs.sun.com/view_bug.do?bug_id=6544224)...您需要将-XDignore.symbol.file传递给javac才能使其正常工作
if you want to set timeouts for specific services, once you've created your proxy you need to cast it to a BindingProvider (which you know already), get the request context and set your properties. The online JAX-WS documentation is wrong, these are the correct property names
MyInterface myInterface = new MyInterfaceService().getMyInterfaceSOAP(); Map<String, Object> requestContext = ((BindingProvider)myInterface).getRequestContext(); requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 3000); // Timeout in millis requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 1000); // Timeout in millis myInterface.callMyRemoteMethodWith(myParameter);
Of course, this is a horrible way to do things, I would create a nice factory for producing these binding providers that can be injected with the timeouts you want.
Note that the REQUEST_TIMEOUT / CONNECT_TIMEOUT properties are actually inherited from the SUN-internal class com.sun.xml.internal.ws.developer.JAXWSProperties and (at least on 32-bit Linux) javac 1.6.0_27 and javac 1.7.0_03 fail to compile this code (similar to bugs.sun.com/view_bug.do?bug_id=6544224 )... you need to pass -XDignore.symbol.file to javac to make it work
更多推荐
发布评论