cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Davide Gesino (JIRA)" <j...@apache.org>
Subject [jira] Created: (CXF-1327) Logging Interceptor with pretty formatting
Date Fri, 21 Dec 2007 13:51:43 GMT
Logging Interceptor with pretty formatting
------------------------------------------

                 Key: CXF-1327
                 URL: https://issues.apache.org/jira/browse/CXF-1327
             Project: CXF
          Issue Type: Wish
          Components: Tooling
            Reporter: Davide Gesino
            Priority: Trivial


LoggingInIterceptor and LoggingOutInterceptor are really useful, but sometimes it is difficult
to read the SOAP messages without having a "pretty" identation, I would a LOG that  outputs
a nice formatted string with XML identation.
Modifying the LoggingOutInterceptor something similar to the example I paste in the following,
obtained modifying the LoggingOutInterceptor.
I hav not included the length limit and used the jdom api instead of stax.
 :

public class PrettyLoggingOutInterceptor extends AbstractPhaseInterceptor {

	private final Log LOG = LogFactory
			.getLog(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.isInfoEnabled()) {
			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.error("fatal parsing the SOAP message");
				LOG.error(e);
			}
		}
	}
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message