@Test public void testGetCookie() 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 = "/"; String cookie1Header = cookie1Name + '=' + cookie1Value + "; expires=Thu, 18-Feb-2016 07:47:08 GMT; path=" + cookie1Path + "; domain=" + cookie1Domain; nettyRequest.headers().add(HttpHeaders.Names.COOKIE, cookie1Header); HttpServerRequest<ByteBuf> request = new HttpServerRequest<ByteBuf>(nettyRequest, PublishSubject.<ByteBuf>create()); Map<String, Set<Cookie>> cookies = request.getCookies(); Assert.assertEquals("Unexpected number of cookies.", 1, cookies.size()); Set<Cookie> cookies1 = cookies.get(cookie1Name); Assert.assertNotNull("No cookie found with name: " + cookie1Name, cookies1); Assert.assertEquals( "Unexpected number of cookies with name: " + cookie1Name, 1, cookies1.size()); Cookie cookie = cookies1.iterator().next(); Assert.assertEquals("Unexpected cookie name.", cookie1Name, cookie.getName()); Assert.assertEquals("Unexpected cookie path.", cookie1Path, cookie.getPath()); }
// Build the HTTP request based on the given parameters private HttpRequest buildRequest( String path, String method, List<HttpParam> parametersQuery, List<HttpParam> parametersForm) { String queryString = String.format("?api_key=%s:%s", username, password); for (HttpParam hp : parametersQuery) { if (hp.value != null && !hp.value.isEmpty()) { queryString += "&" + hp.name + "=" + hp.value; } } DefaultHttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.valueOf(method), baseUri.getPath() + "ari" + path + queryString); // System.out.println(request.getUri()); request.headers().set(HttpHeaders.Names.HOST, "localhost"); request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); return request; }