Search in sources :

Example 91 with WebApplicationContext

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));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) Test(org.junit.Test)

Example 92 with WebApplicationContext

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);
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Properties(java.util.Properties) MockServletContext(org.springframework.mock.web.test.MockServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 93 with WebApplicationContext

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();
}
Also used : DefaultWebSecurityExpressionHandler(org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Test(org.junit.Test)

Example 94 with WebApplicationContext

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;
}
Also used : WebServiceException(com.openmeap.protocol.WebServiceException) Error(com.openmeap.protocol.dto.Error) ConnectionOpenRequest(com.openmeap.protocol.dto.ConnectionOpenRequest) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) ApplicationManagementService(com.openmeap.protocol.ApplicationManagementService) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Result(com.openmeap.protocol.dto.Result)

Example 95 with WebApplicationContext

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"));
}
Also used : PussycatManager(uk.ac.ebi.spot.goci.pussycat.manager.PussycatManager) HttpSession(javax.servlet.http.HttpSession) ServletContext(javax.servlet.ServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Aggregations

WebApplicationContext (org.springframework.web.context.WebApplicationContext)103 Test (org.junit.Test)32 ServletContext (javax.servlet.ServletContext)17 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)13 ApplicationContext (org.springframework.context.ApplicationContext)11 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)11 HashMap (java.util.HashMap)9 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)9 MockServletContext (org.springframework.mock.web.test.MockServletContext)8 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)7 Filter (javax.servlet.Filter)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)6 Binding (groovy.lang.Binding)5 BeanBuilder (hudson.util.spring.BeanBuilder)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4