Announcement Announcement Module
Collapse
No announcement yet.
How to attach a prefix to an element (AbstractDomPayloadEndpoint) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to attach a prefix to an element (AbstractDomPayloadEndpoint)

    I am trying to attach a prefix to elements in my SoapResponse, but with no success.

    This is the desired response:

    <tst:GetElementsResponse xmlns:tst="http.../tst">
    <tst:Element>
    <tst:id>1</tst:id>
    <tst:name>element 1</tst:name>
    </tst:Element>
    </tst:GetElementsResponse>


    And this is what I currently get:

    <GetElementsResponse>
    <Element>
    <id>1<id>
    <name>element 1<name>
    </Element>
    </GetElementsResponse>



    I am building my respose using org.w3c.dom.Element, and tried adding the prefix through element.setPrefix(), but it seems to have no effect.

    Thanks,
    P

  • #2
    The trick is to create an Element with a qualified name, like so:

    Code:
    Element el = document.createElementNS("http://.../tst", "tst:GetElementResponse");
    That should work.

    Comment


    • #3
      Arjen, thanks for your quick reply.
      Unfortunately, doing what you have suggested doesn't help.

      When I just create the element, it has the desired content, but the end result is still missing my prefix (in fact, already in the handleResponse method in my SoapEndpointInterceptor the prefixes are missing from my response).

      I noticed that if the prefix does not contain ":" (i.e. prefix = tst as oppose to tst: ), it shows up in the response, but if I attach it to the element with ":" it gets removed by something along the way.


      I am out of ideas. Please help.
      P

      Comment


      • #4
        A prefix should never end with : The semicolon simply is the separation between prefix and localname. Together they make up the qualified name.

        Comment


        • #5
          Arjen, I realize that ":" is just the separation between prefix and localname. Perhaps I didnt clearly explain what I am doing.
          Here is my code:

          Code:
          private static final String NAMESPACE ="http.../tst";
          private static final String PREFIX = "tst";
          
          Element element = doc.createElementNS(NAMESPACE, "Element");
          element.setPrefix(PREFIX);
          responseElement.appendChild(element);
          		
          Element idElement = doc.createElementNS(NAMESPACE, PREFIX + ":" + "id");
          idElement.appendChild(doc.createTextNode(getId()));
          element.appendChild(idElement);
          ....
          When tracing, I can see that both elements have the prefix set properly, but already in the SoapEndpointIntercoptor's handleResponse, those elements are missing the prefix. So somehow, somewhere soap's parser removes this prefix, but I really need it to be there.

          Hope its a little clearer whats happening.
          And thanks again for your help.

          P

          Comment


          • #6
            Can you dump the entire SOAP message using the SoapEnvelopeLoggingInterceptor? Or - even beter - write the entire message using writeTo(). That gives me somewhat more info.

            The fact that a prefix is not there in the payload does not necessarily mean that it isn't there in the message, that's why I ask...

            Comment


            • #7
              Hi Arjen,

              Here is the entire message written using writeTo() (from inside my Interceptor's handleResponse()):

              Code:
              <?xml version='1.0' encoding='utf-8'?>
              <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
              <soapenv:Header>
              <msdwHdr:ServiceID copyToResponse="1" xmlns:msdwHdr="http://xml.msdw.com/ns/appmw/soap/1.0/header"/>
              <msdwHdr:RequestID copyToResponse="1" xmlns:msdwHdr="http://xml.msdw.com/ns/appmw/soap/1.0/header"/>
              </soapenv:Header>
              <soapenv:Body>
              <GetElements>
              <GetElementsResponse>
              <Element>
              <id>1</id>
              <name>ap</name>
              <description>ap</description>
              <owner>bob</owner>
              <coordinator></coordinator>
              </Element>
              </GetElementsResponse>
              </GetElements>
              </soapenv:Body>
              </soapenv:Envelope>

              As you can see, the prefixes are not there ....

              Thanks,
              P

              Comment


              • #8
                That is very weird, and I'm running out of ideas. You could try upgrading to Xerces 2.8.0, instead of using the Xerces built in to your JDK. Which JDK are you using BTW?

                Comment


                • #9
                  Arjen, thanks for your help.
                  Switching to Xerces 2.8.0 did solve the problem!

                  P

                  Comment

                  Working...
                  X