Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify the generated SOAP request?

I'm at the stage where I created an output interceptor and I get an OuputStream out of the SOAP message. But how could I modify the SOAP envelope right before sending it to the endpoint? I would like to delete some xml elements.

like image 984
kiwifrog Avatar asked Aug 02 '11 01:08

kiwifrog


People also ask

How do you check SOAP request and response?

Click the 'RAW' Tab in SOAP-UI Response Window to understand how the response is sent via HTTP. After processing the request, the http response code (200) is shown which means it is a success. The web-server has processed it successfully.


2 Answers

one way could be to get the document and run it through XSLT transform.

You can get at the document in the handleMessage of your interceptor by calling

@Override
public void handleMessage(SoapMessage message) throws Fault{
    SOAPMessage saaj = message.getContent(SOAPMessage.class);
    Document doc = saaj.getSOAPPart(); // This actually returns a SOAPPart instance but it does implement the w3c Document interface

    //play around with the document, doc is a reference so any changes made to that instance
    //will be forwarded to the rest of the chain
}

careful though that if you have security such as XML signature that must be performed on the soap content you must ensure that your interceptor occurs BEFORE the signature are applied otherwise you will invalidate them.

To play around with the timing of the interceptor you can specify the phase at which it will run. CXF should also honor the order in which you will configure them should they be performed at the same phase.

but don't take my word for it... check these for more info

  • http://cxf.apache.org/docs/interceptors.html
  • http://fusesource.com/docs/esb/4.2/cxf_interceptors/CXFInterceptorIntro.html

debugging through the CXF source code also helped me a great deal in understanding how it worked

---- EDIT ----

(thanks Daniel :-)

For this to work you need to have SAAJOutInterceptor configured in your stack. You can either add it manually or simply make it part of your interceptor. Here is an example of an interceptor that pretty much does what you want.

like image 199
Newtopian Avatar answered Oct 07 '22 02:10

Newtopian


Refer to this link for a description of the Interceptor Phases

https://web.archive.org/web/20131003140105/http://fusesource.com/docs/esb/4.2/cxf_interceptors/CXFInterceptPhasesAppx.html

like image 43
user745079 Avatar answered Oct 07 '22 03:10

user745079