Package org.apache.http.protocol

Examples of org.apache.http.protocol.SyncBasicHttpContext


        }
        if (params == null) {
            throw new IllegalArgumentException("HTTP params may not be null");
        }
        this.session = session;
        this.context = new SyncBasicHttpContext(null);
       
        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
        int linebuffersize = buffersize;
        if (linebuffersize > 512) {
            linebuffersize = 512;
View Full Code Here


        HttpConnectionParams.setConnectionTimeout(params, 10);

        HttpContext[] contexts = new HttpContext[workerCount];
        HttpWorker[] workers = new HttpWorker[workerCount];
        for (int i = 0; i < contexts.length; i++) {
            HttpContext context = new SyncBasicHttpContext();
            Object token = Integer.valueOf(i);
            context.setAttribute("user", token);
            contexts[i] = context;
            workers[i] = new HttpWorker(context, requestCount, target, this.httpclient);
        }

        for (int i = 0; i < workers.length; i++) {
            workers[i].start();
        }
        for (int i = 0; i < workers.length; i++) {
            workers[i].join(10000);
        }
        for (int i = 0; i < workers.length; i++) {
            Exception ex = workers[i].getException();
            if (ex != null) {
                throw ex;
            }
            Assert.assertEquals(requestCount, workers[i].getCount());
        }

        for (int i = 0; i < contexts.length; i++) {
            HttpContext context = contexts[i];
            Integer id = (Integer) context.getAttribute("user");

            for (int r = 0; r < requestCount; r++) {
                Integer state = (Integer) context.getAttribute("r" + r);
                Assert.assertEquals(id, state);
            }
        }

    }
View Full Code Here

        registry.register("*", new BufferingAsyncRequestHandler(new SimpleService()));

        HttpHost target = start(registry, null);

        // Bottom of the pool : a *keep alive* connection to Route 1.
        HttpContext context1 = new SyncBasicHttpContext();
        context1.setAttribute("user", "stuff");

        Future<HttpResponse> future1 = this.httpclient.execute(
                target, new HttpGet("/"), context1, null);
        HttpResponse response1 = future1.get();
        Assert.assertNotNull(response1);
        Assert.assertEquals(200, response1.getStatusLine().getStatusCode());

        // The ConnPoolByRoute now has 1 free connection, out of 2 max
        // The ConnPoolByRoute has one RouteSpcfcPool, that has one free connection
        // for [localhost][stuff]

        Thread.sleep(100);

        // Send a very simple HTTP get (it MUST be simple, no auth, no proxy, no 302, no 401, ...)
        // Send it to another route. Must be a keepalive.
        HttpContext context2 = new SyncBasicHttpContext();

        Future<HttpResponse> future2 = this.httpclient.execute(
                new HttpHost("127.0.0.1", target.getPort(), target.getSchemeName()),
                new HttpGet("/"), context2, null);
        HttpResponse response2 = future2.get();
        Assert.assertNotNull(response2);
        Assert.assertEquals(200, response2.getStatusLine().getStatusCode());

        // ConnPoolByRoute now has 2 free connexions, out of its 2 max.
        // The [localhost][stuff] RouteSpcfcPool is the same as earlier
        // And there is a [127.0.0.1][null] pool with 1 free connection

        Thread.sleep(100);

        // This will put the ConnPoolByRoute to the targeted state :
        // [localhost][stuff] will not get reused because this call is [localhost][null]
        // So the ConnPoolByRoute will need to kill one connection (it is maxed out globally).
        // The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
        // When this happens, the RouteSpecificPool becomes empty.
        HttpContext context3 = new SyncBasicHttpContext();
        Future<HttpResponse> future3 = this.httpclient.execute(
                target, new HttpGet("/"), context3, null);
        HttpResponse response3 = future3.get();
        Assert.assertNotNull(response3);
        Assert.assertEquals(200, response3.getStatusLine().getStatusCode());
View Full Code Here

        }
        if (params == null) {
            throw new IllegalArgumentException("HTTP params may not be null");
        }
        this.session = session;
        this.context = new SyncBasicHttpContext(null);
       
        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
        int linebuffersize = buffersize;
        if (linebuffersize > 512) {
            linebuffersize = 512;
View Full Code Here

        }
        if (params == null) {
            throw new IllegalArgumentException("HTTP params may not be null");
        }
        this.session = session;
        this.context = new SyncBasicHttpContext(null);
       
        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
        int linebuffersize = buffersize;
        if (linebuffersize > 512) {
            linebuffersize = 512;
View Full Code Here

        HttpConnectionParams.setConnectionTimeout(params, 10);

        HttpContext[] contexts = new HttpContext[workerCount];
        HttpWorker[] workers = new HttpWorker[workerCount];
        for (int i = 0; i < contexts.length; i++) {
            HttpContext context = new SyncBasicHttpContext();
            Object token = Integer.valueOf(i);
            context.setAttribute("user", token);
            contexts[i] = context;
            workers[i] = new HttpWorker(context, requestCount, target, this.httpclient);
        }

        for (int i = 0; i < workers.length; i++) {
            workers[i].start();
        }
        for (int i = 0; i < workers.length; i++) {
            workers[i].join(10000);
        }
        for (int i = 0; i < workers.length; i++) {
            Exception ex = workers[i].getException();
            if (ex != null) {
                throw ex;
            }
            Assert.assertEquals(requestCount, workers[i].getCount());
        }

        for (int i = 0; i < contexts.length; i++) {
            HttpContext context = contexts[i];
            Integer id = (Integer) context.getAttribute("user");

            for (int r = 0; r < requestCount; r++) {
                Integer state = (Integer) context.getAttribute("r" + r);
                Assert.assertEquals(id, state);
            }
        }

    }
View Full Code Here

        registry.register("*", new BasicAsyncRequestHandler(new SimpleService()));

        HttpHost target = start(registry, null);

        // Bottom of the pool : a *keep alive* connection to Route 1.
        HttpContext context1 = new SyncBasicHttpContext();
        context1.setAttribute("user", "stuff");

        Future<HttpResponse> future1 = this.httpclient.execute(
                target, new HttpGet("/"), context1, null);
        HttpResponse response1 = future1.get();
        Assert.assertNotNull(response1);
        Assert.assertEquals(200, response1.getStatusLine().getStatusCode());

        // The ConnPoolByRoute now has 1 free connection, out of 2 max
        // The ConnPoolByRoute has one RouteSpcfcPool, that has one free connection
        // for [localhost][stuff]

        Thread.sleep(100);

        // Send a very simple HTTP get (it MUST be simple, no auth, no proxy, no 302, no 401, ...)
        // Send it to another route. Must be a keepalive.
        HttpContext context2 = new SyncBasicHttpContext();

        Future<HttpResponse> future2 = this.httpclient.execute(
                new HttpHost("127.0.0.1", target.getPort(), target.getSchemeName()),
                new HttpGet("/"), context2, null);
        HttpResponse response2 = future2.get();
        Assert.assertNotNull(response2);
        Assert.assertEquals(200, response2.getStatusLine().getStatusCode());

        // ConnPoolByRoute now has 2 free connexions, out of its 2 max.
        // The [localhost][stuff] RouteSpcfcPool is the same as earlier
        // And there is a [127.0.0.1][null] pool with 1 free connection

        Thread.sleep(100);

        // This will put the ConnPoolByRoute to the targeted state :
        // [localhost][stuff] will not get reused because this call is [localhost][null]
        // So the ConnPoolByRoute will need to kill one connection (it is maxed out globally).
        // The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
        // When this happens, the RouteSpecificPool becomes empty.
        HttpContext context3 = new SyncBasicHttpContext();
        Future<HttpResponse> future3 = this.httpclient.execute(
                target, new HttpGet("/"), context3, null);
        HttpResponse response3 = future3.get();
        Assert.assertNotNull(response3);
        Assert.assertEquals(200, response3.getStatusLine().getStatusCode());
View Full Code Here

        }
        if (params == null) {
            throw new IllegalArgumentException("HTTP params may not be null");
        }
        this.session = session;
        this.context = new SyncBasicHttpContext(null);
       
        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
        int linebuffersize = buffersize;
        if (linebuffersize > 512) {
            linebuffersize = 512;
View Full Code Here

        }
        if (params == null) {
            throw new IllegalArgumentException("HTTP params may not be null");
        }
        this.session = session;
        this.context = new SyncBasicHttpContext(null);
       
        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
        int linebuffersize = buffersize;
        if (linebuffersize > 512) {
            linebuffersize = 512;
View Full Code Here

        return connManager;
    }


    protected HttpContext createHttpContext() {
        return new SyncBasicHttpContext(null);
    }
View Full Code Here

TOP

Related Classes of org.apache.http.protocol.SyncBasicHttpContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.