AuxRest extends BaseRest { @Path("/cookies") @GET public Response getCookies(@QueryParam("token") String token) { try { StringDataStore dataStore = this.stringDataStoreFactory.create(Constants.HIDDEN_COOKIE_SPACE); String cookiesData = dataStore.retrieveData(token); if (null == cookiesData) { return responseNotFound("Token not found"); } SignedCookieData cookieData = SignedCookieData.deserialize(cookiesData); String streamingHost = cookieData.getStreamingHost(); Map<String, String> cookies = cookieData.getSignedCookies(); ArrayList<NewCookie> responseCookies = new ArrayList<>(); for (String cookieKey : cookies.keySet()) { responseCookies.add(new NewCookie(cookieKey, cookies.get(cookieKey), "/", streamingHost, "Supports HLS", -1, true)); } String redirectUrl = cookieData.getRedirectUrl(); String html = "<html><head><meta http-equiv='refresh' content='0;URL=\"" + redirectUrl + "\"' /></head></html>"; return Response.ok(html, MediaType.TEXT_HTML_TYPE) .cookie(responseCookies.toArray(new NewCookie[responseCookies.size()])).build(); } catch (Exception e) { return responseBad(e); } }  @Path("/cookies") @GET Response getCookies(@QueryParam("token") String token);  }
@Test public void testGetCookies() { SignedCookieData signedCookieData = new SignedCookieData(); String myUrl = "myUrl"; signedCookieData.setRedirectUrl(myUrl); Map<String, String> cookies = new HashMap<>(); cookies.put("cookieName1", "cookieValue1"); cookies.put("cookieName2", "cookieValue2"); signedCookieData.setSignedCookies(cookies); String domain = "domain"; signedCookieData.setStreamingHost(domain); String data = signedCookieData.serialize(); expect(stringDataStore.retrieveData(token)).andReturn(data); replayAll(); Response response = this.auxRest.getCookies(token); assertEquals("200 response expected", 200, response.getStatus()); assertEquals("2 cookies expected", 2, response.getCookies().size()); Map<String, NewCookie> newCookies = response.getCookies(); NewCookie cookie = newCookies.get("cookieName1"); assertEquals("cookieName1", cookie.getName()); assertEquals("cookieValue1", cookie.getValue()); assertEquals(true, cookie.isSecure()); assertEquals("/", cookie.getPath()); assertEquals(domain, cookie.getDomain()); assertEquals("text/html", response.getHeaderString("Content-Type")); String html = response.getEntity().toString(); assertTrue("response body must contain redirect url", html.contains("URL=\"" + myUrl + "\"")); assertTrue("response must include refresh meta tag", html.contains("meta http-equiv='refresh'")); }