2 Replies Latest reply on Sep 20, 2005 10:26 AM by Thomas Diesler

    logging SOAP message to log4J and not system.out

    Scott Jones Newbie

      I am having problems going from SOAPMessageContext

      to a string that I can pass to Log4J.

      I can send it to smc.writeTo(System.out) but I do not want it to System.out. All of our logging is done via Log4J

        • 1. Re: logging SOAP message to log4J and not system.out
          Scott Jones Newbie

          OK this is what I have working. Let me know if there is a better way

          private void logSoapMessage(MessageContext msgContext) {
           try {
           SOAPMessageContext smc = (SOAPMessageContext) msgContext;
           SOAPMessage message = smc.getMessage();
          
          
           //Set the output for the transformation
           StringWriter writer = new StringWriter();
          
           StreamResult result = new StreamResult(writer);
           TransformerFactory transformerFactory = TransformerFactory.newInstance();
           Transformer transformer = transformerFactory.newTransformer();
           transformer.transform(message.getSOAPPart().getContent(), result);
          
          
           log.info(writer.getBuffer());
          
          
           } catch (Exception e) {
           log.fatal("Exception caught in handler", e);
           throw new JAXRPCException(e.toString(), e);
          
           }
          
           }
          


          • 2. Re: logging SOAP message to log4J and not system.out
            Thomas Diesler Master

            What about

            baos = new ByteArrayOutputStream();
            SOAPMessage.writeTo(baos);
            log.debug(baos);
            


            But we log.debug() all incomming and outgoing messages anyway.