James
James

Reputation: 18379

HttpClient no working on Tomcat, NoSuchMethodError org/apache/http/entity/ContentType

I using the org.apache.http.client to call a POST from Tomcat 7. The same code works on my dev machine, but fails on my server.

I seems to be a classloader issue, but I double checked all the jars, and they have the same jars in their lib directory.

java.lang.NoSuchMethodError: org.apache.http.entity.StringEntity.<init>(Ljava/lang/String;Lorg/apache/http/entity/ContentType;)V
    org.apache.http.client.entity.UrlEncodedFormEntity.<init>(UrlEncodedFormEntity.java:61)
    org.botlibre.util.Utils.httpPOST(Utils.java:424)

I dumped the jars using, and both tomcats are using the same httpclient-4.2.5.jar, and http jars.

My dev machine has tomcat 7.0.50 and the server has 7.0.68

CodeSource src = StringEntity.class.getProtectionDomain().getCodeSource();
if (src != null) {
  System.out.println(src.getLocation());
}
Class klass = StringEntity.class;
URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class");
System.out.println(location);

Upvotes: 0

Views: 1570

Answers (1)

James
James

Reputation: 18379

Ok, the issue was one of my other lib jars had another version of the httpclient classes inside it. For some reason it worked on the dev machine with the same jars, I guess it picked them up in a different order.

This is how I debugged it.

Class klass = ContentType.class;
URL location = klass.getResource('/' + klass.getName().replace('.', '/') + ".class");
System.out.println(location);

Upvotes: 1

Related Questions