private com.gargoylesoftware.htmlunit.util.Cookie createCookie(MockHttpServletRequest request, String sessionid) { return new com.gargoylesoftware.htmlunit.util.Cookie(request.getServerName(), "JSESSIONID", sessionid, request.getContextPath() + "/", null, request.isSecure(), true); }
private static com.gargoylesoftware.htmlunit.util.Cookie createCookie(javax.servlet.http.Cookie cookie) { Date expires = null; if (cookie.getMaxAge() > -1) { expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000); } BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue()); result.setDomain(cookie.getDomain()); result.setComment(cookie.getComment()); result.setExpiryDate(expires); result.setPath(cookie.getPath()); result.setSecure(cookie.getSecure()); if (cookie.isHttpOnly()) { result.setAttribute("httponly", "true"); } return new com.gargoylesoftware.htmlunit.util.Cookie(result); }
@Test // SPR-14066 public void cookieManagerShared() throws Exception { this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build(); WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build(); assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA")); client.getCookieManager().addCookie(new Cookie("localhost", "cookie", "cookieManagerShared")); assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("cookieManagerShared")); }
@Test // SPR-14066 public void cookieManagerShared() throws Exception { WebConnectionHtmlUnitDriver otherDriver = new WebConnectionHtmlUnitDriver(); this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build(); this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc) .withDelegate(otherDriver).build(); assertThat(get("http://localhost/"), equalTo("")); Cookie cookie = new Cookie("localhost", "cookie", "cookieManagerShared"); otherDriver.getWebClient().getCookieManager().addCookie(cookie); assertThat(get("http://localhost/"), equalTo("cookieManagerShared")); }
/** * Converts the specified array of HttpClient cookies into a list of cookies. * @param cookies the cookies to be converted * @return the specified HttpClient cookies, as cookies */ public static List<Cookie> fromHttpClient(final List<org.apache.http.cookie.Cookie> cookies) { final List<Cookie> list = new ArrayList<>(cookies.size()); for (org.apache.http.cookie.Cookie c : cookies) { list.add(new Cookie((ClientCookie) c)); } return list; } }
/** * Converts the specified array of HttpClient cookies into a list of cookies. * @param cookies the cookies to be converted * @return the specified HttpClient cookies, as cookies */ public static List<Cookie> fromHttpClient(final List<org.apache.http.cookie.Cookie> cookies) { final List<Cookie> list = new ArrayList<>(cookies.size()); for (org.apache.http.cookie.Cookie c : cookies) { list.add(new Cookie((ClientCookie) c)); } return list; } }
/** * {@inheritDoc} */ @Override public synchronized void addCookie(final Cookie cookie) { manager_.addCookie(new com.gargoylesoftware.htmlunit.util.Cookie((ClientCookie) cookie)); }
/** * {@inheritDoc} */ @Override public synchronized void addCookie(final Cookie cookie) { manager_.addCookie(new com.gargoylesoftware.htmlunit.util.Cookie((ClientCookie) cookie)); }
public Cookie parseCookie(String hostName, String rawCookie) { String[] cookieParts = rawCookie.split(";"); String valuePart = cookieParts[0]; int idx = valuePart.indexOf("="); String cookieName = valuePart.substring(0, idx); String cookieValue = valuePart.substring(idx + 1, valuePart.length()); Date expiresDate = null; for (String cookiePart : Arrays.copyOfRange(cookieParts, 1, cookieParts.length)) { if (cookiePart.trim().toLowerCase().startsWith("expires=")) { String expiresDateString = cookiePart.split("=")[1]; try { expiresDate = dateFormat.parse(expiresDateString); } catch (ParseException ignored) { } } } return new Cookie(hostName, cookieName, cookieValue, "/", expiresDate, false); } }
public Cookie parseCookie(String hostName, String rawCookie) { String[] cookieParts = rawCookie.split(";"); String valuePart = cookieParts[0]; int idx = valuePart.indexOf('='); String cookieName = valuePart.substring(0, idx); String cookieValue = valuePart.substring(idx + 1, valuePart.length()); Date expiresDate = null; for (String cookiePart : Arrays.copyOfRange(cookieParts, 1, cookieParts.length)) { if (cookiePart.trim().toLowerCase().startsWith("expires=")) { String expiresDateString = cookiePart.split("=")[1]; try { expiresDate = dateFormat.parse(expiresDateString); } catch (ParseException ignored) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("A problem occured while parsing some cookie: ", ignored); } else { LOGGER.error("A technical problem occured while parsing some cookies", ignored); } } } } return new Cookie(hostName, cookieName, cookieValue, "/", expiresDate, false); } }
private com.gargoylesoftware.htmlunit.util.Cookie createCookie(MockHttpServletRequest request, String sessionid) { return new com.gargoylesoftware.htmlunit.util.Cookie(request.getServerName(), "JSESSIONID", sessionid, request.getContextPath() + "/", null, request.isSecure(), true); }
private com.gargoylesoftware.htmlunit.util.Cookie createCookie(MockHttpServletRequest request, String sessionid) { return new com.gargoylesoftware.htmlunit.util.Cookie(request.getServerName(), "JSESSIONID", sessionid, request.getContextPath() + "/", null, request.isSecure(), true); }
private void loadCookies() { try { CookieManager cm = getWebClient().getCookieManager(); File cookiesFile = Directories.META.getDir(cookiesFileName); if (cookiesFile.exists()) { String content = HTMLUtil.readFile(cookiesFile); List<BasicClientCookie> list = new Gson().fromJson(content, new TypeToken<List<BasicClientCookie>>() { }.getType()); for (BasicClientCookie bc : list) { Cookie c = new Cookie(bc.getDomain(), bc.getName(), bc.getValue()); cm.addCookie(c); // LOG.info("Cookie: "+c); } LOG.info("Loaded " + list.size() + " cookies"); } } catch (Throwable th) { LOG.error("error loading cookies...", th); } }
private static com.gargoylesoftware.htmlunit.util.Cookie createCookie(javax.servlet.http.Cookie cookie) { Date expires = null; if (cookie.getMaxAge() > -1) { expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000); } BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue()); result.setDomain(cookie.getDomain()); result.setComment(cookie.getComment()); result.setExpiryDate(expires); result.setPath(cookie.getPath()); result.setSecure(cookie.getSecure()); if (cookie.isHttpOnly()) { result.setAttribute("httponly", "true"); } return new com.gargoylesoftware.htmlunit.util.Cookie(result); }
static com.gargoylesoftware.htmlunit.util.Cookie createCookie(Cookie cookie) { Date expires = null; if (cookie.getMaxAge() > -1) { expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000); } BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue()); result.setDomain(cookie.getDomain()); result.setComment(cookie.getComment()); result.setExpiryDate(expires); result.setPath(cookie.getPath()); result.setSecure(cookie.getSecure()); if (cookie.isHttpOnly()) { result.setAttribute("httponly", "true"); } return new com.gargoylesoftware.htmlunit.util.Cookie(result); } }
@Override public String call() throws Exception { WebClient client = new WebClient(); client.setThrowExceptionOnFailingStatusCode(false); client.getCookieManager().addCookie(new Cookie(contextPath.getHost(), JSESSIONID, jsessionid)); Page page = client.getPage(contextPath + "introspect?mode=" + mode + "&cid=" + cid); if (!(page instanceof TextPage)) { return "" + page.getWebResponse().getStatusCode(); } TextPage textPage = (TextPage) page; return textPage.getContent(); }
private com.gargoylesoftware.htmlunit.util.Cookie convertSeleniumCookieToHtmlUnit(Cookie cookie) { return new com.gargoylesoftware.htmlunit.util.Cookie( cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure(), cookie.isHttpOnly() ); }
final Cookie htmlUnitCookie = new Cookie((ClientCookie) cookie); cookieManager.addCookie(htmlUnitCookie);
public WebResponse getResponse( WebRequest request ) throws IOException { Cookie jsCookie = webClient.getCookieManager().getCookie("JSESSIONID"); if (jsCookie != null && (!jsCookie.getValue().startsWith("\"") && !jsCookie.getValue().endsWith("\""))) { Cookie newCookie = new Cookie(jsCookie.getDomain(), jsCookie.getName(), "\"" + jsCookie.getValue() + "\"", jsCookie.getPath(), jsCookie.getExpires(), jsCookie.isSecure()); webClient.getCookieManager().removeCookie(jsCookie); webClient.getCookieManager().addCookie(newCookie); } return super.getResponse(request); } };
@Override public void addCookie(Cookie cookie) { Page page = lastPage(); if (!(page instanceof HtmlPage)) { throw new UnableToSetCookieException("You may not set cookies on a page that is not HTML"); } String domain = getDomainForCookie(); verifyDomain(cookie, domain); getWebClient().getCookieManager().addCookie( new com.gargoylesoftware.htmlunit.util.Cookie(domain, cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure())); }