private void configure(final ServletEnvironment environment, final HttpServlet servlet, final Class<? extends HttpServlet> type, final String name, final WebServlet annotation) { final ServletRegistration.Dynamic mapping = environment.addServlet(name, servlet); final Set<String> clash = mapping .addMapping(annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value()); if (clash != null && !clash.isEmpty()) { final String msg = String.format( "Servlet registration %s clash with already installed servlets on paths: %s", type.getSimpleName(), Joiner.on(',').join(clash)); if (option(DenyServletRegistrationWithClash)) { throw new IllegalStateException(msg); } else { logger.warn(msg); } } if (annotation.initParams().length > 0) { for (WebInitParam param : annotation.initParams()) { mapping.setInitParameter(param.name(), param.value()); } } mapping.setAsyncSupported(annotation.asyncSupported()); }
private void configure(final ServletEnvironment environment, final Filter filter, final String name, final WebFilter annotation) { final FilterRegistration.Dynamic mapping = environment.addFilter(name, filter); final EnumSet<DispatcherType> dispatcherTypes = EnumSet.copyOf(Arrays.asList(annotation.dispatcherTypes())); if (annotation.servletNames().length > 0) { mapping.addMappingForServletNames(dispatcherTypes, false, annotation.servletNames()); } else { final String[] urlPatterns = annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value(); mapping.addMappingForUrlPatterns(dispatcherTypes, false, urlPatterns); } if (annotation.initParams().length > 0) { for (WebInitParam param : annotation.initParams()) { mapping.setInitParameter(param.name(), param.value()); } } mapping.setAsyncSupported(annotation.asyncSupported()); }
private void checkCorsFilter(SoaConfiguration configuration, ServletEnvironment servlets) { if ( configuration.isAddCorsFilter() ) { // from http://jitterted.com/tidbits/2014/09/12/cors-for-dropwizard-0-7-x/ FilterRegistration.Dynamic filter = servlets.addFilter("CORS", CrossOriginFilter.class); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS"); filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*"); filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*"); filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin"); filter.setInitParameter("allowCredentials", "true"); } }
public void setServlets(ServletEnvironment servlets) { AuthFilter authFilter = (authSpec != null) ? new AuthFilter(authSpec) : null; for ( IndexMapping mapping : mappings ) { String name = Splitter.on('.').split(mapping.getFile()).iterator().next(); servlets.addServlet(name, this).addMapping(mapping.getPath()); servlets.addServlet(name + "-force", this).addMapping(FORCE + mapping.getPath()); if ( !mapping.isAuthServlet() && (authFilter != null) ) { servlets.addFilter("auth-" + name, authFilter).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, mapping.getPath()); servlets.addFilter("auth-" + name + "-force", authFilter).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, FORCE + mapping.getPath()); } } }
public ServletEnvironment servlets() { return this.environment.servlets(); }
public static void enableFor(ServletEnvironment servlets, String path) { servlets.addFilter("blah", CrossOriginResourceSharing.class) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, path); }