Examples of BasicCookieStore


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

  }

  protected boolean prepareForwardingCookies(HttpRequestBase method, HttpServletRequest request, DefaultHttpClient httpClient) throws ServletException {
    Object timedObject = ProxyProfiler.getTimedObject();
    Cookie[] cookies = request.getCookies();
    BasicCookieStore cs = new BasicCookieStore();
    httpClient.setCookieStore(cs);
    if (cookies != null) {
      for (Cookie cookie : cookies) {
        if (cookie != null) {
          String cookiename = cookie.getName();
          if(StringUtil.isNotEmpty(cookiename)) {
            String cookieval = cookie.getValue();
            if (cookiename.startsWith(PASSTHRUID)) {
              cookiename = cookiename.substring(PASSTHRUID.length());
              if(isCookieAllowed(cookiename)) {
                String[] parts = decodeCookieNameAndPath(cookiename);
                if (parts!=null && parts.length==3) {
                  cookiename = parts[0];
                  String path = parts[1];
                  String domain = parts[2];

                  // Got stored domain now see if it matches destination
                  BasicClientCookie methodcookie = new BasicClientCookie(cookiename,cookieval);
                  methodcookie.setDomain(domain);
                  methodcookie.setPath(path);
                  cs.addCookie(methodcookie);
                  if(getDebugHook()!=null) {
                    getDebugHook().getDumpRequest().addCookie(methodcookie.getName(), methodcookie.toString());
                  }
                }
              }
            } else if(isCookieAllowed(cookiename)) {
              BasicClientCookie methodcookie = new BasicClientCookie(cookiename,cookieval);
              String domain = cookie.getDomain();
              if (domain == null) {
                try {
                  domain = method.getURI().getHost();
                  domain = domain.substring(domain.indexOf('.'));
                } catch (Exception e) {
                  domain = "";
                }
              }
              methodcookie.setDomain(domain);
              String path = cookie.getPath();
              if (path == null) {
                path = "/";
              }
              methodcookie.setPath(path);
              cs.addCookie(methodcookie);
              if(getDebugHook()!=null) {
                getDebugHook().getDumpRequest().addCookie(methodcookie.getName(), methodcookie.toString());
              }
            }
          }
View Full Code Here

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

        this.enableCookies  = enableCookies;
    }
   
    @Override
    public CookieStore getCookies() {
        return enableCookies ? this.cookieStore  : new BasicCookieStore();
    }
View Full Code Here

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

    try {
      if(!(getLoginFormUrl().startsWith("/"))){
        requestUrl = requestUrl.concat("/");
      }
      requestUrl = requestUrl.concat(getLoginFormUrl());
      BasicCookieStore cookieStore = new BasicCookieStore();
      DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
     
      if(isForceTrustSSLCertificate()){
        defaultHttpClient = SSLUtil.wrapHttpClient(defaultHttpClient); // Configure httpclient to accept all SSL certificates
      }
      if (isForceDisableExpectedContinue()) {
        defaultHttpClient.getParams().setParameter(
            CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
      }
      if (StringUtil.isNotEmpty(getHttpProxy())) {
        defaultHttpClient = ProxyDebugUtil.wrapHttpClient(defaultHttpClient, getHttpProxy()); // Configure httpclient to direct all traffic through proxy clients
      }

      defaultHttpClient.setCookieStore(cookieStore);
      HttpPost httpost = new HttpPost(requestUrl);
      List<NameValuePair> formParams = getLoginFormParameters(); // retrieve platform specific login parameters
      httpost.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8"));
     
      //getting to interface to avoid
      //java.lang.NoSuchMethodError: org/apache/http/impl/client/DefaultHttpClient.execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/client/methods/CloseableHttpResponse;
      //when run from different version of HttpClient (that's why it is deprecated)
      HttpClient httpClient = defaultHttpClient;

      HttpResponse resp = httpClient.execute(httpost);
      int code = resp.getStatusLine().getStatusCode();
      if (code == HttpStatus.SC_OK) {
        validAuthentication = true;
      }
      List<Cookie> cookies = cookieStore.getCookies();
      setCookieCache(cookies);

    } catch (IOException e) {
      throw new AuthenticationException(e,"FormEndpoint failed to authenticate");
    }
View Full Code Here

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

        @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;
           
View Full Code Here

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

                // 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.impl.client.BasicCookieStore

  }

  @Override
  protected CookieStore createCookieStore()
  {
    return new BasicCookieStore();
  }
View Full Code Here

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

        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.impl.client.BasicCookieStore

                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.impl.client.BasicCookieStore

        });

        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.impl.client.BasicCookieStore

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