gpt4 book ai didi

java - 如何捕获 "Unable to sendViaPost to url"?

转载 作者:搜寻专家 更新时间:2023-10-31 08:03:37 25 4
gpt4 key购买 nike

我正在运行两个相互通信的 axis2 服务。在每次服务启动时,我都会收到此错误:

2014-02-24 13:02:31,258 [INFO ]           HTTPSender  - Unable to sendViaPost to url[http://127.0.0.1:8081/axis2/services/MYSERVICE1.MYSERVICE1HttpSoap12Endpoint/]
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient$NonBlockingInvocationWorker.run(OutInAxisOperation.java:446)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)

由于这个错误并不重要,我想捕获它并打印一些更好的错误消息而不是整个堆栈跟踪。我在哪里发现这个错误?

最佳答案

查看堆栈跟踪,我认为您无法捕捉到它。捕获它需要您在抛出异常的线程中的某处拥有代码。

查看跟踪中最低的堆栈显示:

at java.lang.Thread.run(Thread.java:724)

对我来说,这表明异常发生在一个很可能由 Axis 启动的线程中。因此,您无法捕获它并显示错误消息。

如果这是预期的行为,您可以做的最好的事情就是配置您的日志记录框架,使其不显示来自 Axis 的信息。请注意,这可能意味着您还会错过更多有用的错误消息。

总而言之,我将专注于如何解决“无法发送ViaPost”的问题,而不是抑制日志记录语句。

回答您的评论问题:正如您从堆栈跟踪中看到的那样,异常没有被任何客户端代码捕获,而是被冒泡到线程本身。这是异常的停止点和它停止的地方。如果您要捕获它,则必须在其调用堆栈中包含代码(您不需要,因为当 Axis 创建线程时,会为 Axis 启动的新线程创建新的调用堆栈)。

阅读更多 here .您的情况的唯一区别是,由于未在主线程上抛出异常,因此程序不会退出,但发生异常的线程已终止。

总结一下:调用堆栈中没有代码,因此无法捕获异常。唯一的其他选择是关闭 Axis 的 INFO 语句。

关于java - 如何捕获 "Unable to sendViaPost to url"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21987322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com