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

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

问题描述

我必须为给定的WSDL文件实现webservice客户端。
我使用SDK的'wsimport'工具从WSDL创建Java类,以及包装webservice唯一方法的类( 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的详细信息,我需要使用 getCause() ClientTransportException 上将被抛出。

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并实现我自己的soap客户端?

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

推荐答案

设置读取超时和连接超时,您可以在设置服务和端口实例时配置绑定参数:

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);






如果后端响应缓慢,您将获得响应超时和/或连接超时。这些值遵循套接字类的超时值。


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天全站免登陆