How to add a ResponseHeader using Axis?

Discussion in 'Java' started by stacnebben@hotmail.com, Jul 23, 2005.

  1. Guest

    I am able to set my RequestHeader using the Axis API, but have not
    found a way to set the ResponseHeader. Has anyone else had this issue,
    source code on how to set the ResponseHeader would be greatly
    appreciate.
    Thank you.
    , Jul 23, 2005
    #1
    1. Advertising

  2. Guest

    Not sure how you are setting the request header, as they can be
    manipulated on both the client and server side. I haven't used axis 1.2
    yet, however. The way I do it, for xml encryption and digital
    signatures, is via the javax.xml.rpc.handler.Handler interface and the
    javax.xml.rpc.handler.MessageContext class. In your case, you would
    implement:

    handleResponse(MessageContext context)

    And via the message context convert the message to a Document. Plenty
    of examples out there. Then, you would call a method such as:

    public static boolean sign(Document doc, X509Certificate cert,
    PrivateKey privateKey, boolean debug) throws WSSecurityException
    {
    try
    {
    //Add header to the SOAP message if it does not exist
    String soap_header = "http://schemas.xmlsoap.org/soap/envelope/";
    // Initialize the library - this is now done inside servlet
    WSSInit
    org.apache.xml.security.Init.init();

    /******************* XML SIGNATURE INIT ***********************
    Append the signature element to proper location before signing
    ***************************************************************/
    // Look for the SOAP header
    Element headerElement = null;
    NodeList nodes = doc.getElementsByTagNameNS (soap_header,
    "Header");
    //No nodes are expected to be found (length of zero) - add
    //header here.
    if(nodes.getLength() == 0)
    {
    headerElement = doc.createElementNS (soap_header, "Header");
    nodes = doc.getElementsByTagNameNS (soap_header, "Envelope");
    if(nodes != null)
    {
    Element envelopeElement = (Element)nodes.item(0);
    headerElement.setPrefix(envelopeElement.getPrefix());
    envelopeElement.appendChild(headerElement);
    }
    }
    else
    {
    //This shouldn't happen unless explicity done elsewhere
    Fwlog.debug(SecurityHelper.class, Fwlog.WI, "Unexpectedly Found
    " + nodes.getLength() + " SOAP Header elements... probably ok but not
    tested");
    headerElement = (Element)nodes.item(0);
    }

    ... sign the Doc
    }

    This method, as I use it, is called by both client side and server side
    handlers.

    HTH,
    iksrazal
    http://www.braziloutsource.com/
    , Jul 23, 2005
    #2
    1. Advertising

  3. Guest

    Thank you for the response. I probably should have included how I am
    setting the requestHeader (client side). I want the response message
    (server) to have a similar custom SOAPHeader element. Most of the
    classes used below were auto generated using the Axis WSDL2Java
    utility.

    Test service = new TestLocator();
    ((TestLocator)service).setTestSoapEndpointAddress(endpointURL);
    TestSoap_PortType port = service.getTestSoap();

    SOAPHeaderElement header = new SOAPHeaderElement("http://www.test.org",
    "TestMsgHeader", new TestCustomMsgHeader());
    ((TestSoap_BindingStub)port).setHeader(header);


    I was hoping there was something similar to this that would allow me to
    set the ResponseHeader message.
    Thank you again for any thoughts/comments/code.
    , Jul 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joey Vendetta
    Replies:
    0
    Views:
    3,422
    Joey Vendetta
    Apr 1, 2004
  2. Stefan
    Replies:
    0
    Views:
    707
    Stefan
    May 6, 2004
  3. Replies:
    0
    Views:
    874
  4. hocho888
    Replies:
    1
    Views:
    601
  5. ed
    Replies:
    2
    Views:
    410
    Mike Schilling
    Dec 8, 2006
Loading...

Share This Page