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 Ryan Hoegg <rh...@isisnetworks.net> on 2002/03/08 03:53:28 UTC

[PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Hi all,

Not too sure if this is something you guys want to include.  It is 
within the spec at http://www.xmlrpc.com/spec:

A User-Agent and Host must be specified.

Basically, I needed to be able to set this because a service provider I 
use requires this field to be used as a part of the "authentication" 
process.

So without further ado...

--------------------------------------------------------------------------
diff -u -r1.8 XmlRpcClient.java
--- XmlRpcClient.java    20 Feb 2002 18:06:04 -0000    1.8
+++ XmlRpcClient.java    8 Mar 2002 02:43:19 -0000
@@ -70,7 +70,10 @@
 public class XmlRpcClient
     implements XmlRpcHandler
 {
+    private static final String DEFAULT_USER_AGENT = XmlRpc.version;
+   
     protected URL url;
+    protected String userAgent;
     private String auth;
 
     // pool of worker instances
@@ -131,7 +134,14 @@
                 .getBytes())).trim();
         }
     }
-
+   
+    /**
+      * Set a custom User-Agent header for XML-RPC requests
+      */
+    public void setUserAgent(String customUserAgent)
+    {
+        userAgent = customUserAgent;
+    }
 
     /**
       * Generate an XML-RPC request and send it to the server. Parse 
the result and
@@ -381,6 +391,11 @@
                 con.setRequestProperty("Content-Length",
                         Integer.toString(request.length));
                 con.setRequestProperty("Content-Type", "text/xml");
+                if (userAgent == "") // Client has not given us a 
custom User-Agent property
+                {
+                    userAgent = DEFAULT_USER_AGENT;
+                }
+                con.setRequestProperty("User-Agent", userAgent);
                 if (auth != null)
                 {
                     con.setRequestProperty("Authorization", "Basic " + 
auth);



Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Ryan Hoegg <rh...@isisnetworks.net>.
Daniel Rall wrote:

>Ryan Hoegg <rh...@isisnetworks.net> writes:
>
>>Hi Daniel, and everyone,
>>In my research into my cookie issue, I found some interesting ideas.
>>What would you all think about using the Jakarta Commons HTTP Client
>>instead of java.net.URLConnection?
>>
>>That wouldn't address the server header generation but its feature set
>>is much more complete than URLConnection.
>>
>
>This is an interesting idea.  What specific issues would it address?
>
>>If we are looking for something more generalized, does anyone have any
>>suggestions for one HTTP communication library for the whole package? 
>>The stripped down Catalina for instance?
>>
>>I'm willing to do the legwork if it looks worthwhile.
>>
>
>Would you enumerate the benefits here?
>
Well, I am going to make sure I fully understand how I can use the 
existing code to accomplish my goals (custom HTTP headers and cookie 
support) by going through a Servlet before I give this a full response. 
 My initial feeling is that this would remove some complexity for 
programmers wanting to use the library for  its XML-RPC client only, but 
I will defer this until I try your idea.

Ryan Hoegg

Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Ryan Hoegg <rh...@isisnetworks.net>.
Daniel Rall wrote:

>Ryan Hoegg <rh...@isisnetworks.net> writes:
>
>>Hi Daniel, and everyone,
>>In my research into my cookie issue, I found some interesting ideas.
>>What would you all think about using the Jakarta Commons HTTP Client
>>instead of java.net.URLConnection?
>>
>>That wouldn't address the server header generation but its feature set
>>is much more complete than URLConnection.
>>
>
>This is an interesting idea.  What specific issues would it address?
>
>>If we are looking for something more generalized, does anyone have any
>>suggestions for one HTTP communication library for the whole package? 
>>The stripped down Catalina for instance?
>>
>>I'm willing to do the legwork if it looks worthwhile.
>>
>
>Would you enumerate the benefits here?
>
Well, I am going to make sure I fully understand how I can use the 
existing code to accomplish my goals (custom HTTP headers and cookie 
support) by going through a Servlet before I give this a full response. 
 My initial feeling is that this would remove some complexity for 
programmers wanting to use the library for  its XML-RPC client only, but 
I will defer this until I try your idea.

Ryan Hoegg

Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Ryan Hoegg <rh...@isisnetworks.net> writes:

> Hi Daniel, and everyone,
> In my research into my cookie issue, I found some interesting ideas.
> What would you all think about using the Jakarta Commons HTTP Client
> instead of java.net.URLConnection?
>
> That wouldn't address the server header generation but its feature set
> is much more complete than URLConnection.

This is an interesting idea.  What specific issues would it address?

> If we are looking for something more generalized, does anyone have any
> suggestions for one HTTP communication library for the whole package? 
> The stripped down Catalina for instance?
>
> I'm willing to do the legwork if it looks worthwhile.

Would you enumerate the benefits here?


                             Thanks, Dan

Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Ryan Hoegg <rh...@isisnetworks.net> writes:

> Hi Daniel, and everyone,
> In my research into my cookie issue, I found some interesting ideas.
> What would you all think about using the Jakarta Commons HTTP Client
> instead of java.net.URLConnection?
>
> That wouldn't address the server header generation but its feature set
> is much more complete than URLConnection.

This is an interesting idea.  What specific issues would it address?

> If we are looking for something more generalized, does anyone have any
> suggestions for one HTTP communication library for the whole package? 
> The stripped down Catalina for instance?
>
> I'm willing to do the legwork if it looks worthwhile.

Would you enumerate the benefits here?


                             Thanks, Dan

Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Ryan Hoegg <rh...@isisnetworks.net>.
Hi Daniel, and everyone,
In my research into my cookie issue, I found some interesting ideas.
What would you all think about using the Jakarta Commons HTTP Client 
instead of java.net.URLConnection?

That wouldn't address the server header generation but its feature set 
is much more complete than URLConnection.

If we are looking for something more generalized, does anyone have any 
suggestions for one HTTP communication library for the whole package? 
 The stripped down Catalina for instance?

I'm willing to do the legwork if it looks worthwhile.

Ryan Hoegg

Daniel Rall wrote:

>I'm goning to skip this one (though I'm not against someone else
>sprucing that up and merging it in).  What's actually needed is some
>code normalization between client, client lite, and server header
>generation.
>
>Ryan Hoegg <rh...@isisnetworks.net> writes:
>
>>Hi all,
>>
>>Not too sure if this is something you guys want to include.  It is
>>within the spec at http://www.xmlrpc.com/spec:
>>
>>A User-Agent and Host must be specified.
>>
>>Basically, I needed to be able to set this because a service provider
>>I use requires this field to be used as a part of the "authentication"
>>process.
>>
>>So without further ado...
>>
>>--------------------------------------------------------------------------
>>diff -u -r1.8 XmlRpcClient.java
>>--- XmlRpcClient.java    20 Feb 2002 18:06:04 -0000    1.8
>>+++ XmlRpcClient.java    8 Mar 2002 02:43:19 -0000
>>@@ -70,7 +70,10 @@
>> public class XmlRpcClient
>>     implements XmlRpcHandler
>> {
>>+    private static final String DEFAULT_USER_AGENT = XmlRpc.version;
>>+      protected URL url;
>>+    protected String userAgent;
>>     private String auth;
>>    // pool of worker instances
>>@@ -131,7 +134,14 @@
>>                 .getBytes())).trim();
>>         }
>>     }
>>-
>>+   +    /**
>>+      * Set a custom User-Agent header for XML-RPC requests
>>+      */
>>+    public void setUserAgent(String customUserAgent)
>>+    {
>>+        userAgent = customUserAgent;
>>+    }
>>    /**
>>       * Generate an XML-RPC request and send it to the server. Parse
>>the result and
>>@@ -381,6 +391,11 @@
>>                 con.setRequestProperty("Content-Length",
>>                         Integer.toString(request.length));
>>                 con.setRequestProperty("Content-Type", "text/xml");
>>+                if (userAgent == "") // Client has not given us a
>>custom User-Agent property
>>+                {
>>+                    userAgent = DEFAULT_USER_AGENT;
>>+                }
>>+                con.setRequestProperty("User-Agent", userAgent);
>>                 if (auth != null)
>>                 {
>>                     con.setRequestProperty("Authorization", "Basic "
>>+ auth);
>>



Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Ryan Hoegg <rh...@isisnetworks.net>.
Hi Daniel, and everyone,
In my research into my cookie issue, I found some interesting ideas.
What would you all think about using the Jakarta Commons HTTP Client 
instead of java.net.URLConnection?

That wouldn't address the server header generation but its feature set 
is much more complete than URLConnection.

If we are looking for something more generalized, does anyone have any 
suggestions for one HTTP communication library for the whole package? 
 The stripped down Catalina for instance?

I'm willing to do the legwork if it looks worthwhile.

Ryan Hoegg

Daniel Rall wrote:

>I'm goning to skip this one (though I'm not against someone else
>sprucing that up and merging it in).  What's actually needed is some
>code normalization between client, client lite, and server header
>generation.
>
>Ryan Hoegg <rh...@isisnetworks.net> writes:
>
>>Hi all,
>>
>>Not too sure if this is something you guys want to include.  It is
>>within the spec at http://www.xmlrpc.com/spec:
>>
>>A User-Agent and Host must be specified.
>>
>>Basically, I needed to be able to set this because a service provider
>>I use requires this field to be used as a part of the "authentication"
>>process.
>>
>>So without further ado...
>>
>>--------------------------------------------------------------------------
>>diff -u -r1.8 XmlRpcClient.java
>>--- XmlRpcClient.java    20 Feb 2002 18:06:04 -0000    1.8
>>+++ XmlRpcClient.java    8 Mar 2002 02:43:19 -0000
>>@@ -70,7 +70,10 @@
>> public class XmlRpcClient
>>     implements XmlRpcHandler
>> {
>>+    private static final String DEFAULT_USER_AGENT = XmlRpc.version;
>>+      protected URL url;
>>+    protected String userAgent;
>>     private String auth;
>>    // pool of worker instances
>>@@ -131,7 +134,14 @@
>>                 .getBytes())).trim();
>>         }
>>     }
>>-
>>+   +    /**
>>+      * Set a custom User-Agent header for XML-RPC requests
>>+      */
>>+    public void setUserAgent(String customUserAgent)
>>+    {
>>+        userAgent = customUserAgent;
>>+    }
>>    /**
>>       * Generate an XML-RPC request and send it to the server. Parse
>>the result and
>>@@ -381,6 +391,11 @@
>>                 con.setRequestProperty("Content-Length",
>>                         Integer.toString(request.length));
>>                 con.setRequestProperty("Content-Type", "text/xml");
>>+                if (userAgent == "") // Client has not given us a
>>custom User-Agent property
>>+                {
>>+                    userAgent = DEFAULT_USER_AGENT;
>>+                }
>>+                con.setRequestProperty("User-Agent", userAgent);
>>                 if (auth != null)
>>                 {
>>                     con.setRequestProperty("Authorization", "Basic "
>>+ auth);
>>



Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Daniel Rall <dl...@finemaltcoding.com>.
I'm goning to skip this one (though I'm not against someone else
sprucing that up and merging it in).  What's actually needed is some
code normalization between client, client lite, and server header
generation.

Ryan Hoegg <rh...@isisnetworks.net> writes:

> Hi all,
>
> Not too sure if this is something you guys want to include.  It is
> within the spec at http://www.xmlrpc.com/spec:
>
> A User-Agent and Host must be specified.
>
> Basically, I needed to be able to set this because a service provider
> I use requires this field to be used as a part of the "authentication"
> process.
>
> So without further ado...
>
> --------------------------------------------------------------------------
> diff -u -r1.8 XmlRpcClient.java
> --- XmlRpcClient.java    20 Feb 2002 18:06:04 -0000    1.8
> +++ XmlRpcClient.java    8 Mar 2002 02:43:19 -0000
> @@ -70,7 +70,10 @@
>  public class XmlRpcClient
>      implements XmlRpcHandler
>  {
> +    private static final String DEFAULT_USER_AGENT = XmlRpc.version;
> +      protected URL url;
> +    protected String userAgent;
>      private String auth;
>     // pool of worker instances
> @@ -131,7 +134,14 @@
>                  .getBytes())).trim();
>          }
>      }
> -
> +   +    /**
> +      * Set a custom User-Agent header for XML-RPC requests
> +      */
> +    public void setUserAgent(String customUserAgent)
> +    {
> +        userAgent = customUserAgent;
> +    }
>     /**
>        * Generate an XML-RPC request and send it to the server. Parse
> the result and
> @@ -381,6 +391,11 @@
>                  con.setRequestProperty("Content-Length",
>                          Integer.toString(request.length));
>                  con.setRequestProperty("Content-Type", "text/xml");
> +                if (userAgent == "") // Client has not given us a
> custom User-Agent property
> +                {
> +                    userAgent = DEFAULT_USER_AGENT;
> +                }
> +                con.setRequestProperty("User-Agent", userAgent);
>                  if (auth != null)
>                  {
>                      con.setRequestProperty("Authorization", "Basic "
> + auth);

Re: [PATCH] Add the ability for XmlRpcClient user to set the HTTP User Agent header

Posted by Daniel Rall <dl...@finemaltcoding.com>.
I'm goning to skip this one (though I'm not against someone else
sprucing that up and merging it in).  What's actually needed is some
code normalization between client, client lite, and server header
generation.

Ryan Hoegg <rh...@isisnetworks.net> writes:

> Hi all,
>
> Not too sure if this is something you guys want to include.  It is
> within the spec at http://www.xmlrpc.com/spec:
>
> A User-Agent and Host must be specified.
>
> Basically, I needed to be able to set this because a service provider
> I use requires this field to be used as a part of the "authentication"
> process.
>
> So without further ado...
>
> --------------------------------------------------------------------------
> diff -u -r1.8 XmlRpcClient.java
> --- XmlRpcClient.java    20 Feb 2002 18:06:04 -0000    1.8
> +++ XmlRpcClient.java    8 Mar 2002 02:43:19 -0000
> @@ -70,7 +70,10 @@
>  public class XmlRpcClient
>      implements XmlRpcHandler
>  {
> +    private static final String DEFAULT_USER_AGENT = XmlRpc.version;
> +      protected URL url;
> +    protected String userAgent;
>      private String auth;
>     // pool of worker instances
> @@ -131,7 +134,14 @@
>                  .getBytes())).trim();
>          }
>      }
> -
> +   +    /**
> +      * Set a custom User-Agent header for XML-RPC requests
> +      */
> +    public void setUserAgent(String customUserAgent)
> +    {
> +        userAgent = customUserAgent;
> +    }
>     /**
>        * Generate an XML-RPC request and send it to the server. Parse
> the result and
> @@ -381,6 +391,11 @@
>                  con.setRequestProperty("Content-Length",
>                          Integer.toString(request.length));
>                  con.setRequestProperty("Content-Type", "text/xml");
> +                if (userAgent == "") // Client has not given us a
> custom User-Agent property
> +                {
> +                    userAgent = DEFAULT_USER_AGENT;
> +                }
> +                con.setRequestProperty("User-Agent", userAgent);
>                  if (auth != null)
>                  {
>                      con.setRequestProperty("Authorization", "Basic "
> + auth);