Example usage for org.springframework.web.servlet DispatcherServlet DispatcherServlet

List of usage examples for org.springframework.web.servlet DispatcherServlet DispatcherServlet

Introduction

In this page you can find the example usage for org.springframework.web.servlet DispatcherServlet DispatcherServlet.

Prototype

public DispatcherServlet(WebApplicationContext webApplicationContext) 

Source Link

Document

Create a new DispatcherServlet with the given web application context.

Usage

From source file:eionet.transfer.TransferWebAppInitializer.java

@Override
public void onStartup(ServletContext container) {
    XmlWebApplicationContext appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("/WEB-INF/classes/spring-db-config.xml "
            + "/WEB-INF/classes/spring-init-config.xml " + "/WEB-INF/classes/spring-mvc-config.xml");

    // Listeners/*from   ww  w .  j av a2s .  c  om*/
    //SingleSignOutHttpSessionListener ssoListener = new SingleSignOutHttpSessionListener(appContext);
    //container.addListener(ssoListener);

    //ContextLoaderListener contextLoaderListener = new ContextLoaderListener(appContext);
    //container.addListener(contextLoaderListener);

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

    String location = null;
    try {
        location = System.getProperty("upload.dir", null);
    } catch (Exception e) {
        location = null;
    }

    logger.info("Upload directory configured to: " + (location == null ? "[default]" : location));

    //long maxFileSize = 5000000L;
    //long maxRequestSize = 5000000L;
    //int fileSizeThreshold = 0;
    MultipartConfigElement multipartConfigElement = new MultipartConfigElement(location);
    //MultipartConfigElement multipartConfigElement = new MultipartConfigElement(location, maxFileSize, maxRequestSize, fileSizeThreshold);
    dispatcher.setMultipartConfig(multipartConfigElement);

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

From source file:com.gantzgulch.sharing.configuration.WebInitializer.java

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

    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.getEnvironment().setActiveProfiles("production");
    appContext.scan("com.gantzgulch.sharing");

    ContextLoaderListener contextListener = new ContextLoaderListener(appContext);
    servletContext.addListener(contextListener);

    DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("springSecurityFilterChain");
    FilterRegistration.Dynamic filter = servletContext.addFilter("securityFilter", filterProxy);
    filter.addMappingForUrlPatterns(null, false, "/*");

    AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
    webContext.register(MvcAppConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("sharing",
            new DispatcherServlet(webContext));
    dispatcher.setLoadOnStartup(1);/*from   w  ww.j  av a  2 s  .  c o  m*/
    dispatcher.addMapping("*.htm");
}

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

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {/*  w  ww  .java  2  s . c om*/
        // 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:com.github.djabry.platform.service.config.TestInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet",
            new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);//from  www . j  a  v a 2 s  .  c  o m
    dispatcher.addMapping("/*");

}

From source file:com.mycompany.testeproject.App.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet",
            new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);/*from  w w  w  .j  a  v  a2s  .  c  o  m*/
    dispatcher.addMapping("/rest/*");
}

From source file:org.openwms.client.application.ApplicationInitializer.java

/**
 * {@inheritDoc}/*from w w  w . j ava 2 s.  c o  m*/
 * 
 * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
 */
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // Load application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(WebApplicationContextConfiguration.class);

    // Context loader listener
    servletContext.addListener(new ContextLoaderListener(rootContext));

    // Dispatcher servlet
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}

From source file:com.dominion.salud.mpr.configuration.MPRInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.scan("com.dominion.salud.mpr.configuration");
    ctx.setServletContext(servletContext);
    System.setProperty("mpr.conf.home", findConfigurationAndLogger(ctx));
    ctx.refresh();/*from  w w  w.jav  a 2s.c om*/

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(ctx));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
    dispatcher.addMapping("/controller/*");
    dispatcher.addMapping("/services/*");
    servletContext.addListener(new ContextLoaderListener(ctx));

    // Configuracion GENERAL DEL MODULO
    MPRConstantes._MPR_HOME = StringUtils.endsWith(servletContext.getRealPath("/"), File.separator)
            ? servletContext.getRealPath("/")
            : servletContext.getRealPath("/") + File.separator;
    MPRConstantes._MPR_CONF_HOME = ctx.getEnvironment().getProperty("mpr.conf.home");
    MPRConstantes._MPR_VERSION = ResourceBundle.getBundle("version").getString("version");
    MPRConstantes._MPR_RESOURCES = MPRConstantes._MPR_HOME + "resources" + File.separator;
    MPRConstantes._MPR_TEMP = MPRConstantes._MPR_HOME + "WEB-INF" + File.separator + "temp" + File.separator;
    MPRConstantes._MPR_CONTEXT_NAME = servletContext.getServletContextName();
    MPRConstantes._MPR_CONTEXT_PATH = servletContext.getContextPath();
    MPRConstantes._MPR_CONTEXT_SERVER = servletContext.getServerInfo();

    // Configuracion de LOGS DEL MODULO
    if (StringUtils.isBlank(
            ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile())) {
        ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE"))
                .setFile(MPRConstantes._MPR_HOME + "WEB-INF" + File.separator + "classes" + File.separator
                        + "logs" + File.separator + "mpr-desktop.log");
    }
    MPRConstantes._MPR_LOGS = new File(
            ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile())
                    .getParent();

    // Parametrizacion GENERAL DEL SISTEMA
    MPRConstantes._ENABLE_TECHNICAL_INFORMATION = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.enable.technical.information"))
                    ? Boolean.parseBoolean(ctx.getEnvironment().getProperty("mpr.enable.technical.information"))
                    : false;

    // Parametrizacion de CONEXION A EMPI
    MPRConstantes._EMPI_ENABLE = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.enable"))
            ? Boolean.parseBoolean(ctx.getEnvironment().getProperty("mpr.empi.enable"))
            : false;
    MPRConstantes._EMPI_USUARIO = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.usuario"))
            ? ctx.getEnvironment().getProperty("mpr.empi.usuario")
            : "";
    MPRConstantes._EMPI_SISTEMA = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.sistema"))
            ? ctx.getEnvironment().getProperty("mpr.empi.sistema")
            : "";
    MPRConstantes._EMPI_URL = StringUtils.isNotBlank(ctx.getEnvironment().getProperty("mpr.empi.url"))
            ? ctx.getEnvironment().getProperty("mpr.empi.url")
            : "";

    // Parametrizacion de TAREAS PROGRAMADAS
    MPRConstantes._TASK_BUZON_IN_PROCESS_MESSAGES = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.process.messages"))
                    ? ctx.getEnvironment().getProperty("mpr.task.buzon.in.process.messages")
                    : MPRConstantes._TASK_BUZON_IN_PROCESS_MESSAGES;
    MPRConstantes._TASK_BUZON_OUT_PROCESS_MESSAGES = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.process.messages"))
                    ? ctx.getEnvironment().getProperty("mpr.task.buzon.out.process.messages")
                    : MPRConstantes._TASK_BUZON_OUT_PROCESS_MESSAGES;
    MPRConstantes._TASK_BUZON_IN_HIS_CLEAN = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean"))
                    ? ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean")
                    : MPRConstantes._TASK_BUZON_IN_HIS_CLEAN;
    MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean"))
                    ? ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean")
                    : MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN;
    MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean.old"))
                    ? Integer.parseInt(ctx.getEnvironment().getProperty("mpr.task.buzon.in.his.clean.old"))
                    : MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD;
    MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean.old"))
                    ? Integer.parseInt(ctx.getEnvironment().getProperty("mpr.task.buzon.out.his.clean.old"))
                    : MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD;
    MPRConstantes._TASK_BUZON_IN_CLEAN = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.in.clean"))
                    ? ctx.getEnvironment().getProperty("mpr.task.buzon.in.clean")
                    : MPRConstantes._TASK_BUZON_IN_CLEAN;
    MPRConstantes._TASK_BUZON_OUT_CLEAN = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.out.clean"))
                    ? ctx.getEnvironment().getProperty("mpr.task.buzon.out.clean")
                    : MPRConstantes._TASK_BUZON_OUT_CLEAN;
    MPRConstantes._TASK_BUZON_ERRORES_CLEAN = StringUtils
            .isNotBlank(ctx.getEnvironment().getProperty("mpr.task.buzon.errores.clean"))
                    ? ctx.getEnvironment().getProperty("mpr.task.buzon.errores.clean")
                    : MPRConstantes._TASK_BUZON_ERRORES_CLEAN;

    logger.info("Iniciando el modulo de [" + MPRConstantes._MPR_CONTEXT_NAME + "]");
    logger.debug("     Configuracion GENERAL DEL MODULO");
    logger.debug("          mpr.home: " + MPRConstantes._MPR_HOME);
    logger.debug("          mpr.conf.home: " + MPRConstantes._MPR_CONF_HOME);
    logger.debug("          mpr.version: " + MPRConstantes._MPR_VERSION);
    logger.debug("          mpr.resources: " + MPRConstantes._MPR_RESOURCES);
    logger.debug("          mpr.temp: " + MPRConstantes._MPR_TEMP);
    logger.debug("          mpr.logs: " + MPRConstantes._MPR_LOGS);
    logger.debug("          mpr.logs.file: "
            + ((FileAppender) org.apache.log4j.Logger.getRootLogger().getAppender("LOGFILE")).getFile());
    logger.debug("          mpr.context.name: " + MPRConstantes._MPR_CONTEXT_NAME);
    logger.debug("          mpr.context.path: " + MPRConstantes._MPR_CONTEXT_PATH);
    logger.debug("          mpr.context.server: " + MPRConstantes._MPR_CONTEXT_SERVER);
    logger.debug("          java.version: " + ctx.getEnvironment().getProperty("java.version"));
    logger.debug("");
    logger.debug("     Parametrizacion GENERAL DEL SISTEMA");
    logger.debug("          mpr.enable.technical.information: " + MPRConstantes._ENABLE_TECHNICAL_INFORMATION);
    logger.debug("     Parametrizacion de CONEXION A EMPI");
    logger.debug("          mpr.empi.enable: " + MPRConstantes._EMPI_ENABLE);
    logger.debug("          mpr.empi.usuario: " + MPRConstantes._EMPI_USUARIO);
    logger.debug("          mpr.empi.sistema: " + MPRConstantes._EMPI_SISTEMA);
    logger.debug("          mpr.empi.url: " + MPRConstantes._EMPI_URL);
    logger.debug("     Parametrizacion de TAREAS PROGRAMADAS");
    logger.debug(
            "          mpr.task.buzon.in.process.messages: " + MPRConstantes._TASK_BUZON_IN_PROCESS_MESSAGES);
    logger.debug(
            "          mpr.task.buzon.out.process.messages: " + MPRConstantes._TASK_BUZON_OUT_PROCESS_MESSAGES);
    logger.debug("          mpr.task.buzon.in.his.clean: " + MPRConstantes._TASK_BUZON_IN_HIS_CLEAN);
    logger.debug("          mpr.task.buzon.out.his.clean: " + MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN);
    logger.debug("          mpr.task.buzon.in.his.clean.old: " + MPRConstantes._TASK_BUZON_IN_HIS_CLEAN_OLD);
    logger.debug("          mpr.task.buzon.out.his.clean.old: " + MPRConstantes._TASK_BUZON_OUT_HIS_CLEAN_OLD);
    logger.debug("          mpr.task.buzon.in.clean: " + MPRConstantes._TASK_BUZON_IN_CLEAN);
    logger.debug("          mpr.task.buzon.out.clean: " + MPRConstantes._TASK_BUZON_OUT_CLEAN);
    logger.debug("          mpr.task.buzon.errores.clean: " + MPRConstantes._TASK_BUZON_ERRORES_CLEAN);
    logger.debug("     Variables de ENTORNO de utilidad");
    logger.debug("          catalina.home: " + ctx.getEnvironment().getProperty("catalina.home"));
    logger.debug("          jboss.home.dir: " + ctx.getEnvironment().getProperty("jboss.home.dir"));
    logger.info("Modulo [" + MPRConstantes._MPR_CONTEXT_NAME + "] iniciado correctamente");
}

From source file:org.jtwig.acceptance.AbstractJtwigAcceptanceTest.java

private void startServer() throws Exception {
    jetty = new Server(9090);

    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.register(ConfigClass.class, getClass());
    applicationContext.register(configurationClasses());

    ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(applicationContext));
    ServletContextHandler context = new ServletContextHandler();

    context.setErrorHandler(null); // use Spring exception handler(s)
    context.setContextPath("/");
    context.setBaseResource(Resource.newResource(new ClassPathResource("").getURI().toString()));
    context.setSessionHandler(new SessionHandler());
    context.addServlet(servletHolder, "/");

    jetty.setHandler(context);/*w  ww  . ja v a 2 s . com*/
    jetty.start();
}

From source file:config.JettyConfiguration.java

@Bean
public ServletHolder dispatcherServlet() {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MvcConfiguration.class);
    DispatcherServlet servlet = new DispatcherServlet(ctx);
    ServletHolder holder = new ServletHolder("dispatcher-servlet", servlet);
    holder.setInitOrder(1);// www  . jav a  2 s .  co  m
    return holder;
}

From source file:com.github.cherimojava.orchidae.Starter.java

private ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context)
        throws IOException {
    ServletContextHandler servletContext = new ServletContextHandler();
    servletContext.addEventListener(new ContextLoaderListener(context));
    ServletHolder holder = new ServletHolder("default", new DispatcherServlet(context));
    holder.getRegistration()//from  w  ww  .  j a v  a2s  . c o  m
            .setMultipartConfig(new MultipartConfigElement("./tmp", 20000000, 20000000, 200000));
    servletContext.addServlet(holder, "/*");
    servletContext.addEventListener(new ServletListener(context));
    servletContext.setResourceBase(new FileSystemResource(new File("./")).toString());
    servletContext.setSessionHandler(new SessionHandler());
    return servletContext;
}