List of usage examples for org.springframework.web.context.support GenericWebApplicationContext setServletContext
@Override public void setServletContext(@Nullable ServletContext servletContext)
From source file:com.autentia.wuija.spring.RegisterWebSessionScopeTestContextLoader.java
@Override protected void customizeContext(GenericWebApplicationContext context) { final MockServletContext servlet = new MockServletContext(); context.setServletContext(servlet); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpSession session = new MockHttpSession(); request.setSession(session);//from ww w . j ava2s.c om RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); context.getBeanFactory().registerScope("session", new SessionScope()); }
From source file:grgr.test.cxf.UndertowCxfTest.java
@Test public void testUndertowServlet() throws Exception { ServletContainer servletContainer = Servlets.newContainer(); // parent, webcontext-wide Spring context ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("/UndertowCxfTest-context.xml"); // represents a servlet deployment - representing everything we can find in web.xml DeploymentInfo di = Servlets.deployment().setClassLoader(UndertowCxfTest.class.getClassLoader()) .setContextPath("/").setDeploymentName("ROOT.war").setDisplayName("Default Application") .setUrlEncoding("UTF-8").addServlets( Servlets.servlet("cxf", CXFServlet.class, new ImmediateInstanceFactory<>(new CXFServlet())) .addMapping("/*")); DeploymentManager dm = servletContainer.addDeployment(di); dm.deploy();//from w w w. j av a2 s. co m HttpHandler handler = dm.start(); // parent, webcontext-wide Spring web context GenericWebApplicationContext wac = new GenericWebApplicationContext(); wac.setParent(parent); wac.setServletContext(dm.getDeployment().getServletContext()); wac.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); wac.refresh(); PathHandler path = Handlers.path().addPrefixPath(di.getContextPath(), Handlers.requestDump(handler)); createAndStartServlet(8000, path); }
From source file:org.motechproject.server.osgi.OsgiFrameworkServiceTest.java
private WebApplicationContext getWebApplicationContext() { GenericWebApplicationContext wac = BeanUtils.instantiateClass(GenericWebApplicationContext.class); wac.setParent(applicationContext);//from w w w . ja va2 s . c om wac.setServletContext(new MockServletContext()); return wac; }
From source file:com.example.springsecurity.web.controllers.GenericWebContextLoader.java
protected void prepareContext(GenericWebApplicationContext context) { this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(this.servletContext); }
From source file:com.wbss.mycoffee.in.helper.spring.WebContextLoader.java
@Override public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { final GenericWebApplicationContext webContext = new GenericWebApplicationContext(); SERVLET_CONTEXT.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext); webContext.setServletContext(SERVLET_CONTEXT); createBeanDefinitionReader(webContext).loadBeanDefinitions(mergedConfig.getLocations()); AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext); webContext.refresh();/*from w ww . ja va 2s . c o m*/ webContext.registerShutdownHook(); return webContext; }
From source file:de.uni_koeln.spinfo.maalr.services.editor.TestEditorService.java
@Before public void beforeTest() throws Exception { Database.getInstance().deleteAllEntries(); loginManager.logout();/*from w w w .ja va 2 s .co m*/ GenericWebApplicationContext context = new GenericWebApplicationContext(); MockServletContext servlet = new MockServletContext(); context.setServletContext(servlet); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpSession session = new MockHttpSession(); request.setSession(session); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); context.refresh(); context.getBeanFactory().registerScope("session", new SessionScope()); loginManager.login("admin", "admin"); File file = File.createTempFile("maalr", "test"); File indexDir = new File(file.getParentFile(), "maalr_test" + UUID.randomUUID().toString() + "_idx"); Assert.assertFalse(indexDir.exists()); indexDir.mkdir(); file.deleteOnExit(); LuceneConfiguration environment = new LuceneConfiguration(); environment.setBaseDirectory(indexDir.getAbsolutePath()); Dictionary d = new Dictionary(); d.setEnvironment(environment); }
From source file:org.parancoe.web.test.junit4.WebXmlContextLoader.java
/** * Loads a Spring ApplicationContext from the supplied * <code>locations</code>. and creates a standard {@link GenericWebApplicationContext} instance. * * @return a new application context/*from w ww .ja v a 2 s . c o m*/ * @see org.springframework.test.context.ContextLoader#loadContext * @see GenericWebApplicationContext * @see #createBeanDefinitionReader(GenericApplicationContext) * @see BeanDefinitionReader */ @Override public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Loading ApplicationContext for locations [{}].", StringUtils.arrayToCommaDelimitedString(locations)); } GenericWebApplicationContext context = new GenericWebApplicationContext(); createBeanDefinitionReader(context).loadBeanDefinitions(locations); MockServletContext servletContext = new MockServletContext(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(servletContext); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:com.centeractive.ws.server.core.SoapServer.java
private void configureWebContext() { ServletContext servletContext = getServletContext(); GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(servletContext); webContext.setParent(context);/* www . j a v a 2 s.c o m*/ webContext.refresh(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext); if (webContext != null) { endpoint = webContext.getBean(ENDPOINT_BEAN_NAME, GenericContextDomEndpoint.class); } }
From source file:org.reficio.ws.server.core.SoapServer.java
private void configureWebContext() { ServletContext servletContext = getServletContext(); GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(servletContext); webContext.setParent(context);/* ww w.j a v a 2 s . co m*/ webContext.refresh(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext); if (webContext != null) { endpoint = webContext.getBean(SoapServerConstants.ENDPOINT_BEAN_NAME, GenericContextDomEndpoint.class); } }