Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sign soap header with handler in WebSphere 6.1

 
Sebastian Martin de la Torre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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() + " :\r\n");
logStr.append(strSOAPEnvelope);
logStr.append("\r\n");
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() + " :\r\n");
logStr.append(strSOAPEnvelopeAfter);
logStr.append("\r\n");
logMessage(context, logStr.toString(), System.out);
return true;
} catch (Exception e) {
logger.error(e);
return false;
}
}
}
 
Sebastian Martin de la Torre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want a soap message like that:

<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<ds:Reference URI="#MsgBody">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" />
</ds:Transforms>
<dsigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsigestValue>XXX</dsigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
XXX
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
XXXX
</ds:X509Certificate>
</ds:X509Data>
<ds:KeyValue>
<ds:RSAKeyValue>
<ds:Modulus>
XXXX
</ds:Modulus>
<ds:Exponent>AQAB</ds:Exponent>
</ds:RSAKeyValue>
</ds:KeyValue>
</ds:KeyInfo>
</ds:Signature>

</soapenv:Header>
<soapenv:Body Id="MsgBody">
<Respuesta xmlns="XXX">
<Atributos>
<IdPeticion>1</IdPeticion>
</Atributos>
</Respuesta>
</soapenv:Body>
</soapenv:Envelope>
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic