You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-auto@ws.apache.org by jo...@apache.org on 2006/08/18 11:55:20 UTC

svn commit: r432537 - in /webservices/xmlrpc/trunk: ./ client/src/main/java/org/apache/xmlrpc/client/ common/src/main/java/org/apache/xmlrpc/util/ src/changes/ tests/src/test/java/org/apache/xmlrpc/test/

Author: jochen
Date: Fri Aug 18 02:55:18 2006
New Revision: 432537

URL: http://svn.apache.org/viewvc?rev=432537&view=rev
Log:
Various fixes related to basic authentication.
PR: XMLRPC-103
PR: XMLRPC-104
Submitted by: Landon Fuller, landonf@threerings.net

Modified:
    webservices/xmlrpc/trunk/.classpath
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransport.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransportFactory.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpTransport.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLiteHttpTransport.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransport.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransportFactory.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcStreamTransport.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcSunHttpTransport.java
    webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcTransportFactory.java
    webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/util/HttpUtil.java
    webservices/xmlrpc/trunk/pom.xml
    webservices/xmlrpc/trunk/src/changes/changes.xml
    webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java

Modified: webservices/xmlrpc/trunk/.classpath
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/.classpath?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/.classpath (original)
+++ webservices/xmlrpc/trunk/.classpath Fri Aug 18 02:55:18 2006
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="common/src/main/java"/>
-	<classpathentry kind="src" path="client/src/main/java"/>
-	<classpathentry kind="src" path="server/src/main/java"/>
+	<classpathentry kind="src" output="common/target/classes" path="common/src/main/java"/>
+	<classpathentry kind="src" output="client/target/classes" path="client/src/main/java"/>
+	<classpathentry kind="src" output="server/target/classes" path="server/src/main/java"/>
 	<classpathentry kind="src" path="tests/src/test/java"/>
 	<classpathentry kind="src" path="tests/src/test/resources"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
-	<classpathentry kind="output" path="target/classes"/>
+	<classpathentry kind="output" path="tests/target/test-classes"/>
 </classpath>

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransport.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransport.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransport.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransport.java Fri Aug 18 02:55:18 2006
@@ -16,6 +16,7 @@
 package org.apache.xmlrpc.client;
 
 import java.io.BufferedOutputStream;
+import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -34,6 +35,7 @@
 import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
 import org.apache.xmlrpc.util.HttpUtil;
 import org.apache.xmlrpc.util.XmlRpcIOException;
+import org.xml.sax.SAXException;
 
 
 /** An HTTP transport factory, which is based on the Jakarta Commons
@@ -44,6 +46,7 @@
 	private static final String userAgent = USER_AGENT + " (Jakarta Commons httpclient Transport)";
 	private PostMethod method;
 	private int contentLength = -1;
+	private XmlRpcHttpClientConfig config;      
 
 	/** Creates a new instance.
 	 * @param pClient The client, which will be invoking the transport.
@@ -56,9 +59,10 @@
 		contentLength = pLength;
 	}
 
-	public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
-		XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();      
-		method = new PostMethod(config.getServerURL().toString());
+    protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException {
+        config = (XmlRpcHttpClientConfig) pRequest.getConfig();
+        method = new PostMethod(config.getServerURL().toString());
+        super.initHttpHeaders(pRequest);
         
         if (config.getConnectionTimeout() != 0)
             client.getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout());
@@ -66,9 +70,8 @@
         if (config.getReplyTimeout() != 0)
             client.getHttpConnectionManager().getParams().setSoTimeout(config.getConnectionTimeout());
         
-		method.getParams().setVersion(HttpVersion.HTTP_1_1);
-		return super.sendRequest(pRequest);
-	}
+        method.getParams().setVersion(HttpVersion.HTTP_1_1);
+    }
 
 	protected void setRequestHeader(String pHeader, String pValue) {
 		method.setRequestHeader(new Header(pHeader, pValue));
@@ -99,7 +102,8 @@
 			Credentials creds = new UsernamePasswordCredentials(userName, pConfig.getBasicPassword());
 			AuthScope scope = new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME);
 			client.getState().setCredentials(scope, creds);
-		}
+            client.getParams().setAuthenticationPreemptive(true);
+        }
 	}
 
 	protected void close() throws XmlRpcClientException {
@@ -115,23 +119,35 @@
 		}
 	}
 
-	protected void writeRequest(final RequestWriter pWriter) throws XmlRpcException {
+	protected void writeRequest(final ReqWriter pWriter) throws XmlRpcException {
 		method.setRequestEntity(new RequestEntity(){
-			public boolean isRepeatable() { return false; }
+			public boolean isRepeatable() { return contentLength != -1; }
 			public void writeRequest(OutputStream pOut) throws IOException {
-				/* Make sure, that the socket is not closed by replacing it with our
-				 * own BufferedOutputStream.
-				 */
-				BufferedOutputStream bos = new BufferedOutputStream(pOut){
-					public void close() throws IOException {
-						flush();
-					}
-				};
 				try {
-					pWriter.write(bos);
+                    /* Make sure, that the socket is not closed by replacing it with our
+                     * own BufferedOutputStream.
+                     */
+                    OutputStream ostream;
+                    if (isUsingByteArrayOutput(config)) {
+                        // No need to buffer the output.
+                        ostream = new FilterOutputStream(pOut){
+                            public void close() throws IOException {
+                                flush();
+                            }
+                        };
+                    } else {
+                        ostream = new BufferedOutputStream(pOut){
+                            public void close() throws IOException {
+                                flush();
+                            }
+                        };
+                    }
+					pWriter.write(ostream);
 				} catch (XmlRpcException e) {
 					throw new XmlRpcIOException(e);
-				}
+				} catch (SAXException e) {
+                    throw new XmlRpcIOException(e);
+                }
 			}
 			public long getContentLength() { return contentLength; }
 			public String getContentType() { return "text/xml"; }

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransportFactory.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransportFactory.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransportFactory.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcCommonsTransportFactory.java Fri Aug 18 02:55:18 2006
@@ -20,17 +20,14 @@
  * HTTP Client.
  */
 public class XmlRpcCommonsTransportFactory extends XmlRpcTransportFactoryImpl {
-	private final XmlRpcCommonsTransport COMMONS_TRANSPORT;
-
 	/** Creates a new instance.
 	 * @param pClient The client, which is controlling the factory.
 	 */
 	public XmlRpcCommonsTransportFactory(XmlRpcClient pClient) {
 		super(pClient);
-		COMMONS_TRANSPORT = new XmlRpcCommonsTransport(pClient);
 	}
 
 	public XmlRpcTransport getTransport() {
-		return COMMONS_TRANSPORT;
+		return new XmlRpcCommonsTransport(getClient());
 	}
 }

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpTransport.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpTransport.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpTransport.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpTransport.java Fri Aug 18 02:55:18 2006
@@ -8,6 +8,7 @@
 import org.apache.xmlrpc.XmlRpcException;
 import org.apache.xmlrpc.XmlRpcRequest;
 import org.apache.xmlrpc.util.HttpUtil;
+import org.xml.sax.SAXException;
 
 
 /** Abstract base implementation of an HTTP transport. Base class for the
@@ -15,29 +16,27 @@
  * or {@link org.apache.xmlrpc.client.XmlRpcCommonsTransport}.
  */
 public abstract class XmlRpcHttpTransport extends XmlRpcStreamTransport {
-	protected class ByteArrayRequestWriter extends RequestWriter {
-		private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
-		protected ByteArrayRequestWriter(XmlRpcRequest pRequest)
-				throws XmlRpcException {
-			super(pRequest);
-			super.writeUncompressed(baos);
-		}
-
-		protected void writeUncompressed(OutputStream pStream) throws XmlRpcException {
-			try {
-				baos.writeTo(pStream);
-				pStream.close();
-				pStream = null;
-			} catch (IOException e) {
-				throw new XmlRpcException("Failed to write request: " + e.getMessage(), e);
-			} finally {
-				if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
-			}
-		}
-
-		protected int getContentLength() { return baos.size(); }
-	}
+    protected class ByteArrayReqWriter implements ReqWriter {
+        private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ByteArrayReqWriter(XmlRpcRequest pRequest)
+                throws XmlRpcException, IOException, SAXException {
+            new ReqWriterImpl(pRequest).write(baos);
+        }
+
+        protected int getContentLength() {
+            return baos.size();
+        }
+
+        public void write(OutputStream pStream) throws IOException {
+            try {
+                baos.writeTo(pStream);
+                pStream.close();
+                pStream = null;
+            } finally {
+                if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
+            }
+        }
+    }
 
 	private String userAgent;
 
@@ -95,20 +94,23 @@
 		return super.sendRequest(pRequest);
 	}
 
-	protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig pConfig) throws XmlRpcException {
+	protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig pConfig) {
 		return !pConfig.isEnabledForExtensions()
 			|| !pConfig.isContentLengthOptional();
 	}
 
-	protected RequestWriter newRequestWriter(XmlRpcRequest pRequest)
-			throws XmlRpcException {
+	protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
+			throws XmlRpcException, IOException, SAXException {
 		final XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
-		if (isUsingByteArrayOutput(config)) {
-			ByteArrayRequestWriter result = new ByteArrayRequestWriter(pRequest);
-			setContentLength(result.getContentLength());
-			return result;
+        if (isUsingByteArrayOutput(config)) {
+            ByteArrayReqWriter reqWriter = new ByteArrayReqWriter(pRequest);
+            setContentLength(reqWriter.getContentLength());
+            if (isCompressingRequest(config)) {
+                return new GzipReqWriter(reqWriter);
+            }
+            return reqWriter;
 		} else {
-			return super.newRequestWriter(pRequest);
+			return super.newReqWriter(pRequest);
 		}
 	}
 }

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLiteHttpTransport.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLiteHttpTransport.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLiteHttpTransport.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLiteHttpTransport.java Fri Aug 18 02:55:18 2006
@@ -36,6 +36,7 @@
 import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
 import org.apache.xmlrpc.util.HttpUtil;
 import org.apache.xmlrpc.util.LimitedInputStream;
+import org.xml.sax.SAXException;
 
 
 /** A "light" HTTP transport implementation.
@@ -234,16 +235,15 @@
 		}
 	}
 
-	protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig pConfig) throws XmlRpcException {
+	protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig pConfig) {
 	    boolean result = super.isUsingByteArrayOutput(pConfig);
         if (!result) {
-            throw new XmlRpcException("The Content-Length header is required with HTTP/1.0, and HTTP/1.1 is unsupported by the Lite HTTP Transport.");
+            throw new IllegalStateException("The Content-Length header is required with HTTP/1.0, and HTTP/1.1 is unsupported by the Lite HTTP Transport.");
         }
         return result;
     }
 
-    protected void writeRequest(RequestWriter pWriter) throws XmlRpcException {
-		OutputStream ostream = getOutputStream();
-		pWriter.write(ostream);
+    protected void writeRequest(ReqWriter pWriter) throws XmlRpcException, IOException, SAXException {
+        pWriter.write(getOutputStream());
 	}
 }

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransport.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransport.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransport.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransport.java Fri Aug 18 02:55:18 2006
@@ -17,12 +17,15 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcRequest;
 import org.apache.xmlrpc.common.LocalStreamConnection;
 import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
 import org.apache.xmlrpc.common.XmlRpcStreamRequestProcessor;
+import org.xml.sax.SAXException;
 
 
 /** Another local transport for debugging and testing. This one is
@@ -34,6 +37,7 @@
 public class XmlRpcLocalStreamTransport extends XmlRpcStreamTransport {
 	private final XmlRpcStreamRequestProcessor localServer;
 	private LocalStreamConnection conn;
+    private XmlRpcRequest request;
 	
 	/** Creates a new instance.
 	 * @param pClient The client, which is controlling the transport.
@@ -57,10 +61,17 @@
 		return new ByteArrayInputStream(conn.getResponse().toByteArray());
 	}
 
-	protected void writeRequest(RequestWriter pWriter) throws XmlRpcException {
+	protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
+            throws XmlRpcException, IOException, SAXException {
+	    request = pRequest;
+        return super.newReqWriter(pRequest);
+    }
+
+    protected void writeRequest(ReqWriter pWriter)
+            throws XmlRpcException, IOException, SAXException {
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();		
 		pWriter.write(baos);
-		XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) pWriter.getRequest().getConfig();
+		XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) request.getConfig();
 		conn = new LocalStreamConnection(config, new ByteArrayInputStream(baos.toByteArray()));
 	}
 }

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransportFactory.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransportFactory.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransportFactory.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcLocalStreamTransportFactory.java Fri Aug 18 02:55:18 2006
@@ -25,17 +25,19 @@
  * and parsing.
  */
 public class XmlRpcLocalStreamTransportFactory extends XmlRpcStreamTransportFactory {
-	private final XmlRpcLocalStreamTransport LOCAL_STREAM_TRANSPORT;
+    private final XmlRpcStreamRequestProcessor server;
 
-	/** Creates a new instance.
+    /** Creates a new instance.
 	 * @param pClient The client controlling the factory.
 	 * @param pServer An instance of {@link XmlRpcStreamRequestProcessor}.
 	 */
 	public XmlRpcLocalStreamTransportFactory(XmlRpcClient pClient,
 			XmlRpcStreamRequestProcessor pServer) {
 		super(pClient);
-		LOCAL_STREAM_TRANSPORT = new XmlRpcLocalStreamTransport(pClient, pServer);
-	}
+		server = pServer;
+    }
 
-	public XmlRpcTransport getTransport() { return LOCAL_STREAM_TRANSPORT; }
+	public XmlRpcTransport getTransport() {
+        return new XmlRpcLocalStreamTransport(getClient(), server);
+	}
 }

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcStreamTransport.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcStreamTransport.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcStreamTransport.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcStreamTransport.java Fri Aug 18 02:55:18 2006
@@ -39,72 +39,60 @@
  * the response,
  */
 public abstract class XmlRpcStreamTransport extends XmlRpcTransportImpl {
-	protected class RequestWriter {
-		private final XmlRpcRequest request;
+    protected interface ReqWriter {
+        /**
+         * Writes the requests data to the given output stream.
+         * The method ensures, that the target is being closed.
+         */
+        void write(OutputStream pStream) throws XmlRpcException, IOException, SAXException;
+    }
+
+    protected class ReqWriterImpl implements ReqWriter {
+        private final XmlRpcRequest request;
+
+        protected ReqWriterImpl(XmlRpcRequest pRequest) {
+            request = pRequest;
+        }
+
+        /** Writes the requests uncompressed XML data to the given
+         * output stream. Ensures, that the output stream is being
+         * closed.
+         */
+        public void write(OutputStream pStream)
+                throws XmlRpcException, IOException, SAXException {
+            final XmlRpcStreamConfig config = (XmlRpcStreamConfig) request.getConfig();
+            try {
+                ContentHandler h = getClient().getXmlWriterFactory().getXmlWriter(config, pStream);
+                XmlRpcWriter xw = new XmlRpcWriter(config, h, getClient().getTypeFactory());
+                xw.write(request);
+                pStream.close();
+                pStream = null;
+            } finally {
+                if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
+            }
+        }
+    }
+
+    protected class GzipReqWriter implements ReqWriter {
+        private final ReqWriter reqWriter;
+        protected GzipReqWriter(ReqWriter pReqWriter) {
+            reqWriter = pReqWriter;
+        }
+
+        public void write(OutputStream pStream) throws XmlRpcException, IOException, SAXException {
+            try {
+                GZIPOutputStream gStream = new GZIPOutputStream(pStream);
+                reqWriter.write(gStream);
+                pStream.close();
+                pStream = null;
+            } catch (IOException e) {
+                throw new XmlRpcException("Failed to write request: " + e.getMessage(), e);
+            } finally {
+                if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
+            }
+        }
+    }
 
-		protected RequestWriter(XmlRpcRequest pRequest) {
-			request = pRequest;
-		}
-
-		protected XmlRpcRequest getRequest() {
-			return request;
-		}
-
-		/** Writes the requests XML data to the given output stream,
-		 * possibly compressing it. Ensures, that the output stream
-		 * is being closed.
-		 */
-		protected void write(OutputStream pStream) throws XmlRpcException {
-			XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) request.getConfig();
-			if (isCompressingRequest(config)) {
-				try {
-					GZIPOutputStream gStream = new GZIPOutputStream(pStream);
-					writeUncompressed(gStream);
-					pStream.close();
-					pStream = null;
-				} catch (IOException e) {
-					throw new XmlRpcException("Failed to write request: " + e.getMessage(), e);
-				} finally {
-					if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
-				}
-			} else {
-				writeUncompressed(pStream);
-			}
-		}
-
-		/** Writes the requests uncompressed XML data to the given
-		 * output stream. Ensures, that the output stream is being
-		 * closed.
-		 */
-		protected void writeUncompressed(OutputStream pStream)
-				throws XmlRpcException {
-			final XmlRpcStreamConfig config = (XmlRpcStreamConfig) request.getConfig();
-			try {
-				ContentHandler h = getClient().getXmlWriterFactory().getXmlWriter(config, pStream);
-				XmlRpcWriter xw = new XmlRpcWriter(config, h, getClient().getTypeFactory());
-				xw.write(request);
-				pStream.close();
-				pStream = null;
-			} catch (SAXException e) {
-				Exception ex = e.getException();
-				if (ex != null  &&  ex instanceof XmlRpcException) {
-					throw (XmlRpcException) ex;
-				} else {
-					throw new XmlRpcClientException("Failed to send request: " + e.getMessage(), e);
-				}
-			} catch (IOException e) {
-				throw new XmlRpcException("Failed to write request: " + e.getMessage(), e);
-			} finally {
-				if (pStream != null) { try { pStream.close(); } catch (Throwable ignore) {} }
-			}
-		}
-	}
-
-	protected RequestWriter newRequestWriter(XmlRpcRequest pRequest)
-			throws XmlRpcException {
-		return new RequestWriter(pRequest);
-	}
-	
 	/** Creates a new instance on behalf of the given client.
 	 */
 	protected XmlRpcStreamTransport(XmlRpcClient pClient) {
@@ -122,10 +110,6 @@
 	 */
 	protected abstract boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig pConfig);
 
-	/** Invokes the request writer.
-	 */
-	protected abstract void writeRequest(RequestWriter pWriter) throws XmlRpcException;
-
 	/** Returns the input stream, from which the response is
 	 * being read.
 	 */
@@ -136,12 +120,24 @@
 			&& pConfig.isGzipCompressing();
 	}
 
+    protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
+            throws XmlRpcException, IOException, SAXException {
+        ReqWriter reqWriter = new ReqWriterImpl(pRequest);
+        if (isCompressingRequest((XmlRpcStreamRequestConfig) pRequest.getConfig())) {
+            reqWriter = new GzipReqWriter(reqWriter);
+        }
+        return reqWriter;
+    }
+
+    protected abstract void writeRequest(ReqWriter pWriter)
+        throws XmlRpcException, IOException, SAXException;
+    
 	public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
 		XmlRpcStreamRequestConfig config = (XmlRpcStreamRequestConfig) pRequest.getConfig();
 		boolean closed = false;
 		try {
-			RequestWriter writer = newRequestWriter(pRequest);
-			writeRequest(writer);
+            ReqWriter reqWriter = newReqWriter(pRequest);
+			writeRequest(reqWriter);
 			InputStream istream = getInputStream();
 			if (isResponseGzipCompressed(config)) {
 				istream = new GZIPInputStream(istream);
@@ -153,6 +149,13 @@
 		} catch (IOException e) {
 			throw new XmlRpcException("Failed to read servers response: "
 					+ e.getMessage(), e);
+        } catch (SAXException e) {
+            Exception ex = e.getException();
+            if (ex != null  &&  ex instanceof XmlRpcException) {
+                throw (XmlRpcException) ex;
+            }
+            throw new XmlRpcException("Failed to generate request: "
+                    + e.getMessage(), e);
 		} finally {
 			if (!closed) { try { close(); } catch (Throwable ignore) {} }
 		}

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcSunHttpTransport.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcSunHttpTransport.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcSunHttpTransport.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcSunHttpTransport.java Fri Aug 18 02:55:18 2006
@@ -2,7 +2,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URLConnection;
 
@@ -10,6 +9,7 @@
 import org.apache.xmlrpc.XmlRpcRequest;
 import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
 import org.apache.xmlrpc.util.HttpUtil;
+import org.xml.sax.SAXException;
 
 
 /** Default implementation of an HTTP transport, based on the
@@ -61,13 +61,7 @@
 		}
 	}
 
-	protected void writeRequest(RequestWriter pWriter) throws XmlRpcException {
-		OutputStream ostream;
-		try {
-			 ostream = conn.getOutputStream();
-		} catch (IOException e) {
-			throw new XmlRpcException("Failed to create output stream: " + e.getMessage(), e);
-		}
-		pWriter.write(ostream);
+	protected void writeRequest(ReqWriter pWriter) throws IOException, XmlRpcException, SAXException {
+        pWriter.write(conn.getOutputStream());
 	}
 }

Modified: webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcTransportFactory.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcTransportFactory.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcTransportFactory.java (original)
+++ webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcTransportFactory.java Fri Aug 18 02:55:18 2006
@@ -21,7 +21,7 @@
  * is typically based on singletons.
  */
 public interface XmlRpcTransportFactory {
-	/** Returns an instance of {@link XmlRpcTransport}. This may
+    /** Returns an instance of {@link XmlRpcTransport}. This may
 	 * be a singleton, but the caller should not depend on that:
 	 * A new instance may as well be created for any request.
 	 * @return The configured transport.

Modified: webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/util/HttpUtil.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/util/HttpUtil.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/util/HttpUtil.java (original)
+++ webservices/xmlrpc/trunk/common/src/main/java/org/apache/xmlrpc/util/HttpUtil.java Fri Aug 18 02:55:18 2006
@@ -40,11 +40,12 @@
         if (pUser == null) {
 			return null;
         }
-		String s = pUser + ':' + pPassword;
+        final String s = pUser + ':' + pPassword;
 		if (pEncoding == null) {
 			pEncoding = XmlRpcStreamConfig.UTF8_ENCODING;
 		}
-		return new String(Base64.encode(s.getBytes(pEncoding))).trim();
+        final byte[] bytes = s.getBytes(pEncoding);
+		return Base64.encode(s.getBytes(pEncoding), 0, bytes.length, 0, null);
     }
 
 	/** Returns, whether the HTTP header value <code>pHeaderValue</code>
@@ -140,7 +141,11 @@
 		String auth = st.nextToken();
 	    try {
 	        byte[] c = Base64.decode(auth.toCharArray(), 0, auth.length());
-	        String str = new String(c, pConfig.getBasicEncoding());
+	        String enc = pConfig.getBasicEncoding();
+            if (enc == null) {
+                enc = XmlRpcStreamConfig.UTF8_ENCODING;
+            }
+            String str = new String(c, enc);
 	        int col = str.indexOf(':');
 			if (col >= 0) {
 				pConfig.setBasicUserName(str.substring(0, col));

Modified: webservices/xmlrpc/trunk/pom.xml
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/pom.xml?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/pom.xml (original)
+++ webservices/xmlrpc/trunk/pom.xml Fri Aug 18 02:55:18 2006
@@ -128,6 +128,10 @@
             <email>rhavyn@gmail.com</email>
         </contributor>
         <contributor>
+            <name>Landon Fuller</name>
+            <email>landonf@threerings.net</email>
+        </contributor>
+        <contributor>
             <name>Jimisola Laursen</name>
             <email>lists@jimisola.com</email>
         </contributor>

Modified: webservices/xmlrpc/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/changes/changes.xml?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/src/changes/changes.xml (original)
+++ webservices/xmlrpc/trunk/src/changes/changes.xml Fri Aug 18 02:55:18 2006
@@ -18,6 +18,21 @@
           due-to-email="stanislav.miklik@gmail.com">
         Fixed an endless loop, if the WebServer threw a BindException.
       </action>
+      <action dev="jochen" type="fix" due-to="Landon Fuller"
+          due-to-email="landonf@threerings.net" issue="XMLRPC-104">
+        A NullPointerException was triggered, if the BasicEncoding was set to null.
+      </action>
+      <action dev="jochen" type="fix" due-to="Landon Fuller"
+          due-to-email="landonf@threerings.net" issue="XMLRPC-104">
+		Basic authentication didn't work, if the base64 encoded string with
+		user name and password contained more than 72 characters.
+      </action>
+      <action dev="jochen" type="fix" due-to="Landon Fuller"
+          due-to-email="landonf@threerings.net">
+        Basic authentication didn't work with the commons http transport,
+        because the commons httpclient wasn't configured to send credentials
+        by default. (It was waiting for a challenge.)
+      </action>
     </release>
     <release version="3.0rc1" date="27-Jul-2006">
       <action dev="jochen" type="fix" due-to="Alan Burlison"

Modified: webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java
URL: http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java?rev=432537&r1=432536&r2=432537&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java (original)
+++ webservices/xmlrpc/trunk/tests/src/test/java/org/apache/xmlrpc/test/XmlRpcTestCase.java Fri Aug 18 02:55:18 2006
@@ -17,6 +17,8 @@
 
 import java.io.IOException;
 
+import javax.servlet.ServletException;
+
 import org.apache.xmlrpc.XmlRpcException;
 import org.apache.xmlrpc.client.XmlRpcClientConfig;
 import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
@@ -52,20 +54,23 @@
         return mapping;
     }
 
-    public void setUp() throws Exception {
-        if (providers == null) {
-            XmlRpcHandlerMapping mapping = getHandlerMapping();
-            providers = new ClientProvider[]{
-                new LocalTransportProvider(mapping),
-                new LocalStreamTransportProvider(mapping),
-                new LiteTransportProvider(mapping, true),
+    protected ClientProvider[] initProviders(XmlRpcHandlerMapping pMapping) throws ServletException, IOException {
+        return new ClientProvider[]{
+                new LocalTransportProvider(pMapping),
+                new LocalStreamTransportProvider(pMapping),
+                new LiteTransportProvider(pMapping, true),
                 // new LiteTransportProvider(mapping, false), Doesn't support HTTP/1.1
-                new SunHttpTransportProvider(mapping, true),
-                new SunHttpTransportProvider(mapping, false),
-                new CommonsProvider(mapping),
-                new ServletWebServerProvider(mapping, true),
-                new ServletWebServerProvider(mapping, false)
+                new SunHttpTransportProvider(pMapping, true),
+                new SunHttpTransportProvider(pMapping, false),
+                new CommonsProvider(pMapping),
+                new ServletWebServerProvider(pMapping, true),
+                new ServletWebServerProvider(pMapping, false)
             };
+    }
+
+    public void setUp() throws Exception {
+        if (providers == null) {
+            providers = initProviders(getHandlerMapping());
         }
     }