Examples of BasicCookieStore


Examples of org.apache.http.impl.client.BasicCookieStore

    @Test
    public void testCookieVersionSupportHeader2() throws Exception {
        this.localServer.register("*", new CookieVer1Service());

        final CookieStore cookieStore = new BasicCookieStore();
        final HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        final HttpGet httpget = new HttpGet("/test/");

        final HttpResponse response1 = this.httpclient.execute(getServerHttp(), httpget, context);
        final HttpEntity e1 = response1.getEntity();
        EntityUtils.consume(e1);

        final List<Cookie> cookies = cookieStore.getCookies();
        Assert.assertNotNull(cookies);
        Assert.assertEquals(2, cookies.size());

        final HttpResponse response2 = this.httpclient.execute(getServerHttp(), httpget, context);
        final HttpEntity e2 = response2.getEntity();
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

    @Test
    public void testCookieVersionSupportHeader3() throws Exception {
        this.localServer.register("*", new CookieVer2Service());

        final CookieStore cookieStore = new BasicCookieStore();
        final HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        final HttpGet httpget = new HttpGet("/test/");

        final HttpResponse response1 = this.httpclient.execute(getServerHttp(), httpget, context);
        final HttpEntity e1 = response1.getEntity();
        EntityUtils.consume(e1);

        final List<Cookie> cookies = cookieStore.getCookies();
        Assert.assertNotNull(cookies);
        Assert.assertEquals(1, cookies.size());

        final HttpResponse response2 = this.httpclient.execute(getServerHttp(), httpget, context);
        final HttpEntity e2 = response2.getEntity();
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

    @Test
    public void testSetCookieVersionMix() throws Exception {
        this.localServer.register("*", new SetCookieVersionMixService());

        final CookieStore cookieStore = new BasicCookieStore();
        final HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        final HttpGet httpget = new HttpGet("/test/");

        final HttpResponse response1 = this.httpclient.execute(getServerHttp(), httpget, context);
        final HttpEntity e1 = response1.getEntity();
        EntityUtils.consume(e1);

        final List<Cookie> cookies = cookieStore.getCookies();
        Assert.assertNotNull(cookies);
        Assert.assertEquals(1, cookies.size());
        Assert.assertEquals("right", cookies.get(0).getValue());
        Assert.assertTrue(cookies.get(0) instanceof SetCookie2);
    }
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

    @Before
    public void setUp() throws Exception {
        this.cookieOrigin = new CookieOrigin("localhost", 80, "/", false);
        this.cookieSpec = new BestMatchSpec();
        this.cookieStore = new BasicCookieStore();
    }
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

    public void testRedirectWithCookie() throws Exception {
        final HttpHost target = getServerHttp();

        this.localServer.register("*", new BasicRedirectService());

        final CookieStore cookieStore = new BasicCookieStore();

        final BasicClientCookie cookie = new BasicClientCookie("name", "value");
        cookie.setDomain(target.getHostName());
        cookie.setPath("/");

        cookieStore.addCookie(cookie);

        final HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        final HttpGet httpget = new HttpGet("/oldlocation/");

View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

    private Lookup<CookieSpecProvider> cookieSpecRegistry;

    @Before
    public void setUp() {
        this.target = new HttpHost("localhost.local", 80);
        this.cookieStore = new BasicCookieStore();
        final BasicClientCookie2 cookie1 = new BasicClientCookie2("name1", "value1");
        cookie1.setVersion(1);
        cookie1.setDomain("localhost.local");
        cookie1.setPath("/");
        this.cookieStore.addCookie(cookie1);
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

* form-based logon.
*/
public class ClientFormLogin {

    public static void main(String[] args) throws Exception {
        BasicCookieStore cookieStore = new BasicCookieStore();
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCookieStore(cookieStore)
                .build();
        try {
            HttpGet httpget = new HttpGet("https://someportal/");
            CloseableHttpResponse response1 = httpclient.execute(httpget);
            try {
                HttpEntity entity = response1.getEntity();

                System.out.println("Login form get: " + response1.getStatusLine());
                EntityUtils.consume(entity);

                System.out.println("Initial set of cookies:");
                List<Cookie> cookies = cookieStore.getCookies();
                if (cookies.isEmpty()) {
                    System.out.println("None");
                } else {
                    for (int i = 0; i < cookies.size(); i++) {
                        System.out.println("- " + cookies.get(i).toString());
                    }
                }
            } finally {
                response1.close();
            }

            HttpUriRequest login = RequestBuilder.post()
                    .setUri(new URI("https://someportal/"))
                    .addParameter("IDToken1", "username")
                    .addParameter("IDToken2", "password")
                    .build();
            CloseableHttpResponse response2 = httpclient.execute(login);
            try {
                HttpEntity entity = response2.getEntity();

                System.out.println("Login form get: " + response2.getStatusLine());
                EntityUtils.consume(entity);

                System.out.println("Post logon cookies:");
                List<Cookie> cookies = cookieStore.getCookies();
                if (cookies.isEmpty()) {
                    System.out.println("None");
                } else {
                    for (int i = 0; i < cookies.size(); i++) {
                        System.out.println("- " + cookies.get(i).toString());
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

    public final static void main(String[] args) throws Exception {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            // Create a local instance of cookie store
            CookieStore cookieStore = new BasicCookieStore();

            // Create local HTTP context
            HttpClientContext localContext = HttpClientContext.create();
            // Bind custom cookie store to the local context
            localContext.setCookieStore(cookieStore);

            HttpGet httpget = new HttpGet("http://localhost/");
            System.out.println("Executing request " + httpget.getRequestLine());

            // Pass local context as a parameter
            CloseableHttpResponse response = httpclient.execute(httpget, localContext);
            try {
                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                List<Cookie> cookies = cookieStore.getCookies();
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("Local cookie: " + cookies.get(i));
                }
                EntityUtils.consume(response.getEntity());
            } finally {
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

        connManager.setMaxTotal(100);
        connManager.setDefaultMaxPerRoute(10);
        connManager.setMaxPerRoute(new HttpRoute(new HttpHost("somehost", 80)), 20);

        // Use custom cookie store if necessary.
        CookieStore cookieStore = new BasicCookieStore();
        // Use custom credentials provider if necessary.
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        // Create global request configuration
        RequestConfig defaultRequestConfig = RequestConfig.custom()
            .setCookieSpec(CookieSpecs.BEST_MATCH)
View Full Code Here

Examples of org.apache.http.impl.client.BasicCookieStore

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, clientParams)
        {
            @Override
            protected CookieStore createCookieStore()
            {
                return new BasicCookieStore()
                {
                    @Override
                    public void addCookie(org.apache.http.cookie.Cookie cookie)
                    {
                        responseSetCookies.add(cookie);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.