Search in sources :

Example 11 with NewCookie

use of javax.ws.rs.core.NewCookie in project dropwizard by dropwizard.

the class HttpSessionFactoryTest method passesInHttpSessions.

@Test
public void passesInHttpSessions() throws Exception {
    Response firstResponse = target("/session/").request(MediaType.TEXT_PLAIN).post(Entity.entity("Mr. Peeps", MediaType.TEXT_PLAIN));
    final Map<String, NewCookie> cookies = firstResponse.getCookies();
    firstResponse.close();
    Invocation.Builder builder = target("/session/").request().accept(MediaType.TEXT_PLAIN);
    for (NewCookie cookie : cookies.values()) {
        builder.cookie(cookie);
    }
    assertThat(builder.get(String.class)).isEqualTo("Mr. Peeps");
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) NewCookie(javax.ws.rs.core.NewCookie) AbstractJerseyTest(io.dropwizard.jersey.AbstractJerseyTest) Test(org.junit.Test)

Example 12 with NewCookie

use of javax.ws.rs.core.NewCookie in project jersey by jersey.

the class OutboundMessageContext method getResponseCookies.

/**
     * Get any new cookies set on the message message.
     *
     * @return a read-only map of cookie name (String) to a {@link javax.ws.rs.core.NewCookie new cookie}.
     */
public Map<String, NewCookie> getResponseCookies() {
    List<Object> cookies = headers.get(HttpHeaders.SET_COOKIE);
    if (cookies == null || cookies.isEmpty()) {
        return Collections.emptyMap();
    }
    Map<String, NewCookie> result = new HashMap<String, NewCookie>();
    for (String cookie : HeaderUtils.asStringList(cookies, RuntimeDelegate.getInstance())) {
        if (cookie != null) {
            NewCookie newCookie = HttpHeaderReader.readNewCookie(cookie);
            result.put(newCookie.getName(), newCookie);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) NewCookie(javax.ws.rs.core.NewCookie)

Example 13 with NewCookie

use of javax.ws.rs.core.NewCookie in project jersey by jersey.

the class CookiesParserTest method _testCaseInsensitiveNewCookieParams.

private void _testCaseInsensitiveNewCookieParams(final String expires, final String maxAge, final String path, final String domain, final String comment, final String version, final String secure, final String httpOnly) throws Exception {
    final String header = "foo=bar;" + expires + "=Tue, 15 Jan 2013 21:47:38 GMT;" + maxAge + "=42;" + path + "=/;" + domain + "=.example.com;" + comment + "=Testing;" + version + "=1;" + secure + ";" + httpOnly;
    final NewCookie cookie = CookiesParser.parseNewCookie(header);
    assertThat(cookie.getName(), equalTo("foo"));
    assertThat(cookie.getValue(), equalTo("bar"));
    assertThat(cookie.getExpiry(), equalTo(dateFormat.parse("Tue, 15 Jan 2013 21:47:38 GMT")));
    assertThat(cookie.getMaxAge(), equalTo(42));
    assertThat(cookie.getPath(), equalTo("/"));
    assertThat(cookie.getDomain(), equalTo(".example.com"));
    assertThat(cookie.getComment(), equalTo("Testing"));
    assertThat(cookie.getVersion(), equalTo(1));
    assertThat(cookie.isSecure(), is(true));
    assertThat(cookie.isHttpOnly(), is(true));
}
Also used : NewCookie(javax.ws.rs.core.NewCookie)

Example 14 with NewCookie

use of javax.ws.rs.core.NewCookie in project jersey by jersey.

the class ResponseTest method headerTest.

/*
     * Create an instance of Response using
     * Response.ResponseBuilder.header(String, Object).build()
     * verify that correct status code is returned
     */
@Test
public void headerTest() {
    int status = 200;
    List<String> type = Arrays.asList("text/plain", "text/html");
    List<String> encoding = Arrays.asList("gzip", "compress");
    List<String> lang = Arrays.asList("en-US", "en-GB", "zh-CN");
    String name = "name_1";
    String value = "value_1";
    Cookie ck1 = new Cookie(name, value);
    NewCookie nck1 = new NewCookie(ck1);
    List<String> cookies = Arrays.asList(nck1.toString().toLowerCase());
    Response resp = Response.status(status).header("Content-type", "text/plain").header("Content-type", "text/html").header("Content-Language", "en-US").header("Content-Language", "en-GB").header("Content-Language", "zh-CN").header("Cache-Control", "no-transform").header("Set-Cookie", "name_1=value_1;version=1").build();
    String tmp = verifyResponse(resp, null, status, encoding, lang, type, null, null, cookies);
    if (tmp.endsWith("false")) {
        System.out.println("### " + tmp);
        fail();
    }
}
Also used : NewCookie(javax.ws.rs.core.NewCookie) Cookie(javax.ws.rs.core.Cookie) Response(javax.ws.rs.core.Response) NewCookie(javax.ws.rs.core.NewCookie) Test(org.junit.Test)

Example 15 with NewCookie

use of javax.ws.rs.core.NewCookie in project jersey by jersey.

the class CookieImplTest method testNewCookieToString.

@Test
public void testNewCookieToString() {
    NewCookie cookie = new NewCookie("fred", "flintstone");
    String expResult = "fred=flintstone;Version=1";
    assertEquals(expResult, cookie.toString());
    cookie = new NewCookie("fred", "flintstone", null, null, null, 60, false);
    expResult = "fred=flintstone;Version=1;Max-Age=60";
    assertEquals(expResult, cookie.toString());
    cookie = new NewCookie("fred", "flintstone", null, null, "a modern stonage family", 60, false);
    expResult = "fred=flintstone;Version=1;Comment=\"a modern stonage family\";Max-Age=60";
    assertEquals(expResult, cookie.toString());
}
Also used : NewCookie(javax.ws.rs.core.NewCookie) Test(org.junit.Test)

Aggregations

NewCookie (javax.ws.rs.core.NewCookie)22 Test (org.junit.Test)11 Response (javax.ws.rs.core.Response)9 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Invocation (javax.ws.rs.client.Invocation)3 SimpleSign (ddf.security.samlp.SimpleSign)2 ValidationException (ddf.security.samlp.ValidationException)2 SecurityServiceException (ddf.security.service.SecurityServiceException)2 AbstractJerseyTest (io.dropwizard.jersey.AbstractJerseyTest)2 GET (javax.ws.rs.GET)2 WebTarget (javax.ws.rs.client.WebTarget)2 Cookie (javax.ws.rs.core.Cookie)2 User (keywhiz.auth.User)2 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)2 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)2 IncompatibleVersionException (com.datatorrent.stram.client.WebServicesVersionConversion.IncompatibleVersionException)1 WebServicesClient (com.datatorrent.stram.util.WebServicesClient)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1