how to handle exceptions in ejb 3 based soap webservice
- by Alexandre GUIDET
Hi, I am currently developing an EJB3 based SOAP webservice and I wonder what are the best practices to handles uncatched exceptions and return a well formated SOAP response to the client.
example:
@WebMethod
public SomeResponse processSomeService(
@WebParam(name = "someParameters") SomeParameters someParameters)
{
// the EJB do something with the parameters
// and retrieve a response fot the client
SomeResponse theResponse = this.doSomething(someParameters);
return theResponse;
}
Do I have to catch generic exception like:
@WebMethod
public SomeResponse processSomeService(
@WebParam(name = "someParameters") SomeParameters someParameters)
{
// the EJB do something with the parameters
// and retrieve a response to return to the client
try
{
SomeResponse theResponse = this.doSomething(someParameters);
}
catch (Exception ex)
{
// log the exception
logger.log(Level.SEVERE, "something is going wrong {0}", ex.getMessage());
// get a generic error response not to let the
// technical reason going to the client
SomeResponse theResponse = SomeResponse.createError();
}
return theResponse;
}
Is there some kind of "best practice" in order to achieve this ?
Thank you