Example usage for io.vertx.core.http HttpClientResponse statusCode

List of usage examples for io.vertx.core.http HttpClientResponse statusCode

Introduction

In this page you can find the example usage for io.vertx.core.http HttpClientResponse statusCode.

Prototype

int statusCode();

Source Link

Usage

From source file:com.cyngn.vertx.opentsdb.spi.HttpClientMetricsImpl.java

License:Apache License

@Override
public void responseEnd(HttpMetric requestMetric, HttpClientResponse response) {
    requestMetric.queueMetrics(requests, response.statusCode());
}

From source file:com.hpe.sw.cms.verticle.ScanVerticle.java

License:Apache License

private void processImage(String dricHost, String reigstryHost, String image, String tag) throws Exception {
    final String swarmProtocol = config().getString("swarm.protocol");
    final String swarmHost = config().getString("swarm.host");

    JsonObject hostConfig = new JsonObject();
    hostConfig.put("Privileged", true);

    JsonObject restartPolicy = new JsonObject();
    restartPolicy.put("Name", "no");

    JsonObject createContinaerJson = new JsonObject();
    createContinaerJson.put("AttachStdin", true);
    createContinaerJson.put("AttachStdout", true);
    createContinaerJson.put("AttachStderr", true);
    createContinaerJson.put("Tty", true);
    createContinaerJson.put("OpenStdin", true);
    createContinaerJson.put("StdinOnce", true);
    JsonArray cmds = new JsonArray();
    cmds.add("-l=file").add(dricHost).add(reigstryHost).add(image).add(tag);
    createContinaerJson.put("Cmd", cmds);
    createContinaerJson.put("Image", config().getString("swarm.scan.image"));
    createContinaerJson.put("StopSignal", "SIGTERM");
    createContinaerJson.put("", true);

    hostConfig.put("RestartPolicy", restartPolicy);
    createContinaerJson.put("HostConfig", hostConfig);

    httpClient.postAbs(swarmProtocol + swarmHost + "/containers/create", new Handler<HttpClientResponse>() {
        @Override/*from  w w  w .  j  a va2s.  com*/
        public void handle(HttpClientResponse event) {
            event.bodyHandler(new Handler<Buffer>() {
                @Override
                public void handle(Buffer buffer) {
                    JsonObject retVal = buffer.toJsonObject();
                    String containerId = retVal.getString("Id");
                    getVertx().sharedData().getLocalMap("scanContainerIds").put(containerId, containerId);
                    httpClient.postAbs(swarmProtocol + swarmHost + "/containers/" + containerId + "/start",
                            new Handler<HttpClientResponse>() {
                                @Override
                                public void handle(HttpClientResponse event) {
                                    LOG.info("start container with response code :" + event.statusCode());
                                }
                            }).end();
                }
            });
        }
    }).putHeader("content-type", "application/json")
            .putHeader("content-length", String.valueOf(createContinaerJson.toString().length()))
            .write(createContinaerJson.toString()).end();
}

From source file:com.hubrick.vertx.rest.impl.DefaultRestClientRequest.java

License:Apache License

private void handleResponse(HttpClientResponse httpClientResponse, Class clazz) {
    final Integer firstStatusDigit = httpClientResponse.statusCode() / 100;
    if (firstStatusDigit == 4 || firstStatusDigit == 5) {
        httpClientResponse.bodyHandler((buffer) -> {
            httpClientResponse.exceptionHandler(null);
            if (log.isWarnEnabled()) {
                final String body = new String(buffer.getBytes(), Charsets.UTF_8);
                log.warn("Http request to {} FAILED. Return status: {}, message: {}, body: {}", new Object[] {
                        uri, httpClientResponse.statusCode(), httpClientResponse.statusMessage(), body });
            }/*  ww w . j  av  a2s.c  o m*/

            RuntimeException exception = null;
            switch (firstStatusDigit) {
            case 4:
                exception = new HttpClientErrorException(httpClientResponse, httpMessageConverters,
                        buffer.getBytes());
                break;
            case 5:
                exception = new HttpServerErrorException(httpClientResponse, httpMessageConverters,
                        buffer.getBytes());
                break;
            }
            handleException(exception);
        });
    } else {
        httpClientResponse.bodyHandler((buffer) -> {
            httpClientResponse.exceptionHandler(null);
            if (log.isDebugEnabled()) {
                final String body = new String(buffer.getBytes(), Charsets.UTF_8);
                log.debug("Http request to {} {} SUCCESSFUL. Return status: {}, message: {}, body: {}",
                        new Object[] { method, uri, httpClientResponse.statusCode(),
                                httpClientResponse.statusMessage(), body });
            }

            final RestClientResponse<T> restClientResponse = new DefaultRestClientResponse(
                    httpMessageConverters, clazz, buffer.getBytes(), httpClientResponse, exceptionHandler);

            handleResponse(restClientResponse);
        });
    }
}

From source file:fr.wseduc.smsproxy.providers.ovh.OVHSmsProvider.java

License:Apache License

private void retrieveSmsService(final Message<JsonObject> message, final Handler<String> callBack) {
    ovhRestClient.get("/sms/", new JsonObject(), new Handler<HttpClientResponse>() {
        public void handle(final HttpClientResponse response) {
            logger.debug("[OVH][retrieveSmsService] /sms/ call returned : " + response);
            if (response == null) {
                logger.error("[OVH][retrieveSmsService] /sms/ call response is null.");
                sendError(message, "ovh.apicall.error", null);
                return;
            }// ww w . java  2s.  co  m
            response.bodyHandler(new Handler<Buffer>() {
                public void handle(Buffer body) {
                    if (response.statusCode() == 200) {
                        logger.debug("[OVH][retrieveSmsService] Ok with body : " + body);
                        JsonArray smsServices = new JsonArray(body.toString("UTF-8"));
                        callBack.handle(smsServices.getString(0));
                    } else {
                        logger.error("[OVH][retrieveSmsService] /sms/ reponse code [" + response.statusCode()
                                + "] : " + body.toString("UTF-8"));
                        sendError(message, body.toString("UTF-8"), null);
                    }
                }
            });
        }
    });
}

From source file:io.advantageous.qbit.vertx.http.client.HttpVertxClient.java

License:Apache License

private void handleResponse(final HttpRequest request, final HttpClientResponse httpClientResponse) {
    final int statusCode = httpClientResponse.statusCode();
    final MultiMap<String, String> headers = httpClientResponse.headers().size() == 0 ? MultiMap.empty()
            : new MultiMapWrapper(httpClientResponse.headers());

    if (debug) {/*from   w w w .  ja v a2 s . c  o m*/
        responseCount++;
        puts("status code", httpClientResponse.statusCode(), responseCount);
    }

    httpClientResponse.bodyHandler(buffer -> {

        if (request.getReceiver().isText()) {
            final String body = buffer.toString("UTF-8");

            if (debug) {
                puts("got body", "BODY");
            }

            handleResponseFromServer(request, statusCode, headers, body);
        } else {
            final byte[] body = buffer.getBytes();
            handleResponseFromServerBytes(request, statusCode, headers, body);

        }
    });
}

From source file:io.apiman.gateway.platforms.vertx3.http.HttpApiFactory.java

License:Apache License

public static ApiResponse buildResponse(HttpClientResponse response, Set<String> suppressHeaders) {
    ApiResponse apimanResponse = new ApiResponse();
    apimanResponse.setCode(response.statusCode());
    apimanResponse.setMessage(response.statusMessage());
    multimapToMap(apimanResponse.getHeaders(), response.headers(), suppressHeaders);
    return apimanResponse;
}

From source file:io.apiman.gateway.platforms.vertx3.http.HttpServiceFactory.java

License:Apache License

public static VertxServiceResponse buildResponse(HttpClientResponse response, Set<String> suppressHeaders) {
    VertxServiceResponse apimanResponse = new VertxServiceResponse();
    apimanResponse.setCode(response.statusCode());
    apimanResponse.setMessage(response.statusMessage());
    multimapToMap(apimanResponse.getHeaders(), response.headers(), suppressHeaders);
    return apimanResponse;
}

From source file:io.gravitee.gateway.http.connector.VertxProxyResponse.java

License:Apache License

VertxProxyResponse(final HttpClientResponse httpClientResponse) {
    this.httpClientResponse = httpClientResponse;
    this.status = httpClientResponse.statusCode();
}

From source file:io.gravitee.gateway.http.vertx.VertxHttpClient.java

License:Apache License

private void handleClientResponse(HttpClientResponse clientResponse,
        Handler<ClientResponse> clientResponseHandler) {
    VertxClientResponse proxyClientResponse = new VertxClientResponse(clientResponse.statusCode());

    // Copy HTTP headers
    clientResponse.headers().names().forEach(headerName -> proxyClientResponse.headers().put(headerName,
            clientResponse.headers().getAll(headerName)));

    // Copy body content
    clientResponse.handler(event -> proxyClientResponse.bodyHandler().handle(Buffer.buffer(event.getBytes())));

    // Signal end of the response
    clientResponse.endHandler(v -> proxyClientResponse.endHandler().handle(null));

    clientResponseHandler.handle(proxyClientResponse);
}

From source file:io.gravitee.gateway.services.healthcheck.http.el.EvaluableHttpResponse.java

License:Apache License

public EvaluableHttpResponse(final HttpClientResponse response, final String content) {
    this.statusCode = response.statusCode();
    this.content = content;

    // Copy HTTP headers
    response.headers().names()// w  w w .  j a v  a2  s.c  om
            .forEach(headerName -> httpHeaders.put(headerName, response.headers().getAll(headerName)));
}