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 Valentin Popov <va...@gmail.com> on 2011/06/01 10:59:49 UTC

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector

Use standard example from site (4.1.1 version). All libs are fine, no compilation error. But always have this error. Google answer nothing.  
Please anybody give me a clue .... 

package com.stimulus.archiva.security;

import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;


public class TestCaseWebDAV {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            HttpHost target = new HttpHost("www.apache.org", 80, "http");
            HttpGet req = new HttpGet("/");

            System.out.println("executing request to " + target);

            HttpResponse rsp = httpclient.execute(target, req);
            HttpEntity entity = rsp.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(rsp.getStatusLine());
            Header[] headers = rsp.getAllHeaders();
            for (int i = 0; i < headers.length; i++) {
                System.out.println(headers[i]);
            }
            System.out.println("----------------------------------------");

            if (entity != null) {
                System.out.println(EntityUtils.toString(entity));
            }

        } catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }

	}

}



executing request to http://www.apache.org:80
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector.<init>(Lorg/apache/commons/logging/Log;Lorg/apache/http/protocol/HttpRequestExecutor;Lorg/apache/http/conn/ClientConnectionManager;Lorg/apache/http/ConnectionReuseStrategy;Lorg/apache/http/conn/ConnectionKeepAliveStrategy;Lorg/apache/http/conn/routing/HttpRoutePlanner;Lorg/apache/http/protocol/HttpProcessor;Lorg/apache/http/client/HttpRequestRetryHandler;Lorg/apache/http/client/RedirectStrategy;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/UserTokenHandler;Lorg/apache/http/params/HttpParams;)V
	at org.apache.http.impl.client.AbstractHttpClient.createClientRequestDirector(AbstractHttpClient.java:871)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:804)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
	at com.stimulus.archiva.security.TestCaseWebDAV.main(TestCaseWebDAV.java:29)



Thanks
Valentin Popov

Re: Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector

Posted by Valentin Popov <va...@gmail.com>.
It was eclipse bug, i need reinstall it. After import project, all start working. 

Thanks for help. 


> On 1 June 2011 09:59, Valentin Popov <va...@gmail.com> wrote:
>> Use standard example from site (4.1.1 version). All libs are fine, no compilation error. But always have this error. Google answer nothing.
>> Please anybody give me a clue ....
> 
> I assume you mean the error is as in the subject, i.e.
> 
> Exception in thread "main" java.lang.NoSuchMethodError:
> org.apache.http.impl.client.DefaultRequestDirector
> 
> Googling "NoSuchMethodError" shows that it has the following Javadoc
> description:
> 
>>>> 
> Thrown if an application tries to call a specified method of a class
> (either static or instance), and that class no longer has a definition
> of that method.
> 
> Normally, this error is caught by the compiler; this error can only
> occur at run time if the definition of a class has incompatibly
> changed.
> <<<
> 
> So are you using *exactly* the same classpath for compiling and then
> running the code?
> Are you sure?
> 
>> package com.stimulus.archiva.security;
>> 
>> import java.io.IOException;
>> 
>> import org.apache.http.Header;
>> import org.apache.http.HttpEntity;
>> import org.apache.http.HttpHost;
>> import org.apache.http.HttpResponse;
>> import org.apache.http.client.ClientProtocolException;
>> import org.apache.http.client.methods.HttpGet;
>> import org.apache.http.impl.client.DefaultHttpClient;
>> import org.apache.http.util.EntityUtils;
>> 
>> 
>> public class TestCaseWebDAV {
>> 
>>        /**
>>         * @param args
>>         */
>>        public static void main(String[] args) {
>>                DefaultHttpClient httpclient = new DefaultHttpClient();
>>        try {
>>            HttpHost target = new HttpHost("www.apache.org", 80, "http");
>>            HttpGet req = new HttpGet("/");
>> 
>>            System.out.println("executing request to " + target);
>> 
>>            HttpResponse rsp = httpclient.execute(target, req);
>>            HttpEntity entity = rsp.getEntity();
>> 
>>            System.out.println("----------------------------------------");
>>            System.out.println(rsp.getStatusLine());
>>            Header[] headers = rsp.getAllHeaders();
>>            for (int i = 0; i < headers.length; i++) {
>>                System.out.println(headers[i]);
>>            }
>>            System.out.println("----------------------------------------");
>> 
>>            if (entity != null) {
>>                System.out.println(EntityUtils.toString(entity));
>>            }
>> 
>>        } catch (ClientProtocolException e) {
>>                        // TODO Auto-generated catch block
>>                        e.printStackTrace();
>>                } catch (IOException e) {
>>                        // TODO Auto-generated catch block
>>                        e.printStackTrace();
>>                } finally {
>>            // When HttpClient instance is no longer needed,
>>            // shut down the connection manager to ensure
>>            // immediate deallocation of all system resources
>>            httpclient.getConnectionManager().shutdown();
>>        }
>> 
>>        }
>> 
>> }
>> 
>> 
>> 
>> executing request to http://www.apache.org:80
>> Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector.<init>(Lorg/apache/commons/logging/Log;Lorg/apache/http/protocol/HttpRequestExecutor;Lorg/apache/http/conn/ClientConnectionManager;Lorg/apache/http/ConnectionReuseStrategy;Lorg/apache/http/conn/ConnectionKeepAliveStrategy;Lorg/apache/http/conn/routing/HttpRoutePlanner;Lorg/apache/http/protocol/HttpProcessor;Lorg/apache/http/client/HttpRequestRetryHandler;Lorg/apache/http/client/RedirectStrategy;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/UserTokenHandler;Lorg/apache/http/params/HttpParams;)V
>>        at org.apache.http.impl.client.AbstractHttpClient.createClientRequestDirector(AbstractHttpClient.java:871)
>>        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:804)
>>        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
>>        at com.stimulus.archiva.security.TestCaseWebDAV.main(TestCaseWebDAV.java:29)
>> 
>> 
>> 
>> Thanks
>> Valentin Popov
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


 С Уважением,
Валентин Попов






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


Re: Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector

Posted by Valentin Popov <va...@gmail.com>.


> On 1 June 2011 09:59, Valentin Popov <va...@gmail.com> wrote:
>> Use standard example from site (4.1.1 version). All libs are fine, no compilation error. But always have this error. Google answer nothing.
>> Please anybody give me a clue ....
> 
> I assume you mean the error is as in the subject, i.e.
> 
> Exception in thread "main" java.lang.NoSuchMethodError:
> org.apache.http.impl.client.DefaultRequestDirector
> 
> Googling "NoSuchMethodError" shows that it has the following Javadoc
> description:
> 
>>>> 
> Thrown if an application tries to call a specified method of a class
> (either static or instance), and that class no longer has a definition
> of that method.
> 
> Normally, this error is caught by the compiler; this error can only
> occur at run time if the definition of a class has incompatibly
> changed.
> <<<
> 
> So are you using *exactly* the same classpath for compiling and then
> running the code?
> Are you sure?

I using eclipse, and upgrade lib from 4.0.x to 4.1.1 also rewrite some code to use 4.1.1. 

I use same classpath. But i research strange thing, i add new project add same libs and execution of this code is fine. Maybe it is libs conflicts, but i find nothing. 

> 
>> package com.stimulus.archiva.security;
>> 
>> import java.io.IOException;
>> 
>> import org.apache.http.Header;
>> import org.apache.http.HttpEntity;
>> import org.apache.http.HttpHost;
>> import org.apache.http.HttpResponse;
>> import org.apache.http.client.ClientProtocolException;
>> import org.apache.http.client.methods.HttpGet;
>> import org.apache.http.impl.client.DefaultHttpClient;
>> import org.apache.http.util.EntityUtils;
>> 
>> 
>> public class TestCaseWebDAV {
>> 
>>        /**
>>         * @param args
>>         */
>>        public static void main(String[] args) {
>>                DefaultHttpClient httpclient = new DefaultHttpClient();
>>        try {
>>            HttpHost target = new HttpHost("www.apache.org", 80, "http");
>>            HttpGet req = new HttpGet("/");
>> 
>>            System.out.println("executing request to " + target);
>> 
>>            HttpResponse rsp = httpclient.execute(target, req);
>>            HttpEntity entity = rsp.getEntity();
>> 
>>            System.out.println("----------------------------------------");
>>            System.out.println(rsp.getStatusLine());
>>            Header[] headers = rsp.getAllHeaders();
>>            for (int i = 0; i < headers.length; i++) {
>>                System.out.println(headers[i]);
>>            }
>>            System.out.println("----------------------------------------");
>> 
>>            if (entity != null) {
>>                System.out.println(EntityUtils.toString(entity));
>>            }
>> 
>>        } catch (ClientProtocolException e) {
>>                        // TODO Auto-generated catch block
>>                        e.printStackTrace();
>>                } catch (IOException e) {
>>                        // TODO Auto-generated catch block
>>                        e.printStackTrace();
>>                } finally {
>>            // When HttpClient instance is no longer needed,
>>            // shut down the connection manager to ensure
>>            // immediate deallocation of all system resources
>>            httpclient.getConnectionManager().shutdown();
>>        }
>> 
>>        }
>> 
>> }
>> 
>> 
>> 
>> executing request to http://www.apache.org:80
>> Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector.<init>(Lorg/apache/commons/logging/Log;Lorg/apache/http/protocol/HttpRequestExecutor;Lorg/apache/http/conn/ClientConnectionManager;Lorg/apache/http/ConnectionReuseStrategy;Lorg/apache/http/conn/ConnectionKeepAliveStrategy;Lorg/apache/http/conn/routing/HttpRoutePlanner;Lorg/apache/http/protocol/HttpProcessor;Lorg/apache/http/client/HttpRequestRetryHandler;Lorg/apache/http/client/RedirectStrategy;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/UserTokenHandler;Lorg/apache/http/params/HttpParams;)V
>>        at org.apache.http.impl.client.AbstractHttpClient.createClientRequestDirector(AbstractHttpClient.java:871)
>>        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:804)
>>        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
>>        at com.stimulus.archiva.security.TestCaseWebDAV.main(TestCaseWebDAV.java:29)
>> 
>> 
>> 
>> Thanks
>> Valentin Popov
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 





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


Re: Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector

Posted by sebb <se...@gmail.com>.
On 1 June 2011 09:59, Valentin Popov <va...@gmail.com> wrote:
> Use standard example from site (4.1.1 version). All libs are fine, no compilation error. But always have this error. Google answer nothing.
> Please anybody give me a clue ....

I assume you mean the error is as in the subject, i.e.

Exception in thread "main" java.lang.NoSuchMethodError:
org.apache.http.impl.client.DefaultRequestDirector

Googling "NoSuchMethodError" shows that it has the following Javadoc
description:

>>>
Thrown if an application tries to call a specified method of a class
(either static or instance), and that class no longer has a definition
of that method.

Normally, this error is caught by the compiler; this error can only
occur at run time if the definition of a class has incompatibly
changed.
<<<

So are you using *exactly* the same classpath for compiling and then
running the code?
Are you sure?

> package com.stimulus.archiva.security;
>
> import java.io.IOException;
>
> import org.apache.http.Header;
> import org.apache.http.HttpEntity;
> import org.apache.http.HttpHost;
> import org.apache.http.HttpResponse;
> import org.apache.http.client.ClientProtocolException;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.impl.client.DefaultHttpClient;
> import org.apache.http.util.EntityUtils;
>
>
> public class TestCaseWebDAV {
>
>        /**
>         * @param args
>         */
>        public static void main(String[] args) {
>                DefaultHttpClient httpclient = new DefaultHttpClient();
>        try {
>            HttpHost target = new HttpHost("www.apache.org", 80, "http");
>            HttpGet req = new HttpGet("/");
>
>            System.out.println("executing request to " + target);
>
>            HttpResponse rsp = httpclient.execute(target, req);
>            HttpEntity entity = rsp.getEntity();
>
>            System.out.println("----------------------------------------");
>            System.out.println(rsp.getStatusLine());
>            Header[] headers = rsp.getAllHeaders();
>            for (int i = 0; i < headers.length; i++) {
>                System.out.println(headers[i]);
>            }
>            System.out.println("----------------------------------------");
>
>            if (entity != null) {
>                System.out.println(EntityUtils.toString(entity));
>            }
>
>        } catch (ClientProtocolException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                } catch (IOException e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                } finally {
>            // When HttpClient instance is no longer needed,
>            // shut down the connection manager to ensure
>            // immediate deallocation of all system resources
>            httpclient.getConnectionManager().shutdown();
>        }
>
>        }
>
> }
>
>
>
> executing request to http://www.apache.org:80
> Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector.<init>(Lorg/apache/commons/logging/Log;Lorg/apache/http/protocol/HttpRequestExecutor;Lorg/apache/http/conn/ClientConnectionManager;Lorg/apache/http/ConnectionReuseStrategy;Lorg/apache/http/conn/ConnectionKeepAliveStrategy;Lorg/apache/http/conn/routing/HttpRoutePlanner;Lorg/apache/http/protocol/HttpProcessor;Lorg/apache/http/client/HttpRequestRetryHandler;Lorg/apache/http/client/RedirectStrategy;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/UserTokenHandler;Lorg/apache/http/params/HttpParams;)V
>        at org.apache.http.impl.client.AbstractHttpClient.createClientRequestDirector(AbstractHttpClient.java:871)
>        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:804)
>        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
>        at com.stimulus.archiva.security.TestCaseWebDAV.main(TestCaseWebDAV.java:29)
>
>
>
> Thanks
> Valentin Popov

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