@Override public String requestMethod() { return delegate.requestMethod(); }
public static Filter onlyOn(Filter filter, String... allowedMethods) { return (request, response) -> { if (Sets.newHashSet(allowedMethods).contains(request.requestMethod())) { filter.handle(request, response); } }; }
private void checkAdminUserAnd403OnlyForPatch(Request request, Response response) { if ("PATCH".equals(request.requestMethod())) { apiAuthenticationHelper.checkAdminUserAnd403(request, response); } }
private void checkSecurityOr403(Request request, Response response) { if (Arrays.asList("GET", "HEAD").contains(request.requestMethod().toUpperCase())) { apiAuthenticationHelper.checkUserAnd403(request, response); return; } apiAuthenticationHelper.checkAdminUserAnd403(request, response); }
protected void verifyContentType(Request request, Response response) throws IOException { if (!UPDATE_HTTP_METHODS.contains(request.requestMethod().toUpperCase())) { return; } boolean requestHasBody = request.contentLength() >= 1 || request.raw().getInputStream().available() >= 1 || "chunked".equalsIgnoreCase(request.headers("Transfer-Encoding")); if (requestHasBody) { if (!isJsonContentType(request)) { throw haltBecauseJsonContentTypeExpected(); } } else if (request.headers().stream().noneMatch(headerName -> headerName.toLowerCase().equals("x-gocd-confirm"))) { throw haltBecauseConfirmHeaderMissing(); } }
@Override public PipelineConfig buildEntityFromRequestBody(Request req) { ConfigHelperOptions options = new ConfigHelperOptions(goConfigService.getCurrentConfig(), passwordDeserializer); JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(req.body()); if ("PUT".equalsIgnoreCase(req.requestMethod())) { return PipelineConfigRepresenter.fromJSON(jsonReader, options); } return PipelineConfigRepresenter.fromJSON(jsonReader.readJsonObject("pipeline"), options); }
response.header("Content-Type", image.getContentType()); this.setEtagHeader(response, image.getHash()); if (request.requestMethod().equals("head")) { return new byte[0]; } else {
@Override public String requestMethod() { return delegate.requestMethod(); }
@Override public String requestMethod() { return delegate.requestMethod(); }
log.debug("HueMulator " + request.requestMethod() + " called on api/* with request <<<" + request.pathInfo() + ">>>, and body <<<" + request.body() + ">>>"); if(bridgeSettingMaster.getBridgeSecurity().isSecure()) { String pathInfo = request.pathInfo();
@Override public void handle(Request request, Response response) throws Exception { if (request.requestMethod() != OPTIONS) { Optional<String> bearer = Optional.ofNullable(request.headers(AUTHORIZATION_HEADER_NAME)) .filter(value -> value.startsWith(AUTHORIZATION_HEADER_PREFIX)) .map(value -> value.substring(AUTHORIZATION_HEADER_PREFIX.length())); checkHeaderPresent(bearer); checkValidSignature(bearer); checkIsAdmin(bearer); String login = jwtTokenVerifier.extractLogin(bearer.get()); request.attribute(LOGIN, login); } }
@Override public void handle(Request request, Response response) throws Exception { Metrics.log.debug(request.requestMethod() + " " + request.pathInfo()); response.header("Access-Control-Allow-Origin", "*"); response.type("application/json"); } }
private static Object setupSparkResponse(String name, Request req, Response res) { res.type("application/json"); Optional<String> echoValue = Optional.ofNullable(req.headers("x-echo")); Optional<String> optionalMethod = Optional.ofNullable(req.requestMethod()); String methodValue = ""; if (optionalMethod.isPresent()) { methodValue = optionalMethod.get(); } Optional<String> tagValue = Optional.ofNullable(name); res.header("x-echo", echoValue.orElse("none")); res.header("x-method", methodValue); res.header("x-tag", tagValue.orElse("no tag")); Kraken kraken = new Kraken("Release", "the Kraken"); return new Gson().toJson(kraken); }
@Override public void handle(Exception exception, Request request, Response response) { Metrics.log.error(request.requestMethod() + " " + request.pathInfo(), exception); response.body(ExceptionUtils.getStackTrace(exception)); response.type("text/plain"); response.status(500); } }
notFound("Not found"); before((req, res) -> { LOG.info(req.requestMethod() + " " + req.url()); res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Request-Method", "GET");
res.header("Pragma", "no-cache"); // HTTP 1.0. res.header("Expires", "0"); // Proxies. logger.info("{} -> {}", req.requestMethod(), req.url());
LiveLoggingUtils.MOCK_TRAFFIC_LOGGER.info(LiveLoggingUtils.buildLiveLogInboundFileEntry(request.attribute(GeneralUtils.LOG_REQ_ID), request.requestMethod(), request.pathInfo(), reqHeaders, request.body(), false)); liveLoggingHandler.broadcast(LiveLoggingUtils.buildLiveLogInboundDTO(request.attribute(GeneralUtils.LOG_REQ_ID), request.requestMethod(), request.pathInfo(), reqHeaders, request.body(), false)); });
@Override public void handle(Request request, Response response) throws Exception { Closeable mdcCloseable = MDCBuilder.create() .addContext(MDCBuilder.IP, request.ip()) .addContext(MDCBuilder.HOST, request.host()) .addContext(VERB, request.requestMethod()) .addContext(MDCBuilder.PROTOCOL, "webadmin") .addContext(MDCBuilder.ACTION, request.pathInfo()) .addContext(MDCBuilder.USER, request.attribute(AuthenticationFilter.LOGIN)) .build(); request.attribute(MDC_CLOSEABLE, mdcCloseable); } }
private void configureExceptionHanding() { service.notFound((req, res) -> ErrorResponder.builder() .statusCode(NOT_FOUND_404) .type(NOT_FOUND) .message(String.format("%s %s can not be found", req.requestMethod(), req.pathInfo())) .asString()); service.internalServerError((req, res) -> ErrorResponder.builder() .statusCode(INTERNAL_SERVER_ERROR_500) .type(SERVER_ERROR) .message("WebAdmin encountered an unexpected internal error") .asString()); service.exception(JsonExtractException.class, (ex, req, res) -> { res.status(BAD_REQUEST_400); res.body(ErrorResponder.builder() .statusCode(BAD_REQUEST_400) .type(INVALID_ARGUMENT) .message("JSON payload of the request is not valid") .cause(ex) .asString()); }); }
logger.debug("======== Handling API call via HTTP {}: ========", request.requestMethod()); logger.debug("* Parameter extracted:"); logger.debug(" command = ", request.params(":cmd"));