连接详细信息& java web 服务客户端中的超时

发布于 2024-09-04 16:09:57 字数 1088 浏览 1 评论 0原文

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

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

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

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

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

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

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.

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'.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2024-09-11 16:09:57

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


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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文