Package org.apache.http.protocol

Examples of org.apache.http.protocol.HttpContext


        ConnectionInfo.removeConnection(httpUriRequest.hashCode());
        return content;
    }

    private void execute(final HttpUriRequest httpUriRequest) throws IOException {
      final HttpContext httpContext = new BasicHttpContext();
      setHeaders(httpUriRequest);
      setParams(httpUriRequest.getParams());
      setProxy(httpUriRequest.getParams());
      // statistics
      storeConnectionInfo(httpUriRequest);
View Full Code Here


        }
    }

    private static void cleanConnectionReferences(NHttpClientConnection conn) {

        HttpContext ctx = conn.getContext();       
        Axis2HttpRequest axis2Req =
            (Axis2HttpRequest) ctx.getAttribute(ClientHandler.AXIS2_HTTP_REQUEST);
        axis2Req.clear();   // this is linked via the selection key attachment and will free itself
                            // on timeout of the keep alive connection. Till then minimize the
                            // memory usage to a few bytes

        ctx.removeAttribute(ClientHandler.AXIS2_HTTP_REQUEST);
        ctx.removeAttribute(ClientHandler.OUTGOING_MESSAGE_CONTEXT);
        ctx.removeAttribute(ClientHandler.REQUEST_SOURCE_BUFFER);
        ctx.removeAttribute(ClientHandler.RESPONSE_SINK_BUFFER);

        ctx.removeAttribute(ExecutionContext.HTTP_REQUEST);
        ctx.removeAttribute(ExecutionContext.HTTP_RESPONSE);

        conn.resetOutput();
    }
View Full Code Here

        long d = keepAliveStrat.getKeepAliveDuration(response, context);
        assertEquals(-1, d);
    }

    public void testInvalidKeepAliveHeader() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        HttpResponse response = new BasicHttpResponse(
                new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
        response.addHeader("Keep-Alive", "timeout=whatever, max=20");
        ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
        long d = keepAliveStrat.getKeepAliveDuration(response, context);
View Full Code Here

        long d = keepAliveStrat.getKeepAliveDuration(response, context);
        assertEquals(-1, d);
    }

    public void testKeepAliveHeader() throws Exception {
        HttpContext context = new BasicHttpContext(null);
        HttpResponse response = new BasicHttpResponse(
                new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
        response.addHeader("Keep-Alive", "timeout=300, max=20");
        ConnectionKeepAliveStrategy keepAliveStrat = new DefaultConnectionKeepAliveStrategy();
        long d = keepAliveStrat.getKeepAliveDuration(response, context);
View Full Code Here

        DefaultHttpClient client = new DefaultHttpClient(mgr, params);
       
        HttpContext[] contexts = new HttpContext[workerCount];
        HttpWorker[] workers = new HttpWorker[workerCount];
        for (int i = 0; i < contexts.length; i++) {
            HttpContext context = new BasicHttpContext();
            context.setAttribute("user", Integer.valueOf(i));
            contexts[i] = context;
            workers[i] = new HttpWorker(context, requestCount, target, client);
        }
       
        client.setUserTokenHandler(new UserTokenHandler() {

            public Object getUserToken(final HttpContext context) {
                Integer id = (Integer) context.getAttribute("user");
                return id;
            }
           
        });
       
       
        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;
            }
            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);
                assertNotNull(state);
                assertEquals(id, state);
            }
        }
       
View Full Code Here

        String host = "localhost";
        this.localServer.register("*",
                new BasicRedirectService(host, port, HttpStatus.SC_MULTIPLE_CHOICES));
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        HttpGet httpget = new HttpGet("/oldlocation/");

        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }

        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
       
        assertEquals(HttpStatus.SC_MULTIPLE_CHOICES, response.getStatusLine().getStatusCode());
        assertEquals("/oldlocation/", reqWrapper.getRequestLine().getUri());
    }
View Full Code Here

        String host = "localhost";
        this.localServer.register("*",
                new BasicRedirectService(host, port, HttpStatus.SC_MOVED_PERMANENTLY));
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        HttpGet httpget = new HttpGet("/oldlocation/");

        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }

        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
        HttpHost targetHost = (HttpHost) context.getAttribute(
                ExecutionContext.HTTP_TARGET_HOST);

        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
        assertEquals(host, targetHost.getHostName());
View Full Code Here

        String host = "localhost";
        this.localServer.register("*",
                new BasicRedirectService(host, port, HttpStatus.SC_MOVED_TEMPORARILY));
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        HttpGet httpget = new HttpGet("/oldlocation/");

        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }

        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
        HttpHost targetHost = (HttpHost) context.getAttribute(
                ExecutionContext.HTTP_TARGET_HOST);

        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
        assertEquals(host, targetHost.getHostName());
View Full Code Here

        String host = "localhost";
        this.localServer.register("*",
                new BasicRedirectService(host, port, HttpStatus.SC_SEE_OTHER));
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        HttpGet httpget = new HttpGet("/oldlocation/");

        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }

        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
        HttpHost targetHost = (HttpHost) context.getAttribute(
                ExecutionContext.HTTP_TARGET_HOST);

        assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
        assertEquals(host, targetHost.getHostName());
View Full Code Here

        String host = "localhost";
        this.localServer.register("*",
                new BasicRedirectService(host, port, HttpStatus.SC_NOT_MODIFIED));
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        HttpGet httpget = new HttpGet("/oldlocation/");

        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }

        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
       
        assertEquals(HttpStatus.SC_NOT_MODIFIED, response.getStatusLine().getStatusCode());
        assertEquals("/oldlocation/", reqWrapper.getRequestLine().getUri());
    }
View Full Code Here

TOP

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

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.