use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class DispatcherServletTests method cleanupAfterIncludeWithRestore.
@Test
public void cleanupAfterIncludeWithRestore() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/main.do");
MockHttpServletResponse response = new MockHttpServletResponse();
request.setAttribute("test1", "value1");
request.setAttribute("test2", "value2");
WebApplicationContext wac = new StaticWebApplicationContext();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
TestBean command = new TestBean();
request.setAttribute("command", command);
request.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/form.do");
simpleDispatcherServlet.service(request, response);
assertEquals("value1", request.getAttribute("test1"));
assertEquals("value2", request.getAttribute("test2"));
assertSame(wac, request.getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE));
}
use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class BaseViewTests method dynamicModelOverridesStaticAttributesIfCollision.
@Test
public void dynamicModelOverridesStaticAttributesIfCollision() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("one", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
tv.render(model, request, response);
// Check it contains all
checkContainsAll(model, tv.model);
assertEquals(3, tv.model.size());
assertEquals("else", tv.model.get("something"));
assertTrue(tv.initialized);
}
use of org.springframework.web.context.WebApplicationContext in project spring-security by spring-projects.
the class AbstractAuthorizeTagTests method expressionFromChildContext.
@Test
@SuppressWarnings("rawtypes")
public void expressionFromChildContext() throws IOException {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass", "USER"));
DefaultWebSecurityExpressionHandler expected = new DefaultWebSecurityExpressionHandler();
tag.setAccess("permitAll");
WebApplicationContext wac = mock(WebApplicationContext.class);
when(wac.getBeansOfType(SecurityExpressionHandler.class)).thenReturn(Collections.<String, SecurityExpressionHandler>singletonMap("wipe", expected));
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
assertThat(tag.authorize()).isTrue();
}
use of org.springframework.web.context.WebApplicationContext in project OpenMEAP by OpenMEAP.
the class ApplicationManagementServlet method connectionOpenRequest.
/**
* Pulls parameters out of the request and passes them to the ApplicationManagementPortType bean pulled from the WebApplicationContext
*
* @param req
* @return
*/
public Result connectionOpenRequest(HttpServletRequest req) {
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
ConnectionOpenRequest request = createConnectionOpenRequest(req);
Result result = new Result();
try {
ConnectionOpenResponse response = ((ApplicationManagementService) context.getBean("applicationManagementService")).connectionOpen(request);
result.setConnectionOpenResponse(response);
} catch (WebServiceException wse) {
Error err = new Error();
err.setCode(wse.getType().asErrorCode());
err.setMessage(wse.getMessage());
result.setError(err);
}
return result;
}
use of org.springframework.web.context.WebApplicationContext in project goci by EBISPOT.
the class PussycatAwareHttpSessionListener method sessionDestroyed.
@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
HttpSession session = httpSessionEvent.getSession();
ServletContext servletContext = session.getServletContext();
WebApplicationContext appContext = (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
PussycatManager pussycatManager = appContext.getBean("pussycatManager", PussycatManager.class);
getLog().debug("HttpSession '" + session.getId() + "' destroyed - attempting to unbind resources");
boolean unbound = pussycatManager.unbindResources(session);
getLog().debug("Unbinding resources for HttpSession '" + session.getId() + "' " + (unbound ? "ok" : "failed"));
}
Aggregations