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 ae...@apache.org on 2005/03/30 11:53:59 UTC

cvs commit: ws-xmlrpc/src/java/org/apache/xmlrpc XmlRpc.java

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).
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.35.2.2  +42 -2     ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpc.java
  
  Index: XmlRpc.java
  ===================================================================
  RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpc.java,v
  retrieving revision 1.35.2.1
  retrieving revision 1.35.2.2
  diff -u -r1.35.2.1 -r1.35.2.2
  --- XmlRpc.java	30 Jun 2004 06:09:25 -0000	1.35.2.1
  +++ XmlRpc.java	30 Mar 2005 09:53:59 -0000	1.35.2.2
  @@ -56,6 +56,7 @@
    */
   
   import java.io.InputStream;
  +import java.io.InputStreamReader;
   import java.util.Hashtable;
   import java.util.Stack;
   import java.util.Vector;
  @@ -188,6 +189,16 @@
        */
       static String encoding = XmlWriter.ISO8859_1;
   
  +    /**
  +     * Java's name for the input encoding we're using.  Defaults to
  +     * <code>null</code>, signifying the platform default. This may
  +     * need to be overridden on platforms where the default encoding
  +     * is not compatible with ASCII (eg. EBCDIC) but the network is
  +     * still ASCII-like.
  +     */
  +    static String inputEncoding = null;
  +
  +
       private TypeFactory typeFactory;
   
       /**
  @@ -342,6 +353,28 @@
       }
   
       /**
  +     * Set the input encoding of the XML.
  +     * This is used only if set.
  +     *
  +     * @param enc The Java name of the encoding.
  +     */
  +    public static void setInputEncoding(String enc)
  +    {
  +        inputEncoding = enc;
  +    }
  +
  +    /**
  +     * Return the input encoding. This may be null. This is always a
  +     * Java encoding name, it is not transformed.
  +     *
  +     * @return the Java encoding name to use, if set, otherwise null.
  +     */
  +    public static String getInputEncoding ()
  +    {
  +        return inputEncoding;
  +    }
  +
  +    /**
        * Gets the maximum number of threads used at any given moment.
        */
       public static int getMaxThreads()
  @@ -440,7 +473,14 @@
           }
           try
           {
  -            parser.parse(new InputSource (is));
  +            if(inputEncoding == null)
  +            {         
  +              parser.parse(new InputSource (is));
  +            }
  +            else
  +            {
  +              parser.parse( new InputSource( new InputStreamReader(is, inputEncoding)));
  +            }
           }
           finally
           {
  
  
  

Handling input encoding

Posted by Steve Quint <li...@nanohertz.com>.
I'm taking full advantage of the fact that a committer is actively reading this list...


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
------------------------------------------------------------