Java Code Examples for io.vertx.core.http.HttpServerRequest#path()
The following examples show how to use
io.vertx.core.http.HttpServerRequest#path() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertxHttpServerRequest.java From graviteeio-access-management with Apache License 2.0 | 6 votes |
public VertxHttpServerRequest(HttpServerRequest httpServerRequest) { this.httpServerRequest = httpServerRequest; this.timestamp = System.currentTimeMillis(); this.id = UUID.toString(UUID.random()); this.transactionId = UUID.toString(UUID.random()); this.contextPath = httpServerRequest.path() != null ? httpServerRequest.path().split("/")[0] : null; this.metrics = Metrics.on(timestamp).build(); this.metrics.setRequestId(id()); this.metrics.setHttpMethod(method()); this.metrics.setLocalAddress(localAddress()); this.metrics.setRemoteAddress(remoteAddress()); this.metrics.setHost(httpServerRequest.host()); this.metrics.setUri(uri()); this.metrics.setUserAgent(httpServerRequest.getHeader(HttpHeaders.USER_AGENT)); }
Example 2
Source File: VertxHttpServerMetrics.java From vertx-micrometer-metrics with Apache License 2.0 | 5 votes |
@Override public Handler requestBegin(String remote, HttpServerRequest request) { Handler handler = new Handler(remote, request.path(), request.method().name()); requests.get(local, remote, handler.path, handler.method).increment(); handler.timer = processingTime.start(); return handler; }
Example 3
Source File: TestDefaultEdgeDispatcher.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testOnRequest(@Mocked Router router, @Mocked Route route , @Mocked RoutingContext context , @Mocked HttpServerRequest requst , @Mocked EdgeInvocation invocation) { DefaultEdgeDispatcher dispatcher = new DefaultEdgeDispatcher(); Map<String, String> pathParams = new HashMap<>(); pathParams.put("param0", "testService"); pathParams.put("param1", "v1"); new Expectations() { { router.routeWithRegex("/api/([^\\\\/]+)/([^\\\\/]+)/(.*)"); result = route; route.handler((Handler<RoutingContext>) any); result = route; route.failureHandler((Handler<RoutingContext>) any); result = route; context.pathParams(); result = pathParams; context.request(); result = requst; requst.path(); result = "/api/testService/v1/hello"; invocation.setVersionRule("1.0.0.0-2.0.0.0"); invocation.init("testService", context, "/testService/v1/hello", Deencapsulation.getField(dispatcher, "httpServerFilters")); invocation.edgeInvoke(); } }; dispatcher.init(router); Assert.assertEquals(dispatcher.enabled(), false); Assert.assertEquals(Utils.findActualPath("/api/test", 1), "/test"); Assert.assertEquals(dispatcher.getOrder(), 20000); dispatcher.onRequest(context); // assert done in expectations. }
Example 4
Source File: SfsHttpUtil.java From sfs with Apache License 2.0 | 5 votes |
public static String getRemoteRequestUrl(HttpServerRequest httpServerRequest) { String path = httpServerRequest.path(); String query = httpServerRequest.query(); String serviceUrl = getRemoteServiceUrl(httpServerRequest); return String.format("%s/%s%s", serviceUrl, path, query != null ? ("?" + query) : ""); }
Example 5
Source File: App.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void handle(HttpServerRequest request) { switch (request.path()) { case PATH_PLAINTEXT: handlePlainText(request); break; case PATH_JSON: handleJson(request); break; case PATH_DB: handleDb(request); break; case PATH_QUERIES: new Queries().handle(request); break; case PATH_UPDATES: new Update(request).handle(); break; case PATH_FORTUNES: handleFortunes(request); break; default: request.response().setStatusCode(404); request.response().end(); break; } }
Example 6
Source File: EchoServerVertx.java From apiman with Apache License 2.0 | 5 votes |
private String normaliseResource(HttpServerRequest req) { if (req.query() != null) { String[] normalisedQueryString = req.query().split("&"); Arrays.sort(normalisedQueryString); return req.path() + "?" + SimpleStringUtils.join("&", normalisedQueryString); } else { return req.path(); } }
Example 7
Source File: ProxyVerticle.java From quarantyne with Apache License 2.0 | 4 votes |
private void proxiedRequestHandler(HttpServerRequest frontReq, @Nullable Buffer frontReqBody) { HttpServerResponse frontRep = frontReq.response(); CaseInsensitiveStringKV frontReqHeaders = new CaseInsensitiveStringKV(frontReq.headers().entries()); // inject quarantyne headers, if any HttpRequest qReq = new HttpRequest( HttpRequestMethod.valueOf(frontReq.method().toString().toUpperCase()), frontReqHeaders, RemoteIpAddressesParser.parse(frontReqHeaders, frontReq.remoteAddress().host()), frontReq.path() ); @Nullable final HttpRequestBody qBody = getBody(qReq.getMethod(), frontReqBody, frontReq.getHeader(HttpHeaders.CONTENT_TYPE)); Set<Label> quarantyneLabels = quarantyneClassifier.classify(qReq, qBody); if (configSupplier.get().isBlocked(quarantyneLabels)) { log.info("blocking request {} because we are blocking {}", qReq.getFingerprint(), quarantyneLabels); bouncer.bounce(frontRep); } else { HttpClientRequest backReq = httpClient.request( frontReq.method(), frontReq.uri() ); backReq.headers().setAll(frontReq.headers()); backReq.headers().set(HttpHeaders.HOST, configArgs.getEgress().getHost()); backReq.headers().addAll(quarantyneCheck(quarantyneLabels)); // -------------------------------- backReq.handler(backRep -> { Buffer body = Buffer.buffer(); backRep.handler(body::appendBuffer); backRep.endHandler(h -> { // callback quarantyne with data to record, if needed quarantyneClassifier.record(new HttpResponse(backRep.statusCode()), qReq, qBody); // -------------------------------- frontRep.setStatusCode(backRep.statusCode()); frontRep.headers().setAll(backRep.headers()); frontRep.end(body); }); }); backReq.exceptionHandler(ex -> { log.error("error while querying downstream service", ex); frontRep.setStatusCode(500); frontRep.end("Internal Server Error. This request cannot be satisfied."); }); if (frontReqBody != null) { backReq.end(frontReqBody); } else { backReq.end(); } } }
Example 8
Source File: TestURLMappedEdgeDispatcher.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Test public void testConfigurations(@Mocked RoutingContext context , @Mocked HttpServerRequest requst , @Mocked EdgeInvocation invocation) { ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.enabled", true); URLMappedEdgeDispatcher dispatcher = new URLMappedEdgeDispatcher(); Map<String, URLMappedConfigurationItem> items = Deencapsulation .getField(dispatcher, "configurations"); Assert.assertEquals(items.size(), 0); new Expectations() { { context.get(RestBodyHandler.BYPASS_BODY_HANDLER); result = Boolean.TRUE; context.next(); } }; dispatcher.onRequest(context); ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.path", "/a/b/c/.*"); ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.microserviceName", "serviceName"); ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.prefixSegmentCount", 2); ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service1.versionRule", "2.0.0+"); items = Deencapsulation.getField(dispatcher, "configurations"); Assert.assertEquals(items.size(), 1); URLMappedConfigurationItem item = items.get("service1"); Assert.assertEquals(item.getMicroserviceName(), "serviceName"); Assert.assertEquals(item.getPrefixSegmentCount(), 2); Assert.assertEquals(item.getStringPattern(), "/a/b/c/.*"); Assert.assertEquals(item.getVersionRule(), "2.0.0+"); ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service2.versionRule", "2.0.0+"); ArchaiusUtils.setProperty("servicecomb.http.dispatcher.edge.url.mappings.service3.path", "/b/c/d/.*"); items = Deencapsulation.getField(dispatcher, "configurations"); Assert.assertEquals(items.size(), 1); item = items.get("service1"); Assert.assertEquals(item.getMicroserviceName(), "serviceName"); Assert.assertEquals(item.getPrefixSegmentCount(), 2); Assert.assertEquals(item.getStringPattern(), "/a/b/c/.*"); Assert.assertEquals(item.getVersionRule(), "2.0.0+"); URLMappedConfigurationItem finalItem = item; new Expectations() { { context.get(RestBodyHandler.BYPASS_BODY_HANDLER); result = Boolean.FALSE; context.get(URLMappedEdgeDispatcher.CONFIGURATION_ITEM); result = finalItem; context.request(); result = requst; requst.path(); result = "/a/b/c/d/e"; invocation.setVersionRule("2.0.0+"); invocation.init("serviceName", context, "/c/d/e", Deencapsulation.getField(dispatcher, "httpServerFilters")); invocation.edgeInvoke(); } }; dispatcher.onRequest(context); }
Example 9
Source File: HttpServerRequestAdaptor.java From pinpoint with Apache License 2.0 | 4 votes |
@Override public String getRpcName(HttpServerRequest request) { return request.path(); }