Back Forum Reply New

Adding Soap Header using web service outbound adapter

I was wondering if there's any way of adding a custom soap header before invoking a webservice using spring integration webservice outbound adapter.

Currently I am in design stage so want iron out challenges before moving to development/POC. Here is what I am trying to achieve :

I will be getting Spring Integration's Message from a channel. A chain of Message Handlers will work on this message which contains:

1.) A message transformer : transforms the message to the required Jaxb objects generated using contract xsd's.
2.) Webservice outbound gateway: which should invoke the webservice and send the reply to another reply channel

The catch is that I want to add a custom soap header expected by webservice before invoking it. I can add header enricher between two steps defined above but I am not sure whether they will transform into SOAP Header.

Kindly advice.

Regards,
Sukhi

Your use case might provide some valuable feedback for this issue:
browse/INT-1532
(please vote for it, and you can add a watch as well)

However, it might be simpler than that. Can you describe in a bit more detail what type of information you want to add as a SOAP header? Specifically, is the value determined at runtime based on Message content?

Thanks,
Mark

Hello.
You can do it with request-callback and implementation like this:

Code:
public class MyWebServiceMessageCallback implements WebServiceMessageCallback {
   private Transformer transformer;
   private String authHeader;
   public void setAuthHeader(String authHeader) {       this.authHeader = authHeader;   }
   public void setTransformer(Transformer transformer) {       this.transformer = transformer;   }
   public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {       SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();       transformer.transform(new StringSource(authHeader), soapHeader.getResult());   }
}
Where the authHeader is a simple XML-element like this:

HTML Code:
lt;AuthHeadergt;        lt;Usernamegt;TESTlt;/Usernamegt;        ltasswordgt;TESTlt;/Passwordgt;     lt;/AuthHeadergt;Thanks Cleric for the input..... I may have to try it out... but I am not sure how this approach would work if I need to provide a Jaxb object to be marshalled at runtime and to be used as SOAP header.... but this will definitely give me pointer to find out my way.

Mark,
Thanks for the prompt reply..... Frankly I am unaware about HeaderMapper.... but I can certainly share my use case in detail as it is just a POC. Here is it:

following payload will be received on a channel:

lt;tns:HolidayEnquiry xmlns:tns=quot;HotelEnquirySystemquot;
xmlns:tns1=quot;basequot; xmlns:tns2=quot;Travelquot;
xmlns: xsi=quot;2001/XMLSchema-instancequot;
xsi: schemaLocation=quot;HotelEnquirySystem HotelEnquirySystem.xsd quot;gt;
lt;tns1:CustomerNamegt;XXXlt;/tns1:CustomerNamegt;
lt;tns1:CustomerAddressgt;XXXXlt;/tns1:CustomerAddressgt;
lt;tns1:CustomerMobilegt;XXXXXXlt;/tns1:CustomerMobilegt;
lt;tns1:CustomerEmailgt;XXXXXlt;/tns1:CustomerEmailgt;
lt;tns1: Destinationgt;XXXXlt;/tns1: Destinationgt;
lt;tns1:Budgetgt;0.0lt;/tns1:Budgetgt;
lt;tns: HotelEnquirygt;
lt;tns1: NoOfPeoplegt;0lt;/tns1:NoOfPeoplegt;
lt;tns1: Classgt;Luxurylt;/tns1:Classgt;
lt;tns1: CheckInDategt;2001-01-01lt;/tns1:CheckInDategt;
lt;tns1: CheckOutDategt;2001-01-01lt;/tns1:CheckOutDategt;
lt;/tns: HotelEnquirygt;
lt;tns:TravelEnquirygt;
lt;tns1:Modegt;Trainlt;/tns1:Modegt;
lt;tns1:TravelTypegt;Tolt;/tns1:TravelTypegt;
lt;tns1:Classgt;Luxurylt;/tns1:Classgt;
lt;tns1:TravelDategt;2001-01-01lt;/tns1:TravelDategt;
lt;tns1:ReturnDategt;2001-01-01lt;/tns1:ReturnDategt;
lt;tns1:BoardingCitygt;tns1:BoardingCitylt;/tns1:BoardingCitygt;
lt;/tns:TravelEnquirygt;
lt;/tns:HolidayEnquirygt;

This should be unmarshalled to jaxb objects, some business validations should be done and then it should be sent to another channel. A filter should get message from this channel and invoke a webservice. Now the webservice to be invoked should be somewhat like this:

lt;soapenv:Envelope xmlns:soapenv=quot;soap/envelope/quot; xmlns:hot=quot;HotelFinderContractquot; xmlns:base=quot;basequot;gt;  lt;soapenv:Headergt;     lt;hot:CustomerHeaderTypegt;        lt;!--You may enter the following 6 items in any order--gt;        lt;base:CustomerNamegt;?lt;/base:CustomerNamegt;        lt;base:CustomerAddressgt;?lt;/base:CustomerAddressgt;        lt;base:CustomerMobilegt;?lt;/base:CustomerMobilegt;        lt;base:CustomerEmailgt;?lt;/base:CustomerEmailgt;        lt;base: Destinationgt;?lt;/base: Destinationgt;        lt;base:Budgetgt;?lt;/base:Budgetgt;     lt;/hot:CustomerHeaderTypegt;  lt;/soapenv:Headergt;  lt;soapenv:Bodygt;     lt;hot:HotelFinderRequestgt;        lt;base:CheckInDategt;?lt;/base:CheckInDategt;        lt;base:CheckOutDategt;?lt;/base:CheckOutDategt;        lt;base: Destinationgt;?lt;/base: Destinationgt;        lt;base:NoOfPeoplegt;?lt;/base:NoOfPeoplegt;        lt;base:Classgt;?lt;/base:Classgt;     lt;/hot:HotelFinderRequestgt;  lt;/soapenv:Bodygt;
lt;/soapenv:Envelopegt;

As you can see, service request requires a header which is composed of some elements from HolidayEnquiry. And few others are mapped to HotelFinderRequest in soap:body.

Using transformer, I can transform the incoming message into CustomerHeaderType and HotelFinderRequest jaxb objects but now while invoking webservice how these objects will be marshalled to form required soap:envelope's parts.

I was thinking of using webservice outbound adapter but could not figure out the addition of CustomerHeader.

Can ws:header-enricher can help here?


Originally Posted by Mark FisherYour use case might provide some valuable feedback for this issue:
browse/INT-1532
(please vote for it, and you can add a watch as well)

However, it might be simpler than that. Can you describe in a bit more detail what type of information you want to add as a SOAP header? Specifically, is the value determined at runtime based on Message content?

Thanks,
Mark

Hi Mark,

Would appreciate your inputs.... I have added use case in the thread.

Regards,
Sukhi
¥
Back Forum Reply New