Example usage for javax.servlet ServletContext addServlet

List of usage examples for javax.servlet ServletContext addServlet

Introduction

In this page you can find the example usage for javax.servlet ServletContext addServlet.

Prototype

public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass);

Source Link

Document

Adds the servlet with the given name and class type to this servlet context.

Usage

From source file:com.miko.s4netty.config.WorkerWebInitializer.java

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

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WorkerWebConfig.class);

    logger.debug("WebInitializer onStartup");

    ctx.setConfigLocation("spring/app-worker-config.xml");

    ctx.setServletContext(servletContext);
    Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);/* ww w  .ja v a2 s  . com*/

}

From source file:io.springagora.store.AppInitializer.java

/**
 * RESTful API.// w  ww.  ja v a2  s  .  c om
 * 
 * @param container
 *      {@code ServletContext}. Representation of the context that is serving
 *      the JEE application. Servlets, filters and listeners are registered
 *      via this interface.
 */
private void initializeRESTfulAPI(ServletContext container) {
    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(RestConfig.class);

    DispatcherServlet restDispatcher = new DispatcherServlet(dispatcherContext);
    ServletRegistration.Dynamic servletReg = container.addServlet(dispatcherRestName, restDispatcher);
    servletReg.setLoadOnStartup(2);
    servletReg.addMapping(URL_PATTERN_REST);
}

From source file:io.springagora.store.AppInitializer.java

/**
 * Web Application./*from  w  w  w .  j  a  va  2s. c o  m*/
 * 
 * @param container
 *      {@code ServletContext}. Representation of the context that is serving
 *      the JEE application. Servlets, filters and listeners are registered
 *      via this interface.
 */
private void initializeWebApplication(ServletContext container) {
    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(WebConfig.class);

    DispatcherServlet webDispatcher = new DispatcherServlet(dispatcherContext);
    ServletRegistration.Dynamic servletReg = container.addServlet(dispatcherWebName, webDispatcher);
    servletReg.setLoadOnStartup(1);
    servletReg.addMapping(URL_PATTERN_WEB);

    HiddenHttpMethodFilter filter = new HiddenHttpMethodFilter();
    FilterRegistration.Dynamic filterReg = container.addFilter("Hidden HTTP Method Filter", filter);
    filterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, dispatcherWebName);
}

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   w w w.  j  a  v a 2  s  .com
    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: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 w  ww . j  a  va  2 s.  c  om*/
    dispatcher.addMapping("/*");

}

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
 *///from   www  .  j a  v  a2 s .co m
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:hwolf.showcase.Application.java

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

    context.addListener(new FileCleanerCleanup());
    context.addFilter("PrimeFaces FileUpload Filter", new FileUploadFilter()) //
            .addMappingForServletNames(null, false, "FacesServlet");

    context.addFilter("Browser Stats Filter", new UserAgentListener()) //
            .addMappingForUrlPatterns(null, false, "/push/chart.xhtml");
    Dynamic registration = context.addServlet("Push Servlet", new PushServlet());
    registration.setAsyncSupported(true);
    registration.addMapping("/primepush/*");
}

From source file:com.swordcode.webcore.security.testui.TestAppInitializer.java

@Override
public void onStartup(ServletContext container) throws ServletException {
    // Use Spring AnnotationConfigWebApplicationContext to avoid using any xml files.
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(TestAppConfig.class);
    container.addListener(new ContextLoaderListener(rootContext));

    ServletRegistration.Dynamic vaadinRoot = container.addServlet("vaadin", new SecurityTestUI.Servlet());
    vaadinRoot.setLoadOnStartup(1);/*from ww w . j  a  va  2s  .  c om*/
    vaadinRoot.setAsyncSupported(true);
    vaadinRoot.addMapping("/*");

    //      FilterRegistration.Dynamic jpaFilter = container.addFilter("springJPA", OpenEntityManagerInViewFilter.class);
    //      jpaFilte

    //      Filter f = new OpenEntityManagerInViewFilter();
    //      ServletRegistration.Dynamic filter = container.addFilter("/*", f);//org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.class);
}

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  av 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:org.utb.project.ServletInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext webApplicationContext = getWebContext();
    servletContext.setSessionTrackingModes(new HashSet<SessionTrackingMode>() {
        {//from   ww  w  .j  a  v a  2s  . co  m
            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("/*");
}