Package org.apache.http.client

Examples of org.apache.http.client.CookieStore


        if (method.equalsIgnoreCase("CONNECT")) {
            return;
        }
       
        // Obtain cookie store
        CookieStore cookieStore = (CookieStore) context.getAttribute(
                ClientContext.COOKIE_STORE);
        if (cookieStore == null) {
            this.log.info("Cookie store not available in HTTP context");
            return;
        }
       
        // Obtain the registry of cookie specs
        CookieSpecRegistry registry= (CookieSpecRegistry) context.getAttribute(
                ClientContext.COOKIESPEC_REGISTRY);
        if (registry == null) {
            this.log.info("CookieSpec registry not available in HTTP context");
            return;
        }
       
        // Obtain the target host (required)
        HttpHost targetHost = (HttpHost) context.getAttribute(
                ExecutionContext.HTTP_TARGET_HOST);
        if (targetHost == null) {
            throw new IllegalStateException("Target host not specified in HTTP context");
        }
       
        // Obtain the client connection (required)
        ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
                ExecutionContext.HTTP_CONNECTION);
        if (conn == null) {
            throw new IllegalStateException("Client connection not specified in HTTP context");
        }

        String policy = HttpClientParams.getCookiePolicy(request.getParams());
        if (this.log.isDebugEnabled()) {
            this.log.debug("CookieSpec selected: " + policy);
        }
       
        URI requestURI;
        if (request instanceof HttpUriRequest) {
            requestURI = ((HttpUriRequest) request).getURI();
        } else {
            try {
                requestURI = new URI(request.getRequestLine().getUri());
            } catch (URISyntaxException ex) {
                throw new ProtocolException("Invalid request URI: " +
                        request.getRequestLine().getUri(), ex);
            }
        }
       
        String hostName = targetHost.getHostName();
        int port = targetHost.getPort();
        if (port < 0) {
            port = conn.getRemotePort();
        }
       
        CookieOrigin cookieOrigin = new CookieOrigin(
                hostName,
                port,
                requestURI.getPath(),
                conn.isSecure());
       
        // Get an instance of the selected cookie policy
        CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
        // Get all cookies available in the HTTP state
        List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies());
        // Find cookies matching the given origin
        List<Cookie> matchedCookies = new ArrayList<Cookie>();
        for (Cookie cookie : cookies) {
            if (cookieSpec.match(cookie, cookieOrigin)) {
                if (this.log.isDebugEnabled()) {
View Full Code Here


        if (context == null) {
            throw new IllegalArgumentException("HTTP context may not be null");
        }
       
        // Obtain cookie store
        CookieStore cookieStore = (CookieStore) context.getAttribute(
                ClientContext.COOKIE_STORE);
        if (cookieStore == null) {
            this.log.info("Cookie store not available in HTTP context");
            return;
        }
View Full Code Here

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

        DefaultHttpClient client = new DefaultHttpClient();
       
        CookieStore cookieStore = new BasicCookieStore();
        client.setCookieStore(cookieStore);
       
        BasicClientCookie cookie = new BasicClientCookie("name", "value");
        cookie.setDomain("localhost");
        cookie.setPath("/");
       
        cookieStore.addCookie(cookie);

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

       
View Full Code Here

                .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
                .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
                .build();
        }

        CookieStore defaultCookieStore = this.cookieStore;
        if (defaultCookieStore == null) {
            defaultCookieStore = new BasicCookieStore();
        }

        CredentialsProvider defaultCredentialsProvider = this.credentialsProvider;
View Full Code Here

        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.DEFAULT)
View Full Code Here

        // Start by accessing the secured index.html of war1
        DefaultHttpClient httpclient = new DefaultHttpClient();

        checkAccessDenied(httpclient, warA1 + "index.html");

        CookieStore store = httpclient.getCookieStore();

        log.debug("Saw JSESSIONID=" + getSessionIdValueFromState(store));

        // Submit the login form
        executeFormLogin(httpclient, warA1);
View Full Code Here

        // Start by accessing the secured index.html of war1
        DefaultHttpClient httpclient = new DefaultHttpClient();

        checkAccessDenied(httpclient, warA1 + "index.html");

        CookieStore store = httpclient.getCookieStore();

        log.debug("Saw JSESSIONID=" + getSessionIdValueFromState(store));

        // Submit the login form
        executeFormLogin(httpclient, warA1);
View Full Code Here

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

        @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

     */
    @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

TOP

Related Classes of org.apache.http.client.CookieStore

Copyright © 2018 www.massapicom. 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.