javasbtapache-commons-httpclient

How to add org.apache.http.legacy into sbt


I am using apache httpclient and it could not find

import org.apache.http.impl.client.HttpClients;

quick search on google lead me to org.apache.http.legacy but I couldnt find group, artifact and revision of org.apache.http.legacy

What are they and how do I add that dependency into my build.sbt file? Total stacktrace is

[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:13: cannot find symbol
[error]   symbol:   class HttpClients
[error]   location: package org.apache.http.impl.client
[error] import org.apache.http.impl.client.HttpClients;
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:66: cannot find symbol
[error]   symbol:   variable HttpClients
[error]   location: class utils.LocalUtils
[error]         HttpClient httpclient = HttpClients.createDefault();
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java uses or overrides a deprecated API.
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: Recompile with -Xlint:deprecation for details.
[error] (compile:compileIncremental) javac returned nonzero exit code
[info] Compiling 6 Scala sources and 18 Java sources to /Users/vangapellisanthosh/Development/coupon-engine-play/target/scala-2.11/classes...
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:13: cannot find symbol
[error]   symbol:   class HttpClients
[error]   location: package org.apache.http.impl.client
[error] import org.apache.http.impl.client.HttpClients;
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:66: cannot find symbol
[error]   symbol:   variable HttpClients
[error]   location: class utils.LocalUtils
[error]         HttpClient httpclient = HttpClients.createDefault();
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java uses or overrides a deprecated API.
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: Recompile with -Xlint:deprecation for details.
[error] (compile:compileIncremental) javac returned nonzero exit code
[error] application - 

My code is

HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(URL);
httppost.addHeader(API_KEY, X_API_KEY);
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair(GRANT_TYPE, "password"));
params.add(new BasicNameValuePair(USERNAME, _USERNAME));
params.add(new BasicNameValuePair(PASSWORD, O_PASSWORD));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

if (entity != null) {
    InputStream instream = entity.getContent();
    try {
        System.out.println(instream);
    } finally {
        instream.close();
    }
}

Solution

  • quick search on google lead me to org.apache.http.legacy

    Not sure what you searched for, but I know that is a commonly dependency used for Android projects, not just any regular SBT project

    What you are looking for can be found at MvnRespository

    libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.5.2"