Search in sources :

Example 61 with Cookie

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

the class JAXRSUtils method processCookieParam.

private static Object processCookieParam(Message m, String cookieName, Class<?> pClass, Type genericType, Annotation[] paramAnns, String defaultValue) {
    Cookie c = new HttpHeadersImpl(m).getCookies().get(cookieName);
    if (c == null && defaultValue != null) {
        c = Cookie.valueOf(cookieName + '=' + defaultValue);
    }
    if (c == null) {
        return null;
    }
    if (pClass.isAssignableFrom(Cookie.class)) {
        return c;
    }
    String value = InjectionUtils.isSupportedCollectionOrArray(pClass) && InjectionUtils.getActualType(genericType) == Cookie.class ? c.toString() : c.getValue();
    return InjectionUtils.createParameterObject(Collections.singletonList(value), pClass, genericType, paramAnns, null, false, ParameterType.COOKIE, m);
}
Also used : Cookie(javax.ws.rs.core.Cookie) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl)

Example 62 with Cookie

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

the class CookieHeaderProviderTest method testFromSimpleString.

@Test
public void testFromSimpleString() {
    Cookie c = Cookie.valueOf("foo=bar");
    assertTrue("bar".equals(c.getValue()) && "foo".equals(c.getName()) && 0 == c.getVersion());
}
Also used : Cookie(javax.ws.rs.core.Cookie) Test(org.junit.Test)

Example 63 with Cookie

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

the class CookieHeaderProviderTest method testCookieWithQuotes.

@Test
public void testCookieWithQuotes() {
    Cookie c = Cookie.valueOf("$Version=\"1\"; foo=\"bar\"; $Path=\"/path\"");
    assertTrue("bar".equals(c.getValue()) && "foo".equals(c.getName()) && 1 == c.getVersion() && "/path".equals(c.getPath()) && null == c.getDomain());
}
Also used : Cookie(javax.ws.rs.core.Cookie) Test(org.junit.Test)

Example 64 with Cookie

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

the class CookieHeaderProviderTest method testToStringWithQuotes.

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

Example 65 with Cookie

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

the class CookieHeaderProviderTest method testFromComplexString.

@Test
public void testFromComplexString() {
    Cookie c = Cookie.valueOf("$Version=2;foo=bar;$Path=path;$Domain=domain");
    assertTrue("bar".equals(c.getValue()) && "foo".equals(c.getName()) && 2 == c.getVersion() && "path".equals(c.getPath()) && "domain".equals(c.getDomain()));
}
Also used : Cookie(javax.ws.rs.core.Cookie) Test(org.junit.Test)

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