You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-dev@ws.apache.org by Jochen Wiedmann <jo...@freenet.de> on 2004/06/16 09:53:34 UTC
Patch: Codec handling
Hi,
the following patch makes XmlRpc running with codec 1.2.
Jochen
Re: Patch: Codec handling
Posted by Jochen Wiedmann <jo...@freenet.de>.
Daniel Rall wrote:
> Why is that a problem? I was under the impression that this patch was
> to make XML-RPC work across different versions of Commons Codec. Do
> these Codec methods have different implementations with wildly different
> semantics?
The problem is that the methods have different signatures in terms of the
exceptions they are throwing, at least with commons-codec 1.2:
public Object decode(Object arg) throws DecoderException;
public Object decode(byte[]);
For commons-codec 1.1, it is required to catch the DecoderException.
However, if the compiler believes that we are using decode(byte[]), then it
will treat the try { ... } catch (DecoderException e) {} as an error,
because that method isn't thrown in the try clause.
The cast to Object forces the use of decode(Object). In that case, the
compiler's happy, because the DecoderException is thrown again.
Jochen
Re: Patch: Codec handling
Posted by Daniel Rall <dl...@collab.net>.
Daniel Rall wrote:
> Jochen Wiedmann wrote:
>
>> Daniel L. Rall wrote:
>>
>>>> - return base64Codec.decode(cdata.getBytes());
>>>> + return base64Codec.decode((Object) cdata.getBytes());
>>>
>>>
>>> This cast looks unnecessary. What's the thinking here?
>>
>>
>> No, it's required, because the compiler would pick the old method
>> otherwise.
>
>
> Why is that a problem? I was under the impression that this patch was
> to make XML-RPC work across different versions of Commons Codec. Do
> these Codec methods have different implementations with wildly different
> semantics?
I read Ryan Bloom's original description from "06/15/2004 10:01 AM", and
examined the source code for Commons Codec. It's clear now, and I'm committing
the patch.
Codec's EncoderException should be an unchecked exception (e.g.
RuntimeException). Otherwise, it's Encoder/Decoder interfaces rather get in the
way. Bleh.
Re: Patch: Codec handling
Posted by Daniel Rall <dl...@collab.net>.
Jochen Wiedmann wrote:
> Daniel L. Rall wrote:
>
>>> - return base64Codec.decode(cdata.getBytes());
>>> + return base64Codec.decode((Object) cdata.getBytes());
>>
>> This cast looks unnecessary. What's the thinking here?
>
> No, it's required, because the compiler would pick the old method
> otherwise.
Why is that a problem? I was under the impression that this patch was to make
XML-RPC work across different versions of Commons Codec. Do these Codec methods
have different implementations with wildly different semantics?
Re: Patch: Codec handling
Posted by Jochen Wiedmann <jo...@freenet.de>.
Daniel L. Rall wrote:
>> - return base64Codec.decode(cdata.getBytes());
>> + return base64Codec.decode((Object) cdata.getBytes());
>
>
> This cast looks unnecessary. What's the thinking here?
No, it's required, because the compiler would pick the old method otherwise.
Re: Patch: Codec handling
Posted by "Daniel L. Rall" <dl...@finemaltcoding.com>.
Jochen Wiedmann wrote:
>
> the following patch makes XmlRpc running with codec 1.2.
Comments inline. (And I'm all for "letting it suck" -- +1 on a little less
elegance over interoperability any day.)
> Index: DefaultTypeFactory.java
> ===================================================================
> RCS file: /home/cvspublic/ws-xmlrpc/src/java/org/apache/xmlrpc/DefaultTypeFactory.java,v
> retrieving revision 1.3
> diff -u -r1.3 DefaultTypeFactory.java
> --- DefaultTypeFactory.java 1 May 2003 16:53:15 -0000 1.3
> +++ DefaultTypeFactory.java 15 Jun 2004 20:24:10 -0000
> @@ -128,7 +128,7 @@
> public Object createBase64(String cdata)
> {
> try {
> - return base64Codec.decode(cdata.getBytes());
> + return base64Codec.decode((Object) cdata.getBytes());
This cast looks unnecessary. What's the thinking here?
> }
> catch (DecoderException e) {
> //TODO: consider throwing an exception here?
> Index: XmlWriter.java
> ===================================================================
> RCS file: /home/cvspublic/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
> retrieving revision 1.9
> diff -u -r1.9 XmlWriter.java
> --- XmlWriter.java 12 Sep 2003 09:44:06 -0000 1.9
> +++ XmlWriter.java 15 Jun 2004 20:24:13 -0000
> @@ -212,7 +212,7 @@
> {
> startElement("base64");
> try {
> - this.write(base64Codec.encode((byte[]) obj));
> + this.write((byte[]) base64Codec.encode(obj));
This hack should have an inline comment above it.
> }
> catch (EncoderException e) {
> throw new XmlRpcClientException("Unable to Base 64 encode byte array", e);
> Index: applet/SimpleXmlRpcClient.java
> ===================================================================
> RCS file: /home/cvspublic/ws-xmlrpc/src/java/org/apache/xmlrpc/applet/SimpleXmlRpcClient.java,v
> retrieving revision 1.8
> diff -u -r1.8 SimpleXmlRpcClient.java
> --- applet/SimpleXmlRpcClient.java 14 May 2004 15:47:05 -0000 1.8
> +++ applet/SimpleXmlRpcClient.java 15 Jun 2004 20:24:15 -0000
> @@ -250,7 +250,7 @@
> {
> writer.startElement("base64");
> try {
> - writer.write(base64.encode((byte[]) what));
> + writer.write((byte[]) base64.encode(what));
Ditto.
> }
> catch (EncoderException e) {
> throw new RuntimeException("Incompatible version of org.apache.commons.codec.binary.Base64 used, and an error occurred.");
> @@ -648,7 +648,7 @@
> break;
> case BASE64:
> try {
> - value = base64.decode(cdata.getBytes());
> + value = base64.decode((Object) cdata.getBytes());
Why is this cast necessary? If base64.decode() takes an Object, the byte[]
reference should do just fine.
> }
> catch (DecoderException e) {
> /* FIXME: what should we do here? Probably an Exception?
> Index: util/HttpUtil.java
> ===================================================================
> RCS file: /home/cvspublic/ws-xmlrpc/src/java/org/apache/xmlrpc/util/HttpUtil.java,v
> retrieving revision 1.2
> diff -u -r1.2 HttpUtil.java
> --- util/HttpUtil.java 1 May 2003 16:53:16 -0000 1.2
> +++ util/HttpUtil.java 15 Jun 2004 20:24:15 -0000
> @@ -86,8 +86,8 @@
> else
> {
> try {
> - auth = new String(base64.encode((user + ':' + password)
> - .getBytes())).trim();
> + byte[] bytes = (byte[]) (user + ':' + password).getBytes();
> + auth = new String((byte[]) base64.encode((Object) bytes)).trim();
Another cast from byte[] to Object...
> }
> catch (EncoderException e) {
> // EncoderException is never thrown in the body of Base64.encode(byte[]) in version 1.1