List of usage examples for org.apache.commons.httpclient Cookie Cookie
public Cookie(String paramString1, String paramString2, String paramString3)
From source file:dslab.crawler.pack.CrawlerPack.java
/** * Creates a cookie with the given name and value. * * @param name the cookie name/*from w w w . j av a2 s. c o m*/ * @param value the cookie value * @return CrawlerPack */ public CrawlerPack addCookie(String name, String value) { if (null == name) { log.warn("Cookie name null."); return this; } cookies.add(new Cookie("", name, value)); return this; }
From source file:com.tasktop.c2c.server.common.service.tests.http.MultiUserClientHttpRequestFactoryTest.java
@Test public void testAuthCredentialsChanged() throws URISyntaxException, IOException { SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("foo", "123")); URI uri = new URI("http://localhost/test"); ClientHttpRequest request = requestFactory.createRequest(uri, HttpMethod.GET); HttpClient client = getHttpClient(request); assertNotNull(client);/* ww w . j a va2 s .c o m*/ client.getState().addCookie(new Cookie("test.com", "sessionid", "123")); assertEquals(1, client.getState().getCookies().length); SecurityContextHolder.getContext() .setAuthentication(new UsernamePasswordAuthenticationToken("foo", "1234")); ClientHttpRequest request2 = requestFactory.createRequest(uri, HttpMethod.GET); HttpClient client2 = getHttpClient(request); assertSame(client, client2); assertEquals(0, client.getState().getCookies().length); }
From source file:com.github.abola.crawler.CrawlerPack.java
/** * Creates a cookie with the given name and value. * * @param name the cookie name// w w w. j ava 2 s . c o m * @param value the cookie value * @return CrawlerPack */ public CrawlerPack addCookie(String name, String value) { if (null == name) { log.warn("addCookie: Cookie name null."); return this; } cookies.add(new Cookie("", name, value)); return this; }
From source file:com.sun.faces.regression.admingui.AdminGuiTestCase.java
public void testDeployExerciseUndeploy() throws Exception { HtmlPage page = null;//ww w . ja v a 2 s . co m HtmlSubmitInput button = null; client.setThrowExceptionOnFailingStatusCode(false); CookieManager cm = client.getCookieManager(); cm.clearCookies(); try { page = getPage("/common/index.jsf?bare=true"); } catch (Exception e) { page = getPage("/common/index.jsf"); } Cookie jSessionID = cm.getCookie("JSESSIONID"); Cookie c1 = new Cookie("", "_common_applications_uploadFrame.jsf", "left:0&top:0&badCookieChars:%28%2C%29%2C%3C%2C%3E%2C@%2C%2C%2C%3B%2C%3A%2C%5C%2C%22%2C/%2C%5B%2C%5D%2C%3F%2C%3D%2C%7B%2C%7D%2C%20%2C%09; treeForm_tree-hi=treeForm:tree:applications; JSESSIONID=" + jSessionID.getValue()); cm.addCookie(c1); page = getPage("/common/applications/uploadFrame.jsf?bare=true"); HtmlRadioButtonInput localPackagedFile = (HtmlRadioButtonInput) page .getElementById("form:sheet1:section1:prop1:fileChooseRdBtn"); page = localPackagedFile.click(); // Set the war path HtmlTextInput textInput = (HtmlTextInput) page.getElementById("form:sheet1:section1:prop1:dirPath"); String dirPathValue = System.getProperty("warfile"); System.err.println("DIRPATH:" + dirPathValue); textInput.setValueAttribute(dirPathValue); // Set the appType List<HtmlSelect> selects = new ArrayList<HtmlSelect>(1); selects = getAllElementsOfGivenClass(page.getDocumentElement(), selects, HtmlSelect.class); HtmlSelect type = selects.get(0); HtmlOption option = type.getOption(1); type.setSelectedAttribute(option, true); // Set the contextRoot textInput = (HtmlTextInput) page.getElementById("form:war:psection:cxp:ctx"); textInput.setValueAttribute("admingui_test_war"); // Set the appName textInput = (HtmlTextInput) page.getElementById("form:appClient:psection:nameProp:appName"); textInput.setValueAttribute("admingui_test_war"); textInput.fireEvent(Event.TYPE_CHANGE); // Submit the app button = (HtmlSubmitInput) page.getElementById("form:title:topButtons:uploadButton"); button.focus(); client.setJavaScriptEnabled(false); page = button.click(); client.setJavaScriptEnabled(true); // Now we visit the deployed app and verify it is successfully deployed this.port = 8080; client.setThrowExceptionOnFailingStatusCode(true); cm.clearCookies(); Thread.currentThread().sleep(20000L); page = getPage("/admingui_test_war/faces/main.xhtml"); assertTrue(page.asXml().contains("javax.faces.ViewState")); // Now we undeploy the app using the GUI this.port = 4848; cm.clearCookies(); client.setThrowExceptionOnFailingStatusCode(false); try { page = getPage("/common/index.jsf?bare=true"); } catch (Exception e) { page = getPage("/common/index.jsf"); } jSessionID = cm.getCookie("JSESSIONID"); c1 = new Cookie("", "_common_applications_uploadFrame.jsf", "left:0&top:0&badCookieChars:%28%2C%29%2C%3C%2C%3E%2C@%2C%2C%2C%3B%2C%3A%2C%5C%2C%22%2C/%2C%5B%2C%5D%2C%3F%2C%3D%2C%7B%2C%7D%2C%20%2C%09; treeForm_tree-hi=treeForm:tree:applications; JSESSIONID=" + jSessionID.getValue()); cm.addCookie(c1); client.setJavaScriptEnabled(false); page = getPage("/common/applications/applications.jsf?bare=true"); // In the table of deployed apps, find the one in which we are interested. List<HtmlAnchor> links = page.getAnchors(); HtmlAnchor appLink = null; for (HtmlAnchor cur : links) { String href = cur.getHrefAttribute(); String hrefId = cur.getId(); if (null != href && href.contains("admingui_test_war") && null != hrefId && hrefId.contains(":link") && hrefId.contains(":deployTable")) { appLink = cur; break; } } String id = appLink.getId(); String checkboxId = id.replace("col1:link", "col0:select"); HtmlCheckBoxInput myCheckbox = (HtmlCheckBoxInput) page.getElementById(checkboxId); page = (HtmlPage) myCheckbox.setChecked(true); // remove the app button = (HtmlSubmitInput) page.getElementById("propertyForm:deployTable:topActionsGroup1:button1"); button.removeAttribute("disabled"); page = button.click(); }
From source file:com.intuit.tank.httpclient3.TankHttpClient3.java
/** * /*from w w w . j a va2 s . c o m*/ */ @Override public void setCookie(TankCookie cookie) { Cookie c = new Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue()); c.setPath(cookie.getPath()); httpclient.getState().addCookie(c); }
From source file:com.hp.alm.ali.rest.client.AliRestClient.java
private void addTenantCookie(Cookie ssoCookie) { if (ssoCookie != null) { Cookie tenant_id_cookie = new Cookie(ssoCookie.getDomain(), "TENANT_ID_COOKIE", "0"); tenant_id_cookie.setDomainAttributeSpecified(true); tenant_id_cookie.setPath(ssoCookie.getPath()); tenant_id_cookie.setPathAttributeSpecified(true); httpClient.getState().addCookie(tenant_id_cookie); }//from w ww . j a va2 s. c o m }
From source file:org.apache.abdera.protocol.client.AbderaClient.java
/** * Manually add cookies/*from w w w .ja v a 2 s . c om*/ */ public AbderaClient addCookie(String domain, String name, String value) { Cookie cookie = new Cookie(domain, name, value); client.getState().addCookie(cookie); return this; }
From source file:org.apache.cocoon.util.RequestForwardingHttpMethod.java
/** * Clone cookies, if any.//from w w w .j ava 2s .com * */ private void cloneCookies() { ArrayList newCookiesList = new ArrayList(); javax.servlet.http.Cookie[] cookies = originalRequest.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { String domain = cookies[i].getDomain(); String name = cookies[i].getName(); String path = cookies[i].getPath(); String value = cookies[i].getValue(); Cookie cookie = new Cookie(domain, path, value); cookie.setName(name); newCookiesList.add(cookie); } CookieSpecBase cookieFormatter = new CookieSpecBase(); Header cookieHeader = cookieFormatter .formatCookieHeader((Cookie[]) newCookiesList.toArray(new Cookie[newCookiesList.size()])); this.addRequestHeader(cookieHeader); } }
From source file:org.eclipse.mylyn.gerrit.tests.core.client.GerritClientTest.java
@Test public void testInvalidXrsfKey() throws Exception { if (!GerritFixture.current().canAuthenticate()) { return;// w w w . j a v a 2s . com } WebLocation location = harness.location(); GerritAuthenticationState authState = new GerritAuthenticationState(); authState.setCookie(new Cookie(WebUtil.getHost(location.getUrl()), "xrsfKey", "invalid")); client = GerritClient.create(null, location, null, authState, "invalid", null); client.getAccount(null); }
From source file:org.firstopen.singularity.util.HTTPConnector.java
public void setCookie(String domain, String name, String value) { Cookie cookie = new Cookie(domain, name, value); httpclient.getState().addCookie(cookie); }