Java Code Examples for javax.ws.rs.core.Cookie#valueOf()

The following examples show how to use javax.ws.rs.core.Cookie#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CookieHeaderProviderTest.java    From msf4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testFromStringWithExtendedParameters() {
    String cookieString = "Version=1; Application=msf4j; Path=/carbon; Domain=wso2; Expires=Sun, 06 Nov 1994 " +
            "08:49:37 GMT; Secure; HttpOnly; MaxAge=50; Comment=TestOnly";
    String name = "Application";
    String value = "msf4j";
    String path = "/carbon";
    String domain = "wso2";
    long dateTime = 784111777000L;

    NewCookie cookie = (NewCookie) Cookie.valueOf(cookieString);
    assertEquals(cookie.getName(), name);
    assertEquals(cookie.getValue(), value);
    assertEquals(cookie.getPath(), path);
    assertEquals(cookie.getVersion(), 1);
    assertEquals(cookie.getDomain(), domain);
    assertEquals(cookie.getComment(), "TestOnly");
    assertEquals(cookie.getExpiry().getTime(), dateTime);
    assertEquals(cookie.getMaxAge(), 50);
    assertEquals(cookie.isSecure(), true);
    assertEquals(cookie.isHttpOnly(), true);
}
 
Example 2
Source File: HttpHeadersImpl.java    From msf4j with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Cookie> getCookies() {
    List<String> values = nettyHttpHeaders.getAll(HttpHeaders.COOKIE);
    if (values == null || values.isEmpty()) {
        return Collections.emptyMap();
    }

    Map<String, Cookie> cookieMap = new HashMap<>();
    for (String value : values) {
        if (value == null) {
            continue;
        }
        Cookie cookie = Cookie.valueOf(value);
        cookieMap.put(cookie.getName(), cookie);
    }
    return cookieMap;
}
 
Example 3
Source File: HttpHeadersImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: CookieParameterResolver.java    From everrest with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object resolve(org.everrest.core.Parameter parameter, ApplicationContext context) throws Exception {
    String param = cookieParam.value();
    if (Cookie.class.isAssignableFrom(parameter.getParameterClass())) {
        Cookie cookie = context.getHttpHeaders().getCookies().get(param);
        if (cookie == null && parameter.getDefaultValue() != null) {
            cookie = Cookie.valueOf(parameter.getDefaultValue());
        }
        return cookie;
    } else {
        TypeProducer typeProducer = typeProducerFactory.createTypeProducer(parameter.getParameterClass(), parameter.getGenericType());
        MultivaluedMap<String, String> cookieValues = new MultivaluedMapImpl();
        for (Map.Entry<String, Cookie> entry : context.getHttpHeaders().getCookies().entrySet()) {
            cookieValues.putSingle(entry.getKey(), entry.getValue().getValue());
        }
        return typeProducer.createValue(param, cookieValues, parameter.getDefaultValue());
    }
}
 
Example 5
Source File: SSEClientRule.java    From blueocean-plugin with MIT License 5 votes vote down vote up
/**
 * Checks the headers for the session cookie and extracts it when received, so we can use it on subsequent
 * tests / waits within the same session.
 */
private void checkResponseForCookie(Response httpResponse) {
    List<Object> cookies = httpResponse.getHeaders().get("Set-Cookie");

    if (cookies != null) {
        for (Object rawCookieObj : cookies) {
            String rawCookie = rawCookieObj.toString();
            if (rawCookie.toUpperCase().contains("JSESSIONID")) {
                this.sessionCookie = Cookie.valueOf(rawCookie);
                break;
            }
        }
    }
}
 
Example 6
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: CookieHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromSimpleString() {
    Cookie c = Cookie.valueOf("foo=bar");
    assertTrue("bar".equals(c.getValue())
               && "foo".equals(c.getName())
               && 0 == c.getVersion());
}
 
Example 8
Source File: CookieHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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()));
}
 
Example 9
Source File: CookieHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 10
Source File: CookieHeaderProviderTest.java    From msf4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testFromString() throws Exception {
    Cookie cookie = Cookie.valueOf("JSESSIONID=3508015E4EF0ECA8C4B761FCC4BC1718");
    assertEquals(cookie.getName(), "JSESSIONID");
    assertEquals(cookie.getValue(), "3508015E4EF0ECA8C4B761FCC4BC1718");
}
 
Example 11
Source File: CookieHeaderProviderTest.java    From msf4j with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Cookie value can " +
        "not be null")
public void testFromStringWithoutCookieString() {
    Cookie.valueOf(null);
}
 
Example 12
Source File: CookieHeaderProviderTest.java    From msf4j with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void testFromStringWithoutName() {
    String cookieString = "Version=1; Path=/carbon; Domain=wso2";
    Cookie.valueOf(cookieString);
}
 
Example 13
Source File: CookieHeaderProviderTest.java    From msf4j with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void testFromStringWithoutValue() {
    String cookieString = "Version=1; Application;  Path=/carbon; Domain=wso2";
    Cookie.valueOf(cookieString);
}
 
Example 14
Source File: CookieHeaderProviderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoValue() {
    Cookie c = Cookie.valueOf("foo=");
    assertTrue("".equals(c.getValue())
               && "foo".equals(c.getName()));
}
 
Example 15
Source File: CookieHeaderProviderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testNullValue() throws Exception {
    Cookie.valueOf(null);
}