Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring WS: Handle connection refused and client timeout exceptions

I can't seem to find proper solution to this. I would want to handle and display different message to the user depending on what happened. I'm using Spring WS and calling marshalSendAndReceive. On the returning service method at the moment I would simply catch (WebServiceIOException e), problem is that this exception is thrown by both Connection refused (wrong credentials) and when query takes longer than specified by client side (timeout)? Is there any proper way of handling these two without providing one general message that "something went wrong".

like image 937
Vaelyr Avatar asked Oct 30 '25 16:10

Vaelyr


1 Answers

The WebServiceTemplate does its hard work in the method doSendAndReceive, where there is try...catch block and comprehensive error-handling. One of them is triggerAfterCompletion(int interceptorIndex, MessageContext messageContext, Exception ex), which delegates to the injected ClientInterceptor.

So, you just need to implement properly afterCompletion(MessageContext messageContext, Exception ex) to throw the appropriate business exception.

like image 129
Artem Bilan Avatar answered Nov 02 '25 06:11

Artem Bilan