io.dropwizard.jetty.setup.ServletEnvironment Java Examples
The following examples show how to use
io.dropwizard.jetty.setup.ServletEnvironment.
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: WebServletInstaller.java From dropwizard-guicey with MIT License | 6 votes |
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()); }
Example #2
Source File: WebFilterInstaller.java From dropwizard-guicey with MIT License | 6 votes |
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()); }
Example #3
Source File: SoaBundle.java From soabase with Apache License 2.0 | 5 votes |
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"); } }
Example #4
Source File: IndexServlet.java From soabase with Apache License 2.0 | 5 votes |
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()); } } }
Example #5
Source File: CrossOriginResourceSharing.java From dropwizard-experiment with MIT License | 4 votes |
public static void enableFor(ServletEnvironment servlets, String path) { servlets.addFilter("blah", CrossOriginResourceSharing.class) .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, path); }