You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Daniel Kulp <dk...@apache.org> on 2009/12/04 18:46:24 UTC

Re: Dispatch - how to get exception as soap message

I'm not really seeing a way to do it without writing an interceptor.   CXF, 
generally, tries to discard things that aren't needed anymore whenever it can.   
In this case, by the time the exception is thrown, the SOAPMessage has been 
discarded.

Using an interceptor, you could save the SOAPMessage and then retrieve it 
later view the dispatch.getResponseContext().     It would really be something 
like:

SOAPMessage m = msg.getContent(SOAPMessage.class);
msg.put("my.soap.message", m);


That should stick it in the response context.

Dan


On Thu November 26 2009 5:02:39 am Lukasz Lichota wrote:
> Hi,
> 
> I'm using Dispatch and I'd like to return soap message (as e.g. Source) no
> matter if there was an exception or normal response, is there a way to tell
> Dispatch not to throw SOAPFaultException?
> If not, what's the easiest way to transform it to the whole-message Source?
> I can do something like this:
> 		catch(SOAPFaultException e)
> 		{
> 			SOAPFault fault = e.getFault();
> 			Source response = new DOMSource(fault);
> 		}
> but then response contains only soap:fault without body and envelope. How
>  to easily construct the whole envelope? Do I need to manually create XML
>  for soap elements is maybe there's any utility to do this?
> 

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog

Re: Dispatch - how to get exception as soap message

Posted by Lukasz Lichota <Lu...@sabre.com>.
Thanks, I finally used an other approach using javax.xml.soap package
classes. It's not so bad as I thought. At least I don't need to construct
XML manually.

		catch(SOAPFaultException e)
		{
				SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
				SOAPPart soapPart = soapMessage.getSOAPPart();
				SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
				soapEnvelope.getHeader().detachNode();
				SOAPBody soapBody = soapEnvelope.getBody();
				SOAPFault soapFault = e.getFault();
				soapBody.addChildElement(soapFault);
				Source response = soapPart.getContent();
		}


-- 
View this message in context: http://old.nabble.com/Dispatch---how-to-get-exception-as-soap-message-tp26525334p26674865.html
Sent from the cxf-user mailing list archive at Nabble.com.