Package org.apache.http

Examples of org.apache.http.ConnectionReuseStrategy


        StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_0, 200, "OK");
        HttpResponse response = new BasicHttpResponse(statusline);
        response.addHeader(new Header("Connection", "keep-alive"));
        response.setEntity(entity);

        ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
        assertTrue(s.keepAlive(response));
    }
View Full Code Here


    public void testHTTP10Default() throws Exception {
        StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_0, 200, "OK");
        HttpResponse response = new BasicHttpResponse(statusline);

        ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
        assertFalse(s.keepAlive(response));
    }
View Full Code Here

   
    public void testHTTP11Default() throws Exception {
        StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_1, 200, "OK");
        HttpResponse response = new BasicHttpResponse(statusline);

        ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
        assertTrue(s.keepAlive(response));
    }
View Full Code Here

    public void testFutureHTTP() throws Exception {
        StatusLine statusline = new StatusLine(new HttpVersion(3, 45), 200, "OK");
        HttpResponse response = new BasicHttpResponse(statusline);

        ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
        assertTrue(s.keepAlive(response));
    }
View Full Code Here

        // Use HTTP 1.0
        StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_0, 200, "OK");
        HttpResponse response = new BasicHttpResponse(statusline);
        response.addHeader(new Header("Connection", "keep--alive"));

        ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
        assertFalse(s.keepAlive(response));
    }
View Full Code Here

        // Use HTTP 1.0
        StatusLine statusline = new StatusLine(HttpVersion.HTTP_1_0, 200, "OK");
        HttpResponse response = new BasicHttpResponse(statusline);
        response.addHeader(new Header("Connection", null));

        ConnectionReuseStrategy s = new DefaultConnectionReuseStrategy();
        assertFalse(s.keepAlive(response));
    }
View Full Code Here

       
        HttpHost host = new HttpHost("localhost", 8080);
        context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, host);
       
        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();

        try {
           
            HttpEntity[] requestBodies = {
                    new StringEntity(
                            "This is the first test request", "UTF-8"),
                    new ByteArrayEntity(
                            "This is the second test request".getBytes("UTF-8")),
                    new InputStreamEntity(
                            new ByteArrayInputStream(
                                    "This is the third test request (will be chunked)"
                                    .getBytes("UTF-8")), -1)
            };
           
            for (int i = 0; i < requestBodies.length; i++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket, params);
                }
                HttpPost request = new HttpPost("/servlets-examples/servlet/RequestInfoExample");
                request.setEntity(requestBodies[i]);
                System.out.println(">> Request URI: " + request.getRequestLine().getUri());
                HttpResponse response = httpexecutor.execute(request, conn, context);
                System.out.println("<< Response: " + response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
                System.out.println("==============");
                if (!connStrategy.keepAlive(response, context)) {
                    conn.close();
                } else {
                    System.out.println("Connection kept alive...");
                }
            }
View Full Code Here

        HttpContext context = new HttpExecutionContext(null);
        HttpHost host = new HttpHost("localhost", 8080);
        context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, host);

        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
        ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
       
        try {
           
            String[] targets = {
                    "/",
                    "/servlets-examples/servlet/RequestInfoExample",
                    "/somewhere%20in%20pampa"};
           
            for (int i = 0; i < targets.length; i++) {
                if (!conn.isOpen()) {
                    Socket socket = new Socket(host.getHostName(), host.getPort());
                    conn.bind(socket, params);
                }
                HttpGet request = new HttpGet(targets[i]);
                System.out.println(">> Request URI: " + request.getRequestLine().getUri());
                HttpResponse response = httpexecutor.execute(request, conn, context);
                System.out.println("<< Response: " + response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
                System.out.println("==============");
                if (!connStrategy.keepAlive(response, context)) {
                    conn.close();
                } else {
                    System.out.println("Connection kept alive...");
                }
            }
View Full Code Here

            if (maxConnPerRoute > 0) {
                poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
            }
            connManagerCopy = poolingmgr;
        }
        ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
        if (reuseStrategyCopy == null) {
            if (systemProperties) {
                final String s = System.getProperty("http.keepAlive", "true");
                if ("true".equalsIgnoreCase(s)) {
                    reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
View Full Code Here

                    poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
                }
            }
            connManager = poolingmgr;
        }
        ConnectionReuseStrategy reuseStrategy = this.reuseStrategy;
        if (reuseStrategy == null) {
            if (systemProperties) {
                final String s = System.getProperty("http.keepAlive", "true");
                if ("true".equalsIgnoreCase(s)) {
                    reuseStrategy = DefaultConnectionReuseStrategy.INSTANCE;
View Full Code Here

TOP

Related Classes of org.apache.http.ConnectionReuseStrategy

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.