Search in sources :

Example 51 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method getRequest.

public static HttpServletRequest getRequest() {
    final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    final HttpServletRequest request = requestAttributes.getRequest();
    return request;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 52 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project commons by craftercms.

the class GDataPropertyFilter method checkProperty.

protected boolean checkProperty(final String propertyName) {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    Object attributes = request.getParameter(selectorParameterName);
    if (attributes == null) {
        return true;
    } else {
        List<String> query = parseRequestSelector(attributes.toString());
        if (query == null || query.isEmpty()) {
            log.warn("Result of parsing selector {} is null or empty ignoring selector", attributes);
            return true;
        } else {
            return checkPropertyAgainstPattern(query, propertyName);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 53 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project molgenis by molgenis.

the class MolgenisUiUtilsTest method getCurrentUri.

@Test
public void getCurrentUri() {
    String uri = "/menu/test";
    String queryString = "a=b&c=d";
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute("javax.servlet.forward.request_uri", uri);
    request.setQueryString(queryString);
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
    String currentUri = MolgenisUiUtils.getCurrentUri();
    assertNotNull(currentUri);
    assertEquals(currentUri, uri + "?" + queryString);
    request.setQueryString(null);
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
    currentUri = MolgenisUiUtils.getCurrentUri();
    assertNotNull(currentUri);
    assertEquals(currentUri, uri);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Test(org.testng.annotations.Test)

Example 54 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project molgenis by molgenis.

the class SwaggerControllerTest method testInit.

@Test
@WithMockUser
public void testInit() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
    when(tokenService.generateAndStoreToken("user", "For Swagger UI")).thenReturn("ABCDEFG");
    assertEquals("view-swagger-ui", swaggerController.init(model));
    verify(model).addAttribute("molgenisUrl", "http://localhost/plugin/swagger/swagger.yml");
    verify(model).addAttribute("baseUrl", "http://localhost");
    verify(model).addAttribute("token", "ABCDEFG");
    verifyNoMoreInteractions(model);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 55 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project molgenis by molgenis.

the class SwaggerControllerTest method testInitWithoutUser.

@Test
public void testInitWithoutUser() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
    assertEquals("view-swagger-ui", swaggerController.init(model));
    verify(model).addAttribute("molgenisUrl", "http://localhost/plugin/swagger/swagger.yml");
    verify(model).addAttribute("baseUrl", "http://localhost");
    verifyNoMoreInteractions(model);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) Test(org.testng.annotations.Test)

Aggregations

ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)204 HttpServletRequest (javax.servlet.http.HttpServletRequest)92 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)62 RequestAttributes (org.springframework.web.context.request.RequestAttributes)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)32 Test (org.junit.jupiter.api.Test)28 lombok.val (lombok.val)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 Test (org.junit.Test)18 AuthChecker (com.code.server.login.anotation.AuthChecker)17 HttpSession (javax.servlet.http.HttpSession)12 Before (org.junit.Before)12 HashMap (java.util.HashMap)11 Method (java.lang.reflect.Method)8 Date (java.util.Date)7 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)7 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)7 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)6 Map (java.util.Map)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6