org.apache.http.cookie.CookieSpec Java Examples
The following examples show how to use
org.apache.http.cookie.CookieSpec.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicHttpSolrClientTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue); cookie.setVersion(0); cookie.setPath("/"); cookie.setDomain(jetty.getBaseUrl().getHost()); CookieStore cookieStore = new BasicCookieStore(); CookieSpec cookieSpec = new SolrPortAwareCookieSpecFactory().create(context); // CookieSpec cookieSpec = registry.lookup(policy).create(context); // Add the cookies to the request List<Header> headers = cookieSpec.formatCookies(Collections.singletonList(cookie)); for (Header header : headers) { request.addHeader(header); } context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); }
Example #2
Source File: SolrPortAwareCookieSpecFactory.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public CookieSpec newInstance(final HttpParams params) { if (params != null) { String[] patterns = null; final Collection<?> param = (Collection<?>) params.getParameter( CookieSpecPNames.DATE_PATTERNS); if (param != null) { patterns = new String[param.size()]; patterns = param.toArray(patterns); } return new PortAwareCookieSpec(patterns); } else { return new PortAwareCookieSpec(null); } }
Example #3
Source File: CustomBrowserCompatSpecFactory.java From esigate with Apache License 2.0 | 5 votes |
@Override public CookieSpec create(final HttpContext context) { // SecurityLevel.SECURITYLEVEL_IE_MEDIUM disables path validation AbstractCookieSpec cookieSpec = new BrowserCompatSpec(null, SecurityLevel.SECURITYLEVEL_IE_MEDIUM); cookieSpec.registerAttribHandler(CookieUtil.HTTP_ONLY_ATTR, new HttpOnlyHandler()); return cookieSpec; }
Example #4
Source File: HttpResponseUtils.java From esigate with Apache License 2.0 | 5 votes |
/** * Removes ";jsessionid=<id>" from the url, if the session id is also set in "httpResponse". * <p> * This methods first looks for the following header : * * <pre> * Set-Cookie: JSESSIONID= * </pre> * * If found and perfectly matches the jsessionid value in url, the complete jsessionid definition is removed from * the url. * * @param uri * original uri, may contains a jsessionid. * @param httpResponse * the response which set the jsessionId * @return uri, without jsession */ public static String removeSessionId(String uri, HttpResponse httpResponse) { CookieSpec cookieSpec = new DefaultCookieSpec(); // Dummy origin, used only by CookieSpec for setting the domain for the // cookie but we don't need it CookieOrigin cookieOrigin = new CookieOrigin("dummy", Http.DEFAULT_HTTP_PORT, "/", false); Header[] responseHeaders = httpResponse.getHeaders("Set-cookie"); String jsessionid = null; for (Header header : responseHeaders) { try { List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin); for (Cookie cookie : cookies) { if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) { jsessionid = cookie.getValue(); } break; } } catch (MalformedCookieException ex) { LOG.warn("Malformed header: " + header.getName() + ": " + header.getValue()); } if (jsessionid != null) { break; } } if (jsessionid == null) { return uri; } return UriUtils.removeSessionId(jsessionid, uri); }
Example #5
Source File: HtmlUnitCookieSpecProvider.java From htmlunit with Apache License 2.0 | 4 votes |
@Override public CookieSpec create(final HttpContext context) { return new HtmlUnitBrowserCompatCookieSpec(browserVersion_); }
Example #6
Source File: SolrPortAwareCookieSpecFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public CookieSpec create(final HttpContext context) { return this.cookieSpec; }