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:net.eusashead.hateoas.springhalbuilder.config.WebInitializer.java

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

    // Set up the app ctx
    AnnotationConfigWebApplicationContext rootCtx = new AnnotationConfigWebApplicationContext();
    rootCtx.register(WebConfig.class);

    // Set the listener
    ctx.addListener(new ContextLoaderListener(rootCtx));

    // Register the Spring Dispatcher servlet
    ServletRegistration.Dynamic dispatcher = ctx.addServlet("dispatcher", new DispatcherServlet(rootCtx));
    dispatcher.setLoadOnStartup(1);//from   ww w. j  a  v  a 2s.  c o m
    dispatcher.addMapping("/*");

}

From source file:com.cfitzarl.cfjwed.Main.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Add spring security filter chain
    servletContext.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
            .addMappingForUrlPatterns(null, false, "/*");

    // Add Hibernate session binder
    servletContext.addFilter("jpaTransactionFilter", OpenEntityManagerInViewFilter.class)
            .addMappingForUrlPatterns(null, false, "/*");

    // Define application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(WebApplicationMvcConfigurer.class);
    rootContext.scan("com.cfitzarl.cfjwed");

    // Create a dispatcher servlet that loads the application context
    DispatcherServlet dispatcherServlet = new DispatcherServlet();
    dispatcherServlet.setApplicationContext(rootContext);

    // Add the dispatcher servlet to the servlet context and map it to /
    ServletRegistration.Dynamic servletRegister = servletContext.addServlet("dispatcher", dispatcherServlet);
    servletRegister.setLoadOnStartup(1);
    servletRegister.addMapping("/");

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

From source file:com.volho.example.todo.web.config.WebAppInitializer.java

public void initH2Console(ServletContext servletContext) {
    ServletRegistration.Dynamic h2ConsoleServlet = servletContext.addServlet("H2Console",
            new org.h2.server.web.WebServlet());
    h2ConsoleServlet.addMapping("/console/*");
}

From source file:rashjz.info.com.az.config.MyWebInitializer.java

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

    DispatcherServlet dispatcherServlet = new DispatcherServlet(appContext);
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("SpringDispatcher", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);/*from  ww w  . j  a  v  a 2  s .co m*/
    dispatcher.addMapping("/");

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

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);
    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
}

From source file:com.kajj.tools.logviewer.config.LogViewerWebApplicationInitializer.java

/**
 * Initialization method for the ServletContext. Creates the Spring context and
 * DispatcherServlet.//  w w  w .j av a 2s.  c o  m
 *
 * @param servletContext The ServletContext to initialize.
 * @throws ServletException If the ServletContext fails to initialize.
 */
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    final AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext();
    springContext.setConfigLocation("com.kajj.tools.logviewer.config");
    servletContext.addListener(new ContextLoaderListener(springContext));

    final DispatcherServlet servlet = new DispatcherServlet(springContext);
    final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, servlet);
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping(MAPPING_ANY);
}

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

public void zkUpdateServlet(ServletContext servletContext) {
    ServletRegistration.Dynamic servlet = servletContext.addServlet("auEngine", new DHtmlUpdateServlet());
    servlet.addMapping("/zkau/*");
}

From source file:org.bitcoinrt.spring.config.BitcoinServletInitializer.java

public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext cxt = new AnnotationConfigWebApplicationContext();
    cxt.register(ServerConfig.class);

    DispatcherServlet servlet = new DispatcherServlet(cxt);
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("main", servlet);
    dispatcher.setLoadOnStartup(1);//from  w w w.j a v  a 2  s .co  m
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");
}

From source file:com.github.mjeanroy.junit.servers.samples.jetty.java.configuration.WebApplicationConfiguration.java

private void initSpringMvc(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setContextConfigLocation(configLocation());
    dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);/*w  w  w  . j a  v a2 s.co m*/
    dispatcher.addMapping("/*");
    dispatcher.addMapping("/");
}

From source file:com.mjeanroy.backbone_isomorphic.configuration.WebConfiguration.java

private void initSpringMvc(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setContextConfigLocation(configLocation());
    dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);//  w w  w . ja v  a 2s .  c  o m
    dispatcher.addMapping("/api/*");
    dispatcher.addMapping("/");
}

From source file:org.bitcoinrt.web.config.BitcointWebAppInitializer.java

public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext();
    webAppContext.register(WebConfig.class);

    final DispatcherServlet dispatcherServlet = new DispatcherServlet(webAppContext);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcherServlet", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);//  w  w w .ja v  a  2s.  c  o  m
    dispatcher.addMapping("/site/*");

    UrlRewriteFilter urlRewriteFilter = new UrlRewriteFilter();

    servletContext.addFilter("UrlRewriteFilter", urlRewriteFilter)
            .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");

}