Author: seanoc
Date: Fri Jan 23 06:40:09 2009
New Revision: 737032
URL: http://svn.apache.org/viewvc?rev=737032&view=rev
Log:
CXF-1955 WHICH_JARS text file does not mention commons-collections.jar
CXF-1981 Inconsistent use of logger delegation via LogUtils.
Removed use of DOM from PrettyLoggingOutInterceptor, added test.
Added:
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java
cxf/trunk/distribution/src/main/release/lib/WHICH_JARS
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java?rev=737032&r1=737031&r2=737032&view=diff
==============================================================================
---
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java
(original)
+++
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/AbstractDelegatingLogger.java
Fri Jan 23 06:40:09 2009
@@ -45,7 +45,7 @@
public void log(LogRecord record) {
if (isLoggable(record.getLevel())) {
- internalLog(record);
+ doLog(record);
}
}
Modified: cxf/trunk/distribution/src/main/release/lib/WHICH_JARS
URL:
http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/lib/WHICH_JARS?rev=737032&r1=737031&r2=737032&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/lib/WHICH_JARS (original)
+++ cxf/trunk/distribution/src/main/release/lib/WHICH_JARS Fri Jan 23 06:40:09
2009
@@ -29,7 +29,8 @@
- The above jars
- jaxb-xjc.jar
- velocity.jar
-- velocity-dep.jar
+- commons-collections.jar
+- commons-lang.jar
For JAX-WS support:
- geronimo-ws-metadata.jar [6]
Modified:
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=737032&r1=737031&r2=737032&view=diff
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
(original)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptor.java
Fri Jan 23 06:40:09 2009
@@ -19,11 +19,20 @@
package org.apache.cxf.interceptor;
+
import java.io.OutputStream;
-import java.io.StringWriter;
+import java.io.PrintWriter;
+
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.w3c.dom.DOMConfiguration;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSParser;
+import org.w3c.dom.ls.LSSerializer;
+
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.io.CacheAndWriteOutputStream;
import org.apache.cxf.io.CachedOutputStream;
@@ -31,10 +40,7 @@
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;
+
/**
*
@@ -42,13 +48,13 @@
public class PrettyLoggingOutInterceptor extends AbstractPhaseInterceptor {
private static final Logger LOG =
LogUtils.getL7dLogger(PrettyLoggingOutInterceptor.class);
+ private PrintWriter writer;
- private SAXBuilder saxBuilder = new SAXBuilder();
- private XMLOutputter xmlOutputter = new XMLOutputter();
- public PrettyLoggingOutInterceptor() {
+ public PrettyLoggingOutInterceptor(PrintWriter w) {
super(Phase.PRE_STREAM);
addBefore(StaxOutInterceptor.class.getName());
+ writer = w;
}
public void handleMessage(Message message) throws Fault {
@@ -66,23 +72,40 @@
newOut.registerCallback(new LoggingCallback());
}
- class LoggingCallback implements CachedOutputStreamCallback {
+ public 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());
+ DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
+ DOMImplementationLS domLS = (DOMImplementationLS)
registry.getDOMImplementation("LS");
+ LSParser lsParser =
domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
+
+ LSInput lsInput = domLS.createLSInput();
+ lsInput.setByteStream(cos.getInputStream());
+ org.w3c.dom.Document doc = lsParser.parse(lsInput);
+
+ LSSerializer lsSerializer = domLS.createLSSerializer();
+ DOMConfiguration config = lsSerializer.getDomConfig();
+ config.setParameter("format-pretty-print", true);
+
+ String prettyStr =
lsSerializer.writeToString(doc.getDocumentElement());
+ if (writer != null) {
+ writer.println(prettyStr);
+ writer.close();
+ } else if (LOG.isLoggable(Level.INFO)) {
+ System.out.println("writer is null " + prettyStr);
+ LOG.info(prettyStr);
+ }
+
} catch (Exception e) {
- LOG.severe("fatal parsing the SOAP message " + e.getMessage());
+ e.printStackTrace();
}
+
}
}
}
\ No newline at end of file
Added:
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java?rev=737032&view=auto
==============================================================================
---
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java
(added)
+++
cxf/trunk/rt/core/src/test/java/org/apache/cxf/interceptor/PrettyLoggingOutInterceptorTest.java
Fri Jan 23 06:40:09 2009
@@ -0,0 +1,56 @@
+/**
+ * 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.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
+import org.apache.cxf.io.CachedOutputStream;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrettyLoggingOutInterceptorTest extends Assert {
+
+
+
+ @Test
+ public void testFormatting() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintWriter pw = new PrintWriter(baos);
+
+ PrettyLoggingOutInterceptor p = new PrettyLoggingOutInterceptor(pw);
+ PrettyLoggingOutInterceptor.LoggingCallback l = p.new
LoggingCallback();
+ CachedOutputStream cos = new CachedOutputStream();
+
+ String s = "<today><is><the><twenty> <second> <of> <january> <two>
<thousand> <and> <nine></nine> "
+ +
"</and></thousand></two></january></of></second></twenty></the></is></today>";
+ cos.getOut().write(s.getBytes());
+ l.onClose(cos);
+ String str = baos.toString();
+ //format has changed
+ assertFalse(str.matches(s));
+ assertTrue(str.contains("<today>"));
+
+ }
+
+
+
+}