Example usage for io.vertx.core.http HttpClient getAbs

List of usage examples for io.vertx.core.http HttpClient getAbs

Introduction

In this page you can find the example usage for io.vertx.core.http HttpClient getAbs.

Prototype

HttpClientRequest getAbs(String absoluteURI);

Source Link

Document

Create an HTTP GET request to send to the server using an absolute URI

Usage

From source file:examples.HTTPExamples.java

License:Open Source License

public void exampleFollowRedirect03(HttpClient client) {

    client.redirectHandler(response -> {

        // Only follow 301 code
        if (response.statusCode() == 301 && response.getHeader("Location") != null) {

            // Compute the redirect URI
            String absoluteURI = resolveURI(response.request().absoluteURI(), response.getHeader("Location"));

            // Create a new ready to use request that the client will use
            return Future.succeededFuture(client.getAbs(absoluteURI));
        }/*from   ww w  .j a  v  a 2  s. com*/

        // We don't redirect
        return null;
    });
}

From source file:io.nitor.api.backend.auth.SetupAzureAdConnectAuth.java

License:Apache License

static void processGraphTokenResponse(HttpClientResponse resp, RoutingContext ctx, HttpClient httpClient,
        CookieSessionHandler sessionHandler, List<GraphQuery> graphQueries, String originalUrl) {
    if (resp.statusCode() != OK.code()) {
        resp.bodyHandler(body -> {/*  w  ww .  j a v a 2s  .co m*/
            logger.warn("Failed to fetch graph access token: " + resp.statusMessage() + " - "
                    + resp.getHeader(WWW_AUTHENTICATE) + " ::: " + body);
            ctx.reroute(GET, UNAUTHORIZED_PATH);
        });
        return;
    }
    resp.bodyHandler(body -> {
        JsonObject json = body.toJsonObject();
        String token = json.getString("access_token");
        String refreshToken = json.getString("refresh_token");
        // clean out sensitive stuff
        json.put("access_token", "<censored>");
        json.put("refresh_token", "<censored>");

        logger.debug("Got graph access response: {}", json);
        final AtomicInteger pendingRequests = new AtomicInteger(graphQueries.size());
        final Map<String, String> sessionData = new HashMap<>();
        ofNullable(refreshToken).ifPresent(t -> sessionData.put(GRAPH_ACCESS_TOKEN_KEY, t));
        for (GraphQuery query : graphQueries) {
            String clientRequestId = UUID.randomUUID().toString();
            logger.debug("Requesting " + query.graphQueryURI + "[" + clientRequestId + "]");
            httpClient.getAbs(query.graphQueryURI).putHeader(AUTHORIZATION, "Bearer " + token)
                    .putHeader(ACCEPT, APPLICATION_JSON).putHeader("client-request-id", clientRequestId)
                    .setTimeout(SECONDS.toMillis(10)).exceptionHandler(err -> {
                        if (pendingRequests.getAndSet(-1) != -1) {
                            logger.error("Failed to fetch user information [" + clientRequestId + "]", err);
                            ctx.reroute(GET, UNAUTHORIZED_PATH);
                        }
                    }).handler(r -> processMicrosoftUserInformation(r, ctx, sessionHandler,
                            query.headerMappings, originalUrl, pendingRequests, sessionData, clientRequestId))
                    .end();
        }
    });
}