how to handle exceptions in ejb 3 based soap webservice

Posted by Alexandre GUIDET on Stack Overflow See other posts from Stack Overflow or by Alexandre GUIDET
Published on 2011-01-31T10:20:30Z Indexed on 2011/02/01 7:25 UTC
Read the original article Hit count: 672

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about java

Related posts about web-services