Search in sources :

Example 86 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project warn-report by saaavsaaa.

the class WebRequestClient method testPostWithCookie.

public static String testPostWithCookie(String url, String cookieKey, String cookieValue, HttpEntity paras) throws Exception {
    /*HttpContext localContext = new BasicHttpContext();
		// 在本地上下问中绑定一个本地存储
		localContext.setAttribute(HttpClientContext.COOKIE_STORE, cs);
		cs.addCookie(new BasicClientCookie(cookieKey, cookieValue));*/
    Cookie[] cookies = new Cookie[1];
    cookies[0] = new BasicClientCookie(cookieKey, cookieValue);
    setCookies(cookies);
    return opera(url, paras, false);
}
Also used : BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Cookie(org.apache.http.cookie.Cookie) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie)

Example 87 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project sling-org-apache-sling-testing-clients by apache.

the class FormBasedAuthInterceptor method process.

@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_UNAUTHORIZED) {
        return;
    }
    if (URI.create(HttpClientContext.adapt(context).getRequest().getRequestLine().getUri()).getPath().endsWith(loginPath)) {
        LOG.trace("Request ends with {} so I'm not intercepting the request", loginPath);
        return;
    }
    Cookie loginCookie = getLoginCookie(context, loginTokenName);
    if (loginCookie == null) {
        return;
    }
    LOG.info("Response code was 401 even though {} is set. Removing the cookie.", loginCookie.getName());
    BasicClientCookie expiredLoginTokenCookie = new BasicClientCookie(loginCookie.getName(), "expired");
    // far enough in the past
    expiredLoginTokenCookie.setExpiryDate(new Date(1));
    expiredLoginTokenCookie.setDomain(loginCookie.getDomain());
    expiredLoginTokenCookie.setPath(loginCookie.getPath());
    HttpClientContext.adapt(context).getCookieStore().addCookie(expiredLoginTokenCookie);
}
Also used : Cookie(org.apache.http.cookie.Cookie) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Date(java.util.Date)

Example 88 with BasicClientCookie

use of org.apache.http.impl.cookie.BasicClientCookie in project acceptance-test-harness by jenkinsci.

the class Jenkins method buildHttpClientContext.

private HttpContext buildHttpClientContext() {
    HttpClientContext context = HttpClientContext.create();
    BasicCookieStore cookieStore = new BasicCookieStore();
    for (org.openqa.selenium.Cookie cookie : driver.manage().getCookies()) {
        BasicClientCookie c = new BasicClientCookie(cookie.getName(), cookie.getValue());
        c.setPath(cookie.getPath());
        c.setExpiryDate(cookie.getExpiry());
        c.setDomain(cookie.getDomain());
        cookieStore.addCookie(c);
    }
    context.setCookieStore(cookieStore);
    return context;
}
Also used : BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie)

Aggregations

BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)88 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)36 Test (org.junit.Test)24 HttpResponse (org.apache.http.HttpResponse)19 Cookie (org.apache.http.cookie.Cookie)17 HttpClient (org.apache.http.client.HttpClient)15 HttpGet (org.apache.http.client.methods.HttpGet)15 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)15 Map (java.util.Map)14 RequestConfig (org.apache.http.client.config.RequestConfig)13 HttpPost (org.apache.http.client.methods.HttpPost)9 CookieAttributeHandler (org.apache.http.cookie.CookieAttributeHandler)9 CookieOrigin (org.apache.http.cookie.CookieOrigin)9 URL (java.net.URL)8 HttpEntity (org.apache.http.HttpEntity)8 CookieStore (org.apache.http.client.CookieStore)8 IOException (java.io.IOException)7 Date (java.util.Date)7 ClientCookie (org.apache.http.cookie.ClientCookie)7 HashMap (java.util.HashMap)6