Author: jochen
Date: Fri Sep 15 02:30:43 2006
New Revision: 446558

URL: http://svn.apache.org/viewvc?view=rev&rev=446558
Log:
If the server was throwing an XmlRpcException, then the fault code and fault
string weren't given to the client.
PR: XMLRPC-113
Submitted-by: Juha Syrjala, [EMAIL PROTECTED]


Modified:
    
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalTransport.java
    
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
    
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
    webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/src/changes/changes.xml
    
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
    
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
    
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
    
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
    webservices/xmlrpc/trunk/src/changes/changes.xml
    
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
    
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties

Modified: 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalTransport.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalTransport.java?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalTransport.java
 (original)
+++ 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalTransport.java
 Fri Sep 15 02:30:43 2006
@@ -87,13 +87,11 @@
         Object result;
                try {
                        result = server.execute(pRequest);
-               } catch (Throwable t) {
-                       if (t instanceof XmlRpcClientException) {
-                               throw (XmlRpcClientException) t;
-                       } else {
-                               throw new XmlRpcClientException("Failed to 
invoke method " + pRequest.getMethodName()
-                                                                               
                + ": " + t.getMessage(), t);
-                       }
+        } catch (XmlRpcException e) {
+            throw e;
+        } catch (Throwable t) {
+            throw new XmlRpcClientException("Failed to invoke method " + 
pRequest.getMethodName()
+                    + ": " + t.getMessage(), t);
                }
                if (!config.isEnabledForExtensions()) {
                        if (isExtensionType(result)) {

Modified: 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
 (original)
+++ 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
 Fri Sep 15 02:30:43 2006
@@ -119,6 +119,9 @@
                                          + clazz.getName(), e);
            } catch (InvocationTargetException e) {
                Throwable t = e.getTargetException();
+            if (t instanceof XmlRpcException) {
+                throw (XmlRpcException) t;
+            }
                throw new XmlRpcException("Failed to invoke method "
                                          + pMethod.getName() + " in class "
                                          + clazz.getName() + ": "

Modified: 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
 (original)
+++ 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
 Fri Sep 15 02:30:43 2006
@@ -296,8 +296,9 @@
             if (pContentLength != -1) {
                 output.write(clength);
                 output.write(toHTTPBytes(Integer.toString(pContentLength)));
+                output.write(newline);
             }
-            output.write(doubleNewline);
+            output.write(newline);
         }
     }
 

Modified: webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/src/changes/changes.xml?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/src/changes/changes.xml 
(original)
+++ webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/src/changes/changes.xml Fri 
Sep 15 02:30:43 2006
@@ -8,6 +8,15 @@
         Make the HttpClient creation in XmlRpcCommonsTransport and the
         URLConnection creation in XmlRpcSunHttpTransport protected.
         This is required for cookie support.
+      </action
+      <action dev="jochen" type="fix">
+        The WebServer was producing invalid error responses, if 
contentLengthOptional
+        was set.
+      </action>
+      <action dev="jochen" type="fix" issue="XMLRPC-113" due-to="Juha Syrjala"
+          due-to-email="[EMAIL PROTECTED]">
+        If the server was throwing an XmlRpcException, then the fault code and 
fault
+        string weren't given to the client.
       </action>
     </release>
     <release version="3.0" date="30-Aug-2006">

Modified: 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
 (original)
+++ 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
 Fri Sep 15 02:30:43 2006
@@ -215,4 +215,52 @@
         s = (String) client.execute(XMLRPC96Handler.class.getName() + 
".getHelloWorld", (Object[]) null);
         assertEquals("Hello, world!", s);
     }
+
+    /**
+     * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-113";>
+     * XMLRPC-113</a>
+     */
+    public void testXMLRPC113() throws Exception {
+        for (int i = 0;  i < providers.length;  i++) {
+            testXMLRPC113(providers[i]);
+        }
+    }
+
+    /**
+     * Handler interface for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
+     */ 
+    public interface XMLRPC113Handler {
+        /**
+         * Throws an [EMAIL PROTECTED] XmlRpcException} with the given error 
code.
+         */
+        Object throwCode(int pCode) throws XmlRpcException;
+    }
+
+    /**
+     * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
+     */ 
+    public static class XMLRPC113HandlerImpl implements XMLRPC113Handler {
+        public Object throwCode(int pCode) throws XmlRpcException {
+            throw new XmlRpcException(pCode, "Message: " + pCode);
+        }
+    }
+
+    private void testXMLRPC113(ClientProvider pProvider) throws Exception {
+        XmlRpcClient client = pProvider.getClient();
+        client.setConfig(getConfig(pProvider));
+        XMLRPC113Handler handler = (XMLRPC113Handler) new 
ClientFactory(client).newInstance(XMLRPC113Handler.class);
+        for (int i = 0;  i < 5;  i++) {
+            try {
+                client.execute(XMLRPC113Handler.class.getName() + 
".throwCode", new Object[]{new Integer(i)});
+                fail("Excpected exception");
+            } catch (XmlRpcException e) {
+                assertEquals(i, e.code);
+            }
+            try {
+                handler.throwCode(i);
+            } catch (XmlRpcException e) {
+                assertEquals(i, e.code);
+            }
+        }
+    }
 }

Modified: 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
 (original)
+++ 
webservices/xmlrpc/branches/XMLRPC_3_0_BRANCH/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
 Fri Sep 15 02:30:43 2006
@@ -1,2 +1,3 @@
 
org.apache.xmlrpc.test.JiraTest$XMLRPC89Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC89HandlerImpl
 
org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler
+org.apache.xmlrpc.test.JiraTest$XMLRPC113Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC113HandlerImpl

Modified: 
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
 (original)
+++ 
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/server/ReflectiveXmlRpcHandler.java
 Fri Sep 15 02:30:43 2006
@@ -1,129 +1,132 @@
-/*
- * Copyright 1999,2006 The Apache Software Foundation.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.xmlrpc.server;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.XmlRpcHandler;
-import org.apache.xmlrpc.XmlRpcRequest;
-import org.apache.xmlrpc.common.TypeConverter;
-import org.apache.xmlrpc.common.TypeConverterFactory;
-import org.apache.xmlrpc.common.XmlRpcInvocationException;
-import org.apache.xmlrpc.common.XmlRpcNotAuthorizedException;
-import org.apache.xmlrpc.metadata.Util;
-import 
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
-import 
org.apache.xmlrpc.server.RequestProcessorFactoryFactory.RequestProcessorFactory;
-
-
-/** Default implementation of [EMAIL PROTECTED] XmlRpcHandler}.
- */
-public class ReflectiveXmlRpcHandler implements XmlRpcHandler {
-    private static class MethodData {
-        final Method method;
-        final TypeConverter[] typeConverters;
-        MethodData(Method pMethod, TypeConverterFactory pTypeConverterFactory) 
{
-            method = pMethod;
-            Class[] paramClasses = method.getParameterTypes();
-            typeConverters = new TypeConverter[paramClasses.length];
-            for (int i = 0;  i < paramClasses.length;  i++) {
-                typeConverters[i] = 
pTypeConverterFactory.getTypeConverter(paramClasses[i]);
-            }
-        }
-    }
-    private final AbstractReflectiveHandlerMapping mapping;
-       private final MethodData[] methods;
-    private final Class clazz;
-    private final RequestProcessorFactory requestProcessorFactory;
-
-       /** Creates a new instance.
-        * @param pMapping The mapping, which creates this handler.
-        * @param pClass The class, which has been inspected to create
-        * this handler. Typically, this will be the same as
-        * <pre>pInstance.getClass()</pre>. It is used for diagnostic
-        * messages only.
-        * @param pMethods The method, which will be invoked for
-        * executing the handler. 
-        */
-       public ReflectiveXmlRpcHandler(AbstractReflectiveHandlerMapping 
pMapping,
-                TypeConverterFactory pTypeConverterFactory,
-                Class pClass, RequestProcessorFactory pFactory, Method[] 
pMethods) {
-               mapping = pMapping;
-        clazz = pClass;
-               methods = new MethodData[pMethods.length];
-        requestProcessorFactory = pFactory;
-        for (int i = 0;  i < methods.length;  i++) {
-            methods[i] = new MethodData(pMethods[i], pTypeConverterFactory); 
-        }
-       }
-
-    private Object getInstance(XmlRpcRequest pRequest) throws XmlRpcException {
-        return requestProcessorFactory.getRequestProcessor(pRequest);
-    }
-
-       public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
-           AuthenticationHandler authHandler = 
mapping.getAuthenticationHandler();
-           if (authHandler != null  &&  !authHandler.isAuthorized(pRequest)) {
-               throw new XmlRpcNotAuthorizedException("Not authorized");
-           }
-           Object[] args = new Object[pRequest.getParameterCount()];
-           for (int j = 0;  j < args.length;  j++) {
-               args[j] = pRequest.getParameter(j);
-           }
-           Object instance = getInstance(pRequest);
-           for (int i = 0;  i < methods.length;  i++) {
-            MethodData methodData = methods[i];
-            TypeConverter[] converters = methodData.typeConverters;
-            if (args.length == converters.length) {
-                boolean matching = true;
-                for (int j = 0;  j < args.length;  j++) {
-                    if (!converters[j].isConvertable(args[j])) {
-                        matching = false;
-                        break;
-                    }
-                }
-                if (matching) {
-                    for (int j = 0;  j < args.length;  j++) {
-                        args[j] = converters[j].convert(args[j]);
-                    }
-                    return invoke(instance, methodData.method, args);
-                }
-            }
-           }
-           throw new XmlRpcException("No method matching arguments: " + 
Util.getSignature(args));
-    }
-
-    private Object invoke(Object pInstance, Method pMethod, Object[] pArgs) 
throws XmlRpcException {
-        try {
-               return pMethod.invoke(pInstance, pArgs);
-           } catch (IllegalAccessException e) {
-               throw new XmlRpcException("Illegal access to method "
-                                         + pMethod.getName() + " in class "
-                                         + clazz.getName(), e);
-           } catch (IllegalArgumentException e) {
-               throw new XmlRpcException("Illegal argument for method "
-                                         + pMethod.getName() + " in class "
-                                         + clazz.getName(), e);
-           } catch (InvocationTargetException e) {
-               Throwable t = e.getTargetException();
-               throw new XmlRpcInvocationException("Failed to invoke method "
-                                         + pMethod.getName() + " in class "
-                                         + clazz.getName() + ": "
-                                         + t.getMessage(), t);
-           }
-       }
-}
+/*
+ * Copyright 1999,2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.xmlrpc.server;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcHandler;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.common.TypeConverter;
+import org.apache.xmlrpc.common.TypeConverterFactory;
+import org.apache.xmlrpc.common.XmlRpcInvocationException;
+import org.apache.xmlrpc.common.XmlRpcNotAuthorizedException;
+import org.apache.xmlrpc.metadata.Util;
+import 
org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;
+import 
org.apache.xmlrpc.server.RequestProcessorFactoryFactory.RequestProcessorFactory;
+
+
+/** Default implementation of [EMAIL PROTECTED] XmlRpcHandler}.
+ */
+public class ReflectiveXmlRpcHandler implements XmlRpcHandler {
+    private static class MethodData {
+        final Method method;
+        final TypeConverter[] typeConverters;
+        MethodData(Method pMethod, TypeConverterFactory pTypeConverterFactory) 
{
+            method = pMethod;
+            Class[] paramClasses = method.getParameterTypes();
+            typeConverters = new TypeConverter[paramClasses.length];
+            for (int i = 0;  i < paramClasses.length;  i++) {
+                typeConverters[i] = 
pTypeConverterFactory.getTypeConverter(paramClasses[i]);
+            }
+        }
+    }
+    private final AbstractReflectiveHandlerMapping mapping;
+       private final MethodData[] methods;
+    private final Class clazz;
+    private final RequestProcessorFactory requestProcessorFactory;
+
+       /** Creates a new instance.
+        * @param pMapping The mapping, which creates this handler.
+        * @param pClass The class, which has been inspected to create
+        * this handler. Typically, this will be the same as
+        * <pre>pInstance.getClass()</pre>. It is used for diagnostic
+        * messages only.
+        * @param pMethods The method, which will be invoked for
+        * executing the handler. 
+        */
+       public ReflectiveXmlRpcHandler(AbstractReflectiveHandlerMapping 
pMapping,
+                TypeConverterFactory pTypeConverterFactory,
+                Class pClass, RequestProcessorFactory pFactory, Method[] 
pMethods) {
+               mapping = pMapping;
+        clazz = pClass;
+               methods = new MethodData[pMethods.length];
+        requestProcessorFactory = pFactory;
+        for (int i = 0;  i < methods.length;  i++) {
+            methods[i] = new MethodData(pMethods[i], pTypeConverterFactory); 
+        }
+       }
+
+    private Object getInstance(XmlRpcRequest pRequest) throws XmlRpcException {
+        return requestProcessorFactory.getRequestProcessor(pRequest);
+    }
+
+       public Object execute(XmlRpcRequest pRequest) throws XmlRpcException {
+           AuthenticationHandler authHandler = 
mapping.getAuthenticationHandler();
+           if (authHandler != null  &&  !authHandler.isAuthorized(pRequest)) {
+               throw new XmlRpcNotAuthorizedException("Not authorized");
+           }
+           Object[] args = new Object[pRequest.getParameterCount()];
+           for (int j = 0;  j < args.length;  j++) {
+               args[j] = pRequest.getParameter(j);
+           }
+           Object instance = getInstance(pRequest);
+           for (int i = 0;  i < methods.length;  i++) {
+            MethodData methodData = methods[i];
+            TypeConverter[] converters = methodData.typeConverters;
+            if (args.length == converters.length) {
+                boolean matching = true;
+                for (int j = 0;  j < args.length;  j++) {
+                    if (!converters[j].isConvertable(args[j])) {
+                        matching = false;
+                        break;
+                    }
+                }
+                if (matching) {
+                    for (int j = 0;  j < args.length;  j++) {
+                        args[j] = converters[j].convert(args[j]);
+                    }
+                    return invoke(instance, methodData.method, args);
+                }
+            }
+           }
+           throw new XmlRpcException("No method matching arguments: " + 
Util.getSignature(args));
+    }
+
+    private Object invoke(Object pInstance, Method pMethod, Object[] pArgs) 
throws XmlRpcException {
+        try {
+               return pMethod.invoke(pInstance, pArgs);
+           } catch (IllegalAccessException e) {
+               throw new XmlRpcException("Illegal access to method "
+                                         + pMethod.getName() + " in class "
+                                         + clazz.getName(), e);
+           } catch (IllegalArgumentException e) {
+               throw new XmlRpcException("Illegal argument for method "
+                                         + pMethod.getName() + " in class "
+                                         + clazz.getName(), e);
+           } catch (InvocationTargetException e) {
+               Throwable t = e.getTargetException();
+            if (t instanceof XmlRpcException) {
+                throw (XmlRpcException) t;
+            }
+               throw new XmlRpcInvocationException("Failed to invoke method "
+                                         + pMethod.getName() + " in class "
+                                         + clazz.getName() + ": "
+                                         + t.getMessage(), t);
+           }
+       }
+}

Modified: 
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
 (original)
+++ 
webservices/xmlrpc/trunk/server/src/main/java/org/apache/xmlrpc/webserver/Connection.java
 Fri Sep 15 02:30:43 2006
@@ -276,7 +276,7 @@
             output.write(toHTTPBytes(" 400 Bad Request"));
             output.write(newline);
             output.write(serverName);
-            output.write(doubleNewline);
+            output.write(newline);
             output.write(toHTTPBytes("Method " + pData.getMethod() +
             " not implemented (try POST)"));
         } else if (pError instanceof XmlRpcNotAuthorizedException) {
@@ -285,22 +285,21 @@
             output.write(newline);
             output.write(serverName);
             output.write(wwwAuthenticate);
-            output.write(doubleNewline);
-            output.write(toHTTPBytes("Method " + pData.getMethod() + " 
requires a " +
-            "valid user name and password"));
+            output.write(newline);
+            output.write(toHTTPBytes("Method " + pData.getMethod()
+                    + " requires a " + "valid user name and password"));
         } else {
             output.write(toHTTPBytes(pData.getHttpVersion()));
             output.write(ok);
             output.write(serverName);
             output.write(conclose);
             output.write(ctype);
-            if (pContentLength == -1) {
-                output.write(newline);
-            } else {
+            if (pContentLength != -1) {
                 output.write(clength);
                 output.write(toHTTPBytes(Integer.toString(pContentLength)));
-                output.write(doubleNewline);
+                output.write(newline);
             }
+            output.write(newline);
         }
     }
 

Modified: webservices/xmlrpc/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/changes/changes.xml?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- webservices/xmlrpc/trunk/src/changes/changes.xml (original)
+++ webservices/xmlrpc/trunk/src/changes/changes.xml Fri Sep 15 02:30:43 2006
@@ -14,6 +14,15 @@
         URLConnection creation in XmlRpcSunHttpTransport protected.
         This is required for cookie support.
       </action>
+      <action dev="jochen" type="fix">
+        The WebServer was producing invalid error responses, if 
contentLengthOptional
+        was set.
+      </action>
+      <action dev="jochen" type="fix" issue="XMLRPC-113" due-to="Juha Syrjala"
+          due-to-email="[EMAIL PROTECTED]">
+        If the server was throwing an XmlRpcException, then the fault code and 
fault
+        string weren't given to the client.
+      </action>
     </release>
     <release version="3.0" date="30-Aug-2006">
       <action dev="jochen" type="fix" due-to="Matt Preston"

Modified: 
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
 (original)
+++ 
webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/JiraTest.java
 Fri Sep 15 02:30:43 2006
@@ -215,4 +215,52 @@
         s = (String) client.execute(XMLRPC96Handler.class.getName() + 
".getHelloWorld", (Object[]) null);
         assertEquals("Hello, world!", s);
     }
+
+    /**
+     * Test case for <a href="http://issues.apache.org/jira/browse/XMLRPC-113";>
+     * XMLRPC-113</a>
+     */
+    public void testXMLRPC113() throws Exception {
+        for (int i = 0;  i < providers.length;  i++) {
+            testXMLRPC113(providers[i]);
+        }
+    }
+
+    /**
+     * Handler interface for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
+     */ 
+    public interface XMLRPC113Handler {
+        /**
+         * Throws an [EMAIL PROTECTED] XmlRpcException} with the given error 
code.
+         */
+        Object throwCode(int pCode) throws XmlRpcException;
+    }
+
+    /**
+     * Handler for [EMAIL PROTECTED] JiraTest#testXMLRPC113()}
+     */ 
+    public static class XMLRPC113HandlerImpl implements XMLRPC113Handler {
+        public Object throwCode(int pCode) throws XmlRpcException {
+            throw new XmlRpcException(pCode, "Message: " + pCode);
+        }
+    }
+
+    private void testXMLRPC113(ClientProvider pProvider) throws Exception {
+        XmlRpcClient client = pProvider.getClient();
+        client.setConfig(getConfig(pProvider));
+        XMLRPC113Handler handler = (XMLRPC113Handler) new 
ClientFactory(client).newInstance(XMLRPC113Handler.class);
+        for (int i = 0;  i < 5;  i++) {
+            try {
+                client.execute(XMLRPC113Handler.class.getName() + 
".throwCode", new Object[]{new Integer(i)});
+                fail("Excpected exception");
+            } catch (XmlRpcException e) {
+                assertEquals(i, e.code);
+            }
+            try {
+                handler.throwCode(i);
+            } catch (XmlRpcException e) {
+                assertEquals(i, e.code);
+            }
+        }
+    }
 }

Modified: 
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties?view=diff&rev=446558&r1=446557&r2=446558
==============================================================================
--- 
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
 (original)
+++ 
webservices/xmlrpc/trunk/tests/src/test/resources/org/apache/xmlrpc/test/JiraTest.properties
 Fri Sep 15 02:30:43 2006
@@ -1,2 +1,3 @@
 
org.apache.xmlrpc.test.JiraTest$XMLRPC89Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC89HandlerImpl
 
org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC96Handler
+org.apache.xmlrpc.test.JiraTest$XMLRPC113Handler=org.apache.xmlrpc.test.JiraTest$XMLRPC113HandlerImpl


Reply via email to