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