List of usage examples for io.vertx.core.http HttpServerRequest version
HttpVersion version();
From source file:io.helixservice.feature.restservice.controller.VertxRequestHandler.java
License:Open Source License
/** * Handles incoming Vert.x request, forwarding it to the appropriate controller. * * @param event Vert.x Web request context *///from w w w. ja v a2 s .c o m @Suspendable public void handle(RoutingContext event) { Request<?> request = null; RequestMetricsPublisher requestMetricsPublisher = new RequestMetricsPublisher(eventBus, path); try { HttpServerRequest vertxRequest = event.request(); requestMetricsPublisher.setHttpMethod(event.request().method().name()); request = new Request<>(vertxRequest.method().name(), vertxRequest.uri(), VertxTypeConverter.toGuavaMultimap(vertxRequest.params()), VertxTypeConverter.toGuavaMultimap(vertxRequest.headers()), unmarshalRequestBody(event), vertxRequest.remoteAddress().host(), vertxRequest.version().name()); Response response; Method method = endpoint.getEndpointMethod(); if (method != null) { response = (Response) method.invoke(endpoint.getController(), request); } else { EndpointHandler endpointHandler = this.endpoint.getEndpointHandler(); response = endpointHandler.handle(request); } //noinspection unchecked event.response().headers().addAll(VertxTypeConverter.toVertxMultiMap(response.getHeaders())); Message responseMessage = marshalResponseBody(response); Buffer responseBuffer = Buffer.buffer(responseMessage.getBody()); event.response().setChunked(true).setStatusCode(response.getHttpStatusCode()) .putHeader(CONTENT_TYPE, responseMessage.getContentTypes()).write(responseBuffer).end(); requestMetricsPublisher.setResponseSize(responseBuffer.length()); requestMetricsPublisher .setSuccess(response.getHttpStatusCode() >= 200 && response.getHttpStatusCode() <= 299); } catch (InvocationTargetException t) { int responseSize = handleErrorResponse(event, request, t.getCause()); requestMetricsPublisher.setResponseSize(responseSize); } catch (Throwable t) { int responseSize = handleErrorResponse(event, request, t); requestMetricsPublisher.setResponseSize(responseSize); } finally { requestMetricsPublisher.publish(); } }
From source file:io.helixservice.feature.restservice.filter.FilterHandler.java
License:Open Source License
private Request<byte[]> buildRequest(RoutingContext routingContext) { HttpServerRequest vertxRequest = routingContext.request(); return new Request<>(vertxRequest.method().name(), vertxRequest.uri(), VertxTypeConverter.toGuavaMultimap(vertxRequest.params()), VertxTypeConverter.toGuavaMultimap(vertxRequest.headers()), routingContext.getBody().getBytes(), vertxRequest.remoteAddress().host(), vertxRequest.version().name()); }
From source file:io.nitor.api.backend.proxy.SimpleLogProxyTracer.java
License:Apache License
String dumpSReq(HttpServerRequest req, String indent) { return "\n\t" + indent + req.method().name() + " " + req.uri() + " " + req.version().name() + dumpHeaders(req.headers(), "\t" + indent); }
From source file:org.apache.servicecomb.transport.rest.vertx.accesslog.element.impl.RequestProtocolItem.java
License:Apache License
@Override public String getFormattedItem(AccessLogParam<RoutingContext> accessLogParam) { HttpServerRequest request = accessLogParam.getContextData().request(); if (null == request) { return EMPTY_RESULT; }//from w w w. j a v a2 s . c om if (null == request.version()) { return EMPTY_RESULT; } return getStringVersion(request.version()); }
From source file:org.sfs.util.HttpServerRequestHeaderToJsonObject.java
License:Apache License
public static JsonObject call(HttpServerRequest httpServerRequest) { JsonObject jsonObject = new JsonObject(); String query = httpServerRequest.query(); String requestLine = String.format("%s %s%s %s", httpServerRequest.method(), httpServerRequest.path(), query != null ? '?' + query : "", httpServerRequest.version().toString()); jsonObject.put("request_line", requestLine); MultiMap headers = httpServerRequest.headers(); JsonArray jsonHeaders = new JsonArray(); for (String headerName : headers.names()) { List<String> values = headers.getAll(headerName); JsonObject jsonHeader = new JsonObject(); jsonHeader.put(headerName, values); jsonHeaders.add(jsonHeader);/*from w w w . j a v a2 s . c o m*/ } jsonObject.put("headers", jsonHeaders); return jsonObject; }
From source file:org.wisdom.framework.vertx.HttpUtils.java
License:Apache License
/** * Checks whether the given request should be closed or not once completed. * * @param request the request/*w w w .j a v a 2 s. c om*/ * @return {@code true} if the connection is marked as {@literal keep-alive}, and so must not be closed. {@code * false} otherwise. Notice that if not set in the request, the default value depends on the HTTP version. */ public static boolean isKeepAlive(HttpServerRequest request) { String connection = request.headers().get(HeaderNames.CONNECTION); if (connection != null && connection.equalsIgnoreCase(CLOSE)) { return false; } if (request.version() == HttpVersion.HTTP_1_1) { return !CLOSE.equalsIgnoreCase(connection); } else { return KEEP_ALIVE.equalsIgnoreCase(connection); } }