Return-Path: Delivered-To: apmail-cxf-dev-archive@www.apache.org Received: (qmail 12212 invoked from network); 22 Jan 2009 10:52:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Jan 2009 10:52:50 -0000 Received: (qmail 30571 invoked by uid 500); 22 Jan 2009 10:52:49 -0000 Delivered-To: apmail-cxf-dev-archive@cxf.apache.org Received: (qmail 30532 invoked by uid 500); 22 Jan 2009 10:52:49 -0000 Mailing-List: contact dev-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 dev@cxf.apache.org Received: (qmail 30521 invoked by uid 99); 22 Jan 2009 10:52:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jan 2009 02:52:49 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [192.77.186.17] (HELO mx3.progress.com) (192.77.186.17) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jan 2009 10:52:38 +0000 Received: from mx3.progress.com (127.0.0.1) by mx3.progress.com (MlfMTA v3.2r9) id hf17vc0171sg for ; Thu, 22 Jan 2009 05:52:07 -0500 (envelope-from ) Received: from progress.com ([192.233.92.16]) by mx3.progress.com (SonicWALL 6.2.2.1073) with ESMTP; Thu, 22 Jan 2009 05:52:00 -0500 Received: from NTEXFE02.bedford.progress.com (ntexfe02 [10.128.10.26]) by progress.com (8.13.8/8.13.8) with ESMTP id n0MAq0Fi015178 for ; Thu, 22 Jan 2009 05:52:00 -0500 (EST) Received: from MAIL02.bedford.progress.com ([172.16.2.55]) by NTEXFE02.bedford.progress.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 22 Jan 2009 05:52:00 -0500 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java Date: Thu, 22 Jan 2009 05:51:57 -0500 Message-ID: In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java Thread-Index: Acl8Bvojrxfx2nN3RSum1MQwQ7hJ3AAeGWSg References: <20090121163419.13DC92388A1E@eris.apache.org> <200901211355.04319.dkulp@apache.org> From: "Sean O'Callaghan" To: X-OriginalArrivalTime: 22 Jan 2009 10:52:00.0054 (UTC) FILETIME=[73B28560:01C97C7F] X-Mlf-Version: 6.2.2.1073 X-Mlf-UniqueId: o200901221052000247325 X-Virus-Checked: Checked by ClamAV on apache.org Thanks for that David. Se=E1n. -----Original Message----- From: David Bosschaert [mailto:david.bosschaert@gmail.com]=20 Sent: 21 January 2009 20:28 To: dev@cxf.apache.org Subject: Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml = src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java= You should be able to do something similar with an Dom Level 3 LSSerializer that comes with the JRE. This also has a pretty print function. The code needed would roughly look something like this: DOMImplementationRegistry registry =3D = DOMImplementationRegistry.newInstance(); DOMImplementationLS domLS =3D (DOMImplementationLS) registry.getDOMImplementation("LS"); LSParser lsParser =3D domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); LSInput lsInput =3D domLS.createLSInput(); lsInput.setButeStream(cos.getInputStream()); org.w3c.dom.Document doc =3D lsParser.parse(lsInput); LSSerializer lsSerializer =3D domLS.createLSSerializer(); DOMConfiguration config =3D lsSerializer.getDomConfig(); config.setParameter("format-pretty-print", true); =09 lsSerializer.writeToString(doc.getDocumentElement()); Cheers, David 2009/1/21 Daniel Kulp : > > Is there a way to get this done without introducing the JDOM = dependency? > Benson just spent a lot of work to remove the jdom dependency = throughout the > code and this just adds it back in. > > Dan > > > On Wednesday 21 January 2009 11:34:18 am seanoc@apache.org wrote: >> Author: seanoc >> Date: Wed Jan 21 08:34:17 2009 >> New Revision: 736332 >> >> URL: http://svn.apache.org/viewvc?rev=3D736332&view=3Drev >> Log: >> CXF-1327 Logging Interceptor with pretty formatting >> >> Added: >> >> = cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingO= ut >>Interceptor.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=3D736332&r1=3D= 736331 >>&r2=3D736332&view=3Ddiff >> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= >>=3D=3D=3D --- 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/PrettyLoggingO= ut >>Interceptor.java URL: >> = http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/c= xf >>/interceptor/PrettyLoggingOutInterceptor.java?rev=3D736332&view=3Dauto >> = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= >>=3D=3D=3D --- >> = cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingO= ut >>Interceptor.java (added) +++ >> = cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingO= ut >>Interceptor.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 =3D >> LogUtils.getL7dLogger(PrettyLoggingOutInterceptor.class); + >> + private SAXBuilder saxBuilder =3D new SAXBuilder(); >> + private XMLOutputter xmlOutputter =3D new XMLOutputter(); >> + >> + public PrettyLoggingOutInterceptor() { >> + super(Phase.PRE_STREAM); >> + addBefore(StaxOutInterceptor.class.getName()); >> + } >> + >> + public void handleMessage(Message message) throws Fault { >> + final OutputStream os =3D = message.getContent(OutputStream.class); >> + if (os =3D=3D null) { >> + return; >> + } >> + if (!LOG.isLoggable(Level.ALL)) { >> + return; >> + } >> + >> +// Write the output while caching it for the log message >> + final CacheAndWriteOutputStream newOut =3D 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 =3D >> saxBuilder.build(cos.getInputStream()); + >> xmlOutputter.setFormat(Format.getPrettyFormat()); + >> StringWriter writer =3D 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 > > > > -- > Daniel Kulp > dkulp@apache.org > http://dankulp.com/blog >