Package org.apache.http.protocol

Examples of org.apache.http.protocol.HttpContext


        String host = "localhost";
        this.localServer.register("*",
                new BasicRedirectService(host, port, HttpStatus.SC_USE_PROXY));
       
        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_USE_PROXY, response.getStatusLine().getStatusCode());
        assertEquals("/oldlocation/", reqWrapper.getRequestLine().getUri());
    }
View Full Code Here


        String host = "localhost";
        this.localServer.register("*",
                new BasicRedirectService(host, port, HttpStatus.SC_TEMPORARY_REDIRECT));
       
        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

        int port = this.localServer.getServicePort();
        String host = "localhost";
        this.localServer.register("*", new BasicRedirectService(host, port));

        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();
       
        HttpPost httppost = new HttpPost("/oldlocation/");
        httppost.setEntity(new StringEntity("stuff"));

        HttpResponse response = client.execute(getServerHttp(), httppost, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }
       
        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);

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

        int port = this.localServer.getServicePort();
        String host = this.localServer.getServiceHostName();
        this.localServer.register("*", new RelativeRedirectService());

        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        client.getParams().setBooleanParameter(
                ClientPNames.REJECT_RELATIVE_REDIRECT, false);
        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("/relativelocation/", reqWrapper.getRequestLine().getUri());
        assertEquals(host, targetHost.getHostName());
View Full Code Here

        int port = this.localServer.getServicePort();
        String host = this.localServer.getServiceHostName();
        this.localServer.register("*", new RelativeRedirectService2());

        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        client.getParams().setBooleanParameter(
                ClientPNames.REJECT_RELATIVE_REDIRECT, false);
        HttpGet httpget = new HttpGet("/test/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("/test/relativelocation", reqWrapper.getRequestLine().getUri());
        assertEquals(host, targetHost.getHostName());
View Full Code Here

        cookie.setDomain("localhost");
        cookie.setPath("/");
       
        cookieStore.addCookie(cookie);

        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_OK, response.getStatusLine().getStatusCode());
        assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());
View Full Code Here

        this.localServer.register("*",
                new BasicRedirectService(host, port));

        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        List<Header> defaultHeaders = new ArrayList<Header>(1);
        defaultHeaders.add(new BasicHeader(HTTP.USER_AGENT, "my-test-client"));
       
        client.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, defaultHeaders);
       
        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_OK, response.getStatusLine().getStatusCode());
        assertEquals("/newlocation/", reqWrapper.getRequestLine().getUri());

View Full Code Here

                this.conn = conn;
            }


            public void run() {
                HttpContext context = new BasicHttpContext(null);
                try {
                    while ((servicedSocket != null) &&
                           this.conn.isOpen() && !Thread.interrupted()) {
                        this.httpservice.handleRequest(this.conn, context);
                    }
View Full Code Here

    public void testRequestURIRewriting() throws Exception {
        int port = this.localServer.getServicePort();
        this.localServer.register("*", new SimpleService());
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        String s = "http://localhost:" + port + "/path";
        HttpGet httpget = new HttpGet(s);

        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_OK, response.getStatusLine().getStatusCode());

        assertTrue(reqWrapper instanceof RequestWrapper);
View Full Code Here

    public void testRequestURIRewritingEmptyPath() throws Exception {
        int port = this.localServer.getServicePort();
        this.localServer.register("*", new SimpleService());
       
        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        String s = "http://localhost:" + port;
        HttpGet httpget = new HttpGet(s);

        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_OK, response.getStatusLine().getStatusCode());

        assertTrue(reqWrapper instanceof RequestWrapper);
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.