Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Interception of SOAP message with SOAPHandler  RSS feed

 
Joseph Hwang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to intercept and examine the whole SOAP xml message. This is my SOAPHandler class ;

public class SOAPMessageHandler implements SOAPHandler<SOAPMessageContext> {

@Override
public void close(MessageContext context) {
// TODO Auto-generated method stub
}

@Override
public boolean handleFault(SOAPMessageContext context) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean handleMessage(SOAPMessageContext context) {
// TODO Auto-generated method stub
System.out.println("Server : handleMessage()......");

Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if(!isRequest){

try{
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
SOAPBody soapBody = soapEnv.getBody();

System.out.println(soapHeader.toString());
System.out.println(soapBody.toString());
}
catch(Exception e) {
e.printStackTrace();
}
}
return true;
}

@Override
public Set<QName> getHeaders() {
// TODO Auto-generated method stub
return null;
}
}

But the whole soap xml message are not printed. Console shows ony these messages

20:48:04,217 INFO [stdout] (default task-8) Server : handleMessage()......
20:48:04,217 INFO [stdout] (default task-8) [soap:Header: null]
20:48:04,217 INFO [stdout] (default task-8) [soap:Body: null]

How can i get the whole SOAP xml message in SOAPHandler class?
I need your help! Thanks.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The toString method doesn't generally return interesting information.

You can use SOAPMessage.writeTo to write the XML to some output stream, maybe a ByteArrayOutputStream if you want to process it further in memory.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!