You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Wolf, Chris (IT)" <Ch...@morganstanley.com> on 2008/10/15 21:41:21 UTC

Best approach for "catch-all" exception handling.

Currently, we have some code that defines a custom fault in the
WSDL.  Each service operation in the service impl is bracketed
by try/catch which wraps whatever is caught in the custom
fault and rethrows that.


I'm thinking our lower layers should always throw unchecked 
exceptions and the service impl should NOT be cluttered with
try/catch/rethrow - the unchecked exeptions should be 
allowed to bubble up to some common handler, maybe an
interceptor.


I tried looking in the docs, and post postings but all I found was 
the included email on a roughtly similar topic and this:

http://cwiki.apache.org/confluence/display/CXF20DOC/CXF+Architecture#CXF
Architecture-FaultHandling

..but that paragraph only covers fault handling within interceptors -
not fault 
handling of actual service operation implementation.

Any ideas?

thanks

  -Chris W.

-----Original Message-----
From: Daniel Kulp [mailto:dkulp@apache.org] 
Sent: Tuesday, October 14, 2008 2:56 PM
To: users@cxf.apache.org
Cc: esschul
Subject: Re: How to define my own fault in Java2Wsdl?

On Tuesday 14 October 2008 6:20:29 am esschul wrote:
> Hello ppl!
>
> My env is jdk1.5.016 and I use the java2wsdl-strategy. Every thing is 
> working like expected, except that I'd like to define my own specific 
> fault per method. Unfortunatly I couldn't seem to find anything useful

> in the documentation, or on google code search. Can anyone point me in

> the right direction?
>
> -Espen


Other than recommending reading the JAX-WS spec, I guess I would point
you to the JAX-WS system test I have that tests a bunch of "code first"
things:
http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apa
che/cxf/systest/jaxws/

Specifically, the DocLitWrappedCodeFirstService.java file.   There is 
a "throwException" method on it that throws a couple different types of
exceptions:

The simplest is:
http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apa
che/cxf/systest/jaxws/CustomException.java
Basically, just stick getter and setter methods on the Exception for
each datapoint.

The "standard" jaxws way would be closer to:
http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apa
che/cxf/systest/jaxws/ServiceTestFault.java
That defines a separate JAXB bean for the data and adds a "getFaultInfo"

method that returns that bean.


--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.