axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eran Chinthaka <chinth...@opensource.lk>
Subject Re: [AXIS2] soapFault question
Date Fri, 10 Mar 2006 05:52:54 GMT
Hi Tony,

Seems like you have tried to create the faults using SOAP 1.1 api.

You may also agree that the fault hierarchy in SOAP 1.1 and 1.2 are
different. So some time back we decided to have the SOAP 1.2 api across
the engine for consistency and developer convenience. Users must always
create all the SOAP messages using SOAP 1.2 api. And if they want to
change the version, they just need to switch the factories. Axiom SOAP
implementation will take care of all the other work (like serialization)
transparent to the user.

I changed your code so that it will run properly with the above
explanation. I added some hypothetical information, as I wanted to
re-create the bug. Here we go.

Exception t = new Exception("Eureka, Says Archimedes and runs naked on
the road");

        SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
        SOAPBody soapBody = soapFactory.createSOAPBody(soapEnvelope);
        SOAPFault soapFault = soapFactory.createSOAPFault(soapBody);

        SOAPFaultCode soapFaultCode =
soapFactory.createSOAPFaultCode(soapFault);
        soapFaultCode.declareNamespace("http://someuri.org", "m");

        SOAPFaultValue soapFaultValue =
soapFactory.createSOAPFaultValue(soapFaultCode);
        soapFaultValue.setText("m:FaultException");

        SOAPFaultReason soapFaultReason =
soapFactory.createSOAPFaultReason(soapFault);
        SOAPFaultText soapFaultText =
soapFactory.createSOAPFaultText(soapFaultReason);
        soapFaultText.setText("This is some fault reason");
       
        SOAPFaultDetail soapFaultDetail =
soapFactory.createSOAPFaultDetail(soapFault);

        QName qName = new QName("http://someuri.org", "FaultException");
        OMElement detail = soapFactory.createOMElement(qName, null);
        qName = new QName("http://someuri.org", "ExceptionMessage");
        Throwable e = t;
        while (e != null) {
            OMElement exception = soapFactory.createOMElement(qName, null);
            exception.setText(t.getMessage());
            detail.addChild(exception);
            e = e.getCause();
        }

        System.out.println("soapEnvelope = " + soapEnvelope);

    }

But I agree that throwing an NPE in this case is not a good idea :).

-- Chinthaka

Tony Dean wrote:

>Hi,
>
>What is wrong with the following:
>
>    		SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
>    		SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
>    		SOAPBody soapBody = soapFactory.createSOAPBody(soapEnvelope);
>    		SOAPFault soapFault = soapFactory.createSOAPFault(soapBody);
>    		SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode(soapFault);
>    		soapFaultCode.declareNamespace(Constants.WEBSERVICEMAKER_NS, "m");
>    		soapFaultCode.setText("m:FaultException");
>    		SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason(soapFault);
>    		soapFaultReason.setText(FaultException.class.getName());
>    		SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail(soapFault);
>
>    		QName qName = new QName(Constants.WEBSERVICEMAKER_NS, "FaultException");
>    		OMElement detail = soapFactory.createOMElement(qName, null);
>    		qName = new QName(Constants.WEBSERVICEMAKER_NS, "ExceptionMessage");
>    		Throwable e = t;
>    		while (e != null) {
>        		OMElement exception = soapFactory.createOMElement(qName, null);
>        		exception.setText(t.getMessage());
>        		detail.addChild(exception);
>    			e = e.getCause();
>    		}
>    		
>    		AxisFault axisFault = new AxisFault(soapFault);
>    		throw axisFault;
>
>I end up with a nullPointerException message in the fault as presented to the client instead
of what I intended.  Should be something like:
>
><Body>
>  <Fault>
>    <faultcode xmlns:m="myNamespace">m:FaultException</faultcode>
>    <faultstring>com.sas.web.services.maker.FaultException</faultcode>
>    <detail>
>       <FaultException xmlns="myNamespace">
>          <ExceptionMessage>first exception msg...</ExceptionMessage>
>          <ExceptionMessage>second exception msg...</ExceptionMessage>
>                     ...
>       </FaultException>
>    </detail>
> </Fault>
></Body>
>
>Thanks for any advice.
>
>Tony Dean
>SAS Institute Inc.
>919.531.6704
>tony.dean@sas.com
>
>SAS... The Power to Know
>http://www.sas.com
>
>
>  
>

Mime
View raw message