Velocity Reviews

Velocity Reviews (
-   Java (
-   -   How to add a ResponseHeader using Axis? ( 07-23-2005 05:35 PM

How to add a ResponseHeader using Axis?
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
Thank you. 07-23-2005 07:28 PM

Re: How to add a ResponseHeader using Axis?
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

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
//Add header to the SOAP message if it does not exist
String soap_header = "";
// Initialize the library - this is now done inside servlet

/******************* 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,
//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( ));
//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
headerElement = (Element)nodes.item(0);

... sign the Doc

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

iksrazal 07-25-2005 03:06 PM

Re: How to add a ResponseHeader using Axis?
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

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

SOAPHeaderElement header = new SOAPHeaderElement("",
"TestMsgHeader", new TestCustomMsgHeader());

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.

All times are GMT. The time now is 11:34 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.