You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "D'Arcy, Hamlet B" <Ha...@Pearson.com> on 2009/08/07 18:19:49 UTC
How to throw an exception subclass with custom fields from service
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
hamlet.darcy@pearson.com
+1(952)681-3636
RE: How to throw an exception subclass with custom fields from service
Posted by "D'Arcy, Hamlet B" <Ha...@Pearson.com>.
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
hamlet.darcy@pearson.com
+1(952)681-3636
> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org]
> Sent: Monday, August 10, 2009 2:32 PM
> To: users@cxf.apache.org
> 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
> > hamlet.darcy@pearson.com
> > +1(952)681-3636
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
>
Re: How to throw an exception subclass with custom fields from service
Posted by Daniel Kulp <dk...@apache.org>.
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
> hamlet.darcy@pearson.com
> +1(952)681-3636
--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog
Default endpoint via Zookeeper (D-OSGi)
Posted by "Shulok, Thomas" <th...@lmco.com>.
Hi All,
Working with the Zookeeper discovery setup, and things are working as
long as I explicitly specify org.apache.cxf.ws.address in my service
decoration xml file. If I don't specify it, it will default to
localhost. Not unreasonable, but the problem is, localhost will be the
endpoint that gets registered with Zookeeper. So, when another box
looks for the interface, Zookeeper will tell it that it is on localhost
(i.e. the client itself), and that will fail. With this setup, do you
have to explicitly specify the endpoint, or is there some other default
behavior to leverage that will actually use the real IP of the
registering localhost when it gets entered into Zookeeper so other
clients can find it?
Many thanks,
Thom