dlr 2004/06/30 11:46:58
Modified: src/java/org/apache/xmlrpc DefaultTypeFactory.java
XmlWriter.java
src/java/org/apache/xmlrpc/applet SimpleXmlRpcClient.java
Log:
Work around method signature incompatibilities between version 1.1 and
1.2 of Commons Codec's Base64.encode() and decode() methods.
The 1.1 release had two encode() and decode() methods (each), one that
accepted a byte[] and the other accepted an Object. In both cases,
Encoder/Decoder Exceptions were thrown if the argument wasn't a
byte[]. In Codec 1.2, both methods still exist, but the one that
accepts a byte[] no longer throws the exception (because the input is
guaranteed to be of type byte[]).
So, I have one option (which kind of sucks), I can cast the byte[] to an
Object in the calls to encode/decode to retain compatibility between codec
1.1 and 1.2.
* src/java/org/apache/xmlrpc/DefaultTypeFactory.java
createBase64(String): Cast input to the Base64.decode() method from
byte[] to Object.
* src/java/org/apache/xmlrpc/XmlWriter.java
writeObject(Object): Cast return value of Base64.encode() from
Object to byte[].
* src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java
writeObject(Object, XmlWriter): Cast return value of Base64.encode()
from Object to byte[].
Value.characterData(String): Cast input to the Base64.decode()
method from byte[] to Object.
Submitted by: Jochen Wiedmann
Reported by: Ryan Bloom
Revision Changes Path
1.4 +3 -2 ws-xmlrpc/src/java/org/apache/xmlrpc/DefaultTypeFactory.java
Index: DefaultTypeFactory.java
===================================================================
RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/DefaultTypeFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -u -r1.3 -r1.4
--- DefaultTypeFactory.java 1 May 2003 16:53:15 -0000 1.3
+++ DefaultTypeFactory.java 30 Jun 2004 18:46:58 -0000 1.4
@@ -127,8 +127,9 @@
public Object createBase64(String cdata)
{
- try {
- return base64Codec.decode(cdata.getBytes());
+ try
+ {
+ return base64Codec.decode((Object) cdata.getBytes());
}
catch (DecoderException e) {
//TODO: consider throwing an exception here?
1.11 +7 -4 ws-xmlrpc/src/java/org/apache/xmlrpc/XmlWriter.java
Index: XmlWriter.java
===================================================================
RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -u -r1.10 -r1.11
--- XmlWriter.java 17 Jun 2004 01:40:14 -0000 1.10
+++ XmlWriter.java 30 Jun 2004 18:46:58 -0000 1.11
@@ -211,11 +211,14 @@
else if (obj instanceof byte[])
{
startElement("base64");
- try {
- this.write(base64Codec.encode((byte[]) obj));
+ try
+ {
+ this.write((byte[]) base64Codec.encode(obj));
}
- catch (EncoderException e) {
- throw new XmlRpcClientException("Unable to Base 64 encode byte
array", e);
+ catch (EncoderException e)
+ {
+ throw new XmlRpcClientException
+ ("Unable to Base 64 encode byte array", e);
}
endElement("base64");
}
1.9 +16 -10
ws-xmlrpc/src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java
Index: SimpleXmlRpcClient.java
===================================================================
RCS file:
/home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -u -r1.8 -r1.9
--- SimpleXmlRpcClient.java 14 May 2004 15:47:05 -0000 1.8
+++ SimpleXmlRpcClient.java 30 Jun 2004 18:46:58 -0000 1.9
@@ -249,11 +249,15 @@
else if (what instanceof byte[])
{
writer.startElement("base64");
- try {
- writer.write(base64.encode((byte[]) what));
+ try
+ {
+ writer.write((byte[]) base64.encode(what));
}
- catch (EncoderException e) {
- throw new RuntimeException("Incompatible version of
org.apache.commons.codec.binary.Base64 used, and an error occurred.");
+ catch (EncoderException e)
+ {
+ throw new RuntimeException("Possibly incompatible version " +
+ "of '" + Base64.class.getName() +
+ "' used: " + e);
}
writer.endElement("base64");
}
@@ -647,13 +651,15 @@
}
break;
case BASE64:
- try {
- value = base64.decode(cdata.getBytes());
+ try
+ {
+ value = base64.decode((Object) cdata.getBytes());
}
catch (DecoderException e) {
- /* FIXME: what should we do here? Probably an Exception?
- * tabling because this class is slated for complete
overhaul
- * using the core library.
+ /* FIXME: We should Probably throw an
+ * Exception here. Punting because this class
+ * is slated for complete overhaul using the
+ * core library.
*/
value = cdata;
}