2 Replies Latest reply on Aug 15, 2014 11:51 AM by mh1

    How to configure XML name-space prefixes in Soap messages?

    mh1

      We've built a web-service application on SwitchYard (Fuse Service Works 6.0 GA) and it was noticed that response messages we sent back to clients calling our web-service defined the prefix used for the soap-envelope name-space in the opening Envelope tag of the message (expected) then immediately redefined the prefix to be used in the next line for the soap Header block.

       

      Example:

       

      <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

      <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">

       

      Our partner, responsible for building the client that will consume this web-service, has asked if we could fix the prefix used for various name-spaces in the message such as the soap-envelope name-space. (No need to debate whether we *should* do this, that discussion has been held. Here we're only looking to learn whether we *could* do this. )

       

      To achieve this, we created an interceptor, extending AbstractSoapInterceptor and inserted it into the chain at the PREPARE_SEND stage in whose handleMessage method we create a Map<String,String> to hold prefix, name-space pairs and we save this map to the message's contextual properties map using the key "soap.env.ns.map". In addition, we also add another property whose key/value is "disable.outputstream.optimization"/true because we'd seen a number of sources that recommended that.We also registered our interceptor as an out-interceptor in our switchyard.xml in the expected manner.

       

      So - that all worked more or less. For the purposes of experimentation only, we created the following prefix/name-space definitions in our map:

       

            namespacePrefixes.put("billybobthornton","http://www.w3.org/2003/05/soap-envelope");

            namespacePrefixes.put("abc","http://www.something-else-001.com/aa/bb/cc");

            namespacePrefixes.put("def","http://www.something-else-002.com/dd/ee/ff");

       

      When we then tested this we found that the first tag in our response message paid heed to this new configuration and used "billybobthornton" as the prefix. However, the Header tag that followed was again immediately redefined as it was originally.

       

      Example:

       

      <billybobthornton:Envelope xmlns:billybobthornton="http://www.w3.org/2003/05/soap-envelope">

      <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">

       

      The 'billybobthornton' prefix was used for all parts after the Header block (so the override to use 'env' only seems to apply to the Header block) but we also noted that our other defined prefixes (abc, def etc) were never used and 'stock' prefixes of the form 'ns1', 'ns2' etc were used instead for those parts of the message. (They relate to the content parts of our message in the Body section of the main soap message, FYI)

       

      The question therefore is given the use of the interceptor and the fact it initially appears to have an affect on the outer-most Envelope block, why does the Header block of the message get its prefix redefined and why don't our other prefix selection preferences get chosen?

       

      If anyone can unravel this mystery for us, we'll be eternally grateful.

        • 1. Re: How to configure XML name-space prefixes in Soap messages?
          kcbabo

          This will require debugging into CXF to figure out why the header is not respecting the namespace prefix.  One guess would be that the Header has already been associated with a namespace prefix and is not subject to the overrides in your map.  That's just a shot in the dark though.  Best best would be to locate where "soap.env.ns.map" is used within CXF and then figure out why it's not being applied to the Header element.

          • 2. Re: How to configure XML name-space prefixes in Soap messages?
            mh1

            I'm just pasting this here from the other thread I mistakenly posted this too earlier - for the benefit of anyone else that reads this later.

             

            To give a better insight, here are the three prefix declarations I made in the interceptor:

             

                  namespacePrefixes.put("billybobthornton","http://www.w3.org/2003/05/soap-envelope");

                  namespacePrefixes.put("eps","http://www.my.web.address.uk");

                  namespacePrefixes.put("myprojectname","urn:com.aoa.myprojectname:myprojectname:1.0.0");

             

            And here is the content of the happy path response message:

             

            <billybobthornton:Envelope xmlns:billybobthornton="http://www.w3.org/2003/05/soap-envelope" xmlns:myprojectname="urn:com.aoa.myprojectname:myprojectname:1.0.0" xmlns:eps="http://www.my.web.address.uk">

               <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">

                  <urn:ExchangeHeader xmlns:urn="urn:com.aoa.myprojectname:myprojectname:1.0.0">

                     <!-- Header Content Appears Here -->

                  </urn:ExchangeHeader>

               </env:Header>

               <billybobthornton:Body>

                  <MyWebServiceResponse xmlns="urn:com.aoa.myprojectname:myprojectname:1.0.0">

                     <ns2:MyWebServiceResponseEnv SchemaVersion="1.0" xmlns="http://www.w3.org/2000/09/xmldsig#" xmlns:ns2="http://www.my.web.address.uk">

                       <!-- Body Content Appears Here -->

                     </ns2:MyWebServiceResponseEnv>

                  </MyWebServiceResponse>

               </billybobthornton:Body>

            </billybobthornton:Envelope>

             

            Here the soap-envelope name-space prefix gets redefined in the envelope's Header element. Meanwhile, the prefixes selected for our project name-space have been changed to make one the default name-space and the other is assigned the prefix 'ns2'.

             

            And here is the content of the error path response message:

             

            <billybobthornton:Envelope xmlns:billybobthornton="http://www.w3.org/2003/05/soap-envelope" xmlns:myprojectname="urn:com.aoa.myprojectname:myprojectname:1.0.0" xmlns:eps="http://www.my.web.address.uk">

               <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"/>

               <billybobthornton:Body>

                  <env:Fault xmlns:env="http://www.w3.org/2003/05/soap-envelope">

                     <env:Code>

                        <env:Value>env:Sender</env:Value>

                     </env:Code>

                     <env:Reason>

                        <env:Text xml:lang="en-GB">Message Format Invalid</env:Text>

                     </env:Reason>

                  </env:Fault>

               </billybobthornton:Body>

            </billybobthornton:Envelope>

             

            Here - there's only the redefining the prefix for the soap-envelope name-space that is of concern.