Java Code Examples for io.vertx.core.http.HttpMethod#POST
The following examples show how to use
io.vertx.core.http.HttpMethod#POST .
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 |
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 |
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: TenantManager.java From okapi with Apache License 2.0 | 6 votes |
private void fireTimer(Tenant tenant, ModuleDescriptor md, RoutingEntry re, String path) { String tenantId = tenant.getId(); HttpMethod httpMethod = HttpMethod.POST; String[] methods = re.getMethods(); if (methods != null && re.getMethods().length >= 1) { httpMethod = HttpMethod.valueOf(methods[0]); } ModuleInstance inst = new ModuleInstance(md, re, path, httpMethod, true); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); logger.info("timer call start module {} for tenant {}", md.getId(), tenantId); proxyService.callSystemInterface(headers, tenant, inst, "", cres -> { if (cres.succeeded()) { logger.info("timer call succeeded to module {} for tenant {}", md.getId(), tenantId); } else { logger.info("timer call failed to module {} for tenant {} : {}", md.getId(), tenantId, cres.cause().getMessage()); } }); }
Example 4
Source File: AbstractHttpMessageHandler.java From festival with Apache License 2.0 | 5 votes |
@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 5
Source File: UserBodyRequestParseHandler.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
@Override public void handle(RoutingContext context) { HttpServerRequest req = context.request(); if (req.method() != HttpMethod.POST) { context.fail(405); // Must be a POST } else { if (!req.isExpectMultipart()) { throw new IllegalStateException("Form body not parsed - do you forget to include a BodyHandler?"); } // check required parameters MultiMap params = req.formAttributes(); Optional<String> missingParameter = requiredParams.stream().filter(param -> { String paramValue = params.get(param); if (paramValue == null) { logger.warn("No {} provided in form - did you forget to include a BodyHandler?", param); return true; } return false; }).findFirst(); if (missingParameter.isPresent()) { redirectToPage(context, Collections.singletonMap(ERROR_PARAM, "missing_required_parameters")); } else { context.next(); } } }
Example 6
Source File: CustomPostEndpoint.java From konduit-serving with Apache License 2.0 | 4 votes |
@Override public HttpMethod type() { return HttpMethod.POST; }
Example 7
Source File: SimpleRouteTest.java From quarkus with Apache License 2.0 | 4 votes |
@Route(path = "/body", methods = HttpMethod.POST, consumes = "text/plain") void post(RoutingContext context) { context.response().setStatusCode(200).end("Hello " + context.getBodyAsString() + "!"); }
Example 8
Source File: FormLoginHandlerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
@Override public void handle(RoutingContext context) { HttpServerRequest req = context.request(); if (req.method() != HttpMethod.POST) { context.fail(405); // Must be a POST } else { if (!req.isExpectMultipart()) { throw new IllegalStateException("Form body not parsed - do you forget to include a BodyHandler?"); } MultiMap params = req.formAttributes(); String username = params.get(usernameParam); String password = params.get(passwordParam); String clientId = params.get(Parameters.CLIENT_ID); if (username == null || password == null) { log.warn("No username or password provided in form - did you forget to include a BodyHandler?"); context.fail(400); } else if (clientId == null) { log.warn("No client id in form - did you forget to include client_id query parameter ?"); context.fail(400); } else { Session session = context.session(); // build authentication object with ip address and user agent JsonObject authInfo = new JsonObject() .put("username", username) .put("password", password) .put(Claims.ip_address, remoteAddress(req)) .put(Claims.user_agent, userAgent(req)) .put(Parameters.CLIENT_ID, clientId); authProvider.authenticate(context, authInfo, res -> { if (res.succeeded()) { User user = res.result(); context.setUser(user); if (session != null) { // the user has upgraded from unauthenticated to authenticated // session should be upgraded as recommended by owasp session.regenerateId(); // Note : keep returnURLParam in session in case the user go to previous page // String returnURL = session.remove(returnURLParam); String returnURL = session.get(returnURLParam); if (returnURL != null) { // Now redirect back to the original url doRedirect(req.response(), returnURL); return; } } // Either no session or no return url if (directLoggedInOKURL != null) { // Redirect to the default logged in OK page - this would occur // if the user logged in directly at this URL without being redirected here first from another // url doRedirect(req.response(), directLoggedInOKURL); } else { // Just show a basic page req.response().end(DEFAULT_DIRECT_LOGGED_IN_OK_PAGE); } } else { handleException(context); } }); } } }
Example 9
Source File: InterceptableRoutingContextImplTest.java From vertx-swagger with Apache License 2.0 | 4 votes |
@Override public HttpMethod method() { // TODO Auto-generated method stub return HttpMethod.POST; }
Example 10
Source File: TenantManager.java From okapi with Apache License 2.0 | 4 votes |
private void invokePermissionsForModule(Tenant tenant, ModuleDescriptor mdTo, ModuleDescriptor permsModule, ProxyContext pc, Handler<ExtendedAsyncResult<Void>> fut) { pc.debug("Loading permissions for " + mdTo.getName() + " (using " + permsModule.getName() + ")"); String moduleTo = mdTo.getId(); PermissionList pl = null; InterfaceDescriptor permInt = permsModule.getSystemInterface("_tenantPermissions"); if (permInt.getVersion().equals("1.0")) { pl = new PermissionList(moduleTo, mdTo.getPermissionSets()); } else { pl = new PermissionList(moduleTo, mdTo.getExpandedPermissionSets()); } String pljson = Json.encodePrettily(pl); pc.debug("tenantPerms Req: " + pljson); String permPath = ""; List<RoutingEntry> routingEntries = permInt.getAllRoutingEntries(); ModuleInstance permInst = null; if (!routingEntries.isEmpty()) { for (RoutingEntry re : routingEntries) { if (re.match(null, "POST")) { permPath = re.getStaticPath(); permInst = new ModuleInstance(permsModule, re, permPath, HttpMethod.POST, true); } } } if (permInst == null) { fut.handle(new Failure<>(ErrorType.USER, "Bad _tenantPermissions interface in module " + permsModule.getId() + ". No path to POST to")); return; } pc.debug("tenantPerms: " + permsModule.getId() + " and " + permPath); proxyService.callSystemInterface(tenant, permInst, pljson, pc, cres -> { if (cres.failed()) { fut.handle(new Failure<>(ErrorType.USER, cres.cause())); } else { pc.passOkapiTraceHeaders(cres.result()); pc.debug("tenantPerms request to " + permsModule.getName() + " succeeded for module " + moduleTo + " and tenant " + tenant.getId()); fut.handle(new Success<>()); } }); }
Example 11
Source File: RouteBuilder.java From vxms with Apache License 2.0 | 4 votes |
public static RouteBuilder post(String path, RestHandlerConsumer methodReference, String... consumes) { return new RouteBuilder( new MethodDescriptor(HttpMethod.POST, path, methodReference, consumes, null)); }
Example 12
Source File: FormLoginHandlerImpl.java From vertx-web with Apache License 2.0 | 4 votes |
@Override public void handle(RoutingContext context) { HttpServerRequest req = context.request(); if (req.method() != HttpMethod.POST) { context.fail(405); // Must be a POST } else { if (!req.isExpectMultipart()) { throw new IllegalStateException("HttpServerRequest should have setExpectMultipart set to true, but it is currently set to false."); } MultiMap params = req.formAttributes(); String username = params.get(usernameParam); String password = params.get(passwordParam); if (username == null || password == null) { log.warn("No username or password provided in form - did you forget to include a BodyHandler?"); context.fail(400); } else { Session session = context.session(); UsernamePasswordCredentials authInfo = new UsernamePasswordCredentials(username, password); authProvider.authenticate(authInfo, res -> { if (res.succeeded()) { User user = res.result(); context.setUser(user); if (session != null) { // the user has upgraded from unauthenticated to authenticated // session should be upgraded as recommended by owasp session.regenerateId(); String returnURL = session.remove(returnURLParam); if (returnURL != null) { // Now redirect back to the original url doRedirect(req.response(), returnURL); return; } } // Either no session or no return url if (directLoggedInOKURL != null) { // Redirect to the default logged in OK page - this would occur // if the user logged in directly at this URL without being redirected here first from another // url doRedirect(req.response(), directLoggedInOKURL); } else { // Just show a basic page req.response().end(DEFAULT_DIRECT_LOGGED_IN_OK_PAGE); } } else { context.fail(401); // Failed login } }); } } }
Example 13
Source File: WebAuthnHandlerImpl.java From vertx-web with Apache License 2.0 | 4 votes |
private static boolean matchesRoute(RoutingContext ctx, Route route) { if (route != null) { return ctx.request().method() == HttpMethod.POST && ctx.normalizedPath().equals(route.getPath()); } return false; }
Example 14
Source File: LoraProvider.java From hono with Eclipse Public License 2.0 | 2 votes |
/** * Gets the HTTP method that this provider requires for uplink data. * * @return The HTTP method. This default implementation returns <em>POST</em>. */ default HttpMethod acceptedHttpMethod() { return HttpMethod.POST; }
Example 15
Source File: EverynetProvider.java From hono with Eclipse Public License 2.0 | 2 votes |
/** * {@inheritDoc} * * @return Always {@link HttpMethod#POST}. */ @Override public HttpMethod acceptedHttpMethod() { return HttpMethod.POST; }