Author: ningjiang
Date: Mon Aug 2 14:06:52 2010
New Revision: 981514
URL: http://svn.apache.org/viewvc?rev=981514&view=rev
Log:
Merged revisions 981508 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r981508 | ningjiang | 2010-08-02 21:51:38 +0800 (Mon, 02 Aug 2010) | 1 line
CXF-2923 Logging{In|Out}Intererceptor should check the encoding before
writing the log
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 2 14:06:52 2010
@@ -1 +1 @@
-/cxf/trunk:980898-980941
+/cxf/trunk:980898-980941,981508
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=981514&r1=981513&r2=981514&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
(original)
+++
cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
Mon Aug 2 14:06:52 2010
@@ -279,7 +279,12 @@ public class CachedOutputStream extends
IOUtils.copyAndCloseInput(fin, out);
}
}
+
public void writeCacheTo(StringBuilder out, int limit) throws IOException {
+ writeCacheTo(out, "UTF-8", limit);
+ }
+
+ public void writeCacheTo(StringBuilder out, String charsetName, int limit)
throws IOException {
flush();
if (totalLength < limit
|| limit == -1) {
@@ -291,7 +296,7 @@ public class CachedOutputStream extends
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
byte bytes[] =
((ByteArrayOutputStream)currentStream).toByteArray();
- out.append(IOUtils.newStringFromBytes(bytes, 0, limit));
+ out.append(IOUtils.newStringFromBytes(bytes, charsetName, 0,
limit));
} else {
throw new IOException("Unknown format of currentStream");
}
@@ -304,7 +309,7 @@ public class CachedOutputStream extends
if ((count + x) > limit) {
x = limit - count;
}
- out.append(IOUtils.newStringFromBytes(bytes, 0, x));
+ out.append(IOUtils.newStringFromBytes(bytes, charsetName, 0,
x));
count += x;
if (count >= limit) {
@@ -316,12 +321,17 @@ public class CachedOutputStream extends
fin.close();
}
}
+
public void writeCacheTo(StringBuilder out) throws IOException {
+ writeCacheTo(out, "UTF-8");
+ }
+
+ public void writeCacheTo(StringBuilder out, String charsetName) throws
IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
byte[] bytes =
((ByteArrayOutputStream)currentStream).toByteArray();
- out.append(IOUtils.newStringFromBytes(bytes));
+ out.append(IOUtils.newStringFromBytes(bytes, charsetName));
} else {
throw new IOException("Unknown format of currentStream");
}
@@ -331,7 +341,7 @@ public class CachedOutputStream extends
byte bytes[] = new byte[1024];
int x = fin.read(bytes);
while (x != -1) {
- out.append(IOUtils.newStringFromBytes(bytes, 0, x));
+ out.append(IOUtils.newStringFromBytes(bytes, charsetName, 0,
x));
x = fin.read(bytes);
}
fin.close();
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=981514&r1=981513&r2=981514&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
Mon Aug 2 14:06:52 2010
@@ -38,38 +38,65 @@ public final class IOUtils {
}
/**
- * Use this function instead of new String(byte[]) to avoid surprises from
non-standard default encodings.
+ * Use this function instead of new String(byte[], String) to avoid
surprises from
+ * non-standard default encodings.
* @param bytes
+ * @param charsetName
* @return
*/
- public static String newStringFromBytes(byte[] bytes) {
+ public static String newStringFromBytes(byte[] bytes, String charsetName) {
try {
- return new String(bytes, UTF8_CHARSET.name());
+ return new String(bytes, charsetName);
} catch (UnsupportedEncodingException e) {
throw
- new RuntimeException("Impossible failure:
Charset.forName(\"utf-8\") returns invalid name.");
+ new RuntimeException("Impossible failure: Charset.forName(\""
+ + charsetName + "\") returns invalid
name.");
}
}
-
+
+
/**
- * Use this function instead of new String(byte[], int, int)
+ * Use this function instead of new String(byte[]) to avoid surprises from
non-standard default encodings.
+ * @param bytes
+ * @return
+ */
+ public static String newStringFromBytes(byte[] bytes) {
+ return newStringFromBytes(bytes, UTF8_CHARSET.name());
+ }
+
+ /**
+ * Use this function instead of new String(byte[], int, int, String)
* to avoid surprises from non-standard default encodings.
* @param bytes
+ * @param charsetName
* @param start
* @param length
* @return
*/
- public static String newStringFromBytes(byte[] bytes, int start, int
length) {
+ public static String newStringFromBytes(byte[] bytes, String charsetName,
int start, int length) {
try {
- return new String(bytes, start, length, UTF8_CHARSET.name());
+ return new String(bytes, start, length, charsetName);
} catch (UnsupportedEncodingException e) {
throw
- new RuntimeException("Impossible failure:
Charset.forName(\"utf-8\") returns invalid name.");
+ new RuntimeException("Impossible failure: Charset.forName(\""
+ + charsetName + "\") returns invalid
name.");
}
}
+ /**
+ * Use this function instead of new String(byte[], int, int)
+ * to avoid surprises from non-standard default encodings.
+ * @param bytes
+ * @param start
+ * @param length
+ * @return
+ */
+ public static String newStringFromBytes(byte[] bytes, int start, int
length) {
+ return newStringFromBytes(bytes, UTF8_CHARSET.name(), start, length);
+ }
+
public static int copy(final InputStream input, final OutputStream output)
throws IOException {
return copy(input, output, DEFAULT_BUFFER_SIZE);
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java?rev=981514&r1=981513&r2=981514&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
Mon Aug 2 14:06:52 2010
@@ -25,6 +25,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.message.Message;
@@ -150,7 +151,11 @@ public class LoggingInInterceptor extend
if (bos.size() > limit) {
buffer.getMessage().append("(message truncated to " +
limit + " bytes)\n");
}
- bos.writeCacheTo(buffer.getPayload(), limit);
+ if (StringUtils.isEmpty(encoding)) {
+ bos.writeCacheTo(buffer.getPayload(), limit);
+ } else {
+ bos.writeCacheTo(buffer.getPayload(), encoding, limit);
+ }
bos.close();
} catch (IOException e) {
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java?rev=981514&r1=981513&r2=981514&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
Mon Aug 2 14:06:52 2010
@@ -25,6 +25,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.io.CacheAndWriteOutputStream;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.io.CachedOutputStreamCallback;
@@ -159,7 +160,11 @@ public class LoggingOutInterceptor exten
}
}
try {
- cos.writeCacheTo(buffer.getPayload(), limit);
+ if (StringUtils.isEmpty(encoding)) {
+ cos.writeCacheTo(buffer.getPayload(), limit);
+ } else {
+ cos.writeCacheTo(buffer.getPayload(), encoding, limit);
+ }
} catch (Exception ex) {
//ignore
}