Package javax.ws.rs.core

Examples of javax.ws.rs.core.NewCookie


public class NewCookieHeaderProviderTest extends Assert {
   
       
    @Test
    public void testFromSimpleString() {
        NewCookie c = NewCookie.valueOf("foo=bar");
        assertTrue("bar".equals(c.getValue())
                   && "foo".equals(c.getName()));
    }
View Full Code Here


    }
   
       
    @Test
    public void testFromComplexString() {
        NewCookie c = NewCookie.valueOf(
                      "foo=bar;Comment=comment;Path=path;Max-Age=10;Domain=domain;Secure;Version=1");
        assertTrue("bar".equals(c.getValue())
                   && "foo".equals(c.getName())
                   && 1 == c.getVersion()
                   && "path".equals(c.getPath())
                   && "domain".equals(c.getDomain())
                   && "comment".equals(c.getComment())
                   && 10 == c.getMaxAge());
    }
View Full Code Here

                   && 10 == c.getMaxAge());
    }
   
    @Test
    public void testToString() {
        NewCookie c = new NewCookie("foo", "bar", "path", "domain", "comment", 2, true);
        assertEquals("foo=bar;Comment=comment;Domain=domain;Max-Age=2;Path=path;Secure;Version=1",
                     c.toString());
              
    }
View Full Code Here

       
        if (name == null || value == null) {
            throw new IllegalArgumentException("Set-Cookie is malformed : " + c);
        }
       
        return new NewCookie(name, value, path, domain, comment, maxAge, isSecure);
    }
View Full Code Here

public class CookieParamResource {

    @PUT
    @Produces("text/plain")
    public Response swipe(@CookieParam("jar") @DefaultValue("0") String jarSwipes) {
        return Response.ok("swiped:" + jarSwipes).cookie(new NewCookie("jar", (Integer
            .valueOf(jarSwipes) + 1) + "")).build();
    }
View Full Code Here

    @PUT
    @Produces("text/plain")
    public Response setCookies() {
        ResponseBuilder rb = Response.ok();
        rb.cookie(new NewCookie("name", "value", uri.getBaseUri().getPath() + uri.getPath(), uri
            .getBaseUri().getHost().toLowerCase(), "comment", 10, false));
        rb.cookie(new NewCookie("name2", "value2", uri.getBaseUri().getPath() + uri.getPath(), uri
            .getBaseUri().getHost().toLowerCase(), "comment2", 10, false));
        rb.cookie(new NewCookie("name3", "value3", uri.getBaseUri().getPath() + uri.getPath(), uri
            .getBaseUri().getHost().toLowerCase(), "comment2", 10, false));
        return rb.build();
    }
View Full Code Here

        assertNotNull(r.getMetadata());
        assertEquals(r.getStatus(), 200);

        URI loc = new URI("/defects/5");
        r =
            Response.created(loc).cookie(new NewCookie("cName", "cValue")).expires(new Date())
                .build();
        assertEquals(loc, r.getMetadata().getFirst(HttpHeaders.LOCATION));
        assertTrue(r.getMetadata().getFirst(HttpHeaders.SET_COOKIE).toString().indexOf("cName") > -1);

        r = Response.serverError().build();
View Full Code Here

            rd.createHeaderDelegate(NewCookie.class);
        if (newCookieHeaderDelegate == null) {
            fail("NewCookie header delegate is not regestered in RuntimeDelegateImpl");
        }

        NewCookie expectedNewCookie =
            new NewCookie("MyCookie", "MyCookieValue", ".", "mydomain", 1, "Comment", 21600, true);
        String cookieToParse =
            "MyCookie=MyCookieValue;Version=1; Path=.; Domain=mydomain; Comment=Comment; Max-Age=21600; Secure";

        // Test Parse NewCookie
        NewCookie parsedNewCookie = newCookieHeaderDelegate.fromString(cookieToParse);
        assertEquals(expectedNewCookie, parsedNewCookie);

        expectedNewCookie =
            new NewCookie("MyCookie", "", ".", "mydomain", 1, "Comment", 21600, true);
        cookieToParse =
            "MyCookie=\"\";Version=1; Path=.; Domain=mydomain; Comment=Comment; Max-Age=21600; Secure";
        parsedNewCookie = newCookieHeaderDelegate.fromString(cookieToParse);
        assertEquals(expectedNewCookie, parsedNewCookie);
View Full Code Here

            fail("NewCookie header delegate is not regestered in RuntimeDelegateImpl");
        }

        String expectedCookieSerialization =
            "MyCookie=MyCookieValue;Version=1;Path=.;Domain=mydomain;Comment=Comment;Max-Age=21600;Secure";
        NewCookie cookieToSerialize =
            new NewCookie("MyCookie", "MyCookieValue", ".", "mydomain", 1, "Comment", 21600, true);
        String serializedCookie = cookieToSerialize.toString();
        assertEquals(expectedCookieSerialization, serializedCookie);

        // Negative test - Invalid cookie
        try {
            newCookieHeaderDelegate.toString(null);
View Full Code Here

    }


    @Override
    protected void initialize() {
        CookieManager.setCookie(new NewCookie("", ""));
        String userName = getUser().getUserName();
        callback = getCallback();
        String serviceURI = getConnectionURI().toString();
        basicRegistryResourceClient =
                new BasicRegistryResourceClient(
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.NewCookie

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.