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 Moritz Mädler <ma...@moritz-maedler.de> on 2009/07/06 17:53:47 UTC

Could not throw SOAPFault

Hello,

i want to return SOAPFaults to inform the client in the case sth. went  
wrong on the service side.
To return a SOAPFault I created the following method in my serviceclass:
------
protected void throwSOAPFault(String text) throws AxisFault{
		MessageContext messageContext =  
MessageContext.getCurrentMessageContext();
		Exception t = new Exception(text);
		
		SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
		
		SOAPFaultCode soapFaultCode = soapFactory.createSOAPFaultCode();
		soapFaultCode.declareNamespace("http://someurl", "m");
		
		SOAPFaultValue soapFaultValue = soapFactory.createSOAPFaultValue();
		soapFaultValue.setText("m:FaulException");
		 
messageContext.setProperty(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME,  
soapFaultCode);
		
		SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason();
		SOAPFaultText soapFaultText =  
soapFactory.createSOAPFaultText(soapFaultReason);
		soapFaultText.setText(text);
		 
messageContext 
.setProperty(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME,  
soapFaultReason);
		
		SOAPFaultDetail soapFaultDetail = soapFactory.createSOAPFaultDetail();
		QName qName = new QName("http://someurl", "FaultException");
		OMElement detail = soapFactory.createOMElement(qName, null);
		Throwable e = t;
		while (e != null){
			OMElement exception = soapFactory.createOMElement(qName, null);
			exception.setText(t.getMessage());
			detail.addChild(exception);
			e = e.getCause();
		}
		 
messageContext 
.setProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,  
soapFaultDetail);
		throw new AxisFault(text);
	}
-----
But if i trigger an error through an obviously wrong request, I only  
see the AxisFault in service logfile.

What do I have to do for sending SOAPFaults to the client?

Thanks a lot in advance!

Moritz