9

Hi I am trying to put up a small webapp but I am getting above error. Below is my code

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("SomeURL"); // Using a URL local to my machine
// after setting nameValuePair and setting it on httppost
httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

// This is where I am getting the above mentioned exception
HttpResponse response = httpclient.execute(httppost);

I am using httpclient-4.0-beta2.jar and httpcore-4.0.1.jar. It looks like BasicHttpContext is getting conflicted with some other jars in my app, but I couldn't figure it out. Any clue will be appreciated.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
Ravi Gupta
  • 4,468
  • 12
  • 54
  • 85
  • it may help to list the classpath with which you're running your code. there may be a subtle problem preventing loading of the intended jar file... – atk Oct 24 '09 at 05:22
  • 1
    I tried with a standalone java program and added only those 2 jars and it works fine. Classpath of my original app has more than 50 jars, I am not sure which one is conflicting. – Ravi Gupta Oct 24 '09 at 06:50
  • 1
    If you are using Eclipse IDE goto Java Broswing view(windows-->Show view-->Java Broswing) then browser the Jar file, you will be able to know about the details of the class/methods/variables etc – Narayan Oct 26 '09 at 06:31

1 Answers1

10

It looks like you have a jar file with an old/newer version of BasicHttpContext. If there was a direct conflict, you'd receive a ClassNotFoundException. ClassLoaders are typically jerks about this kind of thing. In this case, the class exists however does not have the method that another library (I believe it's httpclient that's invoking the Context) was compiled against.

DominikAngerer
  • 6,354
  • 5
  • 33
  • 60
Malaxeur
  • 5,973
  • 1
  • 36
  • 34
  • Yes it looks like that my httpclient is for JDK1.5 and httpcore is for JDK1.3 . I tried to get httpcore for JDK1.5 but couldn't find any and using lower version of httpclient throws many more errors. – Ravi Gupta Oct 24 '09 at 05:59
  • When I tried to call the constructor like this HttpContext localContext = new BasicHttpContext(); it says :- No match was found for constructor () in type org.apache.http.protocol.BasicHttpContext Its surely a conflict with an existing jar, I am inching towards rootcause and fix. – Ravi Gupta Oct 24 '09 at 09:23
  • Why would the minimum JDK for a library be relevant, Ravi? – Rob Grant Jul 22 '10 at 15:19
  • Perfect Malaxeur!! Upgrading httpcore to version 4.1 solves my problem too. In my case 'manager.discover(userSuppliedString)' was throwing error and now it is solved. – shaILU Jan 19 '12 at 21:16