Showing posts with label soap. Show all posts
Showing posts with label soap. Show all posts

Monday, April 27, 2015

How to log outgoing/incoming SOAP Requests in Websphere? (61 of 285 technotes for 2015)

Trace for SOAP WS messages can be enabled by following these steps on Websphere 7 administration console:

  • Go to administration console
  • Go to: Servers -> WebSphere application servers -> server > Change Log Detail Levels
  • In the package tree find the package com.ibm.ws.websvcs.trace, click on package name and choose ‘All Mesasges and Traces’, as result you should have log details set as below:

*=info: com.ibm.ws.websvcs.trace.*=all

  • Click on 'OK’ and then Save the changes.

SOAP request/responses can now be found in trace.log on your appl. server.



References: http://bit.ly/1J4dSy5

Pretty printing SOAP messages. (60 of 285 technotes for 2015)

Handy Java code to print SOAPMessages

References: - http://bit.ly/1dkVWoW


public static String getSOAPMessageAsString(SOAPMessage soapMessage) {
     try {

        TransformerFactory tff = TransformerFactory.newInstance();
        Transformer tf = tff.newTransformer();

        // Set formatting
       
        tf.setOutputProperty(OutputKeys.INDENT, "yes");
        tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
              "2");
       

        Source sc = soapMessage.getSOAPPart().getContent();

        ByteArrayOutputStream streamOut = new ByteArrayOutputStream();
        StreamResult result = new StreamResult(streamOut);
        tf.transform(sc, result);

        String strMessage = streamOut.toString();
        return strMessage;
     } catch (Exception e) {
        System.out.println("Exception in getSOAPMessageAsString "
              + e.getMessage());
        return null;
     }

  }