Results 1 to 9 of 9

Thread: How to attach a prefix to an element (AbstractDomPayloadEndpoint)

  1. #1
    Join Date
    Jul 2006
    Posts
    10

    Default 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. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    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.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  3. #3
    Join Date
    Jul 2006
    Posts
    10

    Default

    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

  4. #4
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

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

    Spring Web Services Dev Lead
    Please read the FAQ

  5. #5
    Join Date
    Jul 2006
    Posts
    10

    Default

    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

  6. #6
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    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...
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  7. #7
    Join Date
    Jul 2006
    Posts
    10

    Unhappy

    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

  8. #8
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    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?
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  9. #9
    Join Date
    Jul 2006
    Posts
    10

    Default

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

    P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •