Hi Magnus,
When will the fault comes out first ? From you service itself ?
If it is from the service itself, here what you should do.
- put init(MessageContext msgCtx) method in your service. Save the
message context within your service class, using that method.
- When the correct method is invoked, and when there is a fault,
fill the above message context with the fault informations (I hope you
can remember I explained how to do this)
- Then throw AxisFault.
Everything should happen, as you expect.
Actually, these days I'm improving these a bit. So if there are any
problems, do not hesitate to let me know them.
-- Chinthaka
Magnus Olsson wrote:
Hi Eran,
No, the resaon why I am asking for handling the fault within the service is that I don't know any other way. My goal is that whenever there is an error, the SOAP Fault should be like the one I posted first (with SOAP 1.2 namespace, my fault..).
Your tip was to set the SOAP fault information to the current message context. You gave me some code lines, but where should I put them? Can I write my own fault handler?
Thank your for answers. They are very helpful!
best regards
Magnus
-----Original Message-----
From: Eran Chinthaka [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 13, 2006 9:46 AM
To: [email protected]
Subject: Re: custom SoapFault in Axis2
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:[EMAIL PROTECTED]]
Sent: Saturday, February 11, 2006 3:49 PM
To: [email protected]
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
[EMAIL PROTECTED] 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:[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
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
|