Something like the following will allow you to create your own fault 
code/string and detail message:

                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, 
Constants.FAULT_NS_PREFIX);
                SOAPFaultValue soapFaultValue = 
soapFactory.createSOAPFaultValue(soapFaultCode);
                soapFaultValue.setText(Constants.FAULT_NS_PREFIX + ":" + 
Constants.XML_ELEMENT_FAULTEXCEPTION);/*I18nOK:COS*/
                SOAPFaultReason soapFaultReason = 
soapFactory.createSOAPFaultReason(soapFault);
                SOAPFaultText soapFaultText = 
soapFactory.createSOAPFaultText(soapFaultReason);
                soapFaultText.setText(FaultException.class.getName());
                SOAPFaultDetail soapFaultDetail = 
soapFactory.createSOAPFaultDetail(soapFault);

                QName qName = new QName(Constants.WEBSERVICEMAKER_NS, 
Constants.XML_ELEMENT_FAULTEXCEPTION);
                OMElement detail = soapFactory.createOMElement(qName, null);
                soapFaultDetail.addDetailEntry(detail);
                qName = new QName(Constants.WEBSERVICEMAKER_NS, 
Constants.XML_ELEMENT_EXCEPTIONMESSAGE);
                Throwable e = t;
                while (e != null) {
                        OMElement exception = 
soapFactory.createOMElement(qName, null);
                        exception.setText(t.getClass().getName() + ": " + 
t.getMessage());/*I18nOK:COS*/
                        detail.addChild(exception);
                        e = e.getCause();
                }

Ignore the extra detail... I just cut and pasted my code. 

-----Original Message-----
From: Glen Daniels [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 13, 2006 8:18 AM
To: [email protected]
Subject: Re: [axis2] AXIOM question

Hi Paul:

> This is the code I've used - not sure if its the tightest.
> 
> factory = OMAbstractFactory.getSOAP11Factory();
> SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();

That gets me a "default" fault which has no useful fault code or reason. 
   I actually saw this code, which is what led me to ask the question. :)

Either I should be able to take the fault you get with the above code and 
mutate it to add reason/faultcode/details, or there should be another way to 
generate a fault envelope by specifying some parameters. 
  In either case, the API should be simple and easy to use.  If this isn't 
already the case we should make it so.

This of course leads into a slightly bigger discussion about how to clean up 
the fault classes, which is already a JIRA but needs dealing with.

--Glen

Reply via email to