Hi All,

Hope you can use my tiny hack, and sorry about the TABS!

The UTF-8 hack has been in production use now for months, and works well. More or less I just set the default encoding, and stopped discarding characters with ascii val > 0xFF.

I did the other hack to help ease the panic in our Ops guys. We are using Nagios to monitor our server uptime. Whenever we get an empty HTTP request on an XMLRPC server, we get one of these NoSuchElement nags. So I changed the webserver code to only process tokens in the event that we actually HAVE tokens. Pretty much it.
--- /home/eldorado/xmlrpcorigsrc/WebServer.java 2005-01-11 15:31:04.000000000 
-0800
+++ WebServer.java      2005-01-11 15:53:34.000000000 -0800
@@ -731,62 +731,68 @@
 
                     // tokenize first line of HTTP request
                     StringTokenizer tokens = new StringTokenizer(line);
-                    String method = tokens.nextToken();
-                    String uri = tokens.nextToken();
-                    String httpVersion = tokens.nextToken();
-                    keepAlive = XmlRpc.getKeepAlive()
+                   // only do this if we *might* have a valid header -- 
michael lankheim
+                   if(tokens != null && tokens.hasMoreElements())
+                   {
+                       String method = tokens.nextToken();
+                       String uri = tokens.nextToken();
+                       String httpVersion = tokens.nextToken();
+                       keepAlive = XmlRpc.getKeepAlive()
                             && HTTP_11.equals(httpVersion);
-                    do
-                    {
-                        line = readLine();
-                        if (line != null)
-                        {
-                            if (XmlRpc.debug)
-                            {
-                                System.out.println(line);
-                            }
-                            String lineLower = line.toLowerCase();
-                            if (lineLower.startsWith("content-length:"))
-                            {
-                                contentLength = Integer.parseInt(
-                                        line.substring(15).trim());
-                            }
-                            if (lineLower.startsWith("connection:"))
-                            {
-                                keepAlive = XmlRpc.getKeepAlive() &&
-                                        lineLower.indexOf("keep-alive") > -1;
-                            }
-                            if (lineLower.startsWith("authorization: basic "))
-                            {
-                                parseAuth (line);
-                            }
-                        }
-                    }
-                    while (line != null && line.length() != 0);
-
-                    if ("POST".equalsIgnoreCase(method))
-                    {
-                        ServerInputStream sin = new ServerInputStream(input,
-                                contentLength);
-                        try
-                        {
-                            byte[] result = xmlrpc.execute(sin, user, 
password);
-                            writeResponse(result, httpVersion, keepAlive);
-                        }
-                        catch (AuthenticationFailed unauthorized)
-                        {
-                            keepAlive = false;
-                            writeUnauthorized(httpVersion, method);
-                        }
-                    }
-                    else
-                    {
-                        keepAlive = false;
-                        writeBadRequest(httpVersion, method);
-                    }
-                    output.flush();
-                }
-                while (keepAlive);
+                       do
+                           {
+                               line = readLine();
+                               if (line != null)
+                                   {
+                                       if (XmlRpc.debug)
+                                           {
+                                               System.out.println(line);
+                                           }
+                                       String lineLower = line.toLowerCase();
+                                       if 
(lineLower.startsWith("content-length:"))
+                                           {
+                                               contentLength = 
Integer.parseInt(
+                                                                               
 line.substring(15).trim());
+                                           }
+                                       if (lineLower.startsWith("connection:"))
+                                           {
+                                               keepAlive = 
XmlRpc.getKeepAlive() &&
+                                                   
lineLower.indexOf("keep-alive") > -1;
+                                           }
+                                       if 
(lineLower.startsWith("authorization: basic "))
+                                           {
+                                               parseAuth (line);
+                                           }
+                                   }
+                           }
+                       while (line != null && line.length() != 0);
+                       
+                       if ("POST".equalsIgnoreCase(method))
+                           {
+                               ServerInputStream sin = new 
ServerInputStream(input,
+                                                                             
contentLength);
+                               try
+                                   {
+                                       byte[] result = xmlrpc.execute(sin, 
user, password);
+                                       writeResponse(result, httpVersion, 
keepAlive);
+                                   }
+                               catch (AuthenticationFailed unauthorized)
+                                   {
+                                       keepAlive = false;
+                                       writeUnauthorized(httpVersion, method);
+                                   }
+                           }
+                       else
+                           {
+                               keepAlive = false;
+                               writeBadRequest(httpVersion, method);
+                           }
+                       output.flush();
+                       
+                   }
+               }
+               while (keepAlive);
+               
             }
             catch (Exception exception)
             {
--- /home/eldorado/xmlrpcorigsrc/XmlRpc.java    2005-01-11 15:31:04.000000000 
-0800
+++ XmlRpc.java 2004-07-02 17:02:55.000000000 -0700
@@ -184,7 +184,8 @@
      * Java's name for the encoding we're using.  Defaults to
      * <code>ISO8859_1</code>.
      */
-    static String encoding = XmlWriter.ISO8859_1;
+    //static String encoding = XmlWriter.ISO8859_1;
+    static String encoding = XmlWriter.UTF8;
 
     private TypeFactory typeFactory;
 
@@ -312,7 +313,7 @@
      *
      * @see org.apache.xmlrpc.XmlWriter#canonicalizeEncoding(String)
      */
-    public String getEncoding ()
+    public static String getEncoding ()
     {
         return XmlWriter.canonicalizeEncoding(encoding);
     }
--- /home/eldorado/xmlrpcorigsrc/XmlWriter.java 2005-01-11 15:31:04.000000000 
-0800
+++ XmlWriter.java      2004-07-02 17:00:04.000000000 -0700
@@ -332,7 +332,8 @@
                 write(AMPERSAND_ENTITY);
                 break;
             default:
-                if (c < 0x20 || c > 0xff)
+                //if (c < 0x20 || c > 0xff)
+               if (c < 0x20)
                 {
                     // Though the XML-RPC spec allows any ASCII
                     // characters except '<' and '&', the XML spec

Reply via email to