Author: jochen
Date: Sat Oct 27 07:50:27 2007
New Revision: 589121

URL: http://svn.apache.org/viewvc?rev=589121&view=rev
Log:
It is now possible to set the user-agent header in the clients configuration.
PR: XMLRPC-149
Submitted-By: Andreas Sahlbach <[EMAIL PROTECTED]>

Modified:
    
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcClientConfigImpl.java
    
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpClientConfig.java
    
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpTransport.java
    webservices/xmlrpc/trunk/pom.xml
    webservices/xmlrpc/trunk/src/changes/changes.xml

Modified: 
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcClientConfigImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcClientConfigImpl.java?rev=589121&r1=589120&r2=589121&view=diff
==============================================================================
--- 
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcClientConfigImpl.java
 (original)
+++ 
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcClientConfigImpl.java
 Sat Oct 27 07:50:27 2007
@@ -1,65 +1,81 @@
-/*
- * Copyright 1999,2005 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.client;
-
-import java.io.Serializable;
-import java.net.URL;
-
-import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
-import org.apache.xmlrpc.common.XmlRpcRequestProcessor;
-
-
-/** Default implementation of a clients request configuration.
- */
-public class XmlRpcClientConfigImpl extends XmlRpcHttpRequestConfigImpl
-               implements XmlRpcHttpClientConfig, XmlRpcLocalClientConfig, 
Cloneable, Serializable {
-       private static final long serialVersionUID = 4121131450507800889L;
-       private URL serverURL;
-       private XmlRpcRequestProcessor xmlRpcServer;
-
-       /** Creates a new client configuration with default settings.
-        */
-       public XmlRpcClientConfigImpl() {
-       }
-
-       /** Creates a clone of this client configuration.
-        * @return A clone of this configuration.
-        */
-       public XmlRpcClientConfigImpl cloneMe() {
-               try {
-                       return (XmlRpcClientConfigImpl) clone();
-               } catch (CloneNotSupportedException e) {
-                       throw new IllegalStateException("Unable to create my 
clone");
-               }
-       }
-
-       /** Sets the servers URL.
-        * @param pURL Servers URL
-        */
-       public void setServerURL(URL pURL) {
-               serverURL = pURL;
-       }
-       public URL getServerURL() { return serverURL; }
-       /** Returns the [EMAIL PROTECTED] XmlRpcRequestProcessor} being invoked.
-        * @param pServer Server object being invoked. This will typically
-        * be a singleton instance, but could as well create a new
-        * instance with any call.
-        */
-       public void setXmlRpcServer(XmlRpcRequestProcessor pServer) {
-               xmlRpcServer = pServer;
-       }
-       public XmlRpcRequestProcessor getXmlRpcServer() { return xmlRpcServer; }
-}
+/*
+ * Copyright 1999,2005 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.client;
+
+import java.io.Serializable;
+import java.net.URL;
+
+import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
+import org.apache.xmlrpc.common.XmlRpcRequestProcessor;
+
+
+/** Default implementation of a clients request configuration.
+ */
+public class XmlRpcClientConfigImpl extends XmlRpcHttpRequestConfigImpl
+               implements XmlRpcHttpClientConfig, XmlRpcLocalClientConfig, 
Cloneable, Serializable {
+       private static final long serialVersionUID = 4121131450507800889L;
+       private URL serverURL;
+       private XmlRpcRequestProcessor xmlRpcServer;
+    private String userAgent;
+
+       /** Creates a new client configuration with default settings.
+        */
+       public XmlRpcClientConfigImpl() {
+       }
+
+       /** Creates a clone of this client configuration.
+        * @return A clone of this configuration.
+        */
+       public XmlRpcClientConfigImpl cloneMe() {
+               try {
+                       return (XmlRpcClientConfigImpl) clone();
+               } catch (CloneNotSupportedException e) {
+                       throw new IllegalStateException("Unable to create my 
clone");
+               }
+       }
+
+       /** Sets the servers URL.
+        * @param pURL Servers URL
+        */
+       public void setServerURL(URL pURL) {
+               serverURL = pURL;
+       }
+       public URL getServerURL() { return serverURL; }
+       /** Returns the [EMAIL PROTECTED] XmlRpcRequestProcessor} being invoked.
+        * @param pServer Server object being invoked. This will typically
+        * be a singleton instance, but could as well create a new
+        * instance with any call.
+        */
+       public void setXmlRpcServer(XmlRpcRequestProcessor pServer) {
+               xmlRpcServer = pServer;
+       }
+       public XmlRpcRequestProcessor getXmlRpcServer() { return xmlRpcServer; }
+
+    /**
+     * Returns the user agent header to use 
+     * @return the http user agent header to set when doing xmlrpc requests
+     */
+    public String getUserAgent() {
+        return userAgent;
+    }
+    
+    /**
+     * @param pUserAgent the http user agent header to set when doing xmlrpc 
requests
+     */
+    public void setUserAgent(String pUserAgent) {
+        userAgent = pUserAgent;
+    }
+}

Modified: 
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpClientConfig.java
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpClientConfig.java?rev=589121&r1=589120&r2=589121&view=diff
==============================================================================
--- 
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpClientConfig.java
 (original)
+++ 
webservices/xmlrpc/trunk/client/src/main/java/org/apache/xmlrpc/client/XmlRpcHttpClientConfig.java
 Sat Oct 27 07:50:27 2007
@@ -1,33 +1,39 @@
-/*
- * Copyright 1999,2005 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.client;
-
-import java.net.URL;
-
-import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig;
-
-
-/** Extension of [EMAIL PROTECTED] org.apache.xmlrpc.client.XmlRpcClientConfig}
- * for HTTP based transport. Provides details like server URL,
- * user credentials, and so on.
- */
-public interface XmlRpcHttpClientConfig extends XmlRpcHttpRequestConfig {
-       /** Returns the HTTP servers URL.
-        * @return XML-RPC servers URL; for example, this may be the URL of a
-        * servlet
-        */
-       URL getServerURL();
-}
+/*
+ * Copyright 1999,2005 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.client;
+
+import java.net.URL;
+
+import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig;
+
+
+/** Extension of [EMAIL PROTECTED] org.apache.xmlrpc.client.XmlRpcClientConfig}
+ * for HTTP based transport. Provides details like server URL,
+ * user credentials, and so on.
+ */
+public interface XmlRpcHttpClientConfig extends XmlRpcHttpRequestConfig {
+       /** Returns the HTTP servers URL.
+        * @return XML-RPC servers URL; for example, this may be the URL of a
+        * servlet
+        */
+       URL getServerURL();
+    
+    /**
+     * Returns the user agent header to use 
+     * @return the http user agent header to set when doing xmlrpc requests
+     */
+    String getUserAgent();
+}

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=589121&r1=589120&r2=589121&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
 Sat Oct 27 07:50:27 2007
@@ -1,116 +1,119 @@
-package org.apache.xmlrpc.client;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-
-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
- * concrete implementations, like [EMAIL PROTECTED] 
org.apache.xmlrpc.client.XmlRpcSunHttpTransport},
- * or [EMAIL PROTECTED] org.apache.xmlrpc.client.XmlRpcCommonsTransport}.
- */
-public abstract class XmlRpcHttpTransport extends XmlRpcStreamTransport {
-    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;
-
-       /** The user agent string.
-        */
-       public static final String USER_AGENT = "Apache XML RPC 3.0";
-
-       protected XmlRpcHttpTransport(XmlRpcClient pClient, String pUserAgent) {
-               super(pClient);
-               userAgent = pUserAgent;
-       }
-
-       protected String getUserAgent() { return userAgent; }
-
-       protected abstract void setRequestHeader(String pHeader, String pValue);
-
-       protected void setCredentials(XmlRpcHttpClientConfig pConfig)
-                       throws XmlRpcClientException {
-               String auth;
-               try {
-                       auth = 
HttpUtil.encodeBasicAuthentication(pConfig.getBasicUserName(),
-                                                                               
                          pConfig.getBasicPassword(),
-                                                                               
                          pConfig.getBasicEncoding());
-               } catch (UnsupportedEncodingException e) {
-                       throw new XmlRpcClientException("Unsupported encoding: 
" + pConfig.getBasicEncoding(), e);
-               }
-               if (auth != null) {
-                       setRequestHeader("Authorization", "Basic " + auth);
-               }
-       }
-
-       protected void setContentLength(int pLength) {
-               setRequestHeader("Content-Length", Integer.toString(pLength));
-       }
-
-       protected void setCompressionHeaders(XmlRpcHttpClientConfig pConfig) {
-               if (pConfig.isGzipCompressing()) {
-                       setRequestHeader("Content-Encoding", "gzip");
-               }
-               if (pConfig.isGzipRequesting()) {
-                       setRequestHeader("Accept-Encoding", "gzip");
-               }
-       }
-
-       protected void initHttpHeaders(XmlRpcRequest pRequest) throws 
XmlRpcClientException {
-               XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) 
pRequest.getConfig();
-               setRequestHeader("Content-Type", "text/xml");
-               setRequestHeader("User-Agent", getUserAgent());
-               setCredentials(config);
-               setCompressionHeaders(config);
-       }
-
-       public Object sendRequest(XmlRpcRequest pRequest) throws 
XmlRpcException {
-               initHttpHeaders(pRequest);
-               return super.sendRequest(pRequest);
-       }
-
-       protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig 
pConfig) {
-               return !pConfig.isEnabledForExtensions()
-                       || !pConfig.isContentLengthOptional();
-       }
-
-       protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
-                       throws XmlRpcException, IOException, SAXException {
-               final XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) 
pRequest.getConfig();
-        if (isUsingByteArrayOutput(config)) {
-            ByteArrayReqWriter reqWriter = new ByteArrayReqWriter(pRequest);
-            setContentLength(reqWriter.getContentLength());
-            if (isCompressingRequest(config)) {
-                return new GzipReqWriter(reqWriter);
-            }
-            return reqWriter;
-               } else {
-                       return super.newReqWriter(pRequest);
-               }
-       }
-}
+package org.apache.xmlrpc.client;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+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
+ * concrete implementations, like [EMAIL PROTECTED] 
org.apache.xmlrpc.client.XmlRpcSunHttpTransport},
+ * or [EMAIL PROTECTED] org.apache.xmlrpc.client.XmlRpcCommonsTransport}.
+ */
+public abstract class XmlRpcHttpTransport extends XmlRpcStreamTransport {
+    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;
+
+       /** The user agent string.
+        */
+       public static final String USER_AGENT = "Apache XML RPC 3.0";
+
+       protected XmlRpcHttpTransport(XmlRpcClient pClient, String pUserAgent) {
+               super(pClient);
+               userAgent = pUserAgent;
+       }
+
+       protected String getUserAgent() { return userAgent; }
+
+       protected abstract void setRequestHeader(String pHeader, String pValue);
+
+       protected void setCredentials(XmlRpcHttpClientConfig pConfig)
+                       throws XmlRpcClientException {
+               String auth;
+               try {
+                       auth = 
HttpUtil.encodeBasicAuthentication(pConfig.getBasicUserName(),
+                                                                               
                          pConfig.getBasicPassword(),
+                                                                               
                          pConfig.getBasicEncoding());
+               } catch (UnsupportedEncodingException e) {
+                       throw new XmlRpcClientException("Unsupported encoding: 
" + pConfig.getBasicEncoding(), e);
+               }
+               if (auth != null) {
+                       setRequestHeader("Authorization", "Basic " + auth);
+               }
+       }
+
+       protected void setContentLength(int pLength) {
+               setRequestHeader("Content-Length", Integer.toString(pLength));
+       }
+
+       protected void setCompressionHeaders(XmlRpcHttpClientConfig pConfig) {
+               if (pConfig.isGzipCompressing()) {
+                       setRequestHeader("Content-Encoding", "gzip");
+               }
+               if (pConfig.isGzipRequesting()) {
+                       setRequestHeader("Accept-Encoding", "gzip");
+               }
+       }
+
+       protected void initHttpHeaders(XmlRpcRequest pRequest) throws 
XmlRpcClientException {
+               XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) 
pRequest.getConfig();
+               setRequestHeader("Content-Type", "text/xml");
+        if(config.getUserAgent() != null)
+            setRequestHeader("User-Agent", config.getUserAgent());
+        else
+            setRequestHeader("User-Agent", getUserAgent());
+               setCredentials(config);
+               setCompressionHeaders(config);
+       }
+
+       public Object sendRequest(XmlRpcRequest pRequest) throws 
XmlRpcException {
+               initHttpHeaders(pRequest);
+               return super.sendRequest(pRequest);
+       }
+
+       protected boolean isUsingByteArrayOutput(XmlRpcHttpClientConfig 
pConfig) {
+               return !pConfig.isEnabledForExtensions()
+                       || !pConfig.isContentLengthOptional();
+       }
+
+       protected ReqWriter newReqWriter(XmlRpcRequest pRequest)
+                       throws XmlRpcException, IOException, SAXException {
+               final XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) 
pRequest.getConfig();
+        if (isUsingByteArrayOutput(config)) {
+            ByteArrayReqWriter reqWriter = new ByteArrayReqWriter(pRequest);
+            setContentLength(reqWriter.getContentLength());
+            if (isCompressingRequest(config)) {
+                return new GzipReqWriter(reqWriter);
+            }
+            return reqWriter;
+               } else {
+                       return super.newReqWriter(pRequest);
+               }
+       }
+}

Modified: webservices/xmlrpc/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/pom.xml?rev=589121&r1=589120&r2=589121&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/pom.xml (original)
+++ webservices/xmlrpc/trunk/pom.xml Sat Oct 27 07:50:27 2007
@@ -216,6 +216,10 @@
             <email>[EMAIL PROTECTED]</email>
         </contributor>
         <contributor>
+            <name>Andreas Sahlbach</name>
+            <email>[EMAIL PROTECTED]</email>
+        </contributor>
+        <contributor>
             <name>Ken Weiner</name>
             <email>[EMAIL PROTECTED]</email>
         </contributor>

Modified: webservices/xmlrpc/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/webservices/xmlrpc/trunk/src/changes/changes.xml?rev=589121&r1=589120&r2=589121&view=diff
==============================================================================
--- webservices/xmlrpc/trunk/src/changes/changes.xml (original)
+++ webservices/xmlrpc/trunk/src/changes/changes.xml Sat Oct 27 07:50:27 2007
@@ -5,6 +5,11 @@
   <body>
     <release version="3.1.1-SNAPSHOT" date="Not yet released">
       <action dev="jochen" type="fix" due-to="P&#243;ka Bal&#225;zs" 
due-to-email="[EMAIL PROTECTED]">
+        The XmlRpcCommonsTransport is now always declaring its entities as 
repeatable.
+      </action>
+      <action dev="jochen" type="add" due-to="Andreas Sahlbach" 
due-to-email="[EMAIL PROTECTED]"
+          issue="XMLRPC-149">
+        It is now possible to set the clients user-agent header in the client 
configuration.
       </action>
     </release>
     <release version="3.1" date="2007-Aug-31">


Reply via email to