I am building a Dynamic web project using TomCat 9, and setting java.lang.ClassNotFoundException: org.apache.http.HttpEntity.
My project is make a Oauth call, which takes client ID and Secret from UI(index.html) ---> servlet(outPutValue.java) ----> Addition.java where it makes a call to API with the client crede and should get access token, but now it throws below error if I add IO exception handling
SEVERE: Servlet.service() for servlet [controller.outPutValue] in context with path [/Calculator] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: org.apache.http.HttpEntity at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1269) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104) at controller.outPutValue.doPost(outPutValue.java:48)
Addition Code --
public class addition {
private int first;
private int second;
public int getFirst() {
return first;
}
public void setFirst(int first) {
this.first = first;
}
public int getSecond() {
return second;
}
public void setSecond(int second) {
this.second = second;
}
public void add(String first,String second) throws ClientProtocolException, IOException {
System.out.println("This is after coming to addition");
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("https://api-XYZ.com/oauth2/token");
post.setHeader("Content-Type", "application/x-www-form-urlencoded");
post.setHeader("Accept","application/json");
post.setHeader("Accept-Language", "en-US,en");
List <NameValuePair> body = new ArrayList <NameValuePair>();
body.add(new BasicNameValuePair("client_id",first));
body.add(new BasicNameValuePair("client_secret",second));
body.add(new BasicNameValuePair("grant_type","client_credentials"));
post.setEntity(new UrlEncodedFormEntity(body));
HttpResponse response=null;
response = client.execute(post);
System.out.println(response.getStatusLine().getStatusCode());
String auth_resp=null;
auth_resp = EntityUtils.toString(response.getEntity());
System.out.println(auth_resp);
}
Str--- PFAenter image description here