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 "Desmond Whewell (CV/ETL)" <de...@ericsson.com> on 2007/05/17 12:58:51 UTC

Trouble adding SOAP Header elements when faults occur

I am trying to build my first web-service using Axis2 (vers 1.2) and I
am having trouble with the SOAP Header when faults occur. I have:

@ generated the Java code from the WSDL, with xmlbeans bindings, 

@ implemented the business logic in the generated
MyServiceMessageReceiverInOut, shown in outline below

@ successfully invoked the no-fault case for the service.

If MySkeleton throws a MyFaultException, it is caught and wrapped in an
AxisFault. As a result, the client gets a SOAP Body with an embedded
SOAP Fault, so that's good.

The bit I can't figure out is what I need to do when I have a problem
with one of the SOAP headers and I want to put a particular SOAP header
in the SOAP envelope carrying the SOAP Fault back to the client. I have
searched the list and the Axis2 documentation with no luck.



Cheers, Des

The generated MyServiceMessageReceiverInOut looks roughly like this
structure
-----------------------------
    public void
invokeBusinessLogic(org.apache.axis2.context.MessageContext msgContext,
 
org.apache.axis2.context.MessageContext newMsgContext)
        throws org.apache.axis2.AxisFault {

        try {

            // get the implementation class for the Web Service
            ...
            // prepare the out Envelop
            org.apache.axiom.soap.SOAPEnvelope envelope = null;
            // Find the axisOperation that has been set by the Dispatch
phase.
            ...
            if (op.getName() != null
                & (methodName =
org.apache.axis2.util.JavaUtils.xmlNameToJava(op.getName().getLocalPart(
))) != null) {

                if ("MyOperation".equals(methodName)) {

                    // Unwrap header
                    SOAPHeader sOAPHeader = .....
                    // Check the header and possibley throw
MyServiceFaultException 
                    ...
                    // Unwrap body
                    ...
                    // Invoke the logic
                    result = skel.MySkeleton(body, header); // This can
throw MyServiceFaultException 
                    // Create new envelope
                    envelope =
getSOAPFactory(msgContext).getDefaultEnvelope();
                    // Add the body
                    envelope.getBody().addChild(toOM(result, false));
                    // Replace the header
                    envelope.getHeader().detach();
                    envelope.getBody().insertSiblingBefore(sOAPHeader);
                }
       
                newMsgContext.setEnvelope(envelope);
            }
        } catch (MyFaultException e) {
            // HOW DO I GET SOME HEADERS IN THE SOAP response???
            org.apache.axis2.AxisFault f = createAxisFault(e);
            f.setDetail(toOM(e.getFaultMessage(), false));
            throw f;
        }

        catch (Exception e) {
            throw org.apache.axis2.AxisFault.makeFault(e);
        }
    }
-----------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org