You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Carlos Eduardo Rodrigues de Almeida <ed...@gmail.com> on 2008/09/09 22:04:56 UTC

Custom Exceptions mapping to SOAP Faults

Hi all,

I have a web service that throws a custom Exception, like:

public interface SimpleService
    public int getId(String user, String password) throws WrongUserException;
}

public class WrongUserException extends Exception{
    private int transactionId;

    public WrongUserException(String message) {
        super(message);
    }

    public int getTransactionId() {
         return transactionId;
    }
}

This exception is mapped to a fault, the transactionId is mapped to
the faultDetails, the message is mapped to the faultString but I´m not
able to change the faultCode, it is always Server. I would like to map
it to Client.Authentication for example.

I´m using CXF with Spring.

Thank you,
Eduardo

Re: Custom Exceptions mapping to SOAP Faults

Posted by kouss <ke...@gmail.com>.
Hi,

I have a problem with CXF Soap faults.
I have a wsdl in which I have defined a custom Fault (BadCredentialsFault).
Below is a part of the wsdl : 

....
       <xsd:element name="BadCredentialsFault"
type="tns:BadCredentialsFault" />
       <xsd:complexType name="BadCredentialsFault">
             <xsd:sequence>
                    <xsd:element name="message"
type="xsd:string"></xsd:element>
             </xsd:sequence>
       </xsd:complexType>
...
    <wsdl:message name="BadCredentialsException">
        <wsdl:part name="BadCredentialsException"
element="tns:BadCredentialsFault"></wsdl:part>
    </wsdl:message>
....
    <wsdl:portType name="AuthenticationService">
        <wsdl:operation name="authenticate">
            <wsdl:input message="tns:authenticateRequest" />
            <wsdl:output message="tns:authenticateResponse" />
            <wsdl:fault name="BadCredentialsException"
message="tns:BadCredentialsException"/>
        </wsdl:operation>
...
<wsdl:binding name="authenticationServiceSoapBinding"
type="tns:AuthenticationService">
        <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="authenticate">
            <soap:operation
soapAction="http://www.sfr.com/ws/psw/authentication/v1.0/authentication" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
            <wsdl:fault name="BadCredentialsException">
                <soap:fault name="BadCredentialsException" use="literal"/>
            </wsdl:fault>

On the client side I absolutely need to have a BadCredentialsException
instead of SOAPFaultException but I notice that CXF wrapps my custom
exception BadCredentialsException into a  SOAPFaultException...
I have this xml flow : note that <detail> element is empty 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Bad credentials for login 'tata'</faultstring>
         <detail>
            <stackTrace xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Is there a way to get the real exception on the client side instead of a
SoapFaultException?

Thanks.
-- 
View this message in context: http://www.nabble.com/Custom-Exceptions-mapping-to-SOAP-Faults-tp19400125p21351795.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Custom Exceptions mapping to SOAP Faults

Posted by Carlos Eduardo Rodrigues de Almeida <ed...@gmail.com>.
Thank you Daniel!! It worked!!

Eduardo Almeida


On Thu, Sep 11, 2008 at 2:50 PM, Daniel Kulp <dk...@apache.org> wrote:
>
> This is one of the "bizzare" things in the JAX-WS spec.     By default, it's
> always "server".   However, you can control things if you set the "cause" of
> the custom exception to a javax.xml.ws.soap.SOAPFaultException  that has the
> fault code and such in it.   Note: the fault string then comes from that
> SOAPFaultException as well.
>
>
> Dan
>
>
> On Tuesday 09 September 2008 4:04:56 pm Carlos Eduardo Rodrigues de Almeida
> wrote:
>> Hi all,
>>
>> I have a web service that throws a custom Exception, like:
>>
>> public interface SimpleService
>>     public int getId(String user, String password) throws
>> WrongUserException; }
>>
>> public class WrongUserException extends Exception{
>>     private int transactionId;
>>
>>     public WrongUserException(String message) {
>>         super(message);
>>     }
>>
>>     public int getTransactionId() {
>>          return transactionId;
>>     }
>> }
>>
>> This exception is mapped to a fault, the transactionId is mapped to
>> the faultDetails, the message is mapped to the faultString but I´m not
>> able to change the faultCode, it is always Server. I would like to map
>> it to Client.Authentication for example.
>>
>> I´m using CXF with Spring.
>>
>> Thank you,
>> Eduardo
>
>
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://www.dankulp.com/blog
>

Re: Custom Exceptions mapping to SOAP Faults

Posted by Daniel Kulp <dk...@apache.org>.
This is one of the "bizzare" things in the JAX-WS spec.     By default, it's 
always "server".   However, you can control things if you set the "cause" of 
the custom exception to a javax.xml.ws.soap.SOAPFaultException  that has the 
fault code and such in it.   Note: the fault string then comes from that 
SOAPFaultException as well.


Dan


On Tuesday 09 September 2008 4:04:56 pm Carlos Eduardo Rodrigues de Almeida 
wrote:
> Hi all,
>
> I have a web service that throws a custom Exception, like:
>
> public interface SimpleService
>     public int getId(String user, String password) throws
> WrongUserException; }
>
> public class WrongUserException extends Exception{
>     private int transactionId;
>
>     public WrongUserException(String message) {
>         super(message);
>     }
>
>     public int getTransactionId() {
>          return transactionId;
>     }
> }
>
> This exception is mapped to a fault, the transactionId is mapped to
> the faultDetails, the message is mapped to the faultString but I´m not
> able to change the faultCode, it is always Server. I would like to map
> it to Client.Authentication for example.
>
> I´m using CXF with Spring.
>
> Thank you,
> Eduardo



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