Author: ningjiang
Date: Wed Apr 28 07:13:59 2010
New Revision: 938804
URL: http://svn.apache.org/viewvc?rev=938804&view=rev
Log:
CXF-2785 Base64Utils.decode should handle/wrap all exception types, applied
patch with thanks to Stan
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java?rev=938804&r1=938803&r2=938804&view=diff
==============================================================================
---
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
(original)
+++
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/Base64Utility.java
Wed Apr 28 07:13:59 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/trunk/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java?rev=938804&r1=938803&r2=938804&view=diff
==============================================================================
---
cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
(original)
+++
cxf/trunk/common/common/src/test/java/org/apache/cxf/common/util/Base64UtilityTest.java
Wed Apr 28 07:13:59 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++) {