dlr 2004/06/30 11:49:36
Modified: src/java/org/apache/xmlrpc/util HttpUtil.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. * src/java/org/apache/xmlrpc/util/HttpUtil.java encodeBasicAuthentication(String, String): Cast return value of Base64.encode() from Object to byte[], and assure we call the Object overload. Submitted by: Jochen Wiedmann Reported by: Ryan Bloom Revision Changes Path 1.3 +11 -7 ws-xmlrpc/src/java/org/apache/xmlrpc/util/HttpUtil.java Index: HttpUtil.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/util/HttpUtil.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -u -r1.2 -r1.3 --- HttpUtil.java 1 May 2003 16:53:16 -0000 1.2 +++ HttpUtil.java 30 Jun 2004 18:49:36 -0000 1.3 @@ -85,14 +85,18 @@ } else { - try { - auth = new String(base64.encode((user + ':' + password) - .getBytes())).trim(); + try + { + Object bytes = (user + ':' + password).getBytes(); + auth = new String((byte[]) base64.encode(bytes)).trim(); } - catch (EncoderException e) { - // EncoderException is never thrown in the body of Base64.encode(byte[]) in version 1.1 - // TODO: possibly throw an exception from this method or refactor this class - throw new RuntimeException("Incompatible version of org.apache.commons.codec.binary.Base64 used, and an error condition was encountered."); + catch (EncoderException e) + { + // EncoderException is never thrown in the body of + // Base64.encode(byte[]) in Commons Codec 1.1. + throw new RuntimeException("Possibly incompatible version of '" + + Base64.class.getName() + + "' used: " + e); } } return auth;