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 Steve Quint <li...@nanohertz.com> on 2005/04/04 20:18:44 UTC

[PATCH] Handling input encoding

Resent with '[PATCH]' in the subject to hopefully catch someone's attention.


At 9:53 AM +0000 3/30/05, aevers@apache.org wrote:
>aevers      2005/03/30 01:53:59
>
>  Modified:    src/java/org/apache/xmlrpc Tag: XMLRPC_1_2_BRANCH
>                        XmlRpc.java
>  Log:
>  Allow the input encoding used to be overridden.
>  The default input encoding is 'null' which produces the
>  orignal behaviour.
>  Overriding the input encoding is necessary on platforms
>  like BS2000 or IBM z/OS where the default encoding (often
>  an EBCDIC variant) is not the same as the network encoding
>  (which for XML-RPC is defined to be ASCII).

I was hoping that this would allow me to handle input encoding, but I
just had a chance to look at this patch and it just falls short.

My problem:  I wish to explicitly set the input encoding for XMLRPC
responses that do not contain the proper encoding information in the XML
declaration.  Some vendors (and I believe this to be valid) will set the
document encoding in the content-type *header*.  Others vendors will
omit encoding information altogether, but will always encode the
response a particular way.

Using the above patch to set the encoding for each instance is not
thread safe.  There's also no appropriate method that we can override in
the XmlRpc class (such as a protected "getInputSource" method).

I've included a patch for setting the encoding for each instance of the
XmlRpc object.

===================================================================
Index: src/java/org/apache/xmlrpc/XmlRpc.java
===================================================================
RCS file: /home/cvspublic/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpc.java,v
retrieving revision 1.35.2.2
diff -u -r1.35.2.2 XmlRpc.java
--- src/java/org/apache/xmlrpc/XmlRpc.java	30 Mar 2005 09:53:59 -0000	1.35.2.2
+++ src/java/org/apache/xmlrpc/XmlRpc.java	31 Mar 2005 07:49:10 -0000
@@ -196,10 +196,11 @@
      * is not compatible with ASCII (eg. EBCDIC) but the network is
      * still ASCII-like.
      */
-    static String inputEncoding = null;
+    static String defaultInputEncoding = null;
 
 
     private TypeFactory typeFactory;
+    private String inputEncoding;
 
     /**
      * Creates a new instance with the {@link
@@ -228,6 +229,7 @@
             }
         }
         this.typeFactory = createTypeFactory(typeFactoryName);
+        this.inputEncoding = defaultInputEncoding;
     }
 
     /**
@@ -358,9 +360,9 @@
      *
      * @param enc The Java name of the encoding.
      */
-    public static void setInputEncoding(String enc)
+    public static void setDefaultInputEncoding(String enc)
     {
-        inputEncoding = enc;
+        defaultInputEncoding = enc;
     }
 
     /**
@@ -369,7 +371,30 @@
      *
      * @return the Java encoding name to use, if set, otherwise null.
      */
-    public static String getInputEncoding ()
+    public static String getDefaultInputEncoding ()
+    {
+        return defaultInputEncoding;
+    }
+   
+    /**
+     * Set the input encoding for this XmlRpc instance.  This can be
+     * used when the XMLRPC response does not contain the proper
+     * encoding information in the XML declaration.
+     *
+     * @param enc The Java name of the encoding.
+     */
+    public void setInputEncoding(String enc)
+    {
+        inputEncoding = enc;
+    }
+   
+    /**
+     * Get the input encoding for this XmlRpc instance.  This is a Java
+     * encoding name.
+     *
+     * @return The Java encoding name to use.  <code>null</code> if not set.
+     */
+    public String getInputEncoding()
     {
         return inputEncoding;
     }

-- 

Steve

------------------------------------------------------------
"Always ... always remember: Less is less. More is more. More is
better. And twice as much is good too. Not enough is bad. And too
much is never enough except when it's just about right."
			-- The Tick
------------------------------------------------------------