You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Daniel Kulp <dk...@apache.org> on 2009/01/21 19:55:04 UTC

Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java

 
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=736332&view=rev
> Log:
> CXF-1327 Logging Interceptor with pretty formatting
>
> Added:
>    
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>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=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 @@
>           <artifactId>FastInfoset</artifactId>
>           <version>1.2.2</version>
>          </dependency>
> +
> +       <dependency>
> +         <groupId>jdom</groupId>
> +         <artifactId>jdom</artifactId>
> +         <version>1.0</version>
> +        </dependency>
>
>      </dependencies>
>
>
> Added:
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>Interceptor.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/PrettyLoggingOut
>Interceptor.java (added) +++
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>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 =
> 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



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

RE: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java

Posted by Sean O'Callaghan <SE...@progress.com>.
Thanks for that David.

Seán.


-----Original Message-----
From: David Bosschaert [mailto:david.bosschaert@gmail.com] 
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 = DOMImplementationRegistry.newInstance();
  DOMImplementationLS domLS = (DOMImplementationLS)
registry.getDOMImplementation("LS");
  LSParser lsParser =
domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

  LSInput lsInput = domLS.createLSInput();
  lsInput.setButeStream(cos.getInputStream());
  org.w3c.dom.Document doc = lsParser.parse(lsInput);

  LSSerializer lsSerializer = domLS.createLSSerializer();
  DOMConfiguration config = lsSerializer.getDomConfig();
  config.setParameter("format-pretty-print", true);
        	
  lsSerializer.writeToString(doc.getDocumentElement());

Cheers,

David

2009/1/21 Daniel Kulp <dk...@apache.org>:
>
> 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=736332&view=rev
>> Log:
>> CXF-1327 Logging Interceptor with pretty formatting
>>
>> Added:
>>
>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>>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=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 @@
>>           <artifactId>FastInfoset</artifactId>
>>           <version>1.2.2</version>
>>          </dependency>
>> +
>> +       <dependency>
>> +         <groupId>jdom</groupId>
>> +         <artifactId>jdom</artifactId>
>> +         <version>1.0</version>
>> +        </dependency>
>>
>>      </dependencies>
>>
>>
>> Added:
>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>>Interceptor.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/PrettyLoggingOut
>>Interceptor.java (added) +++
>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>>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 =
>> 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
>
>
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: Managing large attachments

Posted by Sergey Beryozkin <se...@progress.com>.
That's really, really cool then...

Cheers, Sergey

----- Original Message ----- 
From: "Daniel Kulp" <dk...@apache.org>
To: <de...@cxf.apache.org>
Cc: "Sergey Beryozkin" <sb...@progress.com>
Sent: Thursday, January 22, 2009 5:08 PM
Subject: Re: Managing large attachments


> 
> That SHOULD be all that's needed.   The AttachmentInInterceptor stuff does all 
> the magic of buffering on disk if needed.
> 
> Dan
> 
> 
> On Wednesday 21 January 2009 4:50:39 pm Sergey Beryozkin wrote:
>> Hi
>>
>> I've done some initial work in CXF JAXRS for multipart/related requests
>> be supported. At the moment the JAXRS component relies on
>> AttachmentInInterceptor only, which makes it possible to get to all the
>> individual parts.
>>
>> It looks like that just relying on AttachmentInInterceptor alone can
>> suffice in cases when small to medium size attachments are involved.
>>
>> What else is needed for large attachments be handled efficiently ?
>> I'm a bit overwhelmed at the moment with all the info :-) so if someone
>> could provide some overview of how this is done in JAXWS then I'd
>> appreciate it... I remember seeing some discussions about temporarily
>> files, etc...
>>
>> Thanks, Sergey
> 
> 
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog

Re: Managing large attachments

Posted by Daniel Kulp <dk...@apache.org>.
That SHOULD be all that's needed.   The AttachmentInInterceptor stuff does all 
the magic of buffering on disk if needed.

Dan


On Wednesday 21 January 2009 4:50:39 pm Sergey Beryozkin wrote:
> Hi
>
> I've done some initial work in CXF JAXRS for multipart/related requests
> be supported. At the moment the JAXRS component relies on
> AttachmentInInterceptor only, which makes it possible to get to all the
> individual parts.
>
> It looks like that just relying on AttachmentInInterceptor alone can
> suffice in cases when small to medium size attachments are involved.
>
> What else is needed for large attachments be handled efficiently ?
> I'm a bit overwhelmed at the moment with all the info :-) so if someone
> could provide some overview of how this is done in JAXWS then I'd
> appreciate it... I remember seeing some discussions about temporarily
> files, etc...
>
> Thanks, Sergey



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Managing large attachments

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

I've done some initial work in CXF JAXRS for multipart/related requests
be supported. At the moment the JAXRS component relies on
AttachmentInInterceptor only, which makes it possible to get to all the
individual parts. 

It looks like that just relying on AttachmentInInterceptor alone can
suffice in cases when small to medium size attachments are involved.

What else is needed for large attachments be handled efficiently ?
I'm a bit overwhelmed at the moment with all the info :-) so if someone
could provide some overview of how this is done in JAXWS then I'd
appreciate it... I remember seeing some discussions about temporarily
files, etc...

Thanks, Sergey 

Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java

Posted by David Bosschaert <da...@gmail.com>.
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 = DOMImplementationRegistry.newInstance();
  DOMImplementationLS domLS = (DOMImplementationLS)
registry.getDOMImplementation("LS");
  LSParser lsParser =
domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

  LSInput lsInput = domLS.createLSInput();
  lsInput.setButeStream(cos.getInputStream());
  org.w3c.dom.Document doc = lsParser.parse(lsInput);

  LSSerializer lsSerializer = domLS.createLSSerializer();
  DOMConfiguration config = lsSerializer.getDomConfig();
  config.setParameter("format-pretty-print", true);
        	
  lsSerializer.writeToString(doc.getDocumentElement());

Cheers,

David

2009/1/21 Daniel Kulp <dk...@apache.org>:
>
> 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=736332&view=rev
>> Log:
>> CXF-1327 Logging Interceptor with pretty formatting
>>
>> Added:
>>
>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>>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=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 @@
>>           <artifactId>FastInfoset</artifactId>
>>           <version>1.2.2</version>
>>          </dependency>
>> +
>> +       <dependency>
>> +         <groupId>jdom</groupId>
>> +         <artifactId>jdom</artifactId>
>> +         <version>1.0</version>
>> +        </dependency>
>>
>>      </dependencies>
>>
>>
>> Added:
>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>>Interceptor.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/PrettyLoggingOut
>>Interceptor.java (added) +++
>> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>>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 =
>> 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
>
>
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java

Posted by David Bosschaert <da...@gmail.com>.
Well, JDom isn't a problem for Eclipse. Jaxen is the problem. Jaxen is
explicitly disapproved by the Eclipse legal guys.
When doing XPaths with JDom it uses Jaxen and that's where the problem
was before. Fortunately Benson fixed this up.
JDom on its own is not an issue for Eclipse.

Cheers,

David

2009/1/22 Daniel Kulp <dk...@apache.org>:
> On Thursday 22 January 2009 4:54:53 am Sean O'Callaghan wrote:
>> Probably is, was taking the patch submitted by the user.
>> I didn't realize there was an issue with using jdom, what is it?
>
> David knows the details.   Something about one of the JDOM dependencies being
> problematic for Eclipse or something.    In anycase, if there is stuff in the
> JDK that will do it, let's use it.
>
> Note: we also have a PrettyPrintXMLStreamWriter in org.apache.cxf.wsdl.  Could
> possibly be made more generic and put in staxutils someplace.
>
> Dan
>
>
>>
>> Seán.
>>
>> -----Original Message-----
>> From: Daniel Kulp [mailto:dkulp@apache.org]
>> Sent: 21 January 2009 18:55
>> To: dev@cxf.apache.org; seanoc@apache.org
>> Subject: Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml
>> src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
>>
>>
>>
>> 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=736332&view=rev
>> > 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=736332&r1=7363
>> >31 &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 @@
>> >           <artifactId>FastInfoset</artifactId>
>> >           <version>1.2.2</version>
>> >          </dependency>
>> > +
>> > +       <dependency>
>> > +         <groupId>jdom</groupId>
>> > +         <artifactId>jdom</artifactId>
>> > +         <version>1.0</version>
>> > +        </dependency>
>> >
>> >      </dependencies>
>> >
>> >
>> > 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=736332&view=auto
>> > =========================================================================
>> >== === ---
>> > 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 =
>> > 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
>
>
>
> --
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
>

Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java

Posted by Daniel Kulp <dk...@apache.org>.
On Thursday 22 January 2009 4:54:53 am Sean O'Callaghan wrote:
> Probably is, was taking the patch submitted by the user.
> I didn't realize there was an issue with using jdom, what is it?

David knows the details.   Something about one of the JDOM dependencies being 
problematic for Eclipse or something.    In anycase, if there is stuff in the 
JDK that will do it, let's use it.

Note: we also have a PrettyPrintXMLStreamWriter in org.apache.cxf.wsdl.  Could 
possibly be made more generic and put in staxutils someplace.

Dan


>
> Seán.
>
> -----Original Message-----
> From: Daniel Kulp [mailto:dkulp@apache.org]
> Sent: 21 January 2009 18:55
> To: dev@cxf.apache.org; seanoc@apache.org
> Subject: Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml
> src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
>
>
>
> 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=736332&view=rev
> > 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=736332&r1=7363
> >31 &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 @@
> >           <artifactId>FastInfoset</artifactId>
> >           <version>1.2.2</version>
> >          </dependency>
> > +
> > +       <dependency>
> > +         <groupId>jdom</groupId>
> > +         <artifactId>jdom</artifactId>
> > +         <version>1.0</version>
> > +        </dependency>
> >
> >      </dependencies>
> >
> >
> > 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=736332&view=auto
> > =========================================================================
> >== === ---
> > 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 =
> > 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



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

RE: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java

Posted by Sean O'Callaghan <SE...@progress.com>.
Probably is, was taking the patch submitted by the user.
I didn't realize there was an issue with using jdom, what is it?

Seán.

-----Original Message-----
From: Daniel Kulp [mailto:dkulp@apache.org] 
Sent: 21 January 2009 18:55
To: dev@cxf.apache.org; seanoc@apache.org
Subject: Re: svn commit: r736332 - in /cxf/trunk/rt/core: pom.xml src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java


 
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=736332&view=rev
> Log:
> CXF-1327 Logging Interceptor with pretty formatting
>
> Added:
>    
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>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=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 @@
>           <artifactId>FastInfoset</artifactId>
>           <version>1.2.2</version>
>          </dependency>
> +
> +       <dependency>
> +         <groupId>jdom</groupId>
> +         <artifactId>jdom</artifactId>
> +         <version>1.0</version>
> +        </dependency>
>
>      </dependencies>
>
>
> Added:
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>Interceptor.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/PrettyLoggingOut
>Interceptor.java (added) +++
> cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOut
>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 =
> 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



-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog