I BELIEVE that if you set the "cause" of  your exception (ex.initCause(..) or 
pass in to the RuntimeException constructor) to a SOAPFaultException, then it 
would pull the fault code/actor/message and such out of there.   Could be worth 
a shot.

Alternatively, you can subclass the JAXWSMethodInvoker, override the 
createFault method, do whatever you want in there, and then configure that into 
your config.

Dan



On 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. 
> 

-- 
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to