IBM Support

How to pass custom HTTP Headers via HTTP Client Method Service in IBM Sterling B2B Integrator

Technical Blog Post


Abstract

How to pass custom HTTP Headers via HTTP Client Method Service in IBM Sterling B2B Integrator

Body

Author: Manisha Khond, IBM Cognitive Engagement, Watson Supply Chain.

 

IBM Sterling B2B Integrator HTTP Client Method Service supports GET, POST and HEAD methods.

In order to pass custom HTTP Headers, you have to build a message using custom HTTP Headers. This is achieved by using MIME Service.

Below code snippet (bpml) sets the custom headers and then build the MIME document using MIME Service and then assign the MIME document to PrimaryDocument.

        <assign to="MIMEtemp/mime:message/mime:header" from="'host'" append="true" />
        <assign to="MIMEtemp/mime:message/mime:header/@name" from="'xxx.xx.xx.xx'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header" from="'*/*'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header/@name" from="'Accept'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header" from="'fetch'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header/@name" from="'x-csrf-token'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:body" from="Doc1/doc:document-id"/>
        <operation name="MIME encode documents">
            <participant name="MIME"/>
            <output message="packRequest">
                <assign to="mime-document" from="MIMEtemp/mime:message"/>
            </output>
            <input message="packResponse">
                <assign to="." from="*"/>
            </input>
        </operation>
        <assign to="PrimaryDocument" from="mime-document/@*" />

 

The next step is to send the document to HTTP Server. This can be done by establishing HTTP Session with HTTP Client Begin Session Service, then sending the document using HTTP Client Method Service using GET Method. In order to send HTTP headers with Primary Document, you have to set RawRequest parameter to true.

 

Below is the complete bpml:

<process name="mk_http_MethodService_rawrequest">
    
    <sequence name="Main">
        
        <assign to="Doc1" from="PrimaryDocument/@SCIObjectID" />
        <operation name="Assign ID for Doc 1">
            <participant name="This"/>
            <output message="giveDocumentRequest">
                <assign to="." from="*"/>
                <assign to="documentKey" from="'Doc1'"/>
            </output>
            <input message="giveDocumentResponse">
                <assign to="Doc1/doc:document-id" from="documentId/text()" append="true"/>
            </input>
        </operation>
        <operation name="HTTP Client Begin Session Service">
                  <participant name="HTTPClientBeginSession"/>
                      <output message="HTTPClientBeginSessionServiceTypeInputMessage">
                    <assign to="HTTPClientAdapter">HTTPClientAdapter</assign>
                    <assign to="RemoteHost">xxx.xx.xx.xx</assign>
                    <assign to="RemotePort">yyyy</assign>
                    <assign to="." from="*"></assign>
                      </output>
                       <input message="inmsg">
                        <assign to="HTTPClientBeginSessionServiceResults" from="*"></assign>
                      </input>
            </operation>
        <assign to="MIMEtemp/mime:message/mime:header" from="'host'" append="true" />
        <assign to="MIMEtemp/mime:message/mime:header/@name" from="'Host'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header" from="'*/*'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header/@name" from="'Accept'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header" from="'fetch'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:header/@name" from="'x-csrf-token'" append="true"/>
        <assign to="MIMEtemp/mime:message/mime:body" from="Doc1/doc:document-id"/>
        <operation name="MIME encode documents">
            <participant name="MIME"/>
            <output message="packRequest">
                <assign to="mime-document" from="MIMEtemp/mime:message"/>
            </output>
            <input message="packResponse">
                <assign to="." from="*"/>
            </input>
        </operation>
        <assign to="PrimaryDocument" from="mime-document/@*" />
        
        <operation name="Http Client Method Service">
            <participant name="HTTPClientMethod"/>
            <output message="HTTPClientMethodServiceTypeInputMessage">
                <assign to="SessionToken" from="HTTPClientBeginSessionServiceResults/SessionToken/text()"></assign>
                <assign to="MethodType">GET</assign>
                <assign to="URI">/soap/</assign>
                <assign to="RawRequest">true</assign>
                <assign to="RawResponse">true</assign>
                <assign to="ShowResponseCode">true</assign>
                <assign to="ResponseTimeout">300</assign>
                <assign to="." from="*"></assign>
            </output>
            <input message="inmsg">
                <assign to="DefaultError" from="ServerResponse/ResponseReasonPhrase/text()" />
                <assign to="PrimaryDocument" from="PrimaryDocument/@*" />
            </input>
        </operation>
               
        <operation name="HTTP Client End Session Service">
            <participant name="HTTPClientEndSession"/>
            <output message="HTTPClientEndSessionServiceTypeInputMessage">
                <assign to="SessionToken" from="HTTPClientBeginSessionServiceResults/SessionToken/text()"></assign>
                <assign to="." from="*"></assign>
            </output>
            <input message="inmsg" />
        </operation>
        
    </sequence>
</process>

 

 

 

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SS3JSW","label":"IBM Sterling B2B Integrator"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11121217