List of usage examples for org.springframework.web.context.support GenericWebApplicationContext getServletContext
@Override
@Nullable
public ServletContext getServletContext()
From source file:org.parancoe.web.test.junit4.AbstractJspTest.java
/** * Reset all contexts.// www . jav a 2 s . co m */ protected void resetContexts() { GenericWebApplicationContext context = (GenericWebApplicationContext) applicationContext; ServletContext servletContext = context.getServletContext(); pageContext = new MockPageContext(servletContext, request, response); requestContext = new JspAwareRequestContext(pageContext); pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext); }
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();// w w w .ja va 2 s. c om 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); }