Results 1 to 8 of 8

Thread: how to create child elements for SoapHeaderElement?

  1. #1
    Join Date
    May 2007
    Posts
    1

    Default how to create child elements for SoapHeaderElement?

    HI,
    I need to add some WS-Addressing headers into response message. I have created implementation class for SoapEndpointInterceptor interface. I know that I can add header elements to soap message like this:
    Code:
    public boolean handleResponse(MessageContext ctx, Object arg1)
    			throws Exception {
    
    QName qName= new QName("http://something", "blaa", "blaah");
    SoapMessage message=(SoapMessage)ctx.getResponse();
    SoapHeader header = message.getSoapHeader();
    SoapHeaderElement headerElement=header.addHeaderElement(qName);
    But is it possible to add child element for SoapHeaderElement ?
    What i am trying to do here is to add Addressing headers like this to soap message:

    Code:
    <wsa:From>
           <wsa:Address>myAdress</wsa:Address>
    </wsa:From>

  2. #2
    Join Date
    Feb 2005
    Posts
    47

    Default

    Did anyone some up with a solution for this?

    /Magnus

  3. #3
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    37

    Default

    If the message is an instance of SaajSoapMessage you can do the following:

    Code:
    SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
    SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
    You then have an instance of javax.xml.soap.SOAPMessage that you can manipulate however you want.

  4. #4
    Join Date
    Feb 2005
    Posts
    47

    Default

    Yes, but the main reason that I want to use spring-ws is to use the abstraction and be able to switch between axiom and saaj.


    SoapHeaderElement fromHeader = header.addHeaderElement(new QName(URI_NS_WSA_1_1, "from", "wsa"));

    SoapHeaderElement adressHeader = header.addHeaderElement(new QName(URI_NS_WSA_1_1, "adress", "wsa"));
    adressHeader.setText("Magnus Heino");

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(adressHeader.getSource(), fromHeader.getResult());

    Now I get close, but not correct.

    <wsa:from xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsa:adress>Magnus Heino</wsa:adress>
    </wsa:from>
    <wsa:adress xmlns:wsa="http://www.w3.org/2005/08/addressing">Magnus Heino</wsa:adress>

    Because there is no factory for SoapHeaderElements, I get that duplicate entry... :-P

  5. #5
    Join Date
    Feb 2005
    Posts
    47

    Default

    Uhm.. this works.. but...

    SoapHeaderElement fromHeader = header.addHeaderElement(new QName(URI_NS_WSA_1_1, "from", "wsa"));

    SoapHeader headerFactory = ((SoapMessage) soapMessageFactory.createWebServiceMessage()).getS oapHeader();
    SoapHeaderElement adressHeader = headerFactory.addHeaderElement(new QName(URI_NS_WSA_1_1, "adress", "wsa"));
    adressHeader.setText("Magnus Heino");

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(adressHeader.getSource(), fromHeader.getResult());




    <wsa:from xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsa:adress>Magnus Heino</wsa:adress>
    </wsa:from>

  6. #6
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    37

    Default

    Heh... nice

  7. #7

    Default Reading Child Element of SOAP header

    Hi,

    I got a similar problem. I want to read the Address element which is child of the From element.
    Why does SoapHeaderElement not simply contain a getChildElements() method? What would be the best way to get the child Element. Do I need to create a transformer also for reading?

    Thanks,

    Tobias

  8. #8
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    Comment #6 of my web service notes here might help you:
    http://www.jroller.com/gmazza/date/20071102#NWSNotes

Posting Permissions

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