Examples of CookieStore


Examples of org.apache.http.client.CookieStore

   * @param httpClient
   * @throws ClientServicesException
   */
    protected void initialize(DefaultHttpClient httpClient) throws ClientServicesException {
        if (endpoint != null) {
            CookieStore cookies = endpoint.getCookies();
            httpClient.setCookieStore(cookies);
            endpoint.initialize(httpClient);
        }
    }
View Full Code Here

Examples of org.apache.http.client.CookieStore

        @Override
    @SuppressWarnings("unchecked")
        public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {

            CookieStore cookieStore;
            cookieStore = new BasicCookieStore();

            Context ctx = Context.get();
           
            boolean ltpaTokenFound = false;
           
            java.util.Map<java.lang.String, java.lang.Object> cookieMap = ctx.getRequestCookieMap();
            if(cookieMap.containsKey("LtpaToken")) {
                javax.servlet.http.Cookie cookie = (javax.servlet.http.Cookie) cookieMap.get("LtpaToken");
                BasicClientCookie2 cookie1 = new BasicClientCookie2(cookie.getName(), getRawCookieValue(cookie, ctx.getHttpRequest()));
                if(cookie.getDomain()!=null) {
                    cookie1.setDomain(cookie.getDomain());
                }
                else {
                    cookie1.setDomain(_domain);
                }
                if(cookie.getPath()!=null) {
                    cookie1.setPath(cookie.getPath());
                }
                else {
                    cookie1.setPath("/");
                }
                cookieStore.addCookie(cookie1);
                ltpaTokenFound = true;
            }

            if(cookieMap.containsKey("LtpaToken2")) {
                javax.servlet.http.Cookie cookie = (javax.servlet.http.Cookie) cookieMap.get("LtpaToken2");
                BasicClientCookie2 cookie2 = new BasicClientCookie2(cookie.getName(), getRawCookieValue(cookie, ctx.getHttpRequest()));
                if(cookie.getDomain()!=null) {
                    cookie2.setDomain(cookie.getDomain());
                }
                else {
                    cookie2.setDomain(_domain);
                }
                if(cookie.getPath()!=null) {
                    cookie2.setPath(cookie.getPath());
                }
                else {
                    cookie2.setPath("/");
                }
                cookieStore.addCookie(cookie2);
                ltpaTokenFound = true;
            }
           
            if (!ltpaTokenFound && logger.isLoggable(Level.INFO)) {
              String uri = "";
View Full Code Here

Examples of org.apache.http.client.CookieStore

     */
    @Override
    protected Response execRequest(HttpRequestBase httpRequestBase, Args args, Object content) throws ClientServicesException {
      Response response = super.execRequest(httpRequestBase, args, content);

      CookieStore cookieStore = httpClient.getCookieStore();
      List<Cookie> cookies = cookieStore.getCookies();
      //System.out.println(hashCode() +" < "+cookies.size());
      for (Cookie cookie : cookies) {
        //System.out.println(cookie.getName()+"="+cookie.getValue());
        CookieStoreClientService.cookieStore.addCookie(cookie);
      }
View Full Code Here

Examples of org.apache.http.client.CookieStore

            // Have we already logged into this server?
            if (login.hasCookies()) {
                // Use existing cookies
                LOG.info("Using existing cookies to authenticate access to " + target.toString());
                CookieStore store = login.getCookies();
                if (store != null)
                    client.setCookieStore(store);

                // Check if any of the cookies have expired
                if (!store.clearExpired(Calendar.getInstance().getTime())) {
                    // No cookies were cleared so our cookies are still fresh
                    // and we don't need to login again
                    return;
                }

                // If we reach here then some of our cookies have expired and we
                // may no longer be logged in and should login again instead of
                // proceeding with the existing cookies
            }

            try {
                // Use a fresh Cookie Store for new login attempts
                CookieStore store = new BasicCookieStore();
                client.setCookieStore(store);

                // Try to login
                LOG.info("Making login attempt against " + login.getLoginFormURL() + " to obtain authentication for access to "
                        + target.toString());
View Full Code Here

Examples of org.apache.http.client.CookieStore

        String host = this.target.getHostName();
        int port = this.target.getPort();
        this.localServer.register("*",
                new BasicRedirectService(host, port));

        CookieStore cookieStore = new BasicCookieStore();
        this.httpclient.setCookieStore(cookieStore);

        BasicClientCookie cookie = new BasicClientCookie("name", "value");
        cookie.setDomain(host);
        cookie.setPath("/");

        cookieStore.addCookie(cookie);

        HttpContext context = new BasicHttpContext();
        HttpGet httpget = new HttpGet("/oldlocation/");

        Future<HttpResponse> future = this.httpclient.execute(this.target, httpget, context, null);
View Full Code Here

Examples of org.apache.http.client.CookieStore

            // Have we already logged into this server?
            if (login.hasCookies()) {
                // Use existing cookies
                LOG.info("Using existing cookies to authenticate access to " + target.toString());
                CookieStore store = login.getCookies();
                if (store != null)
                    client.setCookieStore(store);
                return;
            }

            try {
                // Use a fresh Cookie Store for new login attempts
                CookieStore store = new BasicCookieStore();
                client.setCookieStore(store);

                // Try to login
                LOG.info("Making login attempt against " + login.getLoginFormURL() + " to obtain authentication for access to "
                        + target.toString());
View Full Code Here

Examples of org.apache.http.client.CookieStore

        }

        final HttpClientContext clientContext = HttpClientContext.adapt(context);

        // Obtain cookie store
        final CookieStore cookieStore = clientContext.getCookieStore();
        if (cookieStore == null) {
            this.log.debug("Cookie store not specified in HTTP context");
            return;
        }

        // Obtain the registry of cookie specs
        final Lookup<CookieSpecProvider> registry = clientContext.getCookieSpecRegistry();
        if (registry == null) {
            this.log.debug("CookieSpec registry not specified in HTTP context");
            return;
        }

        // Obtain the target host, possibly virtual (required)
        final HttpHost targetHost = clientContext.getTargetHost();
        if (targetHost == null) {
            this.log.debug("Target host not set in the context");
            return;
        }

        // Obtain the route (required)
        final RouteInfo route = clientContext.getHttpRoute();
        if (route == null) {
            this.log.debug("Connection route not set in the context");
            return;
        }

        final RequestConfig config = clientContext.getRequestConfig();
        String policy = config.getCookieSpec();
        if (policy == null) {
            policy = CookieSpecs.BEST_MATCH;
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("CookieSpec selected: " + policy);
        }

        URI requestURI = null;
        try {
            requestURI = new URI(request.getRequestLine().getUri());
        } catch (final URISyntaxException ignore) {
        }
        final String path = requestURI != null ? requestURI.getPath() : null;
        final String hostName = targetHost.getHostName();
        int port = targetHost.getPort();
        if (port < 0) {
            port = route.getTargetHost().getPort();
        }

        final CookieOrigin cookieOrigin = new CookieOrigin(
                hostName,
                port >= 0 ? port : 0,
                !TextUtils.isEmpty(path) ? path : "/",
                route.isSecure());

        // Get an instance of the selected cookie policy
        final CookieSpecProvider provider = registry.lookup(policy);
        if (provider == null) {
            throw new HttpException("Unsupported cookie policy: " + policy);
        }
        final CookieSpec cookieSpec = provider.create(clientContext);
        // Get all cookies available in the HTTP state
        final List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies());
        // Find cookies matching the given origin
        final List<Cookie> matchedCookies = new ArrayList<Cookie>();
        final Date now = new Date();
        for (final Cookie cookie : cookies) {
            if (!cookie.isExpired(now)) {
View Full Code Here

Examples of org.apache.http.client.CookieStore

        });

        this.httpclient = HttpClients.createDefault();

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

        // First request : retrieve a domain cookie from remote server.
        URI uri = new URI("http://app.mydomain.fr");
        HttpRequest httpRequest = new HttpGet(uri);
        httpRequest.addHeader("X-Request", "1");
        final HttpResponse response1 = this.httpclient.execute(getServerHttp(),
                httpRequest, context);
        final HttpEntity e1 = response1.getEntity();
        EntityUtils.consume(e1);

        // We should have one cookie set on domain.
        final List<Cookie> cookies = cookieStore.getCookies();
        Assert.assertNotNull(cookies);
        Assert.assertEquals(1, cookies.size());
        Assert.assertEquals("name1", cookies.get(0).getName());

        // Second request : send the cookie back.
View Full Code Here

Examples of org.apache.http.client.CookieStore

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

        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.client.CookieStore

    @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
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.