Search in sources :

Example 66 with Cookie

use of javax.ws.rs.core.Cookie in project cxf by apache.

the class CookieHeaderProviderTest method testToString.

@Test
public void testToString() {
    Cookie c = new Cookie("foo", "bar", "path", "domain", 2);
    assertEquals("$Version=2;foo=bar;$Path=path;$Domain=domain", c.toString());
}
Also used : Cookie(javax.ws.rs.core.Cookie) Test(org.junit.Test)

Example 67 with Cookie

use of javax.ws.rs.core.Cookie in project cxf by apache.

the class HttpHeadersImplTest method testGetCookies.

@Test
public void testGetCookies() throws Exception {
    Message m = new MessageImpl();
    m.setExchange(new ExchangeImpl());
    MetadataMap<String, String> headers = createHeaders();
    headers.putSingle(HttpHeaders.COOKIE, "a=$b;c=d");
    m.put(Message.PROTOCOL_HEADERS, headers);
    HttpHeaders h = new HttpHeadersImpl(m);
    Map<String, Cookie> cookies = h.getCookies();
    assertEquals(2, cookies.size());
    assertEquals("$b", cookies.get("a").getValue());
    assertEquals("d", cookies.get("c").getValue());
}
Also used : Cookie(javax.ws.rs.core.Cookie) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 68 with Cookie

use of javax.ws.rs.core.Cookie in project cxf by apache.

the class HttpHeadersImplTest method testGetCookieWithAttributes.

@Test
public void testGetCookieWithAttributes() throws Exception {
    Message m = new MessageImpl();
    m.setExchange(new ExchangeImpl());
    MetadataMap<String, String> headers = createHeaders();
    headers.putSingle(HttpHeaders.COOKIE, "$Version=1;a=b");
    m.put(Message.PROTOCOL_HEADERS, headers);
    HttpHeaders h = new HttpHeadersImpl(m);
    Map<String, Cookie> cookies = h.getCookies();
    assertEquals(1, cookies.size());
    Cookie cookie = cookies.get("a");
    assertEquals("b", cookie.getValue());
    assertEquals(1, cookie.getVersion());
}
Also used : Cookie(javax.ws.rs.core.Cookie) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 69 with Cookie

use of javax.ws.rs.core.Cookie in project cxf by apache.

the class HttpHeadersImplTest method testGetCookiesWithAttributes.

@Test
public void testGetCookiesWithAttributes() throws Exception {
    Message m = new MessageImpl();
    m.setExchange(new ExchangeImpl());
    MetadataMap<String, String> headers = createHeaders();
    headers.putSingle(HttpHeaders.COOKIE, "$Version=1;a=b, $Version=1;c=d");
    m.put(Message.PROTOCOL_HEADERS, headers);
    HttpHeaders h = new HttpHeadersImpl(m);
    Map<String, Cookie> cookies = h.getCookies();
    assertEquals(2, cookies.size());
    Cookie cookieA = cookies.get("a");
    assertEquals("b", cookieA.getValue());
    assertEquals(1, cookieA.getVersion());
    Cookie cookieC = cookies.get("c");
    assertEquals("d", cookieC.getValue());
    assertEquals(1, cookieA.getVersion());
}
Also used : Cookie(javax.ws.rs.core.Cookie) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 70 with Cookie

use of javax.ws.rs.core.Cookie in project cxf by apache.

the class HttpHeadersImpl method getCookies.

public Map<String, Cookie> getCookies() {
    List<String> values = headers.get(HttpHeaders.COOKIE);
    if (values == null || values.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<String, Cookie> cl = new HashMap<>();
    for (String value : values) {
        if (value == null) {
            continue;
        }
        List<String> cs = getHeaderValues(HttpHeaders.COOKIE, value, getCookieSeparator(value));
        for (String c : cs) {
            Cookie cookie = Cookie.valueOf(c);
            cl.put(cookie.getName(), cookie);
        }
    }
    return cl;
}
Also used : Cookie(javax.ws.rs.core.Cookie) HashMap(java.util.HashMap)

Aggregations

Cookie (javax.ws.rs.core.Cookie)80 Test (org.junit.Test)40 Response (javax.ws.rs.core.Response)18 HashMap (java.util.HashMap)12 WebTarget (javax.ws.rs.client.WebTarget)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 NewCookie (javax.ws.rs.core.NewCookie)7 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)7 Map (java.util.Map)5 Message (org.apache.cxf.message.Message)5 Entitlement (com.sun.identity.entitlement.Entitlement)4 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)4 Privilege (com.sun.identity.entitlement.Privilege)4 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 HttpHeaders (javax.ws.rs.core.HttpHeaders)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 BeforeClass (org.testng.annotations.BeforeClass)4 SSOToken (com.iplanet.sso.SSOToken)3