Example usage for org.apache.http.client CookieStore getCookies

List of usage examples for org.apache.http.client CookieStore getCookies

Introduction

In this page you can find the example usage for org.apache.http.client CookieStore getCookies.

Prototype

List<Cookie> getCookies();

Source Link

Document

Returns all cookies contained in this store.

Usage

From source file:org.debux.webmotion.test.ActionMiscIT.java

@Test
public void flashMessage() throws IOException, URISyntaxException {
    URI uri = createRequest("/message").build();

    HttpGet request = new HttpGet(uri);

    DefaultHttpClient client = new DefaultHttpClient();
    client.execute(request);//w  w  w  .  ja  va2 s  .  co m

    CookieStore cookieStore = client.getCookieStore();
    List<Cookie> cookies = cookieStore.getCookies();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        String value = cookie.getValue();
        if ("wm_flash_infos_my_message".equals(name)) {
            AssertJUnit.assertEquals("\"bla bla bla bla\"", value);
            return;
        }
    }
    throw new RuntimeException("Invalid cookie");
}

From source file:org.debux.webmotion.test.ActionMiscIT.java

@Test
public void cookieManagerCreate() throws IOException, URISyntaxException {
    URI uri = createRequest("/cookie/create").addParameter("secured", "true").build();

    HttpGet request = new HttpGet(uri);

    DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse response = client.execute(request);

    HttpEntity entity = response.getEntity();
    InputStream content = entity.getContent();
    String result = IOUtils.toString(content);
    AssertJUnit.assertTrue(result, result.contains("Value = a_value"));

    CookieStore cookieStore = client.getCookieStore();
    List<Cookie> cookies = cookieStore.getCookies();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        String value = cookie.getValue();
        if ("secured_name".equals(name)) {
            AssertJUnit.assertTrue(value.startsWith("me|-1"));
            return;
        }//from  w  w  w. j  av  a  2  s .  c  o  m
    }
    throw new RuntimeException("Invalid cookie");
}

From source file:org.debux.webmotion.test.ActionMiscIT.java

@Test
public void cookieManagerObjectCreate() throws IOException, URISyntaxException {
    URI uri = createRequest("/cookie/object/create").addParameter("value", "test").build();

    HttpGet request = new HttpGet(uri);

    DefaultHttpClient client = new DefaultHttpClient();
    client.execute(request);//  w  ww.  j  a  v  a 2s .co  m

    CookieStore cookieStore = client.getCookieStore();
    List<Cookie> cookies = cookieStore.getCookies();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        String value = cookie.getValue();
        if ("user_cookie".equals(name)) {
            value = value.replaceAll("\\\\", "");
            AssertJUnit.assertEquals("{\"value\":\"test\"}", value);
            return;
        }
    }
    throw new RuntimeException("Invalid cookie");
}

From source file:org.debux.webmotion.test.ActionMiscIT.java

@Test
public void cookieManagerObjectRemove() throws IOException, URISyntaxException {
    URI uri = createRequest("/cookie/object/remove").build();

    HttpGet request = new HttpGet(uri);

    DefaultHttpClient client = new DefaultHttpClient();
    CookieStore cookieStore = new BasicCookieStore();
    client.setCookieStore(cookieStore);//w w  w. j  a  va2  s  .  c  o m

    BasicClientCookie initialCookie = new BasicClientCookie("user_cookie", "{}");
    initialCookie.setVersion(1);
    initialCookie.setDomain("localhost");
    initialCookie.setPath("/webmotion-test/test/cookie/object");
    cookieStore.addCookie(initialCookie);

    client.execute(request);

    List<Cookie> cookies = cookieStore.getCookies();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        if ("user_cookie".equals(name)) {
            throw new RuntimeException("Invalid cookie");
        }
    }
}

From source file:org.exoplatform.utils.ExoConnectionUtils.java

public static ArrayList<String> getCookieList(CookieStore cookieStore) {
    ArrayList<String> cookieList = new ArrayList<String>();
    List<Cookie> cookies = cookieStore.getCookies();
    String strCookie = "";
    if (!cookies.isEmpty()) {
        for (int i = 0; i < cookies.size(); i++) {
            strCookie = cookies.get(i).getName().toString() + "=" + cookies.get(i).getValue().toString();
            cookieList.add(strCookie);/*from  ww w .jav a2 s. co m*/
        }
    }
    return cookieList;
}