连接细节和Java Web 服务客户端中的超时 [英] Connection details & timeouts in a java web service client

查看:30
本文介绍了连接细节和Java Web 服务客户端中的超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为给定的 WSDL 文件实现一个网络服务客户端.我使用 SDK 的wsimport"工具从 WSDL 创建 Java 类以及一个将 web 服务的唯一方法 (enhanceAddress(auth, param, address)) 包装成一个简单的 java 方法的类.到现在为止还挺好.Web 服务正常运行并正确返回结果.代码如下所示:

I have to implement a webservice client to a given WSDL file. I used the SDK's 'wsimport' tool to create Java classes from the WSDL as well as a class that wrap's the webservice's only method (enhanceAddress(auth, param, address)) into a simple java method. So far, so good. The webservice is functional and returning results correcty. The code looks like this:

try {
  EnhancedAddressList uniservResponse = getWebservicePort().enhanceAddress(m_auth, m_param, uniservAddress);
  //Where the Port^ is the HTTP Soap 1.2 Endpoint
}catch (Throwable e) {
  throw new AddressValidationException("Error during uniserv webservice request.", e);
}

现在的问题:我需要获取有关连接的信息以及可能发生的任何错误,以便填充各种 JMX 值(例如 COUNT_READ_TIMEOUT、COUNT_CONNECT_TIMEOUT 等)不幸的是,该方法并未正式抛出任何异常,因此为了获取有关 ConnectException 的详细信息,我需要在将抛出的 ClientTransportException 上使用 getCause().

The Problem now: I need to get Information about the connection and any error that might occur in order to populate various JMX values (such as COUNT_READ_TIMEOUT, COUNT_CONNECT_TIMEOUT, ...) Unfortunately, the method does not officially throw any Exceptions, so in order to get details about a ConnectException, i need to use getCause() on the ClientTransportException that will be thrown.

更糟糕的是:我试图测试读取超时值,但没有.我更改了 wsdl 文件中服务的位置,以将请求发布到一个 php 脚本,该脚本只是永远等待并且不返回.猜猜看:Web 服务客户端不会超时,但也会永远等待(我在等待 30 多分钟后终止了该应用程序).这不是我的应用程序的选项,因为如果其中一些卡住",我最终会耗尽 tcp 连接.

Even worse: I tried to test the read timeout value, but there is none. I changed the service's location in the wsdl file to post the request to a php script that simply waits forever and does not return. Guess what: The web service client does not time out but waits forever as well (I killed the app after 30+ minutes of waiting). That is not an option for my application as i eventually run out of tcp connections if some of them get 'stuck'.

enhanceAddress(auth, param, address) 方法没有实现,而是用 javax.jws.* 注释,这意味着我无法看到/更改/检查实际执行的代码.

The enhanceAddress(auth, param, address) method is not implemented but annotated with javax.jws.* Annotations, meaning that i cannot see/change/inspect the code that is actually executed.

除了扔掉整个 wsimport/javax.jsw-stuff 并实现我自己的肥皂客户端之外,我还有什么选择吗?

Do i have any option but to throw the whole wsimport/javax.jsw-stuff away and implement my own soap client?

推荐答案

要设置读取超时和连接超时,您可以在设置 Service 和 Port 实例时配置绑定参数:

to setup read-timeout and connect timeouts you can configure the binding parameters when you setup your Service and Port instances:

    Service = new Service();

    Port = Service.getPort();

    ((BindingProvider) Port).getRequestContext().put(
            BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://localhost:8080/service");
    ((BindingProvider) Port).getRequestContext().put(
            BindingProviderProperties.CONNECT_TIMEOUT,
            30);
    ((BindingProvider) Port).getRequestContext().put(
            BindingProviderProperties.REQUEST_TIMEOUT,
            30);

<小时>

现在每当您通过端口"执行服务时,如果后端响应缓慢,您将收到响应超时和/或连接超时.这些值遵循 Socket 类的超时值.


now whenever you execute a service via "Port" you will get response timeouts and/or connection timeouts if the backend is slow to respond. the values follow the timeout values of the Socket Class.

当超过这些超时时间时,您将收到超时异常或连接异常,您可以放置​​计数器代码来跟踪获得的数量.

when these timeouts are exceeded you will get timeout exeption or a connection exception and you can put counter-code to keep track of how many you get.

这篇关于连接细节和Java Web 服务客户端中的超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆