Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2005

Tip: Looking for answers? Try searching our database.

problems with Jakarta Commons HttpClient

Thread view: 
Luca - 19 May 2005 22:48 GMT
Hello, I need to build some HTTP utilities. Jakarta HttpClient seemed
to do the job apparently, but I can't find a way to change the
user-agent header!!!

reading the JavaDocs I got as far as:

getmethod = new GetMethod(url_to_get);
Header ua = new Header("User-Agent","Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)");
getmethod.USER_AGENT = ua;

Alas, for reasons I can't understand, this is not permitted:

    [javac] DocumentRetriever.java:110: USER_AGENT has protected access in
org.apache.commons.httpclient.HttpMethodBase
    [javac]         getmethod.USER_AGENT = ua;
    [javac]                      ^
    [javac] 1 error

what am I missing?

thanks

luca
Arnaud Berger - 20 May 2005 08:43 GMT
Hi,

The error tells it clearly :

the USER_AGENT  variable is declared as "protected" in HttpMethodBase

This means that your class can't access it unless it itself extends some
HttpMethodBase class.
Moreover, this variable is declared as "final", which means it can't be
modified.

So USER_AGENT for HTTP Client can't be anything else that what they
specified in the code.

see this part of HttpMethodBase, especially the getProperty :

   /** The User-Agent header sent on every request. */
   protected static final Header USER_AGENT;

   static {
       String agent = null;
       try {
           agent = System.getProperty("httpclient.useragent");
       } catch (SecurityException ignore) {
       }
       if (agent == null) {
           agent = "Jakarta Commons-HttpClient/2.0.1";
       }
       USER_AGENT = new Header("User-Agent", agent);
   }

Regards,

Arnaud

> Hello, I need to build some HTTP utilities. Jakarta HttpClient seemed
> to do the job apparently, but I can't find a way to change the
[quoted text clipped - 19 lines]
>
> luca
Juha Laiho - 21 May 2005 19:08 GMT
"Arnaud Berger" <a.bergerNO@SPAMlibertycontact.fr> said:

>> Hello, I need to build some HTTP utilities. Jakarta HttpClient seemed
>> to do the job apparently, but I can't find a way to change the
[quoted text clipped - 9 lines]
>So USER_AGENT for HTTP Client can't be anything else that what they
>specified in the code.

Except by setting the system property httpclient.useragent, as was shown
in the code snippet:

>see this part of HttpMethodBase, especially the getProperty :
>
[quoted text clipped - 12 lines]
>        USER_AGENT = new Header("User-Agent", agent);
>    }
Signature

Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
        PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.