Take a look at this article by Eben Hewitt: http://io.typepad.com/eben_hewitt_on_java/2009/07/using-soap-faults-and-exceptions-in-java-jaxws-web-services.html
Since throwing detailed exceptions from the "service" end back over the wire is a little more complex in JAX-WS, we used this approach and it worked well. It is not CXF specific either since it uses standard jax-ws api classes and annotations. HTH On Mon, Jan 14, 2013 at 1:29 AM, Mert ÇALIŞKAN <[email protected]> wrote: > Hi, > > I'm using cxf XX for exposing web services to my clients. When I tried to > customize the fault code I couldn't see any way to achieve this by throwing > a RuntimeException. > > My WebMethod definition is like, > > @WebMethod > User getUser(@WebParam(name = "userId") String userId) throws > UserDoesNotExistException; > > > > My exception definition is like, > > @WebFault(name="UserDoesNotExist") > @XmlAccessorType(XmlAccessType.FIELD) > public class UserDoesNotExistException extends RuntimeException { > > private String userId; > > public UserDoesNotExistException(String userId) { > super("User Does Not Exist"); > this.userId = userId; > } > } > > > When I request for the service with the envelope below, > > > <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:ws="http://ws.service.orca.turktelekom.com.tr/"> > <soapenv:Header/> > <soapenv:Body> > <ws:getUser> > <userId>sample</userId> > </ws:getUser> > </soapenv:Body> > </soapenv:Envelope> > > > I get the response envelope as below, > > > <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> > <soap:Body> > <soap:Fault> > <faultcode>soap:Server</faultcode> > <faultstring>User Does Not Exist</faultstring> > <detail> > <ns1:UserDoesNotExist xmlns:ns1=" > http://ws.service.orca.turktelekom.com.tr/"> > <userId xmlns:ns2=" > http://ws.service.orca.turktelekom.com.tr/">not</userId> > </ns1:UserDoesNotExist> > </detail> > </soap:Fault> > </soap:Body> > </soap:Envelope> > > > If I create a custom fault by extending the > org.apache.cxf.binding.soap.SoapFault I'm able to customize the fault code > and fault string. But I think this is not the appropriate approach since I > need to throw exceptions in my business logic but not the faults. Is there > way to propagate the fault code from my exception to my fault? Because I > can do it for the fault string by constructing the exception with > super(message) call. > > Thanks, > > Mert. > > -- Mark * *
