That's exactly what I had to do. 

A JAX-WS exception needs to have 3 constructors and a getFaultInfo()
method: 

@WebFault(name = "ValidationFault", faultBean = "FailureCollection")
public class ValidationFault extends Exception {

        private FailureCollection faultInfo;

        public ValidationFault() {
        }
        public ValidationFault(String message, FailureCollection
faultInfo) {
                super(message);
                this.faultInfo = faultInfo;
        }
        public ValidationFault(String message, FailureCollection
faultInfo, Throwable cause) {
                super(message, cause);
                this.faultInfo = faultInfo;
        }
        public FailureCollection getFaultInfo() {
                return faultInfo;
        }
}

FailureCollection is a user defined type annotated as a JAXB bean. 

--
Hamlet D'Arcy
[email protected]
+1(952)681-3636  

> -----Original Message-----
> From: Daniel Kulp [mailto:[email protected]] 
> Sent: Monday, August 10, 2009 2:32 PM
> To: [email protected]
> Cc: D'Arcy, Hamlet B
> Subject: Re: How to throw an exception subclass with custom 
> fields from service
> 
> 
> You're probably will need to make the exception look like a 
> "jaxws generated" 
> exception to get the collections to work correctly.   
> Basically, define a JAXB 
> bean that looks like what you want serialized in the details, 
> add a @WebFault 
> annotation, and add a "bean getFaultDetails()" method that 
> returns that bean.   
> That bean can have all the lists and such.  
> 
> Dan
> 
> 
> On Fri August 7 2009 12:19:49 pm D'Arcy, Hamlet B wrote:
> > I want to throw a custom exception from a CXF service.
> >
> > The exception class has a List<Failure> field in it. Failure is a
> > properly JAXB annotated class.
> >
> > Here is one way to write this exception:
> >
> >   public class ValidationException extends RuntimeException {
> >     private List<Failure> failures;
> >
> >     ... Getters/setters omitted
> >   }
> >
> >
> > I can't get this custom exception to serialize properly.
> >
> > I tried subclassing SoapFault and adding fields, but the 
> list was never
> > serialized.
> >
> > I tried subclassing RuntimeException and annotating the 
> custom fields,
> > but getStackTrace/setStackTrace on the parent class can't 
> be serialized.
> >
> >
> > How can I throw an exception from a CXF service that has a 
> List<Failure>
> > field?
> >
> > --
> > Hamlet D'Arcy
> > [email protected]
> > +1(952)681-3636
> 
> -- 
> Daniel Kulp
> [email protected]
> http://www.dankulp.com/blog
> 

Reply via email to