org.apache.http.impl.cookie.BasicClientCookie Java Examples

The following examples show how to use org.apache.http.impl.cookie.BasicClientCookie. 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: CookieHttpClientFactory.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final CookieStore cookieStore = new BasicCookieStore();

  // Populate cookies if needed
  final BasicClientCookie cookie = new BasicClientCookie("name", "value");
  cookie.setVersion(0);
  cookie.setDomain(".mycompany.com");
  cookie.setPath("/");
  cookieStore.addCookie(cookie);

  final DefaultHttpClient httpClient = super.create(method, uri);
  httpClient.setCookieStore(cookieStore);

  return httpClient;
}
 
Example #2
Source File: PornCookieStore.java    From WebVideoBot with MIT License 6 votes vote down vote up
List<BasicClientCookie> prepareBasicClientCookie(String domain) {
    return Stream.of(
            new BasicClientCookie("bs", RandomStringUtils.random(32)),
            new BasicClientCookie("platform", "pc"),
            new BasicClientCookie("ua", "b5b29e4074b1362df9783c4beff7fc0f"),
            new BasicClientCookie("RNLBSERVERID", "ded6646"),
            new BasicClientCookie("g36FastPopSessionRequestNumber", "1"),
            new BasicClientCookie("FastPopSessionRequestNumber", "1"),
            new BasicClientCookie("FPSRN", "1"),
            new BasicClientCookie("performance_timing", "home"),
            new BasicClientCookie("RNKEY", RnkeyUtils.nextKey()))

        .peek(c -> c.setDomain(domain))
        .peek(c -> c.setPath("/"))
        .collect(Collectors.toList());
}
 
Example #3
Source File: Cookie.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new cookie with the specified name and value which applies to the specified domain,
 * the specified path, and expires on the specified date.
 * @param domain the domain to which this cookie applies
 * @param name the cookie name
 * @param value the cookie name
 * @param path the path to which this cookie applies
 * @param expires the date on which this cookie expires
 * @param secure whether or not this cookie is secure (i.e. HTTPS vs HTTP)
 * @param httpOnly whether or not this cookie should be only used for HTTP(S) headers
 */
public Cookie(final String domain, final String name, final String value, final String path, final Date expires,
    final boolean secure, final boolean httpOnly) {
    if (domain == null) {
        throw new IllegalArgumentException("Cookie domain must be specified");
    }

    final BasicClientCookie cookie = new BasicClientCookie(name, value != null ? value : "");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setExpiryDate(expires);
    cookie.setSecure(secure);
    if (httpOnly) {
        cookie.setAttribute("httponly", "true");
    }
    httpClientCookie_ = cookie;
}
 
Example #4
Source File: Cookie.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new cookie with the specified name and value which applies to the specified domain,
 * the specified path, and expires after the specified amount of time.
 * @param domain the domain to which this cookie applies
 * @param name the cookie name
 * @param value the cookie name
 * @param path the path to which this cookie applies
 * @param maxAge the number of seconds for which this cookie is valid; <tt>-1</tt> indicates that the
 *        cookie should never expire; other negative numbers are not allowed
 * @param secure whether or not this cookie is secure (i.e. HTTPS vs HTTP)
 */
public Cookie(final String domain, final String name, final String value, final String path, final int maxAge,
    final boolean secure) {

    final BasicClientCookie cookie = new BasicClientCookie(name, value != null ? value : "");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setSecure(secure);

    if (maxAge < -1) {
        throw new IllegalArgumentException("invalid max age:  " + maxAge);
    }
    if (maxAge >= 0) {
        cookie.setExpiryDate(new Date(System.currentTimeMillis() + (maxAge * 1000)));
    }

    httpClientCookie_ = cookie;
}
 
Example #5
Source File: DefaultHttpClientTemplate.java    From simple-robot-core with Apache License 2.0 6 votes vote down vote up
/**
 * map转化为Cookie,并且添加额外的cookie
 *
 * @param cookies     cookies
 * @param cookieStore cookieStore
 */
private static CookieStore toCookieStore(String domain, Map<String, String> cookies, CookieStore cookieStore) {
    CookieStore newCookieStore = new BasicCookieStore();
    // 添加旧的
    newCookieStore.getCookies().forEach(cookieStore::addCookie);
    // 添加新的
    cookies.entrySet().stream()
            .map(e -> {
                final BasicClientCookie cookie = new BasicClientCookie(e.getKey(), e.getValue());
                cookie.setPath("/");
                cookie.setDomain(domain);
                return cookie;
            })
            .forEach(newCookieStore::addCookie);
    return newCookieStore;
}
 
Example #6
Source File: HttpAsyncClientLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenUseCookiesWithHttpAsyncClient_thenCorrect() throws Exception {
    final BasicCookieStore cookieStore = new BasicCookieStore();
    final BasicClientCookie cookie = new BasicClientCookie(COOKIE_NAME, "1234");
    cookie.setDomain(COOKIE_DOMAIN);
    cookie.setPath("/");
    cookieStore.addCookie(cookie);
    final CloseableHttpAsyncClient client = HttpAsyncClients.custom().build();
    client.start();
    final HttpGet request = new HttpGet(HOST_WITH_COOKIE);

    final HttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);

    final Future<HttpResponse> future = client.execute(request, localContext, null);
    final HttpResponse response = future.get();
    assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
    client.close();
}
 
Example #7
Source File: HttpUtilsAsync.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
public static void getUseCookie(Context context, String url, HashMap hashMap, AsyncHttpResponseHandler responseHandler) {
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    if (BasicUtils.judgeNotNull(hashMap)) {
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            Object key = entry.getKey();
            Object value = entry.getValue();
            Cookie cookie = new BasicClientCookie(key.toString(), value.toString());
            myCookieStore.addCookie(cookie);
        }
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.setCookieStore(myCookieStore);
    client.get(getAbsoluteUrl(url), responseHandler);
}
 
Example #8
Source File: ApacheHttpClient.java    From karate with MIT License 6 votes vote down vote up
@Override
protected void buildCookie(com.intuit.karate.http.Cookie c) {
    BasicClientCookie cookie = new BasicClientCookie(c.getName(), c.getValue());
    for (Entry<String, String> entry : c.entrySet()) {
        switch (entry.getKey()) {
            case DOMAIN:
                cookie.setDomain(entry.getValue());
                break;
            case PATH:
                cookie.setPath(entry.getValue());
                break;
        }
    }
    if (cookie.getDomain() == null) {
        cookie.setDomain(uriBuilder.getHost());
    }
    cookieStore.addCookie(cookie);
}
 
Example #9
Source File: AsyncHttpClient.java    From letv with Apache License 2.0 6 votes vote down vote up
public static CookieStore getuCookie() {
    CookieStore uCookie = new BasicCookieStore();
    try {
        String COOKIE_S_LINKDATA = LemallPlatform.getInstance().getCookieLinkdata();
        if (!TextUtils.isEmpty(COOKIE_S_LINKDATA)) {
            String[] cookies = COOKIE_S_LINKDATA.split("&");
            for (String item : cookies) {
                String[] keyValue = item.split(SearchCriteria.EQ);
                if (keyValue.length == 2) {
                    if (OtherUtil.isContainsChinese(keyValue[1])) {
                        keyValue[1] = URLEncoder.encode(keyValue[1], "UTF-8");
                    }
                    BasicClientCookie cookie = new BasicClientCookie(keyValue[0], keyValue[1]);
                    cookie.setVersion(0);
                    cookie.setDomain(".lemall.com");
                    cookie.setPath("/");
                    uCookie.addCookie(cookie);
                }
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return uCookie;
}
 
Example #10
Source File: ChooseElementTest.java    From esigate with Apache License 2.0 6 votes vote down vote up
/**
 * @see <a href="https://github.com/esigate/esigate/issues/152">NullPointerException on Nested Choose/when/otherwise
 *      tags #152</a>
 * @throws Exception
 */
public void testNestedChoose() throws Exception {
    String page =
            "<esi:choose>\n" + "<esi:when test=\"$exists($(HTTP_COOKIE{'FIRST_COOKIE'}))\">\n" + "<esi:choose>\n"
                    + "<esi:when test=\"$exists($(HTTP_COOKIE{'SECOND_COOKIE'}))\">\n" + "HAS SECOND COOKIE\n"
                    + "</esi:when>\n" + "<esi:otherwise>\n" + "NO SECOND COOKIE\n" + "</esi:otherwise>\n"
                    + "</esi:choose>\n" + "</esi:when>\n" + "<esi:otherwise>\n" + "NO FIRST COOKIE\n"
                    + "</esi:otherwise>\n" + "</esi:choose>";
    String result = render(page);
    assertEquals("NO FIRST COOKIE", result.trim());
    getRequestBuilder().addCookie(new BasicClientCookie("FIRST_COOKIE", "value"));
    result = render(page);
    assertEquals("NO SECOND COOKIE", result.trim());
    getRequestBuilder().addCookie(new BasicClientCookie("SECOND_COOKIE", "value"));
    result = render(page);
    assertEquals("HAS SECOND COOKIE", result.trim());
}
 
Example #11
Source File: WebViewUtil.java    From Huochexing12306 with Apache License 2.0 6 votes vote down vote up
private static void saveCookie(String url){
	String cookie = CookieManager.getInstance().getCookie(url);
	if(cookie !=null && !cookie.equals("")){  
           String[] cookies = cookie.split(";");  
           for(int i=0; i< cookies.length; i++){  
               String[] nvp = cookies[i].split("=");  
               BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]);  
               //c.setVersion(0);  
               c.setDomain("kyfw.12306.cn");
               MyCookieStore myCookieStore = null;
               if (MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore()
               		instanceof MyCookieStore){
               	myCookieStore = (MyCookieStore)MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore();
               }
               if (myCookieStore != null){
               	myCookieStore.addCookie(c);
               }
           }
      }  
	CookieSyncManager.getInstance().sync();
}
 
Example #12
Source File: ZdsHttp.java    From zest-writer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Authentication with google account
 * @param cookies cookies list keys from google auth
 * @param login username associated to zds login
 * @param id user id on ZdS associated to login
 */
public void authToGoogle(List<HttpCookie> cookies, String login, String id) {
    if(login != null && id != null) {
        this.login = login;
        this.idUser = id;
        log.info("L'identifiant de l'utilisateur " + this.login + " est : " + idUser);
        cookieStore = new BasicCookieStore();
        for(HttpCookie cookie:cookies) {
            BasicClientCookie c = new BasicClientCookie(cookie.getName(), cookie.getValue());
            c.setDomain(cookie.getDomain());
            c.setPath(cookie.getPath());
            c.setSecure(cookie.getSecure());
            c.setVersion(cookie.getVersion());
            c.setComment(cookie.getComment());
            cookieStore.addCookie(c);
        }
        context.setCookieStore(cookieStore);
        this.authenticated = true;
    }
    else {
        log.debug("Le login de l'utilisateur n'a pas pu être trouvé");
    }
}
 
Example #13
Source File: CookieManagerTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void testGetCookiesAsHttpCookieStore()
{
    configureMockedWebDriver();
    Cookie seleniumCookie = createSeleniumCookie();
    mockGetCookies(seleniumCookie);
    CookieStore cookieStore = cookieManager.getCookiesAsHttpCookieStore();
    List<org.apache.http.cookie.Cookie> resultCookies = cookieStore.getCookies();
    assertEquals(1, resultCookies.size());
    org.apache.http.cookie.Cookie httpCookie = resultCookies.get(0);
    assertThat(httpCookie, instanceOf(BasicClientCookie.class));
    BasicClientCookie clientCookie = (BasicClientCookie) httpCookie;
    assertAll(
        () -> assertEquals(seleniumCookie.getDomain(), clientCookie.getDomain()),
        () -> assertEquals(seleniumCookie.getExpiry(), clientCookie.getExpiryDate()),
        () -> assertEquals(seleniumCookie.getName(), clientCookie.getName()),
        () -> assertEquals(seleniumCookie.getPath(), clientCookie.getPath()),
        () -> assertEquals(seleniumCookie.getValue(), clientCookie.getValue()),
        () -> assertEquals(seleniumCookie.isSecure(), clientCookie.isSecure()),
        () -> assertEquals(seleniumCookie.getDomain(), clientCookie.getAttribute(ClientCookie.DOMAIN_ATTR)),
        () -> assertEquals(seleniumCookie.getPath(), clientCookie.getAttribute(ClientCookie.PATH_ATTR))
    );
}
 
Example #14
Source File: HttpConnector.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void addRequestCookies(HttpRequestBase method) throws ComponentNotReadyException {
	if (requestCookies == null) {
		return;
	}

	for (DataField field : requestCookiesRecord) {
		if (!field.isNull()) {
			String name = field.getMetadata().getLabelOrName();
			String value = field.getValue().toString();
			BasicClientCookie basicClientCookie = new BasicClientCookie(name, value);
			if (method.getURI() != null) {
				basicClientCookie.setDomain(method.getURI().getHost());
			}
			basicClientCookie.setPath("/");
			cookieStore.addCookie(basicClientCookie);
		}
	}

}
 
Example #15
Source File: HttpUriRequestConverter.java    From webmagic with Apache License 2.0 6 votes vote down vote up
private HttpClientContext convertHttpClientContext(Request request, Site site, Proxy proxy) {
    HttpClientContext httpContext = new HttpClientContext();
    if (proxy != null && proxy.getUsername() != null) {
        AuthState authState = new AuthState();
        authState.update(new BasicScheme(ChallengeState.PROXY), new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
        httpContext.setAttribute(HttpClientContext.PROXY_AUTH_STATE, authState);
    }
    if (request.getCookies() != null && !request.getCookies().isEmpty()) {
        CookieStore cookieStore = new BasicCookieStore();
        for (Map.Entry<String, String> cookieEntry : request.getCookies().entrySet()) {
            BasicClientCookie cookie1 = new BasicClientCookie(cookieEntry.getKey(), cookieEntry.getValue());
            cookie1.setDomain(UrlUtils.removePort(UrlUtils.getDomain(request.getUrl())));
            cookieStore.addCookie(cookie1);
        }
        httpContext.setCookieStore(cookieStore);
    }
    return httpContext;
}
 
Example #16
Source File: CookieConverter.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
/**
 * Converts Selenium cookie to Apache http client.
 * @param browserCookie selenium cookie.
 * @return http client format.
 */
protected ClientCookie convertCookie(Cookie browserCookie) {
    BasicClientCookie cookie = new BasicClientCookie(browserCookie.getName(), browserCookie.getValue());
    String domain = browserCookie.getDomain();
    if (domain != null && domain.startsWith(".")) {
        // http client does not like domains starting with '.', it always removes it when it receives them
        domain = domain.substring(1);
    }
    cookie.setDomain(domain);
    cookie.setPath(browserCookie.getPath());
    cookie.setExpiryDate(browserCookie.getExpiry());
    cookie.setSecure(browserCookie.isSecure());
    if (browserCookie.isHttpOnly()) {
        cookie.setAttribute("httponly", "");
    }
    return cookie;
}
 
Example #17
Source File: DriverTest.java    From esigate with Apache License 2.0 6 votes vote down vote up
public void testForwardCookiesWithPortsAndPreserveHost() throws Exception {
    // Conf
    Properties properties = new PropertiesBuilder() //
            .set(Parameters.REMOTE_URL_BASE, "http://localhost:8080/") //
            .set(Parameters.PRESERVE_HOST, true) //
            .build();

    mockConnectionManager = new MockConnectionManager() {
        @Override
        public HttpResponse execute(HttpRequest httpRequest) {
            Assert.assertNotNull("Cookie should be forwarded", httpRequest.getFirstHeader("Cookie"));
            Assert.assertEquals("JSESSIONID=926E1C6A52804A625DFB0139962D4E13", httpRequest.getFirstHeader("Cookie")
                    .getValue());
            return new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_OK, "OK");
        }
    };

    Driver driver = createMockDriver(properties, mockConnectionManager);

    BasicClientCookie cookie = new BasicClientCookie("_JSESSIONID", "926E1C6A52804A625DFB0139962D4E13");
    request = TestUtils.createIncomingRequest("http://127.0.0.1:8081/foobar.jsp").addCookie(cookie);

    driver.proxy("/foobar.jsp", request.build());
}
 
Example #18
Source File: SyncHttpClient.java    From sealtalk-android with MIT License 6 votes vote down vote up
public void SaveCookies(HttpResponse httpResponse){
	Header[] headers = httpResponse.getHeaders("Set-Cookie");
	String headerstr = headers.toString();

	if (headers != null){
		for(int i=0; i<headers.length; i++){

			String cookie=headers[i].getValue();
			String[] cookievalues = cookie.split(";");

			for(int j=0; j<cookievalues.length; j++){
				String[] keyPair = cookievalues[j].split("=");
				String key = keyPair[0].trim();
				String value = keyPair.length>1?keyPair[1].trim():"";
				BasicClientCookie newCookie = new BasicClientCookie(key, value);
				cookieStore.addCookie(newCookie);
			}
		}
	}
}
 
Example #19
Source File: HttpClient.java    From utils with Apache License 2.0 6 votes vote down vote up
public void setCookies(Map<String, String> cookies, String domain, String path) {
    if (null == cookies || cookies.isEmpty()) {
        return;
    }

    for (String key : cookies.keySet()) {
        BasicClientCookie cookie = new BasicClientCookie(key, cookies.get(key));
        if (domain.startsWith(HTTP_PRO)) {
            domain = domain.substring(HTTP_PRO.length());
        }
        if (domain.startsWith(HTTPS_PRO)) {
            domain = domain.substring(HTTPS_PRO.length());
        }
        cookie.setDomain(domain);
        if (StringUtils.isBlank(path)) {
            cookie.setPath("/");
        } else {
            cookie.setPath(path);
        }
        cookieStore.addCookie(cookie);
    }
}
 
Example #20
Source File: BasicHttpSolrClientTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: JLineupHttpClient.java    From jlineup with Apache License 2.0 6 votes vote down vote up
private void addCookiesToStore(List<Cookie> cookies, CookieStore cookieStore, String domain) {
    for (Cookie cookie : cookies) {
        BasicClientCookie apacheCookie = new BasicClientCookie(cookie.name, cookie.value);
        apacheCookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true");
        if (cookie.domain != null) {
            apacheCookie.setDomain(cookie.domain);
        } else {
            apacheCookie.setDomain(domain);
        }
        if (cookie.expiry != null) {
            apacheCookie.setExpiryDate(cookie.expiry);
        }
        if (cookie.path != null) {
            apacheCookie.setPath(cookie.path);
        }
        apacheCookie.setSecure(cookie.secure);
        cookieStore.addCookie(apacheCookie);
    }
}
 
Example #22
Source File: ApacheCloudStackClient.java    From apache-cloudstack-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * This method creates a cookie for every {@link HeaderElement} of the {@link Header} given as parameter.
 * Then, it adds this newly created cookie into the {@link CookieStore} provided as parameter.
 */
protected void createAndAddCookiesOnStoreForHeader(CookieStore cookieStore, Header header) {
    for (HeaderElement element : header.getElements()) {
        BasicClientCookie cookie = createCookieForHeaderElement(element);
        cookieStore.addCookie(cookie);
    }
}
 
Example #23
Source File: ChooseElementTest.java    From esigate with Apache License 2.0 5 votes vote down vote up
public void testMultipleWhen() throws IOException, HttpErrorPage {
    String page =
            "begin <esi:choose>" + "<esi:when test=\"'$(HTTP_COOKIE{group})'=='Advanced'\">"
                    + "<esi:vars>unexpected cookie '$(HTTP_COOKIE{group})'</esi:vars>" + "</esi:when>"
                    + "<esi:when test=\"'$(HTTP_COOKIE{group})'=='Beginner'\">"
                    + "<esi:vars>expected cookie '$(HTTP_COOKIE{group})'</esi:vars>" + "</esi:when>"
                    + "</esi:choose> end";
    getRequestBuilder().addCookie(new BasicClientCookie("group", "Beginner"));
    String result = render(page);
    assertEquals("begin expected cookie 'Beginner' end", result);
}
 
Example #24
Source File: CookieStoreCollectorTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testIntegrationMethodsFromCollector()
{
    Cookie cookie1 = new BasicClientCookie("name", "value");
    Cookie cookie2 = new BasicClientCookie("name2", "value2");
    CookieStore cookieStore = Stream.of(cookie1, cookie2).parallel().collect(ClientBuilderUtils.toCookieStore());
    assertEquals(cookieStore.getCookies(), List.of(cookie1, cookie2));
}
 
Example #25
Source File: SerializableCookie.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new BasicClientCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setExpiryDate((Date) in.readObject());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
}
 
Example #26
Source File: ApacheCloudStackClientTest.java    From apache-cloudstack-java-client with Apache License 2.0 5 votes vote down vote up
@Test
public void configureDomainForCookieTest() {
    BasicClientCookie basicClientCookie = new BasicClientCookie("name", "value");
    apacheCloudStackClient.configureDomainForCookie(basicClientCookie);

    Assert.assertEquals(cloudStackDomain, basicClientCookie.getDomain());
}
 
Example #27
Source File: ApacheCloudStackClient.java    From apache-cloudstack-java-client with Apache License 2.0 5 votes vote down vote up
/**
 *  It configures the cookie domain with the domain of the Apache CloudStack that is being accessed.
 *  The domain is extracted from {@link #url} variable.
 */
protected void configureDomainForCookie(BasicClientCookie cookie) {
    try {
        HttpHost httpHost = URIUtils.extractHost(new URI(url));
        String domain = httpHost.getHostName();
        cookie.setDomain(domain);
    } catch (URISyntaxException e) {
        throw new ApacheCloudStackClientRuntimeException(e);
    }
}
 
Example #28
Source File: ChooseElementTest.java    From esigate with Apache License 2.0 5 votes vote down vote up
public void testOtherwise() throws IOException, HttpErrorPage {
    String page =
            "begin <esi:choose>" + "<esi:when test=\"'$(HTTP_COOKIE{group})'=='Beginner'\">inside when</esi:when>"
                    + "<esi:otherwise>"
                    + "<esi:vars>inside otherwise with '$(HTTP_COOKIE{group})' cookie</esi:vars>"
                    + "</esi:otherwise>" + "</esi:choose> end";
    getRequestBuilder().addCookie(new BasicClientCookie("group", "Advanced"));
    String result = render(page);
    assertEquals("begin inside otherwise with 'Advanced' cookie end", result);
}
 
Example #29
Source File: SerializableCookie.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new BasicClientCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setExpiryDate((Date) in.readObject());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
}
 
Example #30
Source File: PreferencesCookieStore.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new BasicClientCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setExpiryDate((Date) in.readObject());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
}