@Override public String pathInfo() { return delegate.pathInfo(); }
before(SYSTEM_CONTEXT + "/*", (request, response) -> { if(bridgeSettings.getBridgeSecurity().isSecure()) { String pathInfo = request.pathInfo(); if(pathInfo == null || (!pathInfo.equals(SYSTEM_CONTEXT + "/login") && !pathInfo.equals(SYSTEM_CONTEXT + "/habridge/version"))) { User authUser = bridgeSettings.getBridgeSecurity().getAuthenticatedUser(request);
@Override public String pathInfo() { return delegate.pathInfo(); }
@Override public String pathInfo() { return delegate.pathInfo(); }
@Override public String getPath() { return request.pathInfo(); }
log.debug("HueMulator " + request.requestMethod() + " called on api/* with request <<<" + request.pathInfo() + ">>>, and body <<<" + request.body() + ">>>"); if(bridgeSettingMaster.getBridgeSecurity().isSecure()) { String pathInfo = request.pathInfo(); if(pathInfo != null && pathInfo.contains(HUE_CONTEXT + "/devices")) { User authUser = bridgeSettingMaster.getBridgeSecurity().getAuthenticatedUser(request);
public Object handle(Request request, Response response) throws Exception { String path = request.pathInfo(); for(Map.Entry<String, String> entry : request.params().entrySet()) { String paramName = entry.getKey(); String paramValue = entry.getValue(); path = path.replace(paramValue, paramName.replace(":", "{") + "}"); } getLog().info(path); return "hello world"; }
public void initExceptionHandlers() { Spark.exception(Exception.class, (exc, req, res) -> { LOG.error(String.format("error occured on path=%s", req.pathInfo()), exc); res.status(500); }); }
@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"); } }
@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); } }
public static void logRequestInfo(Request req) { String origin = req.headers("Origin"); String origin2 = req.headers("origin"); String host = req.headers("Host"); log.debug("request host: " + host); log.debug("request origin: " + origin); log.debug("request origin2: " + origin2); // System.out.println("origin = " + origin); // if (DataSources.ALLOW_ACCESS_ADDRESSES.contains(req.headers("Origin"))) { // res.header("Access-Control-Allow-Origin", origin); // } for (String header : req.headers()) { log.debug("request header | " + header + " : " + req.headers(header)); } log.debug("request ip = " + req.ip()); log.debug("request pathInfo = " + req.pathInfo()); log.debug("request host = " + req.host()); log.debug("request url = " + req.url()); }
public static void ensureUserIsLoggedIn(Request request, Response response) { if (request.session().attribute("currentUser") == null) { request.session().attribute("loginRedirect", request.pathInfo()); response.redirect(Path.Web.LOGIN); } };
public static void ensureUserIsLoggedIn(Request request, Response response) { if (request.session().attribute("currentUser") == null) { request.session().attribute("loginRedirect", request.pathInfo()); response.redirect(Path.Web.LOGIN); } };
/** * Checks if the api key provided is correct * * @param req * @param res * @throws SQLException */ private void beforeFilter(Request req, Response res) throws SQLException { res.header("Access-Control-Allow-Origin", "*"); logger.info("API request : [{}]", req.pathInfo()); Settings useRemote = SettingsController.INSTANCE.get(Settings.USE_REMOTE); if (useRemote != null && useRemote.getValue().equalsIgnoreCase("1")) { String clientKey = req.headers(HEADER_AUTHORIZATION); Settings localKey = SettingsController.INSTANCE.get(Settings.REMOTE_API_KEY); if (localKey == null) { Spark.halt(401); } else if (!localKey.getValue().equalsIgnoreCase(clientKey)) { Spark.halt(401); } } else { Spark.halt(401); } }
String extractInboundValue(final RuleMatchingTypeEnum matchingType, final String fieldName, final Request req) { switch (matchingType) { case REQUEST_HEADER: return req.headers(fieldName); case REQUEST_PARAM: return extractRequestParam(req, fieldName); case REQUEST_BODY: return req.body(); case PATH_VARIABLE: return req.params(fieldName); case PATH_VARIABLE_WILD: final int argPosition = NumberUtils.toInt(fieldName, -1); if (argPosition == -1 || req.splat().length < argPosition) { throw new IllegalArgumentException("Unable to perform wildcard matching on the mocked endpoint '" + req.pathInfo() + "'. Path variable arg count does not align."); } return req.splat()[(argPosition - 1)]; case REQUEST_BODY_JSON_ANY: final Map<String, ?> json = GeneralUtils.deserialiseJSONToMap(req.body()); return (json != null)?(String)json.get(fieldName):null; default: throw new IllegalArgumentException("Unsupported Rule Matching Type : " + matchingType); } }
@Override public void handle(Request request, Response response) throws Exception { String path = request.pathInfo(); boolean requestConsumed = false; if (patterns.matches(path)) { renderIndexHtml(request, response); requestConsumed = true; } else { requestConsumed = staticFilesHandler.consume(request.raw(), response.raw()); } if(requestConsumed) { response.body(""); // needed to suppress spark-java route mapping error log } }
String processRequest(final RestfulMock mock, final Request req, final Response res) { logger.debug("processRequest called"); RestfulResponseDTO outcome; switch (mock.getMockType()) { case RULE: outcome = ruleEngine.process(req, mock.getRules()); break; case PROXY_HTTP: outcome = proxyService.waitForResponse(req.pathInfo(), mock); break; case SEQ: default: outcome = mockOrderingCounterService.process(mock); break; } if (outcome == null) { // Load in default values outcome = getDefault(mock); } res.status(outcome.getHttpStatusCode()); res.type(outcome.getResponseContentType()); // Apply any response headers outcome.getHeaders().entrySet().forEach(e -> res.header(e.getKey(), e.getValue()) ); final String response = inboundParamMatchService.enrichWithInboundParamMatches(req, outcome.getResponseBody()); return StringUtils.defaultIfBlank(response,""); }
private static void staticResources() { Route route = (Route) (req, res) -> { if (Constants.DEV_MODE) { String content = getDevStaticResource(req.splat()[0], res); if (content != null) { return content; } //if it's not in the assets we just load it as a normal file } String fullPath = "web" + req.pathInfo(); return getContent(res, fullPath); }; get("/css/*", route); get("/fonts/*", route); get("/js/*", route); get("/images/*", route); }
@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()); }); }