List of usage examples for org.apache.http.client.protocol ClientContext COOKIE_ORIGIN
String COOKIE_ORIGIN
To view the source code for org.apache.http.client.protocol ClientContext COOKIE_ORIGIN.
Click Source Link
From source file:com.googlecode.noweco.webmail.httpclient.UnsecureResponseProcessCookies.java
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP request may not be null"); }/* www . j a v a2s . c o m*/ if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } // Obtain actual CookieSpec instance CookieSpec cookieSpec = (CookieSpec) context.getAttribute(ClientContext.COOKIE_SPEC); if (cookieSpec == null) { this.log.debug("Cookie spec not specified in HTTP context"); return; } // Obtain cookie store CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE); if (cookieStore == null) { this.log.debug("Cookie store not specified in HTTP context"); return; } // Obtain actual CookieOrigin instance CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(ClientContext.COOKIE_ORIGIN); if (cookieOrigin == null) { this.log.debug("Cookie origin not specified in HTTP context"); return; } HeaderIterator it = response.headerIterator(SM.SET_COOKIE); processCookies(it, cookieSpec, cookieOrigin, cookieStore); // see if the cookie spec supports cookie versioning. if (cookieSpec.getVersion() > 0) { // process set-cookie2 headers. // Cookie2 will replace equivalent Cookie instances it = response.headerIterator(SM.SET_COOKIE2); processCookies(it, cookieSpec, cookieOrigin, cookieStore); } }
From source file:org.ops4j.pax.web.itest.jetty.WarFormAuthIntegrationTest.java
private BasicHttpContext testFormWebPath(String path, String user, String passwd, int httpRC) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpHost targetHost = new HttpHost("localhost", 8181, "http"); BasicHttpContext localcontext = new BasicHttpContext(); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("j_username", user)); formparams.add(new BasicNameValuePair("j_password", passwd)); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); HttpPost httppost = new HttpPost(path); httppost.setEntity(entity);/*from w w w .j a v a2 s . com*/ HttpResponse response = httpclient.execute(targetHost, httppost, localcontext); CookieOrigin cookieOrigin = (CookieOrigin) localcontext.getAttribute(ClientContext.COOKIE_ORIGIN); CookieSpec cookieSpec = (CookieSpec) localcontext.getAttribute(ClientContext.COOKIE_SPEC); assertEquals("HttpResponseCode", httpRC, response.getStatusLine().getStatusCode()); return localcontext; }