How to catch "Failed to send ViaPost for URL"?

I am launching two axis2 services that communicate with each other. Every time the service starts, I get this error:

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) 

Since this error is not important, I would like to catch it and print a better error message instead of the entire stack trace. Where can I catch this error?

+6
source share
3 answers

Looking at the stack trace, I don't think you can catch it. This will require that you have the code somewhere in the thread where the exception is thrown.

Looking at the lowest stack on the track, you will see the following:

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

For me, this suggests that the exception occurs in the thread most likely launched by Axis. Because of this, you cannot catch it and show an error message.

If this is the expected behavior, the best thing you can do is set up the logging structure so that you don't show INFO from Axis. Keep in mind that this may mean that you will also miss out on more useful error messages.

In general, I would like to focus on how to solve the "Failed to send ViaPost" problem, rather than suppress the registration expression.

To answer your question with comments: As you can see from the stack trace, the exception does not fall into any client code, but expands to the stream itself. This is the breakpoint for exclusion and where it stops. If you are going to catch it, you will have to have code in the call stack (which you do not do, because when a thread is created by Axis, a new call stack is created for the new thread that Axis starts).

More details here . The only difference in your case is that since the exception is not thrown into the main thread, the program does not exit, but the thread in which the exception occurs is terminated.

To summarize: you do not have code in the call stack and therefore cannot catch the exception. The only other option is to rotate the INFO instructions for Axis.

+1
source

If I understand the question correctly, you are trying to catch something that is no exception.

It:

HTTPSender - unable to send ViaPost for URL [http://127.0.0.1:8081/axis2/services/MYSERVICE1.MYSERVICE1HttpSoap12Endpoint/]

- this is what is being undertaken. When it failed, it threw a ConnectException.

What you can just catch with

 try{ //Code that Makes the Connection } catch (ConnectException e) { e.printStackTrace();//Or What ever your message may be } 

Without seeing any code, it is impossible to give a definitive answer. But this will probably solve the problem.

One warning, if you catch a ConnectException to suppress it, you can suppress it when there is actually a problem that will also throw a ConnectException.

If this happens when you start the server, you can check why this happens before trying to suppress it.

If it refuses the connection you are trying, you might want to make sure that it connects to it, to which an available socket connects.

0
source

2014-02-24 13: 02: 31,258 [INFO] HTTPSender - Unable to execute Send ViaPost for URL [http://127.0.0.1:8081/axis2/services/MYSERVICE1.MYSERVICE1HttpSoap12Endpoint/]

Well, if you look closely, the message you are trying to catch is not ERROR at all. This is the INFO log generated from HTTPSender . The only thing you have to catch in all of this stacktrace is java.net.ConnectException and check the Connection refused message.

You can make this easier for your customers and provide a message by wrapping java.net.ConnectException with Connection refused or throwing an exception with the original exception as the reason.

UPDATE

java.net.ConnectException is an elementary exception in network transactions. Typically, standard libraries do not capture them unless something specific exists.

In this case, if you cannot catch java.net.ConnectException , you can see how to catch AxisFault thrown by org.apache.axis2.description.OutInAxisOperationClient.send .

The snippet below may be useful to you.

 try { ... } catch (RemoteException ex) { if(ex instanceof AxisFault){ logger.error("Axis Fault error: " + ((AxisFault)ex).getFaultString()); throw new CustomExcpetion(" Custom Message "); } } 

Also note that AxisFault is a subclass of java.rmi.RemoteException , and this will not break if you use java.lang.Exception in a catch statement.

Shishir

-1
source

All Articles