2 Replies Latest reply on Dec 5, 2011 3:53 PM by Mschwitz-Oracle

    Replacing default namespace in OSB message flow

    Mschwitz-Oracle
      I'm in the process of setting up a simple OSB proxy and could use some help figuring out how to change a default namespace in the response from the business service.

      The proxy and business service use different namespaces which we'll call "http://foo.com/namespace/proxy" and "http://foo.com/namespace/business". In my routing request message flow, the contents of $body look like this and I'm able to use a Rename action with XQuery expression "./sof:*" to change "http://foo.com/namespace/proxy" to "http://foo.com/namespace/business":

      <sof:Execute xmlns:sof="http://foo.com/namespace/proxy">
      <sof:adminName>MyAdaptor</sof:adminName>
      <sof:request>

      [escaped payload omitted]

      </sof:request>
      </sof:Execute>

      This works fine, but in the response message flow, I need to revert the namespace and am having difficulty because the response uses a default namespace instead of using a prefix:

      <ExecuteResponse xmlns="http://foo.com/namespace/business">
      <ExecuteResult>

      [escaped payload omitted]

      </ExecuteResult>
      </ExecuteResponse>

      If I define a prefix P2L in the expression editor to correspond to "http://foo.com/namespace/business", I'm able to reference the ExecuteResponse element as "./P2L:ExecuteResponse", but then I get stuck.

      If I try use a Rename action to change the namespace for "./P2L:*", only the ExecuteResponse element is renamed to <sof:ExecutResponse xmlns:sof="http://foo.com/namespace/proxy">. Upstream in the calling application, there's an XML stream reader exception because (I assume) ExecuteResult is not found and parsed.

      I also tried using a Replace action against "./P2L:ExecuteResponse/@xmlns" to replace its contents with "http://foo.com/namespace/proxy". I also tried "./P2L:ExecuteResponse/@P2L:xmlns". Neither worked.

      Can anyone tell me what I'm doing wrong, or suggest a different approach? Assume that changing the calling application or business service is not an option.

      Thanks!
        • 1. Re: Replacing default namespace in OSB message flow
          680075
          >
          If I define a prefix P2L in the expression editor to correspond to "http://foo.com/namespace/business", I'm able to reference the ExecuteResponse element as "./P2L:ExecuteResponse", but then I get stuck.

          If I try use a Rename action to change the namespace for "./P2L:*", only the ExecuteResponse element is renamed to <sof:ExecutResponse xmlns:sof="http://foo.com/namespace/proxy">. Upstream in the calling application, there's an XML stream reader exception because (I assume) ExecuteResult is not found and parsed.
          >

          You pattern "./P2L:\*" matches just one element so it's ok that the payload's namespace wasn't touched. If you want to rename namespace for all elements try "//P2L:*". However, I'm not sure whether this is what you want. Try do describe what you do, what you want and what you get instead.

          >
          I also tried using a Replace action against "./P2L:ExecuteResponse/@xmlns" to replace its contents with "http://foo.com/namespace/proxy". I also tried "./P2L:ExecuteResponse/@P2L:xmlns". Neither worked.
          >

          I think it's not a good approach to replace content of xmlns as this attribute is not a common xml attribute.
          • 2. Re: Replacing default namespace in OSB message flow
            Mschwitz-Oracle
            >
            You pattern "./P2L:\*" matches just one element so it's ok that the payload's namespace wasn't touched. If you want to rename namespace for all elements try "//P2L:*". However, I'm not sure whether this is what you want. Try do describe what you do, what you want and what you get instead.
            >

            The problem was a mental lapse on my part. I wanted all elements in the http://foo.com/namespace/business namespace to be renamed to http://foo.com/namespace/proxy, but I was so busy wrestling with the cumbersome business of OSB message flow that I made a basic XPath mistake. ".//P2L:*" accomplished exactly what I needed.

            As to why I needed to do this, the application logic that was having issues with the default namespace is hidden from me, but based on the errors I got back from the XML stream reader, I'm thinking it expects both ExecuteResponse and its child to be in the same namespace. The fact that the business service uses a default namespace instead of a defining a prefix and using it on all applicable elements was giving me problems, as I wasn't sure how to write the query without namespace prefices. ".//P2L:*" worked just fine.