Example usage for javax.servlet ServletRegistration.Dynamic addMapping

List of usage examples for javax.servlet ServletRegistration.Dynamic addMapping

Introduction

In this page you can find the example usage for javax.servlet ServletRegistration.Dynamic addMapping.

Prototype

public Set<String> addMapping(String... urlPatterns);

Source Link

Document

Adds a servlet mapping with the given URL patterns for the Servlet represented by this ServletRegistration.

Usage

From source file:com.kabiliravi.kaman.web.KamanApplicationInitializer.java

private void registerDispatcherServlet(final ServletContext servletContext) {
    WebApplicationContext dispatcherContext = createContext(WebMvcContextConfiguration.class);
    servletContext.addListener(new ContextLoaderListener(dispatcherContext));
    servletContext.addListener(new RequestContextListener());
    DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext);
    ServletRegistration.Dynamic dispatcher;
    dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);//from ww  w . ja  v a  2 s  . co  m
    dispatcher.addMapping("/");
}

From source file:org.davidmendoza.demo.config.StartUpConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(ComponentConfig.class, DataConfig.class, MailConfig.class, WebConfig.class);
    context.setDisplayName("DemoApp");

    FilterRegistration.Dynamic sitemeshFilter = servletContext.addFilter("sitemeshFilter",
            new ConfigurableSiteMeshFilter());
    sitemeshFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter",
            new CharacterEncodingFilter());
    characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");

    servletContext.addListener(new ContextLoaderListener(context));
    //servletContext.setInitParameter("defaultHtmlEscape", "false");

    DispatcherServlet servlet = new DispatcherServlet();
    // no explicit configuration reference here: everything is configured in the root container for simplicity
    servlet.setContextConfigLocation("");

    ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", servlet);
    appServlet.setLoadOnStartup(1);/*from  ww  w  . java2s .c o m*/
    appServlet.setAsyncSupported(true);

    Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
        throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14");
    }
}

From source file:com.rakesh.rp3599.config.WebAppInitializer.java

public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(AppContext.class);

    /** Dispatcher Servlet **/
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);/*from w w w.ja  v a2  s.c  o m*/
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    /** Dispatcher Types Enum **/
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    /** UTF-8 Filter **/
    FilterRegistration.Dynamic characterEncoding = container.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    /** Context Listener **/
    container.addListener(new ContextLoaderListener(rootContext));

}

From source file:com.github.sshw.config.RootApplicationConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(RootApplicationContext.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);/*w ww .  ja  v a 2  s  .  c  o m*/
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain",
            new DelegatingFilterProxy());
    security.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    servletContext.addListener(new ContextLoaderListener(rootContext));
}

From source file:be.wolkmaan.klimtoren.web.config.WebAppInitializer.java

public void zkLoaderServlet(ServletContext servletContext) {
    ServletRegistration.Dynamic servlet = servletContext.addServlet("zkLoader", new DHtmlLayoutServlet());
    servlet.setInitParameter("update-uri", "/zkau");
    servlet.setLoadOnStartup(1);// www  . j  av a  2s .co m
    servlet.addMapping("*.zul");
    servlet.addMapping("*.zhtml");
    servlet.addMapping("/zk/*");
}

From source file:fi.helsinki.opintoni.config.WebConfigurer.java

/**
 * Initializes Metrics./*w  ww . j  av a2 s. c  om*/
 */
private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) {
    log.debug("Initializing Metrics registries");
    servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE, metricRegistry);
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);

    log.debug("Registering Metrics Filter");
    FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter",
            new InstrumentedFilter());

    metricsFilter.addMappingForUrlPatterns(disps, true, "/*");
    metricsFilter.setAsyncSupported(true);

    log.debug("Registering Metrics Servlet");
    ServletRegistration.Dynamic metricsAdminServlet = servletContext.addServlet("metricsServlet",
            new MetricsServlet());

    metricsAdminServlet.addMapping("/metrics/metrics/*");
    metricsAdminServlet.setAsyncSupported(true);
    metricsAdminServlet.setLoadOnStartup(2);
}

From source file:org.shaigor.rest.retro.config.WebAppInitializer.java

/**
 * Registers dispatcher servlet that will make MVC tick
 * @param servletContext to be used during creation and registration
 * @param rootContext web application context to be used during creation and registration
 *///w  w w. j  a  v  a  2s  .  c  om
private void configureSpringMvc(ServletContext servletContext, WebApplicationContext rootContext) {
    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    mvcContext.register(WordsSereviceConfig.class, InsecureWebMvcConfigurer.class);

    mvcContext.setParent(rootContext);

    ServletRegistration.Dynamic appServlet = servletContext.addServlet("webservice",
            new DispatcherServlet(mvcContext));
    appServlet.setLoadOnStartup(1);
    Set<String> mappingConflicts = appServlet.addMapping("/");

    if (!mappingConflicts.isEmpty()) {
        for (String s : mappingConflicts) {
            LOG.error("Mapping conflict: " + s);
        }
        throw new IllegalStateException("'webservice' cannot be mapped to '/'");
    }
}

From source file:org.kew.rmf.reconciliation.config.WebAppInitializer.java

private void configureSpringMvc(ServletContext servletContext, WebApplicationContext rootContext) {
    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    mvcContext.register(MvcConfig.class);

    mvcContext.setParent(rootContext);/* w  ww . j  a va  2 s  .co m*/
    ServletRegistration.Dynamic appServlet = servletContext.addServlet("reconciliation-service",
            new DispatcherServlet(mvcContext));
    appServlet.setLoadOnStartup(1);
    Set<String> mappingConflicts = appServlet.addMapping("/");

    if (!mappingConflicts.isEmpty()) {
        for (String s : mappingConflicts) {
            log.error("Mapping conflict: " + s);
        }
        throw new IllegalStateException("'webservice' cannot be mapped to '/'");
    }
}

From source file:com.gosmarter.it.eis.config.ExcelERPWebApplicationInitializer.java

private void registerDispatcherServlet(ServletContext servletContext) {

    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(RootConfig.class);

    logger.debug("after register(DispatcherConfig function");

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("zkLoader", new DHtmlLayoutServlet());

    dispatcher.setInitParameter("update-uri", "/zkau");

    dispatcher.setLoadOnStartup(1);//  w  ww  .j  a  v a 2s  . c  om
    dispatcher.addMapping("*.zul");

    dispatcher = servletContext.addServlet("auEngine", new DHtmlUpdateServlet());
    dispatcher.addMapping("/zkau/*");

    dispatcher = servletContext.addServlet("dspLoader", new InterpreterServlet());
    dispatcher.setInitParameter("class-resource", "true");
    dispatcher.addMapping("*.dsp");

}

From source file:com.test.config.BackendConsoleWebConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext();
    webCtx.register(BackendConsoleMVCConfig.class);
    webCtx.register(BackendConsoleConfig.class);

    servletContext.addListener(new ContextLoaderListener(webCtx));

    /* Spring Delegating Dispatcher Servlet */
    Servlet dispatcherServlet = new DispatcherServlet(webCtx);
    ServletRegistration.Dynamic dispatcherServletReg = servletContext.addServlet("dispatcherServlet",
            dispatcherServlet);//from   www  . j av  a  2s .  c  o m
    dispatcherServletReg.setLoadOnStartup(1);
    dispatcherServletReg.setInitParameter("contextConfigLocation", "");
    dispatcherServletReg.addMapping("/");

    /* Spring Security Delegating Filter */
    FilterRegistration springSecurityFilterChainReg = servletContext.addFilter("springSecurityFilterChain",
            DelegatingFilterProxy.class);
    springSecurityFilterChainReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST,
            DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.ASYNC), false,
            dispatcherServletReg.getName());
}