SOAPFactory soapFactory;
if (inMessageContext.isSOAP11()) {
soapFactory = OMAbstractFactory.getSOAP11Factory();
} else {
soapFactory = OMAbstractFactory.getSOAP12Factory();
}
soapFaultCode = soapFactory.createSOAPFaultCode();
SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue(soapFaultCode);
soapFaultValue.setText(new QName("http://test.org", "TestFault", "test"));
soapFaultReason = soapFactory.createSOAPFaultReason();
SOAPFaultText soapFaultText = soapFactory.createSOAPFaultText(soapFaultReason);
soapFaultText.setText("This is some FaultReason");
soapFaultDetail = soapFactory.createSOAPFaultDetail();
QName qName = new QName("http://someuri.org", "FaultException");
OMElement detail = soapFactory.createOMElement(qName, soapFaultDetail);
qName = new QName("http://someuri.org", "ExceptionMessage");
Throwable e = new Exception("This is a test Exception");
OMElement exception = soapFactory.createOMElement(qName, null);
exception.setText(e.getMessage());
detail.addChild(exception);
inMessageContext.setProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME, soapFaultCode);
inMessageContext.setProperty(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME, soapFaultReason);
inMessageContext.setProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, soapFaultDetail);
Make sure, you have accessed to inMessageContext, using message context injection. If you do not know how to do it, here is an explanation. Axis2 code base contains a test case and a sample service testing Axis2 fault handling within a service.
Apache Axis2/Java versions post 1.0
Can you provide an example code???