Example usage for org.springframework.web.context.support XmlWebApplicationContext setServletContext

List of usage examples for org.springframework.web.context.support XmlWebApplicationContext setServletContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support XmlWebApplicationContext setServletContext.

Prototype

@Override
    public void setServletContext(@Nullable ServletContext servletContext) 

Source Link

Usage

From source file:com.predic8.membrane.servlet.RouterUtil.java

public static Router initializeRoutersFromSpringWebContext(XmlWebApplicationContext appCtx,
        final ServletContext ctx, String configLocation) {
    appCtx.setServletContext(ctx);
    appCtx.setConfigLocation(configLocation);
    appCtx.refresh();//from   w w  w . j  av a  2s. c  o  m

    Collection<Router> routers = appCtx.getBeansOfType(Router.class).values();
    Router theOne = null;
    for (Router r : routers) {
        r.getResolverMap().addSchemaResolver(new FileSchemaWebAppResolver(ctx));
        if (r.getTransport() instanceof ServletTransport) {
            if (theOne != null)
                throw new RuntimeException("Only one <router> may have a <servletTransport> defined.");
            theOne = r;
        }
    }

    appCtx.start();

    return theOne;
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceModuleConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;// ww w.j  a  v  a2 s.c  om
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceModuleConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceModuleConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.AutowiredRemoteServiceGroupConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;/*from   w w w.  j  ava  2s . c o  m*/
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();
    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "AutowiredRemoteServiceGroupConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();

    AutowiredRemoteServiceGroupConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;//w  w  w  . j  ava2 s .co m
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceControllerConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceControllerConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceGroupConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;//from  w w  w  . ja va2  s .c  o m
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceGroupConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceGroupConfigBeanDefinitionParserTest.appContext = appContext;

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceGroupConfigBeanDefinitionParserTest2.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceGroupConfigBeanDefinitionParserTest.appContext2 = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.CacheControlConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;/*from  w ww .  j  av  a2 s  .c  o  m*/
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();
    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "CacheControlConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();

    CacheControlConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:org.parancoe.web.test.PluginTest.java

@Override
protected ConfigurableApplicationContext createApplicationContext(String[] locations) {
    FileSystemResourceLoader rl = new FileSystemResourceLoader();
    ServletContext servletContext = new MockServletContext(rl);
    XmlWebApplicationContext context = new XmlWebApplicationContext();
    context.setServletContext(servletContext);
    context.setConfigLocations(locations);
    context.refresh();/* w  ww  . j  ava  2 s.c  o m*/
    return context;
}

From source file:org.parancoe.plugin.configuration.TestContextListener.java

@Override
protected void loadApplicationContext() {
    List<String> config = new ArrayList<String>();
    // generici//from w w  w  . j a  v  a2s  .  c o m
    config.add("classpath:org/lambico/spring/dao/hibernate/genericDao.xml");
    config.add("classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml");
    config.add("classpath:org/parancoe/web/parancoeBase.xml");
    config.add("classpath:database-test-server.xml");
    config.add("classpath:applicationContext-test.xml");
    config.add("classpath*:parancoe-plugin.xml");
    config.add("classpath*:applicationContext-plugin.xml");
    config.add("classpath:org/parancoe/plugin/configuration/restful-services.xml");
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setServletContext(servletContext);
    ctx.setConfigLocations(config.toArray(new String[config.size()]));
    ctx.refresh();

    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
    applicationContext = ctx;

    populateDaoMap(ctx);
}

From source file:eu.enhan.timelord.web.init.TimelordWebInit.java

/**
 * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
 *//*from w w w. ja va 2  s .com*/
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootCtx = new AnnotationConfigWebApplicationContext();
    rootCtx.register(AppConfig.class);
    servletContext.addListener(new ContextLoaderListener(rootCtx));

    AnnotationConfigWebApplicationContext webAppCtx = new AnnotationConfigWebApplicationContext();
    webAppCtx.setParent(rootCtx);
    webAppCtx.register(WebConfig.class);

    XmlWebApplicationContext securityCtx = new XmlWebApplicationContext();
    securityCtx.setServletContext(servletContext);
    securityCtx.setParent(rootCtx);
    securityCtx.setConfigLocation("classpath:/spring/security.xml");

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(webAppCtx));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");

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

}

From source file:org.guanxi.idp.persistence.AttributePersistenceTest.java

@Test
public void test() {
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();

    ctx.setConfigLocations(persistenceConfigFiles);
    ctx.setServletContext(servletContext);
    ctx.refresh();/*from w ww .  j a  v a2 s  . c o  m*/

    PersistenceEngine engine = (PersistenceEngine) ctx.getBean("idpPersistenceEngine");

    assertFalse(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME));

    assertTrue(
            engine.persistAttribute(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME, TEST_ATTRIBUTE_VALUE));

    assertTrue(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME));

    assertEquals(engine.getAttributeValue(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME),
            TEST_ATTRIBUTE_VALUE);

    assertTrue(engine.unpersistAttribute(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME));

    assertFalse(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME));
}