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:org.fon.documentmanagementsystem.config.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.setServletContext(servletContext);
    ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);//w  w w  .j a v  a 2s . com
    servlet.setMultipartConfig(new MultipartConfigElement("", 1024 * 1024 * 25, 1024 * 1024 * 25, 0));

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);
    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
}

From source file:com.mycompany.testfile.config.WebConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    ServletRegistration.Dynamic h2ConsoleServlet = servletContext.addServlet("H2Console",
            new org.h2.server.web.WebServlet());
    h2ConsoleServlet.addMapping("/console/*");
    h2ConsoleServlet.setInitParameter("-properties", "src/main/resources");
    h2ConsoleServlet.setLoadOnStartup(1);
}

From source file:id.ac.ipb.ilkom.training.ApplicationInitializer.java

@Override
public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ApplicationConfiguration.class);
    ctx.setServletContext(container);//from www  .j  a  v a  2s  .c  o m

    ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
}

From source file:org.cloudfoundry.caldecott.server.config.SpringWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext();
    springContext.register(WebApplicationConfiguration.class);
    DispatcherServlet servlet = new DispatcherServlet(springContext);
    ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcher", servlet);
    registration.setLoadOnStartup(1);//from  w w w .  ja  v a 2s . co m
    registration.addMapping("/*");
}

From source file:com.econcept.init.MainWebAppplicationInitializer.java

@Override
public void onStartup(ServletContext pContainer) throws ServletException {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext lRootContext = new AnnotationConfigWebApplicationContext();
    lRootContext.scan("com.econcept.init");

    // Manage the lifecycle of the root application context
    pContainer.addListener(new ContextLoaderListener(lRootContext));

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic lDispatcher = pContainer.addServlet("CFXServlet", CXFServlet.class);
    lDispatcher.addMapping("/rest/*");

    // Apply Spring OAuthSecurity to both forward and request dispatcher
    FilterRegistration.Dynamic lFilter = pContainer.addFilter("unicodeFilter", new UnicodeFilter());
    lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");

    // Apply Spring OAuthSecurity to both forward and request dispatcher
    lFilter = pContainer.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"));
    lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");

    pContainer.addListener(AppHttpSessionListener.class);

}

From source file:com.nkapps.billing.configs.WebAppInitializer.java

@Override
public void onStartup(ServletContext container) {
    /*FilterRegistration.Dynamic encodingFilter = container.addFilter("encoding-filter", new CharacterEncodingFilter());
    encodingFilter.setInitParameter("encoding", "UTF-8");
    encodingFilter.setInitParameter("forceEncoding", "true");
    encodingFilter.addMappingForUrlPatterns(null, true, "/*");*/
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(HibernateConfig.class, ServiceConfig.class, RabbitMQConfig.class);

    // Manage the lifecycle of the root application context
    container.addListener(new ContextLoaderListener(rootContext));

    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
    dispatcherServlet.register(MvcConfig.class);

    DispatcherServlet dp = new DispatcherServlet(dispatcherServlet);
    dp.setThrowExceptionIfNoHandlerFound(true);

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", dp);
    dispatcher.setLoadOnStartup(1);/*w  w  w  . j a v  a2  s  .c  o  m*/
    dispatcher.addMapping("/");

}

From source file:com.sishuok.chapter2.initializer.NoXmlWebAppInitializer.java

@Override
public void onStartup(final ServletContext sc) throws ServletException {

    //1?//from  w  w w.jav  a 2 s  . c  o  m
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(RootConfiguration.class);
    sc.addListener(new ContextLoaderListener(rootContext));

    //2?springmvc
    AnnotationConfigWebApplicationContext springMvcContext = new AnnotationConfigWebApplicationContext();
    springMvcContext.register(SpringMvcConfiguration.class);

    //3?DispatcherServlet
    DispatcherServlet dispatcherServlet = new DispatcherServlet(springMvcContext);

    ServletRegistration.Dynamic dynamic = sc.addServlet("dispatcherServlet", dispatcherServlet);
    dynamic.setLoadOnStartup(1);
    dynamic.addMapping("/");

}

From source file:com.oreilly.springdata.rest.RestWebApplicationInitializer.java

public void onStartup(ServletContext container) throws ServletException {

    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(ApplicationConfig.class);

    // Manage the lifecycle of the root application context
    container.addListener(new ContextLoaderListener(rootContext));

    // Register and map the dispatcher servlet
    DispatcherServlet servlet = new RepositoryRestExporterServlet();
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", servlet);
    dispatcher.setLoadOnStartup(1);/*from   www.j a v  a2 s.  com*/
    dispatcher.addMapping("/");
}

From source file:org.ado.biblio.config.AppInitializer.java

public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.setServletContext(container);//www  .  j  av  a 2  s .  c  om

    ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/*");
}

From source file:org.ratty.configs.AppConfig.java

public void onStartup(ServletContext servletContext) throws ServletException {
    final AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.setServletContext(servletContext);
    final ServletRegistration.Dynamic dynamic = servletContext.addServlet("dispatcher",
            new DispatcherServlet(ctx));
    dynamic.addMapping("/");
    dynamic.setLoadOnStartup(1);//from  w  w w.  j a va 2  s .c o  m
}