Reputation: 2500
I have a JAX-WS based application that I am developing. I generate WSDL from the server using wsgen
and then build the client library using wsimport
. I am writing my own custom exceptions to throw with my method calls. The code is structured as follows.
Custom Exception Class:
@WebFault(faultBean = "com.mysite.FaultBean")
public class MyCustomException extends Exception {
private FaultBean faultInfo;
//Getters/Setters/Constructors...
}
Custom Fault Bean:
public class FaultBean {
private String message;
private List<String> messages;
//Getters/Setters/Constructors...
}
I then throw MyCustomException
from my methods in my web service endpoint. When I call one of my web service methods and it throws an exception the client is getting a SOAPFaultException
instead of MyCustomException
. Why is the custom exception not getting used?
Upvotes: 2
Views: 2209
Reputation: 2500
So, after a bit of investigation it turns out the exceptions that were being thrown as a SOAPFaultException
were not coming from where I thought they were. They actually were not thrown as MyCustomException
. So, to solve this for all cases I took advantage of Spring AOP and created an Around aspect to wrap all of my calls to the web service implementation layer.
In this aspect I catch any exception thrown and wrap it in a MyCustomException
before rethrowing it. My client can then handle the exception properly.
Upvotes: 1