dcsimg
Sign soap header with handler in WebSphere 6.1
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, August 4, 2011 09:15 AM

Posts: 2 [Post New]posted Today 13:20:49 Quote Edit Hi, I need to sign an soap message with a handler in WebSphere. The webservices were build with JAX-RPC, anyone can help me. I want to sign the response in the method handleResponse, anyone can write me an example code? This is my handler: public class ServerPeticionSincronaHandler extends GenericHandler { static private Log4SMLogger logger = Log4SMLogger.getLogger(ServerPeticionSincronaHandler.class); private HandlerInfo hi; public ServerPeticionSincronaHandler() { } public void init(HandlerInfo info) {    More>>

Posts: 2

[Post New]posted Today 13:20:49
Quote Edit

Hi,



I need to sign an soap message with a handler in WebSphere. The webservices were build with JAX-RPC, anyone can help me.
I want to sign the response in the method handleResponse, anyone can write me an example code?


This is my handler:


public class ServerPeticionSincronaHandler extends GenericHandler {


static private Log4SMLogger logger = Log4SMLogger.getLogger(ServerPeticionSincronaHandler.class);
private HandlerInfo hi;


public ServerPeticionSincronaHandler() {

}



public void init(HandlerInfo info) {

hi = info;

}



public QName[] getHeaders() {

return hi.getHeaders();

}



public boolean handleRequest(MessageContext context) {

logger.info("ServerHandler: In handleRequest");

logMessage(context, "REQUEST : ", System.out);



try {

// Decompse the SOAP message
SOAPMessageContext smc = (SOAPMessageContext) context;

SOAPMessage msg = smc.getMessage();

SOAPPart sp = msg.getSOAPPart();

SOAPEnvelope se = sp.getEnvelope();

String strSOAPEnvelope = se.toString();

SOAPHeader sh = se.getHeader();

// If there are SOAP Headers, write them to the console

if (sh != null) {

Iterator headers = sh.examineAllHeaderElements();

while (headers.hasNext()) {

SOAPHeaderElement he = (SOAPHeaderElement) headers.next();

logger.info("header element name is " + he.getElementName().getQualifiedName());

logger.info("header element value is " + he.getValue());

}

}

// Log the SOAP Request into a file

StringBuffer logStr = new StringBuffer();

logStr.append("SOAP Request: " + new Date().toString() + " :
");

logStr.append(strSOAPEnvelope);

logStr.append("
");

logMessage(context, logStr.toString(), System.out);

return true;

} catch (Exception e) {

logger.error(e);

return false;

}





}



public boolean handleResponse(MessageContext context) {

logger.info("ServerHandler: In handleResponse");

logMessage(context, "RESPONSE: ", System.out);

logger.info("Entered LogHandlerWithHeaders handleResponse ...");

try {

SOAPMessageContext msgContext = (SOAPMessageContext) context;

SOAPMessage msg = msgContext.getMessage();

SOAPPart sp = msg.getSOAPPart();

SOAPEnvelope se = sp.getEnvelope();

// String strSOAPEnvelope = se.toString();

SOAPHeader sh = se.getHeader();

// Test to see if there is any SOAP Headers, if not add one
if (sh == null) {

sh = se.addHeader();



}

// Add name/value pair to the SOAP Header


// Get the modified SOAP Enveloper

SOAPEnvelope seAfter = sp.getEnvelope();

String strSOAPEnvelopeAfter = seAfter.toString();

// Output the SOAP response to a file

StringBuffer logStr = new StringBuffer();

logStr.append("SOAP Response: " + new Date().toString() + " :
");

logStr.append(strSOAPEnvelopeAfter);

logStr.append("
");

logMessage(context, logStr.toString(), System.out);

return true;
} catch (Exception e) {
logger.error(e);

return false;

}

}

}






I want a soap message like that:



<?xml version='1.0' encoding='utf-8'?>











XXX



XXX




XXXX





XXXX

AQAB









1



   <<Less
About | Sitemap | Contact