Example usage for org.apache.http.impl.client BasicCookieStore BasicCookieStore

List of usage examples for org.apache.http.impl.client BasicCookieStore BasicCookieStore

Introduction

In this page you can find the example usage for org.apache.http.impl.client BasicCookieStore BasicCookieStore.

Prototype

public BasicCookieStore() 

Source Link

Usage

From source file:webchat.client.http.HttpChannelFactory.java

@Override
public ChatFuture<MessageChannel> open(ChatHandler ioh) throws IOException {
    logger.info("Opening Http MessageChannel");
    SettableFuture<MessageChannel> futureChan = SettableFuture.create();
    Runnable r = () -> {//from ww  w .j ava  2 s.  c  o m
        HttpClientContext httpContext = HttpClientContext.create();
        httpContext.setCookieStore(new BasicCookieStore());
        HttpMessageSender sender = new HttpMessageSender(httpContext, commandUrl, formatter);
        HttpMessageReceiver receiver = new HttpMessageReceiver(httpContext, streamUrl, formatter);
        HttpMessageChannel chatSess = new HttpMessageChannel(sender, receiver, ioh);
        chatSess.start();
        ioh.onChannelOpened(chatSess);
        futureChan.set(chatSess);
    };
    new Thread(r).start();
    return new FutureAdapter(futureChan);
}

From source file:org.apache.olingo.samples.client.core.http.CookieHttpClientFactory.java

@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
    final CookieStore cookieStore = new BasicCookieStore();

    // Populate cookies if needed
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    cookie.setVersion(0);//from   www. ja  va  2  s  .c o m
    cookie.setDomain(".mycompany.com");
    cookie.setPath("/");
    cookieStore.addCookie(cookie);

    final DefaultHttpClient httpClient = super.create(method, uri);
    httpClient.setCookieStore(cookieStore);

    return httpClient;
}

From source file:ti.modules.titanium.network.TiCookieStore.java

public TiCookieStore() {
    cookieStore = new BasicCookieStore();
    pref = TiApplication.getInstance().getSharedPreferences(COOKIE_PREFERENCES, 0);

    synchronized (cookieStore) {
        // read from preferences and update local cookie store
        Map<String, ?> allPrefs = pref.getAll();
        if (!allPrefs.isEmpty()) {
            Set<String> keys = allPrefs.keySet();
            for (String key : keys) {
                if (key.startsWith(COOKIE_PREFIX)) {
                    String encodedCookie = (String) allPrefs.get(key);
                    if (encodedCookie != null) {
                        Cookie cookie = decodeCookie(encodedCookie);
                        if (cookie != null) {
                            cookieStore.addCookie(cookie);
                        }// w ww  .j a  va 2s. c o  m
                    }
                }
            }
        }
    }
}

From source file:network.HttpClientAdaptor.java

public HttpClientAdaptor() {

    CookieStore cookieStore = new BasicCookieStore();
    localContext.setCookieStore(cookieStore);

}

From source file:org.xdi.oxauth.dev.TestSessionWorkflow.java

@Parameters({ "userId", "userSecret", "clientId", "clientSecret", "redirectUri" })
@Test//  w  ww  .j  a  va 2 s .c  om
public void test(final String userId, final String userSecret, final String clientId, final String clientSecret,
        final String redirectUri) throws Exception {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try {
        CookieStore cookieStore = new BasicCookieStore();
        httpClient.setCookieStore(cookieStore);
        ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);

        ////////////////////////////////////////////////
        //             TV side. Code 1                //
        ////////////////////////////////////////////////

        AuthorizationRequest authorizationRequest1 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE),
                clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null);

        authorizationRequest1.setAuthUsername(userId);
        authorizationRequest1.setAuthPassword(userSecret);
        authorizationRequest1.getPrompts().add(Prompt.NONE);
        authorizationRequest1.setState("af0ifjsldkj");
        authorizationRequest1.setRequestSessionId(true);

        AuthorizeClient authorizeClient1 = new AuthorizeClient(authorizationEndpoint);
        authorizeClient1.setRequest(authorizationRequest1);
        AuthorizationResponse authorizationResponse1 = authorizeClient1.exec(clientExecutor);

        //        showClient(authorizeClient1, cookieStore);

        String code1 = authorizationResponse1.getCode();
        String sessionId = authorizationResponse1.getSessionId();
        Assert.assertNotNull("code1 is null", code1);
        Assert.assertNotNull("sessionId is null", sessionId);

        // TV sends the code to the Backend
        // We don't use httpClient and cookieStore during this call

        ////////////////////////////////////////////////
        //             Backend  1 side. Code 1        //
        ////////////////////////////////////////////////

        // Get the access token
        TokenClient tokenClient1 = new TokenClient(tokenEndpoint);
        TokenResponse tokenResponse1 = tokenClient1.execAuthorizationCode(code1, redirectUri, clientId,
                clientSecret);

        String accessToken1 = tokenResponse1.getAccessToken();
        Assert.assertNotNull("accessToken1 is null", accessToken1);

        // Get the user's claims
        UserInfoClient userInfoClient1 = new UserInfoClient(userInfoEndpoint);
        UserInfoResponse userInfoResponse1 = userInfoClient1.execUserInfo(accessToken1);

        Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse1.getStatus() == 200);
        //        System.out.println(userInfoResponse1.getEntity());

        ////////////////////////////////////////////////
        //             TV side. Code 2                //
        ////////////////////////////////////////////////

        AuthorizationRequest authorizationRequest2 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE),
                clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null);

        authorizationRequest2.getPrompts().add(Prompt.NONE);
        authorizationRequest2.setState("af0ifjsldkj");
        authorizationRequest2.setSessionId(sessionId);

        AuthorizeClient authorizeClient2 = new AuthorizeClient(authorizationEndpoint);
        authorizeClient2.setRequest(authorizationRequest2);
        AuthorizationResponse authorizationResponse2 = authorizeClient2.exec(clientExecutor);

        //        showClient(authorizeClient2, cookieStore);

        String code2 = authorizationResponse2.getCode();
        Assert.assertNotNull("code2 is null", code2);

        // TV sends the code to the Backend
        // We don't use httpClient and cookieStore during this call

        ////////////////////////////////////////////////
        //             Backend  2 side. Code 2        //
        ////////////////////////////////////////////////

        // Get the access token
        TokenClient tokenClient2 = new TokenClient(tokenEndpoint);
        TokenResponse tokenResponse2 = tokenClient2.execAuthorizationCode(code2, redirectUri, clientId,
                clientSecret);

        String accessToken2 = tokenResponse2.getAccessToken();
        Assert.assertNotNull("accessToken2 is null", accessToken2);

        // Get the user's claims
        UserInfoClient userInfoClient2 = new UserInfoClient(userInfoEndpoint);
        UserInfoResponse userInfoResponse2 = userInfoClient2.execUserInfo(accessToken2);

        Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse2.getStatus() == 200);
        //        System.out.println(userInfoResponse2.getEntity());
    } finally {
        if (httpClient != null) {
            httpClient.getConnectionManager().shutdown();
        }
    }
}

From source file:edu.richmond.bannerweb.NetworkManager.java

public NetworkManager() {
    //Bannerweb requires cookie handling, so we have to do all this stuff!
    mCookieStore = new BasicCookieStore();
    mLocalContext = new BasicHttpContext();
    mLocalContext.setAttribute(ClientContext.COOKIE_STORE, mCookieStore);

    mHttpClient = new DefaultHttpClient();

    //We also need to make an initial GET to the Bannerweb login page (To get the cookies).
    getInitialCookies();//from  ww w . j  av  a 2  s .  co m
}

From source file:io.cloudslang.content.httpclient.build.CookieStoreBuilderTest.java

@Test
public void buildCookieStoreWithCookies() throws IOException {
    BasicCookieStore basicCookieStore = new BasicCookieStore();
    SerializableSessionObject sessionObjectHolder = new SerializableSessionObject();
    sessionObjectHolder.setValue(CookieStoreBuilder.serialize(basicCookieStore));
    BasicCookieStore cookieStore = (BasicCookieStore) cookieStoreBuilder
            .setCookieStoreSessionObject(sessionObjectHolder).buildCookieStore();

    assertNotNull(cookieStore);/* w ww .  j ava  2s  .c om*/
    assertEquals(0, cookieStore.getCookies().size());
    assertEquals(basicCookieStore.getCookies(), cookieStore.getCookies());
}

From source file:org.eclipse.lyo.testsuite.server.trsutils.EasySSLClient.java

void initCookiePolicy() {
    httpClient.setCookieStore(new BasicCookieStore());
}

From source file:pl.raszkowski.sporttrackersconnector.garminconnect.AuthorizerIT.java

private void buildHttpClient() {
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

    CookieStore cookieStore = new BasicCookieStore();

    httpClient = httpClientBuilder.disableRedirectHandling().setDefaultCookieStore(cookieStore).build();
}

From source file:org.nuxeo.ecm.automation.client.rest.api.RestClient.java

public RestClient(HttpAutomationClient httpAutomationClient) {
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpAutomationClient.http(),
            new BasicCookieStore(), false);
    ApacheHttpClient4 client = new ApacheHttpClient4(handler);

    if (httpAutomationClient.getRequestInterceptor() != null) {
        client.addFilter(httpAutomationClient.getRequestInterceptor());
    }/*w ww.  ja v a  2s .c om*/

    String apiURL = httpAutomationClient.getBaseUrl();
    apiURL = replaceAutomationEndpoint(apiURL);
    service = client.resource(apiURL);
}