cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing SOAP header information in a custom adaptor module

Former Member
0 Kudos

Hi Guys,

Could anyone point me in the direction of information on how to access the SOAP:Header element when writing a custom adaptor module for a http/ SOAP communication channel?

I'm trying to add some WS-Security stuff which isn't available in XI 3.0.

Many thanks,

John

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

if you won't find a way to do it

maybe you can go for: Do Not Use SOAP Envelope

and fill everything (soap body and header) inside your mapping ?

Regards,

Michal Krawczyk

Former Member
0 Kudos

Michal,

I like your thinking. I'm not sure how easy it would be to do in the mapping, but I could do it in the adaptor module if I check the Don't use SOAP Envelope.

Naturally I'd prefer not to have to write a module that needs to remove the

<?xml version="1.0" encoding="UTF-8"?>

and wrap everything up from scratch, but it's definitely a route to investigate.

Thank you very much,

John

MichalKrawczyk
Active Contributor
0 Kudos

hi,

but you can also try logging (to file, etc.) the whole message in the adpater module just to check, maybe you can have access to the whole of it

(since it's not an XI message as with other adapter modules) ?

I never had to write anything for SOAP adapter but you can try it

Regards,

Michal Krawczyk

Former Member
0 Kudos

Just about to check what a call to getDocument on the Message class will return when using a SOAP Envelope. ;o)

Have previously written Adaptor Modules without using an envelope.

John

Former Member
0 Kudos

Just to follow on with the results of the getDocument when using a SOAP envelope.

The result is exactly the same irrespective of whether using a SOAP envelope or not.

getDocument returns the convents of the SOAP:Body element if using a SOAP envelope.

The following is trapped on WireShark/ Ethereal

<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>
<SOAP:Header/>
<SOAP:Body>
<ns1:getInformation xmlns:ns1='http://www.XXXXXX.com/types/xsd'>
......
</ns1:getInformation></SOAP:Body></SOAP:Envelope>

The following is the result returned from getDocument

<?xml version="1.0" encoding="UTF-8"?> 
<ns1:getInformation xmlns:ns1="http://www.XXXXXX.com/types/xsd">
....
</ns1:getInformation>

If Do not use SOAP Envelope is checked then the data going through WireShark/ Ethereal looks like this.

<?xml version="1.0" encoding="UTF-8"?> 
<ns1:getInformation xmlns:ns1="http://www.XXXXXX.com/types/xsd">
....
</ns1:getInformation>

and getDocument is exactly the same.

Hope this is of use to anyone else forging down the same path

John

Answers (1)

Answers (1)

Former Member
0 Kudos

The solution is as follows:

Mark as Do Not Use SOAPEnvelope in the communication channel.

It may be possible to use the SAP implementation of MessageFactory, SOAPEnvelope etc., I forced XI the Apache Axis implementation, a thread on which can be found here Link: [;

The SOAP Envelope is created by


/* 
javax.xml.soap.MessageFactory mf= org.apache.axis.soap.MessageFactoryImpl.newInstance();

This doesn't work it creates a com.sap.engine.services.webservices.jaxm.soap.SOAPMessageImpl
*/
org.apache.axis.message.SOAPEnvelope env = new org.apache.axis.message.SOAPEnvelope();
org.apache.axis.Message iSoapMessage = new org.apache.axis.Message(env);
SOAPMessage sm = iSoapMessage;


SOAPBody iBody = se.getBody();

if(iBody!=null)
{
	/* 
	iBody.addDocument(iDoc);
	addDocument failed for some reason when called in XI returning
	Exception caught by adapter framework: Exception in method process.
	The code below is copied straight from the addDocument method, but it works.
	*/
	org.w3c.dom.Element iDocRoot= iDoc.getDocumentElement();
	org.apache.axis.message.SOAPBodyElement bodyElement = new org.apache.axis.message.SOAPBodyElement(iDocRoot);
	iBody.addChildElement(bodyElement);
}

In order to get a document representation of the Envelope you can use


Document iEnvelopeDoc = ((org.apache.axis.message.SOAPEnvelope)env).getAsDocument();

You are now in a position to add or adjust the SOAP Envelope as your require. It enabled me to add WS-Security information to a message.

It is normally possible to use javax.xml.transform.Transformer on the various classes SOAPEnvelope, SOAPBody etc. as they implement Node. However doing this in XI caused a crash.

The final document can be then be set in the xmlPayload before being sent out the door.

Hope this helps someone,

John

yasha_dubey
Participant
0 Kudos

Hi John ,

I too have a similar scenario, where I have to insert two parameters in the HTTP response.

I am planning to write a custom module for it and just call the module before sending the response.

I am not sure of how can I access both the body and header and alter the header and send the final HTTP Response and Body back to the sender.

I am using a Rest Sender Adapter : HTTP protocol and a SOAP receiver. Its a synchronous call.

Have raised the question on SCN too, but your post seemed quite similar to mine.

If you could throw some light, would be quite helpful.

Thanks,
Pragya

Former Member
0 Kudos

Hi Pragya,

I haven't done this kind of thing is a while (I wrote that adaptor six years ago), but as far as I can remember from working on a number of adaptors that worked on messages both before and after the SOAP adaptor, you can't get at the parameters in the HTTP header of a message.

I'm sure you're already familar with all of this, but just to cover what happens in a SOAP adapter.

SOAP is an XML document added as a payload to the body of an HTTP message. If you write an adaptor module then the data you can change is the data that's passed into that module normally. i.e. what you'd see in SXMB_MONI.

The adaptor module I wrote could not get at the SoapEnvelope and Body section of the message as that would normally be done by the SoapAdaptor after the work by my module, so I set the SoapAdaptor module to not add a SoapEnvelope and the WS_Secutity module I wrote created all that around the message. It added details to the message that had been passed in to the soap adapter, not the message that's sent out from the Soap Adapter. I don't believe that's possible.

We have also written modules that modify the response sent back from a Web Service adding details in an adaptor module before it is sent through mapping. Again, these are details added to the payload of the Soap message, not the HTTP message.

My understanding is that the standard soap adaptor handles the HTTP communication, or calls and API which does it. It may be possible to write a new Soap adaptor that creates the SoapEnvelopes and opens HTTP channels, or calls whatever Sap APIs can do that, and can add extra detail to the HTTP layer, but I've never gone down that road.

Hope that's some help, if not just shout.

Kind regards,

John