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:cn.org.once.cstack.initializer.ApplicationConfig.java

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

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

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);/*from   w ww  .ja v  a  2s  .  com*/
    dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);
    dispatcher.setAsyncSupported(true);

    FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain",
            new DelegatingFilterProxy());
    EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
            DispatcherType.ASYNC);

    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/scripting/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/gitlab/*");

    security.setAsyncSupported(true);

    servletContext.addListener(new ContextLoaderListener(rootContext));

}

From source file:net.ljcomputing.sr.config.StatusReporterWebConfiguration.java

/**
 * @see org.springframework.boot.context.web.SpringBootServletInitializer#onStartup(javax.servlet.ServletContext)
 *//*from   w w  w . j a  v  a 2  s  .co  m*/
public void onStartup(ServletContext container) throws ServletException {
    logger.info("onStartup ...");
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(StatusReporterWebConfiguration.class);
    ctx.setServletContext(container);

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

    servlet.setInitParameter("throwExceptionIfNoHandlerFound", "true");
    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");

    logger.warn("servlet name: {}", servlet.getName());
    logger.warn("servlet throwExceptionIfNoHandlerFound: {}",
            servlet.getInitParameter("throwExceptionIfNoHandlerFound"));
}

From source file:br.com.joaops.awc.AwcApplicationInitializer.java

@Override
public void onStartup(ServletContext sc) throws ServletException {
    WebApplicationContext context = getContext();
    sc.addListener(new ContextLoaderListener(context));
    sc.addFilter("CharacterEncodingFilter", getCharacterEncodingFilter()).addMappingForUrlPatterns(null, true,
            MAPPING_URL);/*w  ww.j  a va2s. c  om*/
    sc.addFilter("RequestContextFilter", getRequestContextFilter()).addMappingForUrlPatterns(null, true,
            MAPPING_URL);
    sc.addFilter("OpenEntityManagerInViewFilter", getOpenEntityManagerInViewFilter())
            .addMappingForUrlPatterns(null, true, MAPPING_URL);
    //sc.addFilter("securityFilter", getDelegatingFilterProxy()).addMappingForUrlPatterns(null, true, MAPPING_URL);
    ServletRegistration.Dynamic dispatcher = sc.addServlet("LoversBookServlet", new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.setAsyncSupported(Boolean.TRUE);
    dispatcher.addMapping(MAPPING_URL);
}

From source file:org.owasp.webgoat.application.WebGoatServletListener.java

private void loadServlets(ServletContextEvent sce) {
    final ServletContext servletContext = sce.getServletContext();
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
            false);//from w w w  . j  a va 2  s .co m
    provider.addIncludeFilter(new AnnotationTypeFilter(LessonServletMapping.class));
    Set<BeanDefinition> candidateComponents = provider.findCandidateComponents("org.owasp.webgoat");
    try {
        for (BeanDefinition beanDefinition : candidateComponents) {
            Class controllerClass = Class.forName(beanDefinition.getBeanClassName());
            LessonServletMapping pathAnnotation = (LessonServletMapping) controllerClass
                    .getAnnotation(LessonServletMapping.class);
            final ServletRegistration.Dynamic dynamic = servletContext
                    .addServlet(controllerClass.getSimpleName(), controllerClass);
            dynamic.addMapping(pathAnnotation.path());
        }
    } catch (Exception e) {
        logger.error("Error", e);
    }
}

From source file:org.utb.project.ServletInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext webApplicationContext = getWebContext();
    servletContext.setSessionTrackingModes(new HashSet<SessionTrackingMode>() {
        {//from w w w. j a va 2 s .c  om
            add(SessionTrackingMode.COOKIE);
        }
    });
    servletContext.addListener(new ContextLoaderListener(webApplicationContext));

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("ProyectoSoftware",
            new DispatcherServlet(webApplicationContext));
    dispatcher.setAsyncSupported(true);
    dispatcher.setLoadOnStartup(0);
    dispatcher.addMapping("/*");
}

From source file:com.alliander.osgp.webdevicesimulator.application.config.WebDeviceSimulatorInitializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {/*  ww  w .j  a  v  a2s  . c o  m*/
        // Force the timezone of application to UTC (required for
        // Hibernate/JDBC)
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final String logLocation = (String) initialContext
                .lookup("java:comp/env/osp/webDeviceSimulator/log-config");
        LogbackConfigurer.initLogging(logLocation);
        InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
                new DispatcherServlet(rootContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);

        servletContext.addListener(new ContextLoaderListener(rootContext));
    } catch (final NamingException e) {
        throw new ServletException("naming exception", e);
    } catch (final FileNotFoundException e) {
        throw new ServletException("Logging file not found", e);
    } catch (final JoranException e) {
        throw new ServletException("Logback exception", e);
    }
}

From source file:at.ac.tuwien.infosys.configuration.WebAppInitializer.java

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

    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();

    root.scan("at.ac.tuwien.infosys");

    context.addListener(new ContextLoaderListener(root));

    final ServletRegistration.Dynamic appServlet = context.addServlet("appServlet",
            new DispatcherServlet(new GenericWebApplicationContext()));
    appServlet.setAsyncSupported(true);/*from ww w  . j  a  v a2s  .c  om*/
    appServlet.setLoadOnStartup(1);
    appServlet.addMapping("/*");
}

From source file:net.orpiske.tcs.service.config.WebAppInitializer.java

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

    mvcContext.setParent(rootContext);//from   w  w  w .j  a  v a  2  s .  c om

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

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

}

From source file:br.com.joaops.smt.SmtApplicationInitializer.java

@Override
public void onStartup(ServletContext sc) throws ServletException {
    WebApplicationContext context = getContext();
    sc.addListener(new ContextLoaderListener(context));
    sc.addFilter("CharacterEncodingFilter", getCharacterEncodingFilter()).addMappingForUrlPatterns(null, true,
            MAPPING_URL);/*from   w w  w.j  a  v a 2 s .  c  o  m*/
    sc.addFilter("RequestContextFilter", getRequestContextFilter()).addMappingForUrlPatterns(null, true,
            MAPPING_URL);
    sc.addFilter("OpenEntityManagerInViewFilter", getOpenEntityManagerInViewFilter())
            .addMappingForUrlPatterns(null, true, MAPPING_URL);
    sc.addFilter("securityFilter", getDelegatingFilterProxy()).addMappingForUrlPatterns(null, false,
            MAPPING_URL); //Deixar como false, para que no d erro no multi tenant! Onde o mtodo SecurityContextHolder.getContext().getAuthentication() sempre retornava nulo depois do login
    ServletRegistration.Dynamic dispatcher = sc.addServlet("LoversBookServlet", new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.setAsyncSupported(Boolean.TRUE);
    dispatcher.addMapping(MAPPING_URL);
}

From source file:org.homiefund.init.WebAppBoostrapper.java

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

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

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

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

    servletContext.addFilter("encodingFilter", new CharacterEncodingFilter("UTF-8", true))
            .addMappingForUrlPatterns(null, false, "/*");

    servletContext.addFilter("httpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null,
            true, "/*");
}