You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Glenn Murray <gm...@Mines.EDU> on 2005/07/19 23:17:26 UTC

HttpClient() throws ExceptionInInitializerError in JUnit swingui

Hi,

I asked about this before and since I didn't get an answer I thought
I'd try again with more details.

HttpClient cannot be instantiated in junit.swingui.TestRunner, but
throws an ExceptionInInitializerError.  I've tried this with
httpclient-2.0.2 and httpclient-3.0-rc3 and various versions of
commons-logging.jar.  This is an easy bug to reproduce.  Compile the
HttpClientBug class below with

javac -classpath .:commons-httpclient-2.0.2.jar:junit_3.8.1.jar HttpClientBug.java

The class cannot be run without commons-logging.jar in the classpath,
since without it org/apache/commons/logging/LogFactory cannot be
found.  However, if commons-logging.jar is included, then this will
pass:

java -cp .:commons-httpclient-2.0.2.jar:commons-logging.jar:junit_3.8.1.jar junit.textui.TestRunner HttpClientBug

and this will fail:

java -cp .:commons-httpclient-2.0.2.jar:commons-logging.jar:junit_3.8.1.jar junit.swingui.TestRunner HttpClientBug

I've verified it on Linux and WinXP with Java 1.5.  The Error messsage
complains that "You have more than one version of
'org.apache.commons.logging.Log' visible, which is not allowed," but
the only one is in commons-logging.jar.  Does anyone have a clue to
what is going on here?

Thanks,
Glenn


import junit.framework.TestCase;
import org.apache.commons.httpclient.HttpClient;
public class HttpClientBug  extends TestCase {
   public void testIt() {
        System.out.println("Yo, "+System.getProperty("user.name")+"!");
        HttpClient client = new HttpClient();
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: CircularRedirectException

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Marcelo,

disable redirects by calling HttpMethod.setFollowRedirects(false).

There is no need to change the date of a cookie. Cookies without
a date are supposed to live as long as the browser/client session,
which is exactly what's happening with HttpClient.

hope that helps,
  Roland





"Marcelo Chryssovergis" <ma...@iea.org.br> 
26.07.2005 09:50
Please respond to
"HttpClient User Discussion"


To
"'HttpClient User Discussion'" <ht...@jakarta.apache.org>
cc

Subject
CircularRedirectException






Hello my friends

I´m trying to log in to a site that uses both cookies AND session control.

Here what am I doing:

I enter the site
Get the cookies
Send the cookies back (with the date changed, from null to a valid date)
Do the login (with PostMethod)

At this moment, I verify if I have to logoff the oppened session left
behind. And almost aways I have this connection open. When I send the url
responsible to execute de logoff (with GetMethod), I get an exception: 

org.apache.commons.httpclient.CircularRedirectException: Circular redirect
to 'http://www.siteI´mWorking.com:80/'

How can I fix it??

I guess I have to log off then log in again, because de session is pendent
at the server.. 

Thanks a lot!

Marcelo




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


CircularRedirectException

Posted by Marcelo Chryssovergis <ma...@iea.org.br>.
Hello my friends

I´m trying to log in to a site that uses both cookies AND session control.

Here what am I doing:

I enter the site
Get the cookies
Send the cookies back (with the date changed, from null to a valid date)
Do the login (with PostMethod)

At this moment, I verify if I have to logoff the oppened session left
behind. And almost aways I have this connection open. When I send the url
responsible to execute de logoff (with GetMethod), I get an exception: 

org.apache.commons.httpclient.CircularRedirectException: Circular redirect
to 'http://www.siteI´mWorking.com:80/'

How can I fix it??

I guess I have to log off then log in again, because de session is pendent
at the server.. 

Thanks a lot!

Marcelo




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpClient() throws ExceptionInInitializerError in JUnit swingui

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Glen,

yes, that's what I meant. I guess you're out of luck here.
Classloader issues are tricky, especially with applications
that create their own.

sorry,
  Roland





Glenn Murray <gm...@Mines.EDU> 
26.07.2005 00:50
Please respond to
"HttpClient User Discussion"


To
HttpClient User Discussion <ht...@jakarta.apache.org>
cc

Subject
Re: HttpClient() throws ExceptionInInitializerError in JUnit swingui








On Thu, 21 Jul 2005, Roland Weber wrote:
> Hi Glenn,
>
> try loading commons-logging in the boot classpath.
> Most classloaders will check their parents for a
> class first, and this might prevent the testrunner
> from loading commons-logging multiple times.
>
> hope that helps,
>   Roland

Hi Roland,

Thanks for the tip.  I have to confess some ignorance about
bootclasspath.  After reading on the web about it on the
web, I tried putting commons-logging.jar into
/usr/lib/j2sdk1.5-sun/jre/lib/ but that didn't change
anything.  I also tried:

java -Xbootclasspath/a:lib/commons-logging.jar  -cp 
.:commons-httpclient-2.0.2.jar:commons-logging.jar:junit_3.8.1.jar 
junit.swingui.TestRunner HttpClientBug

but that had the same result.  I then tried

java -Xbootclasspath/a:lib/commons-logging.jar  -cp 
.:commons-httpclient-2.0.2.jar:junit_3.8.1.jar junit.swingui.TestRunner 
HttpClientBug

but then LogFactory couldn't be found.  Are these the sort
of things you meant?

Thanks,
Glenn


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpClient() throws ExceptionInInitializerError in JUnit swingui

Posted by Glenn Murray <gm...@Mines.EDU>.

On Thu, 21 Jul 2005, Roland Weber wrote:
> Hi Glenn,
>
> try loading commons-logging in the boot classpath.
> Most classloaders will check their parents for a
> class first, and this might prevent the testrunner
> from loading commons-logging multiple times.
>
> hope that helps,
>   Roland

Hi Roland,

Thanks for the tip.  I have to confess some ignorance about
bootclasspath.  After reading on the web about it on the
web, I tried putting commons-logging.jar into
/usr/lib/j2sdk1.5-sun/jre/lib/ but that didn't change
anything.  I also tried:

java -Xbootclasspath/a:lib/commons-logging.jar  -cp .:commons-httpclient-2.0.2.jar:commons-logging.jar:junit_3.8.1.jar junit.swingui.TestRunner HttpClientBug

but that had the same result.  I then tried

java -Xbootclasspath/a:lib/commons-logging.jar  -cp .:commons-httpclient-2.0.2.jar:junit_3.8.1.jar junit.swingui.TestRunner HttpClientBug

but then LogFactory couldn't be found.  Are these the sort
of things you meant?

Thanks,
Glenn


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpClient() throws ExceptionInInitializerError in JUnit swingui

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Glenn,

try loading commons-logging in the boot classpath.
Most classloaders will check their parents for a
class first, and this might prevent the testrunner
from loading commons-logging multiple times.

hope that helps,
  Roland




Glenn Murray <gm...@mines.edu> 
Sent by: Glenn Murray <gl...@beautiful.mines.edu>
20.07.2005 20:30
Please respond to
"HttpClient User Discussion"


To
HttpClient User Discussion <ht...@jakarta.apache.org>
cc

Subject
Re: HttpClient() throws ExceptionInInitializerError in JUnit swingui






On Wed, 20 Jul 2005, Roland Weber wrote:
> Hi Glenn, ... It seems that the Swing version of the JUnit
> TestRunner somehow loads it's own copy of commons-logging.
> ...

Hi Roland,

Thanks for the reply, it did help, you are right.  I found
the following message:

http://www.mail-archive.com/commons-user@jakarta.apache.org/msg02958.html

which indicates a swingui classloader interaction problem
and a work-around:

Solution: Disable "Reload classes every run" or start JUnit
with command line option -noloading before the name of the
Testsuite.

This was two years ago;  I wonder if a fix has been made.
Reloading the classes every run is an essential feature of
JUnit for me.

Cheers,
Glenn


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpClient() throws ExceptionInInitializerError in JUnit swingui

Posted by Glenn Murray <gm...@mines.edu>.
On Wed, 20 Jul 2005, Roland Weber wrote:
> Hi Glenn, ... It seems that the Swing version of the JUnit
> TestRunner somehow loads it's own copy of commons-logging.
> ...

Hi Roland,

Thanks for the reply, it did help, you are right.  I found
the following message:

http://www.mail-archive.com/commons-user@jakarta.apache.org/msg02958.html

which indicates a swingui classloader interaction problem
and a work-around:

Solution: Disable "Reload classes every run" or start JUnit
with command line option -noloading before the name of the
Testsuite.

This was two years ago;  I wonder if a fix has been made.
Reloading the classes every run is an essential feature of
JUnit for me.

Cheers,
Glenn


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: HttpClient() throws ExceptionInInitializerError in JUnit swingui

Posted by Roland Weber <RO...@de.ibm.com>.
Hi Glenn,

> I've verified it on Linux and WinXP with Java 1.5.  The Error messsage
> complains that "You have more than one version of
> 'org.apache.commons.logging.Log' visible, which is not27, 2005
From: Roland Weber <RO...@de.ibm.com>
X-MIMETrack: S/MIME Sign by Notes Client on Roland Weber/Germany/IBM(Release 6.5.4|March
 27, 2005) at 20.07.2005 07:29:09,
	Serialize by Notes Client on Roland Weber/Germany/IBM(Release 6.5.4|March
 27, 2005) at 20.07.2005 07:29:09,
	Serialize complete at 20.07.2005 07:29:09,
	S/MIME Sign failed at 20.07.2005 07:29:09: The cryptographic key was not
 found,
	Serialize by Router on D12ML067/12/M/IBM(Release 6.53HF247 | January 6, 2005) at
 20/07/2005 07:41:50,
	Serialize complete at 20/07/2005 07:41:50
Message-ID: <OF...@de.ibm.com>
Date: Wed, 20 Jul 2005 07:41:49 +0200
Content-Type: text/plain; charset="US-ASCII"
X-Virus-Checked: Checked by ClamAV on apache.org
X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N

Hi John,

please post a wire log so we know what's going on:
http://jakarta.apache.org/commons/httpclient/logging.html

cheers,
  Roland





"Pan John-CXP001" <jo...@motorola.com> 
20.07.2005 05:42 allowed," but
> the only one is in commons-logging.jar.  Does anyone have a clue to
> what is going on here?

It seems that the Swing version of the JUnit TestRunner somehow loads
it's own copy of commons-logging. If I remember correctly, you mentioned
in a previous mail that you can compile without commons-logging being in
the classpath? This may indicate that there is some version of commons-
logging available not in the explicit classpath but maybe somewhere in
the bootclasspath, or that your compiler invocation supplies an extended
classpath you are not aware of.
Why or how junit.swingui.TestRunner should load commons-logging, I am
unable to tell. It may have it's own copy hidden somewhere, or it may
load the one from the classpath into a different classloader than the
one which will load HttpClient. I have neither the time nor the 
environment
to track this down.

Have you tried to provide commons-logging in the bootclasspath instead of
the regular classpath? Then it will be available in a different 
cl
Please respond to
"HttpClient User Discussion"


To
<ht...@jakarta.apache.org>
cc

Subject
Help on the httpclient






I wrote a simple http client to talk with the http server running on one
of our routers. The server version is 1.0.  However, when I do a GET on
the router, I got the following error message.
 
2005-7-19 20:35:10
org.apache.commons.httpclient.auth.AuthChallengeProcessor
selectAuthScheme
info: basic authentication scheme selected
Fatal protocol violation: The server 10.79.134.111 failed to respond
with a valid HTTP response
org.apache.commons.httpclient.ProtocolException: The server
10.79.134.111 failed to respond with a valid HTTP response
 at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBa
se.java:1846)
 at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase
.java:1592)
 at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java
:995)
 at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMe
thodDirassloader,
which may make a big difference. If that also fails, you can try to run
a "Hello World" testcase with commons-logging in the bootclasspath, to see
whether junit.swingui.TestRunner chokes by itself even without HttpClient.

You can also try to get help from the commons-logging community. I believe
they have plenty of experience with classloader problems.

hope that helps,
  Roland


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


ector.java:393)
 at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMetho
dDirector.java:168)
 at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
96)
 at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
24)
 at com.motorola.moca.bcm.bcmutils.BcmRuncmd.main(BcmRuncmd.java:57)

When I use the IE browser to access the same webpage
"http://10.79.134.111/execcmd?sh&vers
<http://10.79.134.111/execcmd?sh&vers> &" on my router, it works fine.
I am confused since I don't know it's my client problem or it's router's
http server problem.
 
Any help will be appreciated;
 
 
--John
 
 
------------------------------------------------------------------------
-------------------------------
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.auth.*;
import org.apache.commons.httpclient.HttpVersion;
import java.io.*;
 
public class BcmRuncmd {
  public BcmRuncmd() {
  }

  // Define the url
  // http://10.79.134.111/execcmd?sh&vers
<http://10.79.134.111/execcmd?sh&vers> &  -- works on IE
  private static String url = "http://10.79.134.111/execcmd?sh&vers
<http://10.79.134.111/execcmd?sh&vers> &";
  //private static   String url =
"http://mail-archives.apache.org/mod_mbox/jakarta-httpclient-user/200507
.mbox/threads.html
<http://mail-archives.apache.org/mod_mbox/jakarta-httpclient-user/200507
.mbox/threads.html> ";

    public static void main(String[] args) {
     // Create an instance of HttpClient.
      HttpClient client = new HttpClient();
 
      //Set Authentication
      client.getParams().setAuthenticationPreemptive(true);
      client.getParams().setVersion(HttpVersion.HTTP_1_0);
      UsernamePasswordCredentials upc = new
UsernamePasswordCredentials("john", "mypwd");
      client.getState().setCredentials(AuthScope.ANY,upc);
 
      // Create a method instance.
      GetMethod method = new GetMethod(url);
      method.setDoAuthentication(true);
 
      // Provide custom retry handler is necessary
      method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));
 
      try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
 
        System.out.println("Status Text >>> " +
HttpStatus.getStatusText(statusCode));
        if (statusCode != HttpStatus.SC_OK) {
          System.err.println("Method failed: " +
method.getStatusLine());
        }
 

        // Read the response body.
         System.out.println(new
String(method.getResponseBodyAsString()));
 
      } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " +
e.getMessage());
        e.printStackTrace();
      } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
      } finally {
        // Release the connection.
        method.releaseConnection();
      }
    }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org