Java Code Examples for io.vertx.core.http.HttpMethod#valueOf()

The following examples show how to use io.vertx.core.http.HttpMethod#valueOf() . 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: TenantManager.java    From okapi with Apache License 2.0 6 votes vote down vote up
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 2
Source File: RoutingEntry.java    From okapi with Apache License 2.0 5 votes vote down vote up
/**
 * Set routing methods.
 * @param methods HTTP method name or "*" for all
 */
public void setMethods(String[] methods) {
  for (String s : methods) {
    if (!s.equals("*")) {
      HttpMethod.valueOf(s);
    }
  }
  this.methods = methods;
}
 
Example 3
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Invoke API by sending HTTP request with the given options.
 *
 * @param <T> Type
 * @param path The sub-path of the HTTP URL
 * @param method The request method, one of "GET", "POST", "PUT", "HEAD" and "DELETE"
 * @param queryParams The query parameters
 * @param body The request body object
 * @param headerParams The header parameters
 * @param cookieParams The cookie parameters
 * @param formParams The form parameters
 * @param accepts The request's Accept headers
 * @param contentTypes The request's Content-Type headers
 * @param authNames The authentications to apply
 * @param returnType The return type into which to deserialize the response
 * @param resultHandler The asynchronous response handler
 */
public <T> void invokeAPI(String path, String method, List<Pair> queryParams, Object body, MultiMap headerParams,
                          MultiMap cookieParams, Map<String, Object> formParams, String[] accepts, String[] contentTypes, String[] authNames,
                          TypeReference<T> returnType, Handler<AsyncResult<T>> resultHandler) {

    updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);

    if (accepts != null && accepts.length > 0) {
        headerParams.add(HttpHeaders.ACCEPT, selectHeaderAccept(accepts));
    }

    if (contentTypes != null) {
        headerParams.add(HttpHeaders.CONTENT_TYPE, selectHeaderContentType(contentTypes));
    }

    HttpMethod httpMethod = HttpMethod.valueOf(method);
    HttpRequest<Buffer> request = getWebClient().requestAbs(httpMethod, basePath + path);

    if (httpMethod == HttpMethod.PATCH) {
        request.putHeader("X-HTTP-Method-Override", "PATCH");
    }

    queryParams.forEach(entry -> {
        if (entry.getValue() != null) {
            request.addQueryParam(entry.getName(), entry.getValue());
        }
    });

    headerParams.forEach(entry -> {
        if (entry.getValue() != null) {
            request.putHeader(entry.getKey(), entry.getValue());
        }
    });

    defaultHeaders.forEach(entry -> {
        if (entry.getValue() != null) {
            request.putHeader(entry.getKey(), entry.getValue());
        }
    });

    final MultiMap cookies = MultiMap.caseInsensitiveMultiMap().addAll(cookieParams).addAll(defaultCookies);
    request.putHeader("Cookie", buildCookieHeader(cookies));

    Handler<AsyncResult<HttpResponse<Buffer>>> responseHandler = buildResponseHandler(returnType, resultHandler);
    if (body != null) {
        sendBody(request, responseHandler, body);
    } else if (formParams != null && !formParams.isEmpty()) {
        Map<String, String> formMap = formParams.entrySet().stream().collect(toMap(Map.Entry::getKey, entry -> parameterToString(entry.getValue())));
        MultiMap form = MultiMap.caseInsensitiveMultiMap().addAll(formMap);
        request.sendForm(form, responseHandler);
    } else {
        request.send(responseHandler);
    }
}
 
Example 4
Source File: RestClientInvocation.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private HttpMethod getMethod() {
  OperationMeta operationMeta = invocation.getOperationMeta();
  RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
  String method = swaggerRestOperation.getHttpMethod();
  return HttpMethod.valueOf(method);
}
 
Example 5
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 6
Source File: MethodOverrideHandlerImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
private HttpMethod methodFromHeader(HttpServerRequest request) {
  String method = request.headers().get("X-HTTP-METHOD-OVERRIDE");
  return (method != null)
    ? HttpMethod.valueOf(method)
    : null;
}