use of org.apache.http.impl.cookie.BasicClientCookie in project lucene-solr by apache.
the class SolrPortAwareCookieSpecTest method testDomainValidate4.
@Test
public void testDomainValidate4() throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
final CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false);
final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
cookie.setDomain(".a.b.c");
h.validate(cookie, origin);
cookie.setDomain(".b.c");
try {
h.validate(cookie, origin);
Assert.fail("MalformedCookieException should have been thrown");
} catch (final MalformedCookieException ex) {
// expected
}
}
use of org.apache.http.impl.cookie.BasicClientCookie in project ma-modules-public by infiniteautomation.
the class MangoStoreClient method login.
/**
* Login to the store
* @param email
* @param password
* @param retries
* @throws ClientProtocolException
* @throws IOException
* @throws HttpException
*/
public void login(String email, String password, int retries) throws ClientProtocolException, IOException, HttpException {
BasicCookieStore cookieStore = new BasicCookieStore();
httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
HttpPost httppost = new HttpPost(storeUrl + "/login");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("submit", "Login"));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
// Execute and get the response.
HttpResponse response = executeRequest(httppost, 302, retries);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
try {
for (Header header : response.getAllHeaders()) {
if (header.getName().equals("Set-Cookie")) {
// Set our cookie here
String[] cookiePath = header.getValue().split(";");
// Now we have JSESSIONID=stuff , Path=/
String[] cookie = cookiePath[0].split("=");
String[] path = cookiePath[1].split("=");
this.sessionId = cookie[1];
BasicClientCookie c = new BasicClientCookie(cookie[0], cookie[1]);
c.setDomain(storeUrl);
c.setPath(path[1]);
c.setVersion(0);
cookieStore.addCookie(c);
}
}
} finally {
instream.close();
}
}
return;
}
use of org.apache.http.impl.cookie.BasicClientCookie in project knox by apache.
the class HadoopAuthCookieStoreTest method testOozieCookieWorkaroundKnox1171.
/**
* Test for the issue reported as KNOX-1171
* Tests the required to workaround Oozie 4.3/Hadoop 2.4 not properly formatting the hadoop.auth cookie.
* See the following jiras for additional context:
* https://issues.apache.org/jira/browse/HADOOP-10710
* https://issues.apache.org/jira/browse/HADOOP-10379
*/
@Test
public void testOozieCookieWorkaroundKnox1171() {
String rawValue = "u=knox&p=knox/host.example.com.com@EXAMPLE.COM&t=kerberos&e=1517900515610&s=HpSXUOhoXR/2wXrsgPz5lSbNuf8=";
String quotedValue = "\"" + rawValue + "\"";
HadoopAuthCookieStore store;
List<Cookie> cookies;
Cookie cookie;
store = new HadoopAuthCookieStore();
store.addCookie(new BasicClientCookie("hadoop.auth", rawValue));
cookies = store.getCookies();
cookie = cookies.get(0);
assertThat(cookie.getValue(), is(quotedValue));
store = new HadoopAuthCookieStore();
store.addCookie(new BasicClientCookie("hadoop.auth", quotedValue));
cookies = store.getCookies();
cookie = cookies.get(0);
assertThat(cookie.getValue(), is(quotedValue));
store = new HadoopAuthCookieStore();
store.addCookie(new BasicClientCookie("hadoop.auth", null));
cookies = store.getCookies();
cookie = cookies.get(0);
assertThat(cookie.getValue(), is(nullValue()));
store = new HadoopAuthCookieStore();
store.addCookie(new BasicClientCookie("hadoop.auth", ""));
cookies = store.getCookies();
cookie = cookies.get(0);
assertThat(cookie.getValue(), is(""));
}
use of org.apache.http.impl.cookie.BasicClientCookie in project opacclient by opacapp.
the class Heidi method getResultById.
@Override
public DetailedItem getResultById(String id, final String homebranch) throws IOException {
if (sessid == null) {
start();
}
// Homebranch
if (homebranch != null && !"".equals(homebranch)) {
cookieStore.addCookie(new BasicClientCookie("zweig", homebranch));
}
String html = httpGet(opac_url + "/titel.cgi?katkey=" + id + "&sess=" + sessid, ENCODING, false, cookieStore);
Document doc = Jsoup.parse(html);
DetailedItem item = new DetailedItem();
item.setId(id);
Elements table = doc.select(".titelsatz tr");
for (Element tr : table) {
if (tr.select("th").size() == 0 || tr.select("td").size() == 0) {
continue;
}
String d = tr.select("th").first().text();
String c = tr.select("td").first().text();
if (d.equals("Titel:")) {
item.setTitle(c);
} else if ((d.contains("URL") || d.contains("Link")) && tr.select("td a").size() > 0) {
item.addDetail(new Detail(d, tr.select("td a").first().attr("href")));
} else {
item.addDetail(new Detail(d, c));
}
}
if (doc.select(".ex table tr").size() > 0) {
table = doc.select(".ex table tr");
DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy").withLocale(Locale.GERMAN);
for (Element tr : table) {
if (tr.hasClass("exueber") || tr.select(".exsig").size() == 0 || tr.select(".exso").size() == 0 || tr.select(".exstatus").size() == 0) {
continue;
}
Copy copy = new Copy();
copy.setShelfmark(tr.select(".exsig").first().text());
copy.setBranch(tr.select(".exso").first().text());
String status = tr.select(".exstatus").first().text();
if (status.contains("entliehen bis")) {
copy.setReturnDate(fmt.parseLocalDate(status.replaceAll("entliehen bis ([0-9.]+) .*", "$1")));
copy.setReservations(status.replaceAll(".*\\(.*Vormerkungen: ([0-9]+)\\)", "$1"));
copy.setStatus("entliehen");
} else {
copy.setStatus(status);
}
item.addCopy(copy);
}
}
for (Element a : doc.select(".status1 a")) {
if (a.attr("href").contains("bestellung.cgi")) {
item.setReservable(true);
item.setReservation_info(id);
break;
}
}
for (Element a : doc.select(".titelsatz a")) {
if (a.text().trim().matches("B.+nde")) {
Map<String, String> volumesearch = new HashMap<>();
volumesearch.put("query", getQueryParamsFirst(a.attr("href")).get("query"));
item.setVolumesearch(volumesearch);
}
}
return item;
}
use of org.apache.http.impl.cookie.BasicClientCookie in project tutorials by eugenp.
the class HttpClientCookieLiveTest method givenUsingDeprecatedApi_whenSettingCookiesOnTheHttpClient_thenCorrect.
@Test
public final void givenUsingDeprecatedApi_whenSettingCookiesOnTheHttpClient_thenCorrect() throws IOException {
final BasicCookieStore cookieStore = new BasicCookieStore();
final BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", "1234");
cookie.setDomain(".github.com");
cookie.setPath("/");
cookieStore.addCookie(cookie);
final HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
final HttpGet request = new HttpGet("http://www.github.com");
response = (CloseableHttpResponse) client.execute(request);
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
}
Aggregations