1

I am trying to make an application connect to Google Plus API, but for this I need to have some request parameters kept secret. This is why I cannot just make a simple ajax request or create a form with hidden inputs. My solution is to make a request to a servlet and from there, with HttpClient another request to Google. Here is the problem:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            System.out.println(TestClass.makeRequest());
}

TestClass.makeRequest() creates the HttpPost object, gets the response and returns a String.

When I run this on the server, I get this error:

java.lang.ClassNotFoundException: org.apache.http.HttpEntity

I do not understand why this happens. Can you provide a solution please? Any other methods for transmitting hidden parameters in a request are helpful.

Dragos
  • 2,911
  • 12
  • 39
  • 55
  • What is `TestClass`? Is it referencing any libraries that are present in your dev environment but not on your server? – Palpatim Oct 15 '12 at 19:32
  • Looks like you're missing `httpcore-4.0.1.jar` in your servlet classpath. – Reimeus Oct 15 '12 at 19:33
  • @Palpatim TestClass is a class created by me in order to keep all the HttpClient-related code in one place. All the HttpComponents are added to the buildpath. – Dragos Oct 15 '12 at 19:38
  • @Reimeus httpcore and all the jars within the HttpComponents project are included in the BuildPath. I am using Eclipse, so any missing jars should have been spotted when compiling, right? – Dragos Oct 15 '12 at 19:40
  • @Dragos what @Reimeus is saying, and what I was coming around to, is that your build environment may not be the same as your run environment. If your deployment package doesn't include the `httpcore` jar, then you'll get these errors, even if it compiles just fine. See the first result from Google for your error: http://stackoverflow.com/questions/9663927/java-lang-noclassdeffounderror-org-apache-http-client-httpclient – Palpatim Oct 15 '12 at 19:42
  • @Dragis Are you sure that the jars are are in the runtime classpath? Copy them into WEB-INF/lib of your web app and re-run. – Reimeus Oct 15 '12 at 19:48
  • @Palpatim Yep, that was it. I do not understand why, but it worked. Thank you. Could you add a response so I can accept it? By the way, does my solution to the hidden-params-problem sound ok? – Dragos Oct 15 '12 at 19:50
  • Since @Dragos first correctly identified the missing `httpcore` library, I'll let them get the accepted answer. – Palpatim Oct 15 '12 at 19:54
  • @Palpatim Do you mean Reimeus? – Dragos Oct 15 '12 at 19:56
  • @Reimeus That was the problem. I do not understand why, but it worked. Please post a response so I can accept it. Thank you! – Dragos Oct 15 '12 at 19:57
  • D'oh! Yes, that is correct. Sorry! – Palpatim Oct 15 '12 at 19:57

1 Answers1

1

It appears that while you have all the necessary jar files in your build path, they are not deployed with your servlet. These 2 operating environments are different.

To make the 3d party libraries available to your servlet classes make sure to that httpcore-4.0.1.jar and all other dependent jars are deployed to the

WEB-INF/lib

directory of your web app.

Reimeus
  • 158,255
  • 15
  • 216
  • 276