/** * Maps one or many filters to be executed before any matching routes * * @param path the path * @param acceptType the accept type * @param filters The filters */ public static void before(String path, String acceptType, Filter... filters) { for (Filter filter : filters) { getInstance().before(path, acceptType, filter); } }
/** * Maps a filter to be executed before any matching routes * * @param path the path * @param filter The filter */ public static void before(String path, Filter filter) { getInstance().before(path, filter); }
/** * Maps an array of filters to be executed before any matching routes * * @param path the path * @param filters the filters */ public static void before(String path, Filter... filters) { for (Filter filter : filters) { getInstance().before(path, filter); } }
/** * Maps one or many filters to be executed before any matching routes * * @param filters The filters */ public static void before(Filter... filters) { for (Filter filter : filters) { getInstance().before(filter); } }
/** * Maps one or many filters to be executed before any matching routes * * @param path the path * @param acceptType the accept type * @param filters The filters */ public static void before(String path, String acceptType, Filter... filters) { for (Filter filter : filters) { getInstance().before(path, acceptType, filter); } }
/** * Maps a filter to be executed before any matching routes * * @param path the path * @param filter The filter */ public static void before(String path, Filter filter) { getInstance().before(path, filter); }
/** * Maps one or many filters to be executed before any matching routes * * @param filters The filters */ public static void before(Filter... filters) { for (Filter filter : filters) { getInstance().before(filter); } }
spark.before((request, response) -> { response.header("Access-Control-Allow-Origin", "*"); response.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
/** * Maps an array of filters to be executed before any matching routes * * @param path the path * @param filters the filters */ public static void before(String path, Filter... filters) { for (Filter filter : filters) { getInstance().before(path, filter); } }
private void configureMetrics() { service.before(new MetricPreFilter(metricFactory)); service.after(new MetricPostFilter()); }
private void configureCORS() { if (configuration.isEnabled()) { service.before(new CORSFilter(configuration.getUrlCORSOrigin())); new CORSRoute().define(service); LOGGER.info("Web admin set up to enable CORS from {}", configuration.getUrlCORSOrigin()); } }
@Override public void configure(HierarchicalConfiguration config) throws ConfigurationException { if (configuration.isEnabled()) { service.port(configuration.getPort().get().getValue()); configureExceptionHanding(); configureHTTPS(); configureCORS(); configureMetrics(); service.before((request, response) -> response.type(Constants.JSON_CONTENT_TYPE)); configureMDC(); routesList.forEach(routes -> { service.before(routes.getBasePath(), authenticationFilter); service.before(routes.getBasePath() + "/*", authenticationFilter); routes.define(service); }); publicRoutes.forEach(routes -> routes.define(service)); service.awaitInitialization(); port = new Port(service.port()); LOGGER.info("Web admin server started"); } }
private void enableCORS(final String origin, final String methods) { server.options("/*", (request, response) -> { String accessControlRequestHeaders = request.headers("Access-Control-Request-Headers"); if (accessControlRequestHeaders != null) { response.header("Access-Control-Allow-Headers", accessControlRequestHeaders); } String accessControlRequestMethod = request.headers("Access-Control-Request-Method"); if (accessControlRequestMethod != null) { response.header("Access-Control-Allow-Methods", accessControlRequestMethod); } return "OK"; }); server.before((request, response) -> { response.header("Access-Control-Allow-Origin", origin); response.header("Access-Control-Request-Method", methods); }); }
service.before((request, response) -> { if (!authenticator.isAuthenticated(request)) {