5 Replies Latest reply on Sep 20, 2013 2:50 PM by user8318116

    How to transform both soap header and body in message flow of the service proxy

    user8318116

      I'm new to OSB.

      I'm trying to implement a simple service proxy, where the backend service expects values in both soap header and body

      I was wondering how I can transform *both* soap header and soap body in the message flow of the proxy service.

      For message proessing, I have to select either a header or body variable, not both. In the cook book, there is no sample for transforming both.

      Is it possible and if not, is there an alternate approach?  Thanks

        • 1. Re: How to transform both soap header and body in message flow of the service proxy
          AbhishekJ

          Hi,

           

          SOAP header and body are respectively stored in context variables $header and $body within OSB proxy service message flow. Any time a communication action is executed the contents of these two variables at that point of time within that context will be sent to the target service as SOAP Header and SOAP Body.

          What you need to do is have two replace actions before you call the target service and replace contents of $body in one replace action and content of $header in another replace action.

          Something like this:

          1. Replace node contents of . in variable body with <MyNode>something</MyNode>

          2. Replace node contents of . in variable header with <MyHeader>something</MyHeader>

          3. <<Your communication actions, which could be Service Callout, Route, or Publish or any variations of these three >>

           

          When the communication action is executed, the target service will receive a SOAP Envelope like this:

          <soap:Envelope

          xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

          soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

            <soap:Header>

          <MyHeader>something</MyHeader>

            </soap:Header>

            <soap:Body >

          <MyNode>something</MyNode>

            </soap:Body>

           

          < /soap:Envelope>

          • 2. Re: How to transform both soap header and body in message flow of the service proxy
            user8318116

            Thanks for showing me how the two context variables are processed by OSB.

            I added Replace action for the header processing but I get the error. what is the problem?
            --- Details:
            I use XSLT Resources instead of XQuery Resources becasue there is no xsd and wsdl for the header.
            The xsl file has no error, but when I go to service proxy > message flow, I see the red error ribbon at the Replace action for the header

            With the Replace action being selected, under Properties,
            XPath: <XPath>
            In Variable: header
            Expression: Xslt: OSBServiceProxy/transformation/xHeader
            x Replace entire node (selected)

            I click on Expression link > XQuery/XSLT Expression Editor screen appears, XSLT Resources is selected and
            For Input Document, if nothing is entered, I get
            - XQuery expression validation failed: XQuery error for the input: line1, column 1:{err}XP0003: Inva;id expression: ...

            and if I put $header, I get
            - XQuery expression validation failed: The Xpath expression is not defined.

            I cannot remove the error.

            • 3. Re: How to transform both soap header and body in message flow of the service proxy
              AbhishekJ

              Here is what you need to input for each of the fields of a Replace action:

              XPath = You can leave it blank

              In Variable = header

              Replace node contents selected (if you choose Replace entire node content option then your XQuery/XSLT expression should return a SOAP:Header element as root node).

              In the Expression link:

              Select XSLT resource if you want output of an XSLT to be the content of $header

              Once you select(browse) the XSLT, you need to provide a mandatory Bind Input (this is the input to the XSLT), you can choose to put $header here if your XSLT is actually returning a hardcoded response irrespective of input or provide the expected input variable to XSLT if it needs one.

              Additionally, if your XSLT defined any params then you need to provide Bind Variables as well, one for each param.

               

              Click on Validate at this point and it should be valid, and you should be able to save it now.

              Also, What are you doing in the XSLT? It would be easier to do the same in XQuery text usually. For ex. if its a hardcoded header content then you can simply type in the XML content in XQuery Text tab.

              • 4. Re: How to transform both soap header and body in message flow of the service proxy
                user8318116

                For XPath, I cannot leave it blank becasue when I drag and drop a Replace action, it is already pre-populated with <XPath> (this is a link to XPath Expression Editor).

                I put $header for Bind Input for XSLT. Below is my xHeader.xsl. The input soap header ($header) holds one element and the output will have two elements, Security and Localization.

                Note that I normally does  <xsl:template match = "/"><xsl:apply-templates/></xsl:template> at the top of xsl, but as the input is $header so I removed those.

                -----

                <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

                      <xsl:template match = "*[local-name()='Security']/*[local-name()='UsernameToken']">       

                              <Security xmlns = "http://schemas.xmlsoap.org/ws/2002/12/secext">

                                   <hd:UsernameToken xmlns:hd = "http://schemas.xmlsoap.org/ws/2002/12/secext">

                                       <hd:Username>asserted:<xsl:value-of select = "*[local-name()='Username']"/></hd:Username>

                                       <hd:Password><xsl:value-of select = "'Irrelevant'"/></hd:Password>

                                    </hd:UsernameToken>

                               </Security>

                               <Localization xmlns = "http://schemas.xmlsoap.org/ws/2002/12/secext">

                                   <hd:Locale xmlns:hd = "http://schemas.xmlsoap.org/ws/2002/12/secext">en-US</hd:Locale>

                                   <hd:Timezone xmlns:hd = "http://schemas.xmlsoap.org/ws/2002/12/secext">+00:00</hd:Timezone>

                               </Localization>

                      </xsl:template>

                </xsl:stylesheet>

                ----

                In the message flow, I have two Replace actions in sequence under Request Action. The first one for header and the second one for bodyt.

                The body Replace action did not have an error, but after I added the header Replace action above the body Replace action), I see both Replace actions have error.

                ERROR: XPath validation failed: The XPath expression is not defined

                In the message flow, from top to bottom, I have these elements: service proxy > RouteToXXX > Routing > Request (two Replace actions) and Response (one Replace action) pair.

                • 5. Re: How to transform both soap header and body in message flow of the service proxy
                  user8318116

                  I was able to remove the errors by deleting and re-creating the two Replace actions. Somehow OSB did not like them. do not know why. Anyway I ran it and got the error message. What causes OPEN_TAG error?

                  --- Error message from OSB ---

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

                  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

                  <soapenv:Body>

                  <soapenv:Fault>

                    <faultcode>soapenv:Server</faultcode>

                    <faultstring>BEA-382513: OSB Replace action failed updating variable "header": org.apache.xmlbeans.XmlException: error: Unexpected element: OPEN_TAG</faultstring>

                    <detail>

                     <con:fault xmlns:con="http://www.bea.com/wli/sb/context">

                      <con:errorCode>BEA-382513</con:errorCode>

                      <con:reason>OSB Replace action failed updating variable "header": org.apache.xmlbeans.XmlException: error: Unexpected element: OPEN_TAG</con:reason>

                      <con:location>

                       <con:node>RouteToXXX</con:node>

                       <con:path>request-pipeline</con:path>

                      </con:location>

                     </con:fault>

                    </detail>

                  </soapenv:Fault>

                  </soapenv:Body>

                  </soapenv:Envelope>

                   

                  Thanks