You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Magnus Olsson <ma...@idainfront.se> on 2006/02/10 15:58:07 UTC

custom SoapFault in Axis2

Hi,

is it possible to create the following SOAP Fault in axis2?

<soap:Envelope xmlns:soap="<http://schemas.xmlsoap.org/soap/envelope/>"> 
 <soap:Body> 
  <soap:Fault xmlns:c="<http://www.company.se/faultcodes/2005-12-01/>"> 
   <faultcode>c:InvalidInsuranceId</faultcode> 
   <faultstring>Illegal insurance number</faultstring> 
   <detail> 
    <foo:FaultData xmlns:foo="<http://schemas.foo.org/foo/2005-12-01/>"> 
     <faultingMessage> 
     <!-- custom message --> 
     </faultingMessage> 
     <xpath> 
     <!-- custom message --> 
     </xpath> 
     <callStack> 
     <!-- custom message  --> 
     </callStack> 
     <anyElement> 
     <!-- custom message  --> 
     </anyElement> 
    </foo:FaultData> 
   </detail> 
  </soap:Fault> 
 </soap:Body> 
</soap:Envelope> 

I tried with the following service, which didn't succeed.

    public void pingF(OMElement element) throws AxisFault
    {
        AxisFault fault = new AxisFault("Illegal insurance number");
        QName code = new QName("http://www.company.se/faultcodes/2005-12-01/", "InvalidInsuranceId", "c");
        fault.setFaultCode(code);

        OMFactory factory = OMAbstractFactory.getOMFactory();      
        OMNamespace ns = factory.createOMNamespace("http://schemas.foo.org/foo/2005-12-01/","ssek");
        OMElement root = factory.createOMElement("FaultData",ns);
        
        OMElement elt1 = factory.createOMElement("faultingMessage", null);
        root.addChild(elt1);
        
        fault.setDetail(root);
        throw fault;
    }


regards,

Magnus

Re: custom SoapFault in Axis2

Posted by Eran Chinthaka <ch...@opensource.lk>.
Hi Donner and Magnus,

Let me explain a bit about Axis2 (current) fault handling.

Axis2 SOAP API is SOAP 1.2, which is actually a superset of SOAP 1.1. So
you need to handle everything using SOAP 1.2 API. But depending on the
factory you use, you will get SOAP 1.1 or SOAP 1.2 serialization.

Answering your initial question of creating custom SOAP Faults,
When there is a fault, you can set the SOAP fault information to the
current message context and those will be fed in to the SOAP fault that
will be send.

For example, if you want to set your own SOAPFaultCode, do the following.

SoapFactory soapFactory = OMAbstractFactory.getSOAP11Factory(); // or
getSOAP12Factory() if you want SOAP 1.2
SOAPFaultCode faultCode = soapFactory.createSOAPFaultCode(soapFault);
msgCtx.setProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, faultCode);

// set other fault properties

throw new AxisFault("reason for exception", exception);

If you wanna see how this is being extracted, you can see
org.apache.axis2.engine.AxisEngine.extractFaultInformationFromMessageContext().

But to tell you the truth, there is a know defect with OM :-( . I will
be fixing that soon. The defect is that you can not create
SOAPFaultCode, SOAPFaultReason or any other child of SOAPFault, wothout
passing a SOAPFault in to it as the parent. This is, at least for me, a
bit inconvenient. I will be changing that ASAP.

Hope this information will be helpful.



Regards,
Eran Chinthaka



donnerdrummel2000-mailing@yahoo.de wrote:

>Hi Magnus,
>
>The problem you probably have is that your fault is a
>SOAP 1.1 fault. The Axis2 AxisFault is mapped to
>SOAP1.2 Fault wich is a superset of the 1.1 one. To
>create a 'real' SOAP1.1 Fault have a look at
>org.apache.axis2.soap.impl.dom.soap11.SOAP11FaultImpl
>
>Ted
>--- Magnus Olsson <ma...@idainfront.se>
>schrieb:
>
>  
>
>>Hi,
>>
>>is it possible to create the following SOAP Fault in
>>axis2?
>>
>><soap:Envelope
>>
>>    
>>
>xmlns:soap="<http://schemas.xmlsoap.org/soap/envelope/>">
>  
>
>> <soap:Body> 
>>  <soap:Fault
>>
>>    
>>
>xmlns:c="<http://www.company.se/faultcodes/2005-12-01/>">
>  
>
>>   <faultcode>c:InvalidInsuranceId</faultcode> 
>>   <faultstring>Illegal insurance
>>number</faultstring> 
>>   <detail> 
>>    <foo:FaultData
>>
>>    
>>
>xmlns:foo="<http://schemas.foo.org/foo/2005-12-01/>">
>  
>
>>     <faultingMessage> 
>>     <!-- custom message --> 
>>     </faultingMessage> 
>>     <xpath> 
>>     <!-- custom message --> 
>>     </xpath> 
>>     <callStack> 
>>     <!-- custom message  --> 
>>     </callStack> 
>>     <anyElement> 
>>     <!-- custom message  --> 
>>     </anyElement> 
>>    </foo:FaultData> 
>>   </detail> 
>>  </soap:Fault> 
>> </soap:Body> 
>></soap:Envelope> 
>>
>>I tried with the following service, which didn't
>>succeed.
>>
>>    public void pingF(OMElement element) throws
>>AxisFault
>>    {
>>        AxisFault fault = new AxisFault("Illegal
>>insurance number");
>>        QName code = new
>>
>>    
>>
>QName("http://www.company.se/faultcodes/2005-12-01/",
>  
>
>>"InvalidInsuranceId", "c");
>>        fault.setFaultCode(code);
>>
>>        OMFactory factory =
>>OMAbstractFactory.getOMFactory();      
>>        OMNamespace ns =
>>
>>    
>>
>factory.createOMNamespace("http://schemas.foo.org/foo/2005-12-01/","ssek");
>  
>
>>        OMElement root =
>>factory.createOMElement("FaultData",ns);
>>        
>>        OMElement elt1 =
>>factory.createOMElement("faultingMessage", null);
>>        root.addChild(elt1);
>>        
>>        fault.setDetail(root);
>>        throw fault;
>>    }
>>
>>
>>regards,
>>
>>Magnus
>>
>>    
>>
>
>
>
>	
>
>	
>		
>___________________________________________________________ 
>Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
>
>  
>

RE: custom SoapFault in Axis2

Posted by do...@yahoo.de.
Hi Magnus,

The problem you probably have is that your fault is a
SOAP 1.1 fault. The Axis2 AxisFault is mapped to
SOAP1.2 Fault wich is a superset of the 1.1 one. To
create a 'real' SOAP1.1 Fault have a look at
org.apache.axis2.soap.impl.dom.soap11.SOAP11FaultImpl

Ted
--- Magnus Olsson <ma...@idainfront.se>
schrieb:

> Hi,
> 
> is it possible to create the following SOAP Fault in
> axis2?
> 
> <soap:Envelope
>
xmlns:soap="<http://schemas.xmlsoap.org/soap/envelope/>">
> 
>  <soap:Body> 
>   <soap:Fault
>
xmlns:c="<http://www.company.se/faultcodes/2005-12-01/>">
> 
>    <faultcode>c:InvalidInsuranceId</faultcode> 
>    <faultstring>Illegal insurance
> number</faultstring> 
>    <detail> 
>     <foo:FaultData
>
xmlns:foo="<http://schemas.foo.org/foo/2005-12-01/>">
> 
>      <faultingMessage> 
>      <!-- custom message --> 
>      </faultingMessage> 
>      <xpath> 
>      <!-- custom message --> 
>      </xpath> 
>      <callStack> 
>      <!-- custom message  --> 
>      </callStack> 
>      <anyElement> 
>      <!-- custom message  --> 
>      </anyElement> 
>     </foo:FaultData> 
>    </detail> 
>   </soap:Fault> 
>  </soap:Body> 
> </soap:Envelope> 
> 
> I tried with the following service, which didn't
> succeed.
> 
>     public void pingF(OMElement element) throws
> AxisFault
>     {
>         AxisFault fault = new AxisFault("Illegal
> insurance number");
>         QName code = new
>
QName("http://www.company.se/faultcodes/2005-12-01/",
> "InvalidInsuranceId", "c");
>         fault.setFaultCode(code);
> 
>         OMFactory factory =
> OMAbstractFactory.getOMFactory();      
>         OMNamespace ns =
>
factory.createOMNamespace("http://schemas.foo.org/foo/2005-12-01/","ssek");
>         OMElement root =
> factory.createOMElement("FaultData",ns);
>         
>         OMElement elt1 =
> factory.createOMElement("faultingMessage", null);
>         root.addChild(elt1);
>         
>         fault.setDetail(root);
>         throw fault;
>     }
> 
> 
> regards,
> 
> Magnus
> 



	

	
		
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de