Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How to add a ResponseHeader using Axis? (http://www.velocityreviews.com/forums/t145054-how-to-add-a-responseheader-using-axis.html)

stacnebben@hotmail.com 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
appreciate.
Thank you.


iksrazal@terra.com.br 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
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/


stacnebben@hotmail.com 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
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.



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.