Search in sources :

Example 21 with RequestContext

use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.

the class SessionScope method remove.

@Override
@Nullable
public Object remove(String name) {
    RequestContext context = RequestContextHolder.getRequired();
    WebSession session = getSession(context);
    if (session != null) {
        Object sessionMutex = WebUtils.getSessionMutex(session);
        synchronized (sessionMutex) {
            return remove(session, name);
        }
    }
    return null;
}
Also used : WebSession(cn.taketoday.web.session.WebSession) RequestContext(cn.taketoday.web.RequestContext) Nullable(cn.taketoday.lang.Nullable)

Example 22 with RequestContext

use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.

the class ServletTestExecutionListenerTests method assertRequestAttributesExist.

private RequestContext assertRequestAttributesExist() {
    RequestContext requestAttributes = RequestContextHolder.get();
    assertThat(requestAttributes).as("request attributes should exist").isNotNull();
    return requestAttributes;
}
Also used : RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext)

Example 23 with RequestContext

use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.

the class ServletTestExecutionListenerTests method assertSetUpOutsideOfStelAttributeDoesNotExist.

private void assertSetUpOutsideOfStelAttributeDoesNotExist() {
    RequestContext requestAttributes = assertRequestAttributesExist();
    Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL);
    assertThat(setUpOutsideOfStel).as(SET_UP_OUTSIDE_OF_STEL + " should NOT exist as a request attribute").isNull();
}
Also used : RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext)

Example 24 with RequestContext

use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.

the class ServletTestExecutionListenerTests method assertSetUpOutsideOfStelAttributeExists.

private void assertSetUpOutsideOfStelAttributeExists() {
    RequestContext requestAttributes = assertRequestAttributesExist();
    Object setUpOutsideOfStel = requestAttributes.getAttribute(SET_UP_OUTSIDE_OF_STEL);
    assertThat(setUpOutsideOfStel).as(SET_UP_OUTSIDE_OF_STEL + " should exist as a request attribute").isNotNull();
}
Also used : RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext)

Example 25 with RequestContext

use of cn.taketoday.web.RequestContext in project today-framework by TAKETODAY.

the class CorsFilterTests method validActualRequest.

@Test
public void validActualRequest() throws ServletException, IOException {
    MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(), "/test.html");
    request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com");
    request.addHeader("header2", "foo");
    MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain filterChain = (filterRequest, filterResponse) -> {
        final RequestContext context = ServletUtils.getRequestContext(request, response);
        assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("https://domain2.com");
        final String header = response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS);
        assertThat(header).isEqualTo("header3, header4");
    };
    filter.doFilter(request, response, filterChain);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CorsFilter(cn.taketoday.web.servlet.filter.CorsFilter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FilterChain(jakarta.servlet.FilterChain) IOException(java.io.IOException) RequestContext(cn.taketoday.web.RequestContext) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) ServletException(jakarta.servlet.ServletException) Test(org.junit.jupiter.api.Test) HttpMethod(cn.taketoday.http.HttpMethod) HttpHeaders(cn.taketoday.http.HttpHeaders) Assertions.fail(org.assertj.core.api.Assertions.fail) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ServletUtils(cn.taketoday.web.servlet.ServletUtils) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) FilterChain(jakarta.servlet.FilterChain) RequestContext(cn.taketoday.web.RequestContext) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

RequestContext (cn.taketoday.web.RequestContext)109 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)65 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)46 Test (org.junit.jupiter.api.Test)42 ModelAndView (cn.taketoday.web.view.ModelAndView)22 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)22 HashMap (java.util.HashMap)22 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)12 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)12 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)12 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)12 WebServletApplicationContext (cn.taketoday.web.servlet.WebServletApplicationContext)10 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)9 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)9 Map (java.util.Map)8 Properties (java.util.Properties)8 MockServletContext (cn.taketoday.web.mock.MockServletContext)6 WebSession (cn.taketoday.web.session.WebSession)6 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)6 View (cn.taketoday.web.view.View)6