List of usage examples for io.netty.handler.codec.http Cookie setDomain
void setDomain(String domain);
From source file:com.titilink.camel.rest.common.AdapterRestletUtil.java
License:LGPL
/** * ?Cookie/*from ww w . ja v a 2 s.c o m*/ * * @param cookie * @return */ public static org.restlet.data.Cookie parseToRestletCookie(Cookie cookie) { if (null == cookie) { LOGGER.error("cookie=null"); return null; } org.restlet.data.Cookie restletCookie = new org.restlet.data.Cookie(); restletCookie.setDomain(cookie.getDomain()); restletCookie.setVersion(cookie.getVersion()); restletCookie.setName(cookie.getName()); restletCookie.setValue(cookie.getValue()); restletCookie.setPath(cookie.getPath()); return restletCookie; }
From source file:io.nebo.container.NettyHttpServletRequest.java
License:Apache License
@Override public Cookie[] getCookies() { String cookieString = this.request.headers().get(COOKIE); if (cookieString != null) { Set<io.netty.handler.codec.http.Cookie> cookies = CookieDecoder.decode(cookieString); if (!cookies.isEmpty()) { Cookie[] cookiesArray = new Cookie[cookies.size()]; int index = 0; for (io.netty.handler.codec.http.Cookie c : cookies) { Cookie cookie = new Cookie(c.getName(), c.getValue()); cookie.setComment(c.getComment()); if (c.getDomain() != null) cookie.setDomain(c.getDomain()); cookie.setMaxAge((int) c.getMaxAge()); cookie.setPath(c.getPath()); cookie.setSecure(c.isSecure()); cookie.setVersion(c.getVersion()); cookiesArray[index] = cookie; index++;//from ww w. jav a 2 s . c o m } return cookiesArray; } } return new Cookie[0]; }
From source file:io.reactivex.netty.protocol.http.client.CookieTest.java
License:Apache License
@Test public void testSetCookie() throws Exception { DefaultHttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""); String cookie1Name = "PREF"; String cookie1Value = "ID=a95756377b78e75e:FF=0:TM=1392709628:LM=1392709628:S=a5mOVvTB7DBkexgi"; String cookie1Domain = ".google.com"; String cookie1Path = "/"; Cookie cookie = new DefaultCookie(cookie1Name, cookie1Value); cookie.setPath(cookie1Path);/*from ww w . j a va 2 s . com*/ cookie.setDomain(cookie1Domain); new HttpClientRequest<ByteBuf>(nettyRequest).withCookie(cookie); String cookieHeader = nettyRequest.headers().get(HttpHeaders.Names.COOKIE); Assert.assertNotNull("No cookie header found.", cookieHeader); Set<Cookie> decodeCookies = CookieDecoder.decode(cookieHeader); Assert.assertNotNull("No cookie found with name.", decodeCookies); Assert.assertEquals("Unexpected number of cookies.", 1, decodeCookies.size()); Cookie decodedCookie = decodeCookies.iterator().next(); Assert.assertEquals("Unexpected cookie name.", cookie1Name, decodedCookie.getName()); Assert.assertEquals("Unexpected cookie path.", cookie1Path, decodedCookie.getPath()); Assert.assertEquals("Unexpected cookie domain.", cookie1Domain, decodedCookie.getDomain()); }