如果在指定时间内没有响应,则丢弃Webservice调用(Discard Webservice call if no response in specified time)

编程入门 行业动态 更新时间:2024-10-11 21:23:30
如果在指定时间内没有响应,则丢弃Webservice调用(Discard Webservice call if no response in specified time)

如果在特定时间内没有来自服务器的响应,如何从客户端程序(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

更多推荐

本文发布于:2023-08-05 16:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1435148.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间内   Webservice   Discard   time   response

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!