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);
}
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());
}
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());
}
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());
}
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()));
}
Aggregations