1

Actually client resides in tomcat 8080 & REST API resides in 9090. The URL's will be different when it moves to higher environments. I don't see a call happening to the REST API with httpasyncclient. I copied the code from Apache website https://hc.apache.org/httpcomponents-asyncclient-dev/examples.html

Not sure, how to make the call successful even though I receive an Exception in response

CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
    try {
        client.start();
        JsonObject obj = new JsonObject();
        obj.addProperty("username", "username");
        obj.addProperty("password", "password");



        String serverURL = "http://localhost:9090/project/api";

        HttpPost postRequest = new HttpPost(serverURL);
        StringEntity params = new StringEntity(obj.toString(), "UTF-8");
        params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "x-www-form-urlencoded"));
        postRequest.setEntity(params);

        Future<HttpResponse> future = client.execute(postRequest, null);
        HttpResponse response = future.get();


    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    } finally {
        try {
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }    

I didn't find any useful information on fixing this. Any help would make my day

Caused by: java.lang.ArrayStoreException: org.apache.http.impl.cookie.RFC2965VersionAttributeHandler
    at org.apache.http.impl.cookie.DefaultCookieSpecProvider.create(DefaultCookieSpecProvider.java:93)
    at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:152)
    at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)
    at org.apache.http.impl.nio.client.MainClientExec.prepareRequest(MainClientExec.java:520)
    at org.apache.http.impl.nio.client.MainClientExec.prepare(MainClientExec.java:146)
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:124)
    at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
    at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:74)
    at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:107)
    at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:91)

javadocs say

Open Declaration java.util.concurrent.ExecutionException Exception thrown when attempting to retrieve the result of a task that aborted by throwing an exception. This exception can be inspected using the getCause() method.

1 Answer 1

0

The most probably reason - conflicts in httpclient version. F.e. project dependencies include httpclient and httpasyncclient. httpasyncclient has transitive dependency for another version of httpclient. As the result project dependency has 2 incompatible versions of httpclient. One of such case with detailed explanation is described here: https://stackoverflow.com/a/49898063/4651234

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.