axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eran Chinthaka <chinth...@opensource.lk>
Subject Re: custom SoapFault in Axis2
Date Mon, 13 Feb 2006 08:46:29 GMT
Hi Magnus,

Do you wanna handle the fault within the service itself ? Ok, we have
message context injection to enable that.

Simply have an init method with one or two message contexts as the params.

public void init(MessageContext inMsgCtxt) or
public void init(MessageContext inMsgCtxt, MessageContext outMsgCtxt).

So before you service class gets invoked with the correct method the
message is destined to, Axis2 will pass you the message contexts using
the init method.

So if you wanna access the message context, you have either one or both
of them. Better use the first method ;-) .

-- Chinthaka

Magnus Olsson wrote:

>Hi Eran,
> 
>thank you for your answer. I am trying your tip, but I have trobule accessing the current
message context. My service is something like this: 
> 
>public void pingF(OMElement element) throws AxisFault
>{
>     .......
>}
> 
>How do I access the current message context from here?
>
>best regards
>Magnus
>
>-----Original Message-----
>From: Eran Chinthaka [mailto:chinthaka@opensource.lk]
>Sent: Saturday, February 11, 2006 3:49 PM
>To: axis-user@ws.apache.org
>Subject: Re: custom SoapFault in Axis2
>
>
>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   <mailto:magnus.olsson@idainfront.se> <magnus.olsson@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/> <http://schemas.xmlsoap.org/soap/envelope/>">
>
>  
>
>   <soap:Body> <soap:Body> 
>
>  < soap:Fault
>
>
>
>    
>
>xmlns:c="  <http://www.company.se/faultcodes/2005-12-01/> <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/> <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/" <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/" <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
>
>
>
>  
>
>
>  
>

Mime
View raw message