0

I am running the following program on jetty asynchronous http client.

Code is 
public static void main(String[] args) throws InterruptedException, TimeoutException, ExecutionException {
            String url2="http://www.google.co.in";

        //  JettyHttp.sendHttpSyncReq(url2);
            JettyHttp.sendHttpAsyncReq(url2);

    }
    public static void sendHttpAsyncReq(String url) throws InterruptedException, TimeoutException, ExecutionException
    {
        SslContextFactory sslContextFactory = new SslContextFactory();
        HttpClient httpClient =new HttpClient(sslContextFactory);
        long total_t1=System.currentTimeMillis();


        httpClient.newRequest(url).send(new Response.CompleteListener() {

            @Override
            public void onComplete(Result arg0) {
                // TODO Auto-generated method stub

            }
        });

        long total_t2=System.currentTimeMillis();
        System.out.println(total_t2-total_t1 +" ==");


    }

Error I am getting is

Exception in thread "main" java.util.concurrent.RejectedExecutionException: org.eclipse.jetty.client.HttpClient@412429c is stopped
    at org.eclipse.jetty.client.HttpDestination.send(HttpDestination.java:198)
    at org.eclipse.jetty.client.HttpClient.send(HttpClient.java:485)
    at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:486)
    at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:479)
    at com.nielsen.http.JettyHttp.sendHttpAsyncReq(JettyHttp.java:38)
    at com.nielsen.http.JettyHttp.main(JettyHttp.java:28)

Please Help me in this to get out of error::

1 Answer 1

1

You forgot to start the HttpClient.

SslContextFactory sslContextFactory = new SslContextFactory();
HttpClient httpClient =new HttpClient(sslContextFactory);
httpClient.start();

Keep in mind that you only need 1 HttpClient for all of your requests and connections. The HttpClient object fits in the same logical role as a browser, with it managing the many tabs of connections.

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.