Package java.net

Examples of java.net.HttpCookie


                .path(cometdServletPath)
                .content(new StringContentProvider(handshakeContent), "application/json;charset=UTF-8")
                .timeout(5, TimeUnit.SECONDS)
                .send();
        assertEquals(200, handshake.getStatus());
        HttpCookie browserCookie = httpClient.getCookieStore().get(URI.create(cometdURL)).get(0);
        assertEquals("BAYEUX_BROWSER", browserCookie.getName());
        Message.Mutable[] messages = parser.parse(handshake.getContentAsString());
        assertEquals(1, messages.length);
        String clientId = messages[0].getClientId();

        String connectContent1 = "[{" +
View Full Code Here


    }

    private static List<HttpCookie> toHttpCookie(Set<Cookie> nettyCookies) {
        List<HttpCookie> result = new ArrayList<HttpCookie>();
        for (Cookie n : nettyCookies) {
            HttpCookie cookie = new HttpCookie(n.getName(), n.getValue());
            cookie.setSecure(n.isSecure());
            cookie.setPath(n.getPath());
            cookie.setDomain(n.getDomain());
            // Unspecified max-age in Netty is Integer.MIN_VALUE, while it's -1 in java.net.HttpCookie
            long maxAge = n.getMaxAge() == Integer.MIN_VALUE ? -1 : n.getMaxAge();
            cookie.setMaxAge(maxAge);
            cookie.setDiscard(n.isDiscard());
            cookie.setVersion(n.getVersion());
            result.add(cookie);
        }
        return result;
    }
View Full Code Here

        {
            if (builder == null)
                builder = new StringBuilder();
            if (builder.length() > 0)
                builder.append("; ");
            HttpCookie cookie = cookies.get(i);
            builder.append(cookie.getName()).append("=").append(cookie.getValue());
        }
        return builder;
    }
View Full Code Here

    @Test
    public void setsOneOutboundCookie() throws IOException, InterruptedException, ExecutionException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                response.cookie(new HttpCookie("a", "b")).end();
            }
        }).start().get();
        URLConnection urlConnection = httpGet(webServer, "/");
        List<HttpCookie> cookies = cookies(urlConnection);
        assertEquals(1, cookies.size());
View Full Code Here

    @Test
    public void setsTwoOutboundCookies() throws IOException, InterruptedException, ExecutionException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                response.cookie(new HttpCookie("a", "b")).cookie(new HttpCookie("c", "d")).end();
            }
        }).start().get();
        URLConnection urlConnection = httpGet(webServer, "/");
        List<HttpCookie> cookies = cookies(urlConnection);
        assertEquals(2, cookies.size());
View Full Code Here

    @Test
    public void doesntSetMaxAgeIfUnspecified() throws IOException, InterruptedException, ExecutionException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                response.cookie(new HttpCookie("a", "b")).end();
            }
        }).start().get();
        URLConnection urlConnection = httpGet(webServer, "/");
        List<HttpCookie> cookies = cookies(urlConnection);
        assertEquals(-1, cookies.get(0).getMaxAge());
View Full Code Here

                        .content(body)
                        .end();
            }
        }).start().get();
        URLConnection urlConnection = httpGet(webServer, "/");
        urlConnection.addRequestProperty("Cookie", new HttpCookie("someName", "someValue").toString());
        assertEquals("Your cookie value: someValue", contents(urlConnection));
    }
View Full Code Here

                        .content(body)
                        .end();
            }
        }).start().get();
        URLConnection urlConnection = httpGet(webServer, "/");
        urlConnection.addRequestProperty("Cookie", new HttpCookie("a", "b").toString());
        urlConnection.addRequestProperty("Cookie", new HttpCookie("c", "d").toString() + "; " + new HttpCookie("e", "f").toString());
        assertEquals("Your cookies: a=b c=d e=f", contents(urlConnection));
    }
View Full Code Here

        t.setSecure(true);
        t.setPath("/path");
        CookieEncoder e = new CookieEncoder(true);
        e.addCookie(t);
        urlConnection.addRequestProperty("Cookie", e.encode());
        String s = new HttpCookie("c", "d").toString();
        urlConnection.addRequestProperty("Cookie", s + "; " + new HttpCookie("e", "f").toString());
        assertEquals("Your cookies: a=b; age:5000; secure:true; path:/path| c=d; age:-1; secure:false| e=f; age:-1; secure:false|", contents(urlConnection));
    }
View Full Code Here

            if ("Set-Cookie".equals(header.getKey())) {
                List<String> value = header.getValue();
                for (String cookie : value) {
                    //since this processing is per header, there is only one cookie to parse
                    Cookie nettCookie = new CookieDecoder().decode(cookie).iterator().next();
                    HttpCookie c  = new HttpCookie(nettCookie.getName(),nettCookie.getValue());
                    cookies.add(c);
                }
            }
        }
        return sort(cookies);
View Full Code Here

TOP

Related Classes of java.net.HttpCookie

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.