0
votes

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

1 Answers

1
votes

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.