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:com.adavr.http.Client.java

public Client() {
    httpClient = new DefaultHttpClient(new BasicClientConnectionManager());
    localContext = new BasicHttpContext();
    byteStream = new ByteArrayOutputStream();

    CookieStore cookieStore = new BasicCookieStore();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    httpClient.addRequestInterceptor(new HttpRequestInterceptor() {

        @Override/*from   w w  w . j av  a  2  s.  c  o m*/
        public void process(final HttpRequest request, final HttpContext context)
                throws HttpException, IOException {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip");
            }
        }
    });

    httpClient.addResponseInterceptor(new HttpResponseInterceptor() {

        @Override
        public void process(final HttpResponse response, final HttpContext context)
                throws HttpException, IOException {
            HttpEntity entity = response.getEntity();
            Header ceheader = entity.getContentEncoding();
            if (ceheader != null) {
                HeaderElement[] codecs = ceheader.getElements();
                for (HeaderElement codec : codecs) {
                    if (codec.getName().equalsIgnoreCase("gzip")) {
                        response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                        return;
                    }
                }
            }
        }
    });

    httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT);
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, DEFAULT_USER_AGENT);
    HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {

        @Override
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            if (executionCount >= DEFAULT_RETRY) {
                // Do not retry if over max retry count
                return false;
            }
            System.out.println(exception.getClass().getName());
            if (exception instanceof NoHttpResponseException) {
                // Retry if the server dropped connection on us
                return true;
            }
            if (exception instanceof SSLHandshakeException) {
                // Do not retry on SSL handshake exception
                return false;
            }
            HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
            boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
            if (idempotent) {
                // Retry if the request is considered idempotent
                return true;
            }
            return false;
        }
    };

    httpClient.setHttpRequestRetryHandler(myRetryHandler);
}

From source file:com.falcon.orca.actors.Generator.java

public Generator(final ActorRef collector, final String url, final HttpMethods method, final byte[] data,
        final List<Header> headers, final List<Cookie> cookies, final boolean isBodyDynamic,
        final boolean isUrlDynamic, final DynDataStore dataStore)
        throws URISyntaxException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
    this.collector = collector;
    this.dataStore = dataStore;
    this.isBodyDynamic = isBodyDynamic;
    this.method = method;
    this.url = url;
    this.headers = headers;
    this.staticRequestData = data != null ? Arrays.copyOf(data, data.length) : new byte[0];

    this.isUrlDynamic = isUrlDynamic;
    CookieStore cookieStore = new BasicCookieStore();
    if (cookies != null) {
        cookies.forEach(cookieStore::addCookie);
    }/*from   w  ww.  j  a va  2  s .  c o m*/
    TrustStrategy trustStrategy = (x509Certificates, s) -> true;
    SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(null, trustStrategy).build();
    this.client = HttpClientBuilder.create().setSSLContext(sslContext)
            .setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build();
}

From source file:co.paralleluniverse.comsat.webactors.AbstractWebActorTest.java

@Test
public void testWebSocketMsg()
        throws IOException, InterruptedException, ExecutionException, DeploymentException {
    BasicCookieStore cookieStore = new BasicCookieStore();
    final HttpGet httpGet = new HttpGet("http://localhost:8080");
    HttpClients.custom().setDefaultRequestConfig(requestConfig).setDefaultCookieStore(cookieStore).build()
            .execute(httpGet, new BasicResponseHandler());

    final SettableFuture<String> res = new SettableFuture<>();
    final WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
    wsContainer.setAsyncSendTimeout(timeout);
    wsContainer.setDefaultMaxSessionIdleTimeout(timeout);
    try (final Session ignored = wsContainer.connectToServer(sendAndGetTextEndPoint("test it", res),
            getClientEndPointConfig(cookieStore), URI.create("ws://localhost:8080/ws"))) {
        final String s = res.get();
        assertEquals("test it", s);
    }/*from  w  w  w .  j av a  2  s .c  om*/
}

From source file:org.xdi.oxauth.interop.SupportClaimsRequestSpecifyingSubValue.java

@Parameters({ "userId", "userSecret", "redirectUri", "redirectUris", "hostnameVerifier" })
@Test/*from  w w  w  .  ja v a  2 s  .c  om*/
public void supportClaimsRequestSpecifyingSubValueSucceed(final String userId, final String userSecret,
        final String redirectUri, final String redirectUris, String hostnameVerifier) throws Exception {
    showTitle("OC5:FeatureTest-Support claims Request Specifying sub Value (succeed)");

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);

    // 1. Register client
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setResponseTypes(responseTypes);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();

    showClient(registerClient);
    assertEquals(registerResponse.getStatus(), 200,
            "Unexpected response code: " + registerResponse.getEntity());
    assertNotNull(registerResponse.getClientId());
    assertNotNull(registerResponse.getClientSecret());
    assertNotNull(registerResponse.getRegistrationAccessToken());
    assertNotNull(registerResponse.getClientIdIssuedAt());
    assertNotNull(registerResponse.getClientSecretExpiresAt());

    String clientId = registerResponse.getClientId();
    String clientSecret = registerResponse.getClientSecret();

    DefaultHttpClient httpClient = createHttpClient(HostnameVerifierType.fromString(hostnameVerifier));
    CookieStore cookieStore = new BasicCookieStore();
    httpClient.setCookieStore(cookieStore);
    ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);

    List<String> scopes = Arrays.asList("openid", "email");
    String nonce = UUID.randomUUID().toString();
    String state = UUID.randomUUID().toString();

    // 2. Request authorization (first time)
    AuthorizationRequest authorizationRequest1 = new AuthorizationRequest(responseTypes, clientId, scopes,
            redirectUri, nonce);
    authorizationRequest1.setAuthUsername(userId);
    authorizationRequest1.setAuthPassword(userSecret);
    authorizationRequest1.getPrompts().add(Prompt.NONE);
    authorizationRequest1.setState(state);

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

    assertNotNull(authorizationResponse1.getLocation(), "The location is null");
    assertNotNull(authorizationResponse1.getIdToken(), "The ID Token is null");
    assertNotNull(authorizationResponse1.getAccessToken(), "The Access Token is null");
    assertNotNull(authorizationResponse1.getState(), "The state is null");
    assertNotNull(authorizationResponse1.getScope(), "The scope is null");

    String sessionId = authorizationResponse1.getSessionId();

    // 3. Request authorization
    AuthorizationRequest authorizationRequest2 = new AuthorizationRequest(responseTypes, clientId, scopes,
            redirectUri, nonce);
    //authorizationRequest2.setAuthUsername(userId);
    //authorizationRequest2.setAuthPassword(userSecret);
    authorizationRequest2.getPrompts().add(Prompt.NONE);
    authorizationRequest2.setState(state);
    authorizationRequest2.setSessionId(sessionId);

    JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest2,
            SignatureAlgorithm.HS256, clientSecret);
    jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.GIVEN_NAME, ClaimValue.createNull()));
    jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.FAMILY_NAME, ClaimValue.createNull()));
    jwtAuthorizationRequest
            .addIdTokenClaim(new Claim(JwtClaimName.SUBJECT_IDENTIFIER, ClaimValue.createSingleValue(userId)));

    String authJwt = jwtAuthorizationRequest.getEncodedJwt();
    authorizationRequest2.setRequest(authJwt);

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

    assertNotNull(authorizationResponse2.getLocation(), "The location is null");
    assertNotNull(authorizationResponse2.getAccessToken(), "The accessToken is null");
    assertNotNull(authorizationResponse2.getTokenType(), "The tokenType is null");
    assertNotNull(authorizationResponse2.getIdToken(), "The idToken is null");
    assertNotNull(authorizationResponse2.getState(), "The state is null");

    String idToken = authorizationResponse2.getIdToken();
    String accessToken = authorizationResponse2.getAccessToken();

    // 4. Validate id_token
    Jwt jwt = Jwt.parse(idToken);
    assertNotNull(jwt.getHeader().getClaimAsString(JwtHeaderName.TYPE));
    assertNotNull(jwt.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ISSUER));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.AUDIENCE));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.ACCESS_TOKEN_HASH));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.AUTHENTICATION_TIME));
    assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.EMAIL));

    RSAPublicKey publicKey = JwkClient.getRSAPublicKey(jwksUri,
            jwt.getHeader().getClaimAsString(JwtHeaderName.KEY_ID));
    RSASigner rsaSigner = new RSASigner(SignatureAlgorithm.RS256, publicKey);

    assertTrue(rsaSigner.validate(jwt));

    // 5. Request user info
    UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint);
    UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken);

    showClient(userInfoClient);
    assertEquals(userInfoResponse.getStatus(), 200,
            "Unexpected response code: " + userInfoResponse.getStatus());
    assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER));
    assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL));
    assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME));
    assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME));
}

From source file:io.vertigo.struts2.FileDownloader4Tests.java

/**
 * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
 *
 * @param seleniumCookieSet//from   w w  w  . j a  va 2  s  . c om
 * @return BasicCookieStore
 */
private static BasicCookieStore mimicCookieState(final Set<Cookie> seleniumCookieSet) {
    final BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
    for (final Cookie seleniumCookie : seleniumCookieSet) {
        final BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookieStore.addCookie(duplicateCookie);
    }

    return mimicWebDriverCookieStore;
}

From source file:org.obm.sync.ServicesClientModule.java

@Override
protected void configure() {
    logger = LoggerFactory.getLogger(ObmSyncIntegrationTest.class);
    configuration = new ObmSyncConfiguration(new Configuration(), new Configuration.ObmSync());
    exceptionFactory = new SyncClientAssert();
    cookieStore = new BasicCookieStore();
    httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();

    bind(String.class).annotatedWith(Names.named("origin")).toInstance("integration-testing");
    bind(Logger.class).annotatedWith(Names.named(LoggerModule.OBM_SYNC)).toInstance(logger);
    bind(ConfigurationService.class).toInstance(configuration);
    bind(DomainConfiguration.class).toInstance(configuration);
    bind(LocatorConfiguration.class).toInstance(configuration);
    bind(CloseableHttpClient.class).toInstance(httpClient);
    bind(LocatorService.class).to(ArquillianLocatorService.class);
}

From source file:com.emc.storageos.driver.dellsc.scapi.rest.RestClient.java

/**
 * Instantiates a new Rest client./* www  . j  a  va2 s . com*/
 *
 * @param host Host name or IP address of the Dell Storage Manager server.
 * @param port Port the DSM data collector is listening on.
 * @param user The DSM user name to use.
 * @param password The DSM password.
 */
public RestClient(String host, int port, String user, String password) {
    this.baseUrl = String.format("https://%s:%d/api/rest", host, port);

    try {
        // Set up auth handling
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(host, port),
                new UsernamePasswordCredentials(user, password));
        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        HttpHost target = new HttpHost(host, port, "https");
        authCache.put(target, basicAuth);

        // Set up our context
        httpContext = HttpClientContext.create();
        httpContext.setCookieStore(new BasicCookieStore());
        httpContext.setAuthCache(authCache);

        // Create our HTTPS client
        SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                return true;
            }
        }).build();

        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext,
                SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        this.httpClient = HttpClients.custom().setHostnameVerifier(new AllowAllHostnameVerifier())
                .setDefaultCredentialsProvider(credsProvider).setSSLSocketFactory(sslSocketFactory).build();
    } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
        // Hopefully default SSL handling is set up
        LOG.warn("Failed to configure HTTP handling, falling back to default handler.");
        LOG.debug("Config error: {}", e);
        this.httpClient = HttpClients.createDefault();
    }
}

From source file:biz.mosil.webtools.MosilWeb.java

/**
 * Constructor//from  ww w .  j  a v a  2s.com
 * */
public MosilWeb(Context _context) {
    mHostName = "";
    mContext = _context;

    mHttpContext = new BasicHttpContext();
    mHttpContext.setAttribute(ClientContext.COOKIE_STORE, new BasicCookieStore());

    mHttpParams = new BasicHttpParams();
    mHttpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
    HttpConnectionParams.setConnectionTimeout(mHttpParams, MosilWebConf.CONNECT_TIME);
    HttpConnectionParams.setSoTimeout(mHttpParams, MosilWebConf.SOCKET_TIME);
}

From source file:com.phonty.improved.Balance.java

public String get() {
    StringBuilder builder = new StringBuilder();
    String value = "0";

    CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(Login.SESSION_COOKIE);
    client.setCookieStore(cookieStore);/*from   ww  w  .jav  a 2s .c  o  m*/

    try {
        String locale = context.getResources().getConfiguration().locale.getCountry();
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("locale", locale));
        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = client.execute(httppost);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
                value = Parse(line);
                this.VALUE = value;
            }
        } else {
            this.VALUE = "0.0";
        }

    } catch (ClientProtocolException e) {
        this.VALUE = "0.0";
        e.printStackTrace();
    } catch (IOException e) {
        this.VALUE = "0.0";
        e.printStackTrace();
    }

    return value;
}

From source file:org.xdi.oxauth.ws.rs.SSOWithMultipleBackendServicesHttpTest.java

@Parameters({ "redirectUris", "userId", "userSecret", "redirectUri", "hostnameVerifier" })
@Test//from  w  w  w . j  ava  2s .c o  m
public void sessionWorkFlow1(final String redirectUris, final String userId, final String userSecret,
        final String redirectUri, String hostnameVerifier) throws Exception {
    showTitle("sessionWorkFlow1");

    // Register client
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();

    showClient(registerClient);
    assertEquals(registerResponse.getStatus(), 200,
            "Unexpected response code: " + registerResponse.getEntity());
    assertNotNull(registerResponse.getClientId());
    assertNotNull(registerResponse.getClientSecret());
    assertNotNull(registerResponse.getRegistrationAccessToken());
    assertNotNull(registerResponse.getClientIdIssuedAt());
    assertNotNull(registerResponse.getClientSecretExpiresAt());

    String clientId = registerResponse.getClientId();
    String clientSecret = registerResponse.getClientSecret();

    DefaultHttpClient httpClient = createHttpClient(HostnameVerifierType.fromString(hostnameVerifier));
    CookieStore cookieStore = new BasicCookieStore();
    httpClient.setCookieStore(cookieStore);
    ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);

    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);
    assertEquals(authorizationResponse1.getStatus(), 302,
            "Unexpected response code: " + authorizationResponse1.getStatus());
    assertNotNull(authorizationResponse1.getLocation(), "The location is null");
    assertNotNull(authorizationResponse1.getCode(), "The authorization code is null");
    assertNotNull(authorizationResponse1.getSessionId(), "The sessionId is null");
    assertNotNull(authorizationResponse1.getState(), "The state is null");
    assertNotNull(authorizationResponse1.getScope(), "The scope is null");

    String code1 = authorizationResponse1.getCode();
    String sessionId = authorizationResponse1.getSessionId();

    // 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);

    showClient(tokenClient1);
    assertEquals(tokenResponse1.getStatus(), 200, "Unexpected response code: " + tokenResponse1.getStatus());
    assertNotNull(tokenResponse1.getEntity(), "The entity is null");
    assertNotNull(tokenResponse1.getAccessToken(), "The access token is null");
    assertNotNull(tokenResponse1.getExpiresIn(), "The expires in value is null");
    assertNotNull(tokenResponse1.getTokenType(), "The token type is null");
    assertNotNull(tokenResponse1.getRefreshToken(), "The refresh token is null");

    String accessToken1 = tokenResponse1.getAccessToken();

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

    showClient(userInfoClient1);
    assertEquals(userInfoResponse1.getStatus(), 200,
            "Unexpected response code: " + userInfoResponse1.getStatus());
    assertNotNull(userInfoResponse1.getClaim(JwtClaimName.SUBJECT_IDENTIFIER),
            "Unexpected result: subject not found");
    assertNotNull(userInfoResponse1.getClaim(JwtClaimName.NAME), "Unexpected result: name not found");
    assertNotNull(userInfoResponse1.getClaim(JwtClaimName.GIVEN_NAME),
            "Unexpected result: given_name not found");
    assertNotNull(userInfoResponse1.getClaim(JwtClaimName.FAMILY_NAME),
            "Unexpected result: family_name not found");
    assertNotNull(userInfoResponse1.getClaim(JwtClaimName.EMAIL), "Unexpected result: email not found");

    ////////////////////////////////////////////////
    //             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);
    assertEquals(authorizationResponse2.getStatus(), 302,
            "Unexpected response code: " + authorizationResponse2.getStatus());
    assertNotNull(authorizationResponse2.getLocation(), "The location is null");
    assertNotNull(authorizationResponse2.getCode(), "The authorization code is null");
    assertNotNull(authorizationResponse2.getState(), "The state is null");
    assertNotNull(authorizationResponse2.getScope(), "The scope is null");

    String code2 = authorizationResponse2.getCode();

    // 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);

    showClient(tokenClient2);
    assertEquals(tokenResponse2.getStatus(), 200, "Unexpected response code: " + tokenResponse2.getStatus());
    assertNotNull(tokenResponse2.getEntity(), "The entity is null");
    assertNotNull(tokenResponse2.getAccessToken(), "The access token is null");
    assertNotNull(tokenResponse2.getExpiresIn(), "The expires in value is null");
    assertNotNull(tokenResponse2.getTokenType(), "The token type is null");
    assertNotNull(tokenResponse2.getRefreshToken(), "The refresh token is null");

    String accessToken2 = tokenResponse2.getAccessToken();

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

    showClient(userInfoClient2);
    assertEquals(userInfoResponse2.getStatus(), 200,
            "Unexpected response code: " + userInfoResponse2.getStatus());
    assertNotNull(userInfoResponse2.getClaim(JwtClaimName.SUBJECT_IDENTIFIER),
            "Unexpected result: subject not found");
    assertNotNull(userInfoResponse2.getClaim(JwtClaimName.NAME), "Unexpected result: name not found");
    assertNotNull(userInfoResponse2.getClaim(JwtClaimName.GIVEN_NAME),
            "Unexpected result: given_name not found");
    assertNotNull(userInfoResponse2.getClaim(JwtClaimName.FAMILY_NAME),
            "Unexpected result: family_name not found");
    assertNotNull(userInfoResponse2.getClaim(JwtClaimName.EMAIL), "Unexpected result: email not found");
}