SOAP message handler for logging inbound SOAP results

I recently had the need to log the results of some calls to soap service my app was making. I attached the SimpleHandler to the xml.rpc.client.BasicService

public class SimpleHandler extends GenericHandler {
...
    @Override
    public boolean handleResponse(MessageContext context) {
        try {
            // get the soap header
            SOAPMessageContext smc = (SOAPMessageContext) context;
            SOAPMessage soapMessage = smc.getMessage();
            
            // Create transformer
            TransformerFactory tff = TransformerFactory.newInstance();
            Transformer tf = tff.newTransformer();
            
            // Get reply content
            Source sc = soapMessage.getSOAPPart().getContent();
            
            // Set output transformation
            ByteArrayOutputStream streamOut = new ByteArrayOutputStream();
            StreamResult result = new StreamResult(streamOut);
            tf.transform(sc, result);

            String strMessage = streamOut.toString();
            log.info("SOAP MESSAGE:\\n"+strMessage+"\\n");
        } catch (Exception e) {
            log.error("Exception in SimpleHander!");
            throw new JAXRPCException(e);
        }
        return true;
    }
...
}
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Randy Carver

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today