Examples of CookieStore


Examples of com.mastfrog.netty.http.client.CookieStore

public class TestModuleTest {

    @Test
    public void test(TestHarness harn) throws Throwable {
        assertTrue(true);
        CookieStore store = new CookieStore();
        CallResult res = harn.get("/ok").setCookieStore(store).go().assertStatus(OK);
        res.assertHasHeader(Headers.SET_COOKIE.name());
        assertTrue(store.iterator().hasNext());
        res.assertCookieValue("xid", "1").throwIfError();

        res = harn.get("/ok").setCookieStore(store).go().assertStatus(OK);
        res.assertCookieValue("xid", "2");
        res.throwIfError();
        assertEquals(store + " " + store.size(), 1, store.size());
        Iterator<Cookie> iter = store.iterator();
        assertTrue(store + "", iter.hasNext());
        iter.next();
        assertFalse(store + "", iter.hasNext());

        res = harn.get("/cookie").setCookieStore(store).addQueryPair("key", "foo")
                .addQueryPair("value", "bar").go()
                .assertStatus(OK)
                .assertCookieValue("foo", "bar");

        res = harn.get("/cookie").setCookieStore(store).addQueryPair("key", "wump")
                .addQueryPair("value", "baz").go()
                .assertStatus(OK)
                .assertCookieValue("wump", "baz");

        assertEquals(store + "", "baz", store.get("wump"));
        assertEquals(store + "", "bar", store.get("foo"));

    }
View Full Code Here

Examples of java.net.CookieStore

                    headers.put(CHUNKED_FIELD);
            }
        }

        // Cookies
        CookieStore cookieStore = getHttpClient().getCookieStore();
        if (cookieStore != null)
        {
            StringBuilder cookies = convertCookies(cookieStore.get(request.getURI()), null);
            cookies = convertCookies(request.getCookies(), cookies);
            if (cookies != null)
                request.header(HttpHeader.COOKIE.asString(), cookies.toString());
        }
View Full Code Here

Examples of net.sf.jpluck.http.CookieStore

            return Document.ZLIB_COMPRESSION;
        }
    }

    public CookieStore getCookieStore() {
        CookieStore cookieStore = null;
        String cookiesTxt = getCookiesTxt();
        if (cookiesTxt.length() > 0) {
            try {
                cookieStore = NetscapeCookieStore.createFromFile(new File(getCookiesTxt()));
            } catch (Exception e) {
View Full Code Here

Examples of org.apache.http.client.CookieStore

        if (method.equalsIgnoreCase("CONNECT")) {
            return;
        }
       
        // Obtain cookie store
        CookieStore cookieStore = (CookieStore) context.getAttribute(
                ClientContext.COOKIE_STORE);
        if (cookieStore == null) {
            this.log.info("Cookie store not available in HTTP context");
            return;
        }
       
        // Obtain the registry of cookie specs
        CookieSpecRegistry registry = (CookieSpecRegistry) context.getAttribute(
                ClientContext.COOKIESPEC_REGISTRY);
        if (registry == null) {
            this.log.info("CookieSpec registry not available in HTTP context");
            return;
        }
       
        // Obtain the target host (required)
        HttpHost targetHost = (HttpHost) context.getAttribute(
                ExecutionContext.HTTP_TARGET_HOST);
        if (targetHost == null) {
            throw new IllegalStateException("Target host not specified in HTTP context");
        }
       
        // Obtain the client connection (required)
        ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
                ExecutionContext.HTTP_CONNECTION);
        if (conn == null) {
            throw new IllegalStateException("Client connection not specified in HTTP context");
        }

        String policy = HttpClientParams.getCookiePolicy(request.getParams());
        if (this.log.isDebugEnabled()) {
            this.log.debug("CookieSpec selected: " + policy);
        }
       
        URI requestURI;
        if (request instanceof HttpUriRequest) {
            requestURI = ((HttpUriRequest) request).getURI();
        } else {
            try {
                requestURI = new URI(request.getRequestLine().getUri());
            } catch (URISyntaxException ex) {
                throw new ProtocolException("Invalid request URI: " +
                        request.getRequestLine().getUri(), ex);
            }
        }
       
        String hostName = targetHost.getHostName();
        int port = targetHost.getPort();
        if (port < 0) {
            port = conn.getRemotePort();
        }
       
        CookieOrigin cookieOrigin = new CookieOrigin(
                hostName,
                port,
                requestURI.getPath(),
                conn.isSecure());
       
        // Get an instance of the selected cookie policy
        CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
        // Get all cookies available in the HTTP state
        List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies());
        // Find cookies matching the given origin
        List<Cookie> matchedCookies = new ArrayList<Cookie>();
        for (Cookie cookie : cookies) {
            if (cookieSpec.match(cookie, cookieOrigin)) {
                if (this.log.isDebugEnabled()) {
View Full Code Here

Examples of org.apache.http.client.CookieStore

                ClientContext.COOKIE_SPEC);
        if (cookieSpec == null) {
            return;
        }
        // Obtain cookie store
        CookieStore cookieStore = (CookieStore) context.getAttribute(
                ClientContext.COOKIE_STORE);
        if (cookieStore == null) {
            this.log.info("CookieStore not available in HTTP context");
            return;
        }
View Full Code Here

Examples of org.apache.http.client.CookieStore

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

        DefaultHttpClient client = new DefaultHttpClient();
       
        CookieStore cookieStore = new BasicCookieStore();
        client.setCookieStore(cookieStore);
       
        BasicClientCookie cookie = new BasicClientCookie("name", "value");
        cookie.setDomain("localhost");
        cookie.setPath("/");
       
        cookieStore.addCookie(cookie);

        HttpContext context = new BasicHttpContext();
        HttpGet httpget = new HttpGet("/oldlocation/");

       
View Full Code Here

Examples of org.apache.http.client.CookieStore

        this.localServer.register("*", new CookieVer0Service());
       
        DefaultHttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);

        CookieStore cookieStore = new BasicCookieStore();
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
       
        HttpGet httpget = new HttpGet("/test/");
       
        HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
        HttpEntity e1 = response1.getEntity();
        if (e1 != null) {
            e1.consumeContent();
        }
       
        List<Cookie> cookies = cookieStore.getCookies();
        assertNotNull(cookies);
        assertEquals(1, cookies.size());

        HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
        HttpEntity e2 = response2.getEntity();
View Full Code Here

Examples of org.apache.http.client.CookieStore

        this.localServer.register("*", new CookieVer1Service());
       
        DefaultHttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);

        CookieStore cookieStore = new BasicCookieStore();
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
       
        HttpGet httpget = new HttpGet("/test/");
       
        HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
        HttpEntity e1 = response1.getEntity();
        if (e1 != null) {
            e1.consumeContent();
        }
       
        List<Cookie> cookies = cookieStore.getCookies();
        assertNotNull(cookies);
        assertEquals(2, cookies.size());

        HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
        HttpEntity e2 = response2.getEntity();
View Full Code Here

Examples of org.apache.http.client.CookieStore

        this.localServer.register("*", new CookieVer2Service());
       
        DefaultHttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);

        CookieStore cookieStore = new BasicCookieStore();
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
       
        HttpGet httpget = new HttpGet("/test/");
       
        HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
        HttpEntity e1 = response1.getEntity();
        if (e1 != null) {
            e1.consumeContent();
        }
       
        List<Cookie> cookies = cookieStore.getCookies();
        assertNotNull(cookies);
        assertEquals(1, cookies.size());

        HttpResponse response2 = client.execute(getServerHttp(), httpget, context);
        HttpEntity e2 = response2.getEntity();
View Full Code Here

Examples of org.apache.http.client.CookieStore

        this.localServer.register("*", new SetCookieVersionMixService());
       
        DefaultHttpClient client = new DefaultHttpClient();
        client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);

        CookieStore cookieStore = new BasicCookieStore();
        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
       
        HttpGet httpget = new HttpGet("/test/");
       
        HttpResponse response1 = client.execute(getServerHttp(), httpget, context);
        HttpEntity e1 = response1.getEntity();
        if (e1 != null) {
            e1.consumeContent();
        }
       
        List<Cookie> cookies = cookieStore.getCookies();
        assertNotNull(cookies);
        assertEquals(1, cookies.size());
        assertEquals("right", cookies.get(0).getValue());
        assertTrue(cookies.get(0) instanceof SetCookie2);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.