Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 80667 invoked from network); 21 Jan 2009 16:34:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Jan 2009 16:34:43 -0000 Received: (qmail 23249 invoked by uid 500); 21 Jan 2009 16:34:43 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 23193 invoked by uid 500); 21 Jan 2009 16:34:42 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 23184 invoked by uid 99); 21 Jan 2009 16:34:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jan 2009 08:34:42 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jan 2009 16:34:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 13DC92388A1E; Wed, 21 Jan 2009 08:34:19 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java Date: Wed, 21 Jan 2009 16:34:18 -0000 To: commits@cxf.apache.org From: seanoc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090121163419.13DC92388A1E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: seanoc Date: Wed Jan 21 08:34:17 2009 New Revision: 736332 URL: http://svn.apache.org/viewvc?rev=736332&view=rev Log: CXF-1327 Logging Interceptor with pretty formatting Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java Modified: cxf/trunk/rt/core/pom.xml Modified: cxf/trunk/rt/core/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/pom.xml?rev=736332&r1=736331&r2=736332&view=diff ============================================================================== --- cxf/trunk/rt/core/pom.xml (original) +++ cxf/trunk/rt/core/pom.xml Wed Jan 21 08:34:17 2009 @@ -77,6 +77,12 @@ FastInfoset 1.2.2 + + + jdom + jdom + 1.0 + Added: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java?rev=736332&view=auto ============================================================================== --- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java (added) +++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java Wed Jan 21 08:34:17 2009 @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.interceptor; + +import java.io.OutputStream; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.io.CacheAndWriteOutputStream; +import org.apache.cxf.io.CachedOutputStream; +import org.apache.cxf.io.CachedOutputStreamCallback; +import org.apache.cxf.message.Message; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; +import org.jdom.Document; +import org.jdom.input.SAXBuilder; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +/** + * + */ +public class PrettyLoggingOutInterceptor extends AbstractPhaseInterceptor { + + private static final Logger LOG = LogUtils.getL7dLogger(PrettyLoggingOutInterceptor.class); + + private SAXBuilder saxBuilder = new SAXBuilder(); + private XMLOutputter xmlOutputter = new XMLOutputter(); + + public PrettyLoggingOutInterceptor() { + super(Phase.PRE_STREAM); + addBefore(StaxOutInterceptor.class.getName()); + } + + public void handleMessage(Message message) throws Fault { + final OutputStream os = message.getContent(OutputStream.class); + if (os == null) { + return; + } + if (!LOG.isLoggable(Level.ALL)) { + return; + } + +// Write the output while caching it for the log message + final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os); + message.setContent(OutputStream.class, newOut); + newOut.registerCallback(new LoggingCallback()); + } + + class LoggingCallback implements CachedOutputStreamCallback { + + public void onFlush(CachedOutputStream cos) { + + } + + public void onClose(CachedOutputStream cos) { + + try { + Document jdoCument = saxBuilder.build(cos.getInputStream()); + xmlOutputter.setFormat(Format.getPrettyFormat()); + StringWriter writer = new StringWriter(); + xmlOutputter.output(jdoCument, writer); + LOG.info(writer.getBuffer().toString()); + } catch (Exception e) { + LOG.severe("fatal parsing the SOAP message " + e.getMessage()); + } + } + } +} \ No newline at end of file