Not sure this is exactly what you're looking for but we adopted the
practice of having all @WebMethods throw a ServiceException following the
patterns outlined in this helpful article:

http://io.typepad.com/eben_hewitt_on_java/2009/07/using-soap-faults-and-exceptions-in-java-jaxws-web-services.html

Whatever business logic exception gets thrown, say from DAO classes, etc is
wrapped in that *ServiceException *that contains another bean class
called *ServiceFaultBean
*- it carries back the information on the real cause of the exception.

package com.acme.book.util;

import javax.xml.bind.annotation.XmlType;
import javax.xml.ws.WebFault;

/**
 * Class: ServiceException
 *
 * Custom Exception that is thrown from JAX-WS @WebMethod annotated methods
in a service
 * implementation bean (SIB).
 */
@XmlType(name = "ServiceException", namespace = "http://util.book.acme.com/
")
@WebFault(name = "ServiceException", targetNamespace = "
http://util.book.acme.com/";)
public class ServiceException extends BaseException {

   private  ServiceFaultBean faultBean;
....
....
....


package com.acme.book.util;

import javax.xml.bind.annotation.XmlType;
import javax.xml.ws.WebFault;

/**
 * Class: BaseException
 *
 * Custom Exception that others will extend
 *
 */
@XmlType(name = "BaseException", namespace = "http://util.book.acme.com/";)
@WebFault(name = "BaseException", targetNamespace = "
http://util.book.acme.com/";)
public class BaseException extends Exception {


   /**
    * Java type that transports as soapenv:Fault detail element.
    */
   private ServiceFaultBean faultInfo;

   // Used with ExceptionConstants enum
   private String errorCode;
   private String errorMessage;

   // Source exception - root cause and associated details message
   private String source;
   private String details;
....
....



package com.acme.book.util;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;

/**
 * Class: ServiceFaultBean
 *
 * The Java type that is passed as a soapenv:Fault detail element. Used in
JAX-WS web services
 * exceptions, fault beans hold the details of the SOAP fault. This one is
used by the { @link
 * WebServiceException ).
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ServiceFaultBean", namespace = "http://util.book.acme.com/
")
public class ServiceFaultBean {
   private String faultMessage;
   private String faultCause;

   private String errorCodeKey;
   private String errorMessageKey;
....
....


Usage is something like this (logging statements removed to shorten):  (and
we were not using CXF at the time this was originally done and don't use
Interceptors so I can't speak to that).

   *@WebMethod*
   public Book getBook(@WebParam(name = "bookID") String bookID) *throws
ServiceException* {


      Book book;

      try {
         book = BookOrderServiceDAO.getBook(bookID);
      }
      catch (DataValidationException e) {

  *       throw new ServiceException(e.getMessage(), e.getErrorCode(), e);*
      }
      catch (NotFoundException e) {

*         throw new ServiceException(e.getMessage(), e.getErrorCode(), e);*
      }

HTH

On Mon, Apr 30, 2012 at 7:17 AM, dkundo <[email protected]> wrote:

> In my project the web services tier wraps the business logic tier. The BL
> tier generates many types of exceptions. I don't want to enclose all the WS
> -> BL tiers interaction with try..catch blocks, so I'm thinking about
> creating an interceptor which will catch all exceptions and transform them
> into a proper WebFault class.
> While it's possible to provide an interceptor for the outfault chain, it
> seems like at this point the original exception data has been lost already
> as I'm getting the general SOAPFault.
> Any ideas on how to achieve what I want?
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/generic-exception-handling-tp5675691.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>



*Mark
*

Reply via email to