Package org.apache.http.protocol

Examples of org.apache.http.protocol.HttpContext


        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);
        Mockito.when(conn.getRemotePort()).thenReturn(1234);

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);

        CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
                ClientContext.COOKIE_ORIGIN);
        Assert.assertNotNull(cookieOrigin);
        Assert.assertEquals(this.target.getHostName(), cookieOrigin.getHost());
        Assert.assertEquals(80, cookieOrigin.getPort());
        Assert.assertEquals("/stuff", cookieOrigin.getPath());
View Full Code Here


        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.TRUE);
        Mockito.when(conn.getRemoteAddress()).thenReturn(InetAddress.getByName("localhost"));
        Mockito.when(conn.getRemotePort()).thenReturn(1234);

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);

        CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
                ClientContext.COOKIE_ORIGIN);
        Assert.assertNotNull(cookieOrigin);
        Assert.assertEquals(this.target.getHostName(), cookieOrigin.getHost());
        Assert.assertEquals(443, cookieOrigin.getPort());
        Assert.assertEquals("/stuff", cookieOrigin.getPath());
View Full Code Here

        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);

        Header[] headers1 = request.getHeaders(SM.COOKIE);
View Full Code Here

        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);

        Header[] headers1 = request.getHeaders(SM.COOKIE);
View Full Code Here

        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);

        Header[] headers1 = request.getHeaders(SM.COOKIE);
View Full Code Here

        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);

        Header[] headers1 = request.getHeaders(SM.COOKIE);
View Full Code Here

    public long getCacheUpdates() {
        return cacheUpdates.get();
    }

    public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException {
        HttpContext defaultContext = null;
        return execute(target, request, defaultContext);
    }
View Full Code Here

        HttpResponse resp = execute(target, request, context);
        return handleAndConsume(responseHandler,resp);
    }

    public HttpResponse execute(HttpUriRequest request) throws IOException {
        HttpContext context = null;
        return execute(request, context);
    }
View Full Code Here

                new IgnoreSpecFactory());
    }

    @Test(expected=IllegalArgumentException.class)
    public void testRequestParameterCheck() throws Exception {
        HttpContext context = new BasicHttpContext();
        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(null, context);
    }
View Full Code Here

        HttpRoutedConnection conn = Mockito.mock(HttpRoutedConnection.class);
        Mockito.when(conn.getRoute()).thenReturn(route);
        Mockito.when(conn.isSecure()).thenReturn(Boolean.FALSE);

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
        context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
        context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);

        HttpRequestInterceptor interceptor = new RequestAddCookies();
        interceptor.process(request, context);

        Header[] headers1 = request.getHeaders(SM.COOKIE);
        Assert.assertNotNull(headers1);
        Assert.assertEquals(2, headers1.length);
        Assert.assertEquals("$Version=1; name1=\"value1\"", headers1[0].getValue());
        Assert.assertEquals("$Version=1; name2=\"value2\"", headers1[1].getValue());
        Header[] headers2 = request.getHeaders(SM.COOKIE2);
        Assert.assertNotNull(headers2);
        Assert.assertEquals(0, headers2.length);

        CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(
                ClientContext.COOKIE_ORIGIN);
        Assert.assertNotNull(cookieOrigin);
        Assert.assertEquals(this.target.getHostName(), cookieOrigin.getHost());
        Assert.assertEquals(this.target.getPort(), cookieOrigin.getPort());
        Assert.assertEquals("/", cookieOrigin.getPath());
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.