Example usage for javax.servlet ServletRegistration.Dynamic getName

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

Introduction

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

Prototype

public String getName();

Source Link

Document

Gets the name of the Servlet or Filter that is represented by this Registration.

Usage

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

/**
 * @see org.springframework.boot.context.web.SpringBootServletInitializer#onStartup(javax.servlet.ServletContext)
 *///  w  w  w. j  a v  a 2  s  .c o  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: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 ww  w. j  a  v a  2  s. 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());
}