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 dl...@apache.org on 2005/05/02 06:22:21 UTC

cvs commit: ws-xmlrpc/src/java/org/apache/xmlrpc XmlRpcClientException.java XmlRpcClientRequestProcessor.java XmlRpcException.java XmlWriter.java

dlr         2005/05/01 21:22:21

  Modified:    src/java/org/apache/xmlrpc XmlRpcClientException.java
                        XmlRpcClientRequestProcessor.java
                        XmlRpcException.java XmlWriter.java
  Log:
  Partially revert overly strict handling of character encoding when
  writing XML, and some unreleased and inappropriate API changes.
  
  * src/java/org/apache/xmlrpc/XmlWriter.java
    (chardata): Removed exception thrown when characters outside
     of the valid range for XML are encountered.  Instead, pass these
     characters along (valid for XML-RPC), either entity-encoding them
     as &#xxx; if less than 0x20, or literally if greater than 0x7f.
     This doesn't appear to cause complaints from the XML parsers used
     in SourceCast, likely because the XML specification demands that
     parsers support UTF-8 and UTF-16.  This is a revision to the change
     made in CVS rev 1.4 of XmlWriter.java.  This change is the analog
     of CVS rev 1.6.2.1, as committed to the XMLRPC_1_2 branch.
  
    (writeObject): Revert API incorrectness introduced in CVS rev
     1.7.  Since XmlWriter is used by both the server and the clients,
     its APIs should throw the base XmlRpcException, not
     XmlRpcClientException.  This is an API change back to the previous
     state from 1.2, but okay since this inappropriate incarnation of
     the API was never actually released.
  
  * src/java/org/apache/xmlrpc/XmlRpcClientRequestProcessor.java
    (encodeRequest): Wrap XmlRpcException exception thrown by
     XmlWriter.writeObject() in a XmlRpcClientException.
  
  * src/java/org/apache/xmlrpc/XmlRpcException.java
    (cause, getCause): New APIs to support nested exceptions.
  
    (XmlRpcException): Added overload to set "cause".  Adjusted existing
     decl accordingly.
  
  * src/java/org/apache/xmlrpc/XmlRpcClientException.java
    (cause, getCause): Removed, pushed up into superclass.
  
  Target release: 2.0
  Reviewed by: Jochen Wiedmann (XmlWriter changes)
  
  Revision  Changes    Path
  1.3       +2 -26     ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientException.java
  
  Index: XmlRpcClientException.java
  ===================================================================
  RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- XmlRpcClientException.java	22 Apr 2005 10:25:57 -0000	1.2
  +++ XmlRpcClientException.java	2 May 2005 04:22:21 -0000	1.3
  @@ -29,11 +29,6 @@
   public class XmlRpcClientException extends XmlRpcException
   {
       /**
  -     * The underlying cause of this exception.
  -     */
  -    public Throwable cause;
  -
  -    /**
        * Create an XmlRpcClientException with the given message and
        * underlying cause exception.
        *
  @@ -42,25 +37,6 @@
        */
       public XmlRpcClientException(String message, Throwable cause)
       {
  -        super(0, message);
  -        this.cause = cause;
  -    }
  -
  -    /**
  -     * Returns the cause of this throwable or null if the cause is nonexistent
  -     * or unknown. (The cause is the throwable that caused this throwable to
  -     * get thrown.)
  -     * 
  -     * This implementation returns the cause that was supplied via the constructor,
  -     * according to the rules specified for a "legacy chained throwable" that
  -     * predates the addition of chained exceptions to Throwable.
  -     *
  -     * See the <a
  -     * href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Throwable.html">JDK
  -     * 1.4 Throwable documentation</a> for more information.
  -     */
  -    public Throwable getCause()
  -    {
  -        return cause;
  +        super(0, message, cause);
       }
   }
  
  
  
  1.4       +12 -4     ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientRequestProcessor.java
  
  Index: XmlRpcClientRequestProcessor.java
  ===================================================================
  RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientRequestProcessor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- XmlRpcClientRequestProcessor.java	22 Apr 2005 10:25:57 -0000	1.3
  +++ XmlRpcClientRequestProcessor.java	2 May 2005 04:22:21 -0000	1.4
  @@ -40,8 +40,9 @@
        * @param encoding the Java name for the encoding to use.
        * @return byte [] the encoded request.
        */
  -    public void encodeRequest(XmlRpcClientRequest request, String encoding, OutputStream out)
  -    throws XmlRpcClientException, IOException
  +    public void encodeRequest(XmlRpcClientRequest request, String encoding,
  +                              OutputStream out)
  +        throws XmlRpcClientException, IOException
       {
           XmlWriter writer;
   
  @@ -57,7 +58,14 @@
           for (int i = 0; i < l; i++)
           {
               writer.startElement("param");
  -            writer.writeObject(request.getParameter(i));
  +            try
  +            {
  +                writer.writeObject(request.getParameter(i));
  +            }
  +            catch (XmlRpcException e)
  +            {
  +                throw new XmlRpcClientException("Failure writing request", e);
  +            }
               writer.endElement("param");
           }
           writer.endElement("params");
  
  
  
  1.4       +39 -4     ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcException.java
  
  Index: XmlRpcException.java
  ===================================================================
  RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcException.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -u -r1.3 -r1.4
  --- XmlRpcException.java	22 Apr 2005 10:25:57 -0000	1.3
  +++ XmlRpcException.java	2 May 2005 04:22:21 -0000	1.4
  @@ -35,13 +35,48 @@
       public final int code;
   
       /**
  -     *
  -     * @param code
  -     * @param message
  +     * The underlying cause of this exception.
  +     */
  +    private Throwable cause;
  +
  +    /**
  +     * @see #XmlRpcException(int, String, Throwable)
        */
       public XmlRpcException(int code, String message)
       {
  +        this(code, message, null);
  +    }
  +
  +    /**
  +     * Creates an instance with the specified message and root cause
  +     * exception.
  +     *
  +     * @param int The fault code for this problem.
  +     * @param message The message describing this exception.
  +     * @param cause The root cause of this exception.
  +     */
  +    public XmlRpcException(int code, String message, Throwable cause)
  +    {
           super(message);
           this.code = code;
  +        this.cause = cause;
  +    }
  +
  +    /**
  +     * Returns the cause of this throwable or null if the cause is nonexistent
  +     * or unknown. (The cause is the throwable that caused this throwable to
  +     * get thrown.)
  +     * 
  +     * This implementation returns the cause that was supplied via the constructor,
  +     * according to the rules specified for a "legacy chained throwable" that
  +     * predates the addition of chained exceptions to Throwable.
  +     *
  +     * See the <a
  +     * href="http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Throwable.html">JDK
  +     * 1.4 Throwable documentation</a> for more information.
  +     */
  +    public Throwable getCause()
  +    {
  +        return cause;
       }
   }
  
  
  
  1.13      +40 -13    ws-xmlrpc/src/java/org/apache/xmlrpc/XmlWriter.java
  
  Index: XmlWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlWriter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -u -r1.12 -r1.13
  --- XmlWriter.java	22 Apr 2005 10:25:57 -0000	1.12
  +++ XmlWriter.java	2 May 2005 04:22:21 -0000	1.13
  @@ -133,13 +133,13 @@
        * href="http://xml-rpc.com/spec">XML-RPC specification</a>).
        */
       public void writeObject(Object obj)
  -        throws XmlRpcClientException, IOException
  +        throws XmlRpcException, IOException
       {
           startElement("value");
           if (obj == null)
           {
  -            throw new XmlRpcClientException
  -                ("null values not supported by XML-RPC", null);
  +            throw new XmlRpcException
  +                (0, "null values not supported by XML-RPC");
           }
           else if (obj instanceof String)
           {
  @@ -179,8 +179,8 @@
               }
               catch (EncoderException e)
               {
  -                throw new XmlRpcClientException
  -                    ("Unable to Base 64 encode byte array", e);
  +                throw new XmlRpcException
  +                    (0, "Unable to Base 64 encode byte array", e);
               }
               endElement("base64");
           }
  @@ -228,7 +228,7 @@
           }
           else
           {
  -            throw new XmlRpcClientException("unsupported Java type: "
  +            throw new XmlRpcException(0, "Unsupported Java type: "
                                          + obj.getClass(), null);
           }
           endElement("value");
  @@ -285,13 +285,18 @@
        * Writes text as <code>PCDATA</code>.
        *
        * @param text The data to write.
  -     * @exception XmlRpcClientException Unsupported character data found.
  +     * @exception XmlRpcException Unsupported character data found.
        * @exception IOException Problem writing data.
        */
       protected void chardata(String text)
  -        throws XmlRpcClientException, IOException
  +        throws XmlRpcException, IOException
       {
           int l = text.length ();
  +        String enc = super.getEncoding();
  +        boolean isUnicode = UTF8.equals(enc) || "UTF-16".equals(enc);
  +        // ### TODO: Use a buffer rather than going character by
  +        // ### character to scale better for large text sizes.
  +        //char[] buf = new char[32];
           for (int i = 0; i < l; i++)
           {
               char c = text.charAt (i);
  @@ -312,16 +317,38 @@
                   write(AMPERSAND_ENTITY);
                   break;
               default:
  -                if (c < 0x20 || c > 0xff)
  +                if (c < 0x20 || c > 0x7f)
                   {
                       // Though the XML-RPC spec allows any ASCII
                       // characters except '<' and '&', the XML spec
                       // does not allow this range of characters,
                       // resulting in a parse error from most XML
  -                    // parsers.
  -                    throw new XmlRpcClientException("Invalid character data " +
  -                                              "corresponding to XML entity &#" +
  -                                              String.valueOf((int) c) + ';', null);
  +                    // parsers.  However, the XML spec does require
  +                    // XML parsers to support UTF-8 and UTF-16.
  +                    if (isUnicode)
  +                    {
  +                        if (c < 0x20)
  +                        {
  +                            // Entity escape the character.
  +                            write("&#");
  +                            // ### Do we really need the String conversion?
  +                            write(String.valueOf((int) c));
  +                            write(';');
  +                        }
  +                        else // c > 0x7f
  +                        {
  +                            // Write the character in our encoding.
  +                            write(new String(String.valueOf(c).getBytes(enc)));
  +                        }
  +                    }
  +                    else
  +                    {
  +                        throw new XmlRpcException(0, "Invalid character data "
  +                                                  + "corresponding to XML "
  +                                                  + "entity &#"
  +                                                  + String.valueOf((int) c)
  +                                                  + ';');
  +                    }
                   }
                   else
                   {