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

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

Introduction

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

Prototype

@Nullable
public final WebApplicationContext getWebApplicationContext() 

Source Link

Document

Return this servlet's WebApplicationContext.

Usage

From source file:com.serotonin.m2m2.Lifecycle.java

private void configureUrls(WebAppContext context) {
    try {//from www .  ja v a  2s .c o m
        ServletHolder sh = context.getServletHandler().getServlet("springDispatcher");
        DispatcherServlet servlet = (DispatcherServlet) sh.getServlet();
        BlabberUrlHandlerMapping urlMap = (BlabberUrlHandlerMapping) servlet.getWebApplicationContext()
                .getBean("mappings");

        for (HandlerInterceptorDefinition def : ModuleRegistry
                .getDefinitions(HandlerInterceptorDefinition.class))
            urlMap.addInterceptor(def.getInterceptor());
        urlMap.initInterceptors();

        for (UriMappingDefinition def : ModuleRegistry.getDefinitions(UriMappingDefinition.class)) {
            String modulePath = "/modules/" + def.getModule().getName();
            String viewName = null;
            if (def.getJspPath() != null) {
                viewName = modulePath + "/" + def.getJspPath();
            }
            UrlHandler handler = def.getHandler();
            Controller controller = new UrlHandlerController(handler, modulePath, viewName);

            urlMap.registerHandler(def.getPath(), controller);
        }

        for (UrlMappingDefinition def : ModuleRegistry.getDefinitions(UrlMappingDefinition.class)) {
            String modulePath = "/modules/" + def.getModule().getName();
            String viewName = null;
            if (def.getJspPath() != null) {
                viewName = modulePath + "/" + def.getJspPath();
            }
            UrlHandler handler = def.getHandler();
            Controller controller = new UrlHandlerController(handler, modulePath, viewName);

            urlMap.registerHandler(def.getUrlPath(), controller);
        }
    } catch (Exception e) {
        BlabberUrlHandlerMapping urlMap;
        throw new RuntimeException(e);
    }
}

From source file:org.motechproject.server.appointments.Activator.java

private void serviceAdded(HttpService service) {
    try {/*from   w w w.  jav  a 2s . co m*/
        DispatcherServlet dispatcherServlet = new DispatcherServlet();
        dispatcherServlet.setContextConfigLocation(CONTEXT_CONFIG_LOCATION);
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            service.registerServlet(SERVLET_URL_MAPPING, dispatcherServlet, null, null);
            logger.debug("Servlet registered");
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }

        // register all annotated handlers
        EventAnnotationBeanPostProcessor.registerHandlers(BeanFactoryUtils
                .beansOfTypeIncludingAncestors(dispatcherServlet.getWebApplicationContext(), Object.class));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.motechproject.server.demo.Activator.java

private void serviceAdded(HttpService service) {
    try {//from   w  w w  . ja  v a  2 s  . c  om
        DispatcherServlet dispatcherServlet = new DispatcherServlet();
        dispatcherServlet.setContextConfigLocation(CONTEXT_CONFIG_LOCATION);
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            service.registerServlet(SERVLET_URL_MAPPING, dispatcherServlet, null, null);
            logger.debug("Servlet registered");
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }

        // register all annotated handlers
        EventAnnotationBeanPostProcessor.registerHandlers(BeanFactoryUtils
                .beansOfTypeIncludingAncestors(dispatcherServlet.getWebApplicationContext(), Object.class));

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:org.motechproject.server.outbox.Activator.java

private void serviceAdded(HttpService service) {
    try {/*  ww w.  j a v a 2s .c om*/
        DispatcherServlet dispatcherServlet = new DispatcherServlet();
        dispatcherServlet.setContextConfigLocation(CONTEXT_CONFIG_LOCATION);
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            service.registerServlet(SERVLET_URL_MAPPING, dispatcherServlet, null, null);
            logger.debug("Servlet registered");
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }

        // register all annotated handlers
        EventAnnotationBeanPostProcessor.registerHandlers(BeanFactoryUtils
                .beansOfTypeIncludingAncestors(dispatcherServlet.getWebApplicationContext(), Object.class));

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.motechproject.server.voxeo.Activator.java

private void serviceAdded(HttpService service) {
    try {/* ww  w . j  a va2 s . com*/
        DispatcherServlet dispatcherServlet = new DispatcherServlet();
        dispatcherServlet.setContextConfigLocation(CONTEXT_CONFIG_LOCATION);
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
            service.registerServlet(SERVLET_URL_MAPPING, dispatcherServlet, null, null);
            logger.debug("Servlet registered");
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }

        // register all annotated handlers
        EventAnnotationBeanPostProcessor.registerHandlers(BeanFactoryUtils
                .beansOfTypeIncludingAncestors(dispatcherServlet.getWebApplicationContext(), Object.class));
        // create tree objects in the database
        bootStrap();

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}