Java Code Examples for io.vertx.core.http.HttpMethod#GET

The following examples show how to use io.vertx.core.http.HttpMethod#GET . 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: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private boolean checkHttpMethod(RoutingContext routingContext, FunctionInvoker invoker) {
    if (invoker.hasInput()) {
        if (routingContext.request().method() != HttpMethod.POST) {
            routingContext.fail(405);
            log.error("Must be POST for: " + invoker.getName());
            return false;
        }
    }
    if (routingContext.request().method() != HttpMethod.POST && routingContext.request().method() != HttpMethod.GET) {
        routingContext.fail(405);
        log.error("Must be POST or GET for: " + invoker.getName());
        return false;

    }
    return true;
}
 
Example 2
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private boolean checkHttpMethod(RoutingContext routingContext, FunctionInvoker invoker) {
    if (invoker.hasInput()) {
        if (routingContext.request().method() != HttpMethod.POST) {
            routingContext.fail(405);
            log.error("Must be POST for: " + invoker.getName());
            return false;
        }
    }
    if (routingContext.request().method() != HttpMethod.POST && routingContext.request().method() != HttpMethod.GET) {
        routingContext.fail(405);
        log.error("Must be POST or GET for: " + invoker.getName());
        return false;

    }
    return true;
}
 
Example 3
Source File: AbstractParameterResolver.java    From festival with Apache License 2.0 5 votes vote down vote up
protected MultiMap resolveParams(RoutingContext routingContext) {
    Map<String, String> pathParams = routingContext.pathParams();
    if (routingContext.request().method() == HttpMethod.GET) {
        return routingContext.queryParams().addAll(pathParams);
    } else {
        HttpServerRequest httpServerRequest = routingContext.request();
        return httpServerRequest.formAttributes().addAll(pathParams);
    }
}
 
Example 4
Source File: UserController.java    From festival with Apache License 2.0 5 votes vote down vote up
@PermitAll
@RouteMapping(value = "/hello", method = HttpMethod.GET, timeout = 1000)
public void hello(RoutingContext routingContext) {
    routingContext.response()
            .putHeader("content-type", "text/plain")
            .end("Hello World from Vert.x-Web!");
}
 
Example 5
Source File: UserController.java    From festival with Apache License 2.0 5 votes vote down vote up
@PermitAll
@RouteMapping(value = "/hello", method = HttpMethod.GET, timeout = 1000)
public void hello(RoutingContext routingContext) {
    routingContext.response()
            .putHeader("content-type", "text/plain")
            .end("Hello World from Vert.x-Web!");
}
 
Example 6
Source File: AbstractHttpMessageHandler.java    From festival with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] handle(RoutingContext routingContext, Parameter[] parameters) throws Exception {
    HttpServerRequest httpServerRequest = routingContext.request();
    HttpMethod httpMethod = httpServerRequest.method();
    if (httpMethod == HttpMethod.GET || httpMethod == HttpMethod.POST
            || httpMethod == HttpMethod.PUT || httpMethod == HttpMethod.DELETE) {
        return doHandle(routingContext, parameters);
    }
    return new Object[0];
}
 
Example 7
Source File: VertxWebSocketReactorHandler.java    From gravitee-gateway with Apache License 2.0 5 votes vote down vote up
private boolean isWebSocket(HttpServerRequest httpServerRequest) {
    String connectionHeader = httpServerRequest.getHeader(HttpHeaders.CONNECTION);
    String upgradeHeader = httpServerRequest.getHeader(HttpHeaders.UPGRADE);

    return httpServerRequest.method() == HttpMethod.GET &&
            HttpHeaderValues.UPGRADE.contentEqualsIgnoreCase(connectionHeader) &&
            HttpHeaderValues.WEBSOCKET.contentEqualsIgnoreCase(upgradeHeader);
}
 
Example 8
Source File: MyDeclarativeRoutes.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Route(path = "/hello", methods = HttpMethod.GET)
public void greetings(RoutingContext rc) {
    String name = rc.request().getParam("name");
    if (name == null) {
        name = "world";
    }
    rc.response().end("hello " + name);
}
 
Example 9
Source File: Request.java    From NetDiscovery with Apache License 2.0 5 votes vote down vote up
public Request(String url, String spiderName) {

        this.url = url;
        try {
            this.urlParser = new URLParser(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        this.spiderName = spiderName;
        this.httpMethod = HttpMethod.GET;
        autoUA();
    }
 
Example 10
Source File: TestVertxClientRequestToHttpServletRequest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void getMethod() {
  new Expectations() {
    {
      clientRequest.method();
      result = HttpMethod.GET;
    }
  };

  Assert.assertEquals("GET", request.getMethod());
}
 
Example 11
Source File: TestVertxServerRequestToHttpServletRequest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetMethod() {
  new Expectations() {
    {
      vertxRequest.method();
      result = HttpMethod.GET;
    }
  };

  Assert.assertEquals("GET", request.getMethod());
}
 
Example 12
Source File: Request.java    From NetDiscovery with Apache License 2.0 5 votes vote down vote up
public Request(String url) {

        this.url = url;
        try {
            this.urlParser = new URLParser(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        this.httpMethod = HttpMethod.GET;
        autoUA();
    }
 
Example 13
Source File: RouteBuilder.java    From vxms with Apache License 2.0 4 votes vote down vote up
public static RouteBuilder get(String path, RestHandlerConsumer methodReference, String... consumes) {
    return new RouteBuilder(
            new MethodDescriptor(HttpMethod.GET, path, methodReference, consumes, null));
}
 
Example 14
Source File: DeviceRegistryTokenAuthProvider.java    From enmasse with Apache License 2.0 4 votes vote down vote up
private Future<User> authorize(final JsonObject authInfo, final TokenReview tokenReview, final TenantInformation tenant, final Span parentSpan) {

        final HttpMethod method = HttpMethod.valueOf(authInfo.getString(METHOD));
        ResourceVerb verb = ResourceVerb.update;
        if (method == HttpMethod.GET) {
            verb = ResourceVerb.get;
        }

        final Span span = TracingHelper.buildChildSpan(this.tracer, parentSpan.context(), "check user roles", getClass().getSimpleName())
                .withTag("namespace", tenant.getNamespace())
                .withTag("name", tenant.getProjectName())
                .withTag("tenant.name", tenant.getName())
                .withTag(Tags.HTTP_METHOD.getKey(), method.name())
                .start();

        final String role = RbacSecurityContext.rbacToRole(tenant.getNamespace(), verb, IOT_PROJECT_PLURAL, tenant.getProjectName(), IoTCrd.GROUP);
        final RbacSecurityContext securityContext = new RbacSecurityContext(tokenReview, this.authApi, null);
        var f = this.authorizations
                .computeIfAbsentAsync(role, authorized -> {
                    span.log("cache miss");
                    return securityContext.isUserInRole(role);
                });

        var f2 = MoreFutures.map(f)
                .otherwise(t -> {
                    log.info("Error performing authorization", t);
                    TracingHelper.logError(span, t);
                    return false;
                })
                .<User>flatMap(authResult -> {
                    if (authResult) {
                        return Future.succeededFuture();
                    } else {
                        log.debug("Bearer token not authorized");
                        TracingHelper.logError(span, "Bearer token not authorized");
                        return Future.failedFuture(UNAUTHORIZED);
                    }
                });

        return MoreFutures
                .whenComplete(f2, span::finish);
    }
 
Example 15
Source File: BeanTest.java    From okapi with Apache License 2.0 4 votes vote down vote up
@Test
public void testModuleDescriptor2() {
  int fail = 0;

  final String docModuleDescriptor = "{" + LS
    + "  \"id\" : \"sample-module-1\"," + LS
    + "  \"name\" : \"sample module\"," + LS
    + "  \"provides\" : [ {" + LS
    + "    \"id\" : \"sample\"," + LS
    + "    \"version\" : \"1.0\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS
    + "      \"pathPattern\" : \"/users/{id}\"," + LS
    + "      \"level\" : \"30\"," + LS
    + "      \"type\" : \"request-response\"," + LS
    + "      \"permissionsRequired\" : [ \"sample.needed\" ]," + LS
    + "      \"permissionsDesired\" : [ \"sample.extra\" ]," + LS
    + "      \"modulePermissions\" : [ \"sample.modperm\" ]" + LS
    + "    } ]" + LS
    + "  }, {" + LS
    + "    \"id\" : \"_tenant\"," + LS
    + "    \"version\" : \"1.0\"," + LS
    + "    \"interfaceType\" : \"system\"," + LS
    + "    \"handlers\" : [ {" + LS
    + "      \"methods\" : [ \"POST\", \"DELETE\" ]," + LS
    + "      \"path\" : \"/_/tenant\"," + LS
    + "      \"level\" : \"10\"," + LS
    + "      \"type\" : \"system\"" + LS
    + "    } ]" + LS
    + "  } ]," + LS
    + "  \"filters\" : [ {" + LS
    + "    \"methods\" : [ \"*\" ]," + LS
    + "    \"pathPattern\" : \"/*\"," + LS
    + "    \"rewritePath\" : \"/events\"," + LS
    + "    \"type\" : \"request-response\"" + LS
    + "  } ]" + LS
    + "}";

  try {
    final ModuleDescriptor md = Json.decodeValue(docModuleDescriptor,
      ModuleDescriptor.class);
    String pretty = Json.encodePrettily(md);
    assertEquals(docModuleDescriptor, pretty);
    final ModuleInstance mi = new ModuleInstance(md, md.getFilters()[0], "/test/123", HttpMethod.GET, true);
    assertEquals("/events/test/123", mi.getPath());
  } catch (DecodeException ex) {
    ex.printStackTrace();
    fail = 400;
  }
  assertEquals(0, fail);
}
 
Example 16
Source File: ConflictingRouteTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Route(path = "/conflict/me", methods = HttpMethod.GET, order = 1)
void getCurrentUserAccount(RoutingContext ctx) {
    ctx.response().end("/me called");
}
 
Example 17
Source File: ConflictingRouteTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Route(path = "/conflict/:id", methods = HttpMethod.GET, order = 2)
void getAccount(RoutingContext ctx) {
    ctx.response().end(ctx.pathParam("id"));
}
 
Example 18
Source File: MyDeclarativeRoutes.java    From quarkus-quickstarts with Apache License 2.0 4 votes vote down vote up
@Route(path = "/", methods = HttpMethod.GET)
public void handle(RoutingContext rc) {
    rc.response().end("hello");
}
 
Example 19
Source File: CustomGetEndpoint.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod type() {
    return HttpMethod.GET;
}
 
Example 20
Source File: AssetServingEndpoint.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
@Override
public HttpMethod type() {
    return HttpMethod.GET;
}