Author: ningjiang
Date: Wed Apr 28 09:30:44 2010
New Revision: 938837
URL: http://svn.apache.org/viewvc?rev=938837&view=rev
Log:
Merged revisions 938804 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r938804 | ningjiang | 2010-04-28 15:13:59 +0800 (Wed, 28 Apr 2010) | 1 line
CXF-2785 Base64Utils.decode should handle/wrap all exception types, applied
patch with thanks to Stan
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr 28 09:30:44 2010
@@ -1 +1 @@
-/cxf/trunk:935945,935995,936318,937409
+/cxf/trunk:935945,935995,936318,937409,938804
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java?rev=938837&r1=938836&r2=938837&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
Wed Apr 28 09:30:44 2010
@@ -176,8 +176,13 @@ public final class Base64Utility {
}
public static byte[] decode(String id) throws Base64Exception {
- char[] cd = id.toCharArray();
- return decodeChunk(cd, 0, cd.length);
+ try {
+ char[] cd = id.toCharArray();
+ return decodeChunk(cd, 0, cd.length);
+ } catch (Exception e) {
+ LOG.warning("Invalid base64 encoded string : " + id);
+ throw new Base64Exception(new Message("BASE64_RUNTIME_EXCEPTION",
LOG), e);
+ }
}
public static void decode(char[] id,
@@ -188,8 +193,8 @@ public final class Base64Utility {
try {
ostream.write(decodeChunk(id, o, l));
- } catch (IOException e) {
- // convert exception to Base64Exception
+ } catch (Exception e) {
+ LOG.warning("Invalid base64 encoded string : " + id);
throw new Base64Exception(new Message("BASE64_RUNTIME_EXCEPTION",
LOG), e);
}
}
@@ -201,8 +206,11 @@ public final class Base64Utility {
try {
char[] cd = id.toCharArray();
ostream.write(decodeChunk(cd, 0, cd.length));
- } catch (IOException e) {
- throw new Base64Exception(new Message("BASE64_DECODE_IOEXCEPTION",
LOG), e);
+ } catch (IOException ioe) {
+ throw new Base64Exception(new Message("BASE64_DECODE_IOEXCEPTION",
LOG), ioe);
+ } catch (Exception e) {
+ LOG.warning("Invalid base64 encoded string : " + id);
+ throw new Base64Exception(new Message("BASE64_RUNTIME_EXCEPTION",
LOG), e);
}
}
Modified:
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java?rev=938837&r1=938836&r2=938837&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
Wed Apr 28 09:30:44 2010
@@ -98,6 +98,17 @@ public class Base64UtilityTest extends A
}
@Test
+ public void testDecodeInvalidString() throws Exception {
+ try {
+ String in = "QWxhZGRpbjpcGVuIHNlc2FtZQ==";
+ byte bytes[] = Base64Utility.decode(in);
+ fail("This test should be fail");
+ } catch (Base64Exception e) {
+ //nothing to do
+ }
+ }
+
+ @Test
public void testEncodeDecodeStreams() throws Exception {
byte bytes[] = new byte[100];
for (int x = 0; x < bytes.length; x++) {