use of jakarta.servlet.http.HttpServletRequestWrapper in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method getHeader.
@Override
public String getHeader(String s, boolean checkCase) {
if ("content-type".equalsIgnoreCase(s)) {
return getContentType();
}
String name = b.request.getHeader(s);
if (name == null) {
if (b.headers.get(s) != null) {
return b.headers.get(s);
}
if (s.startsWith(X_ATMOSPHERE) && isNotNoOps()) {
// Craziness with Struts 2 who wraps String attribute as BigDecimal
// https://github.com/Atmosphere/atmosphere/issues/1367
Object o = attributeWithoutException(b.request, s);
if (o == null || String.class.isAssignableFrom(o.getClass())) {
name = (String) o;
} else {
try {
if (HttpServletRequestWrapper.class.isAssignableFrom(b.request.getClass())) {
HttpServletRequest hsr = b.request;
while (hsr instanceof HttpServletRequestWrapper) {
hsr = (HttpServletRequest) ((HttpServletRequestWrapper) hsr).getRequest();
o = attributeWithoutException(hsr, s);
if (o == null || String.class.isAssignableFrom(o.getClass())) {
name = (String) o;
break;
}
}
}
} catch (Exception ex) {
logger.warn("", ex);
}
}
}
}
if (name == null && checkCase) {
return getHeader(s.toLowerCase(), false);
}
if (name == null && "connection".equalsIgnoreCase(s)) {
return "keep-alive";
}
return name;
}
use of jakarta.servlet.http.HttpServletRequestWrapper in project spring-security by spring-projects.
the class FilterChainProxyTests method setup.
@BeforeEach
public void setup() throws Exception {
this.matcher = mock(RequestMatcher.class);
this.filter = mock(Filter.class);
willAnswer((Answer<Object>) (inv) -> {
Object[] args = inv.getArguments();
FilterChain fc = (FilterChain) args[2];
HttpServletRequestWrapper extraWrapper = new HttpServletRequestWrapper((HttpServletRequest) args[0]);
fc.doFilter(extraWrapper, (HttpServletResponse) args[1]);
return null;
}).given(this.filter).doFilter(any(), any(), any());
this.fcp = new FilterChainProxy(new DefaultSecurityFilterChain(this.matcher, Arrays.asList(this.filter)));
this.fcp.setFilterChainValidator(mock(FilterChainProxy.FilterChainValidator.class));
this.request = new MockHttpServletRequest("GET", "");
this.request.setServletPath("/path");
this.response = new MockHttpServletResponse();
this.chain = mock(FilterChain.class);
}
use of jakarta.servlet.http.HttpServletRequestWrapper in project spring-framework by spring-projects.
the class DispatcherServletTests method existingMultipartRequestButWrapped.
@Test
public void existingMultipartRequestButWrapped() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def");
request.addPreferredLocale(Locale.CANADA);
request.addUserRole("role1");
MockHttpServletResponse response = new MockHttpServletResponse();
ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext().getBean("multipartResolver");
MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request);
complexDispatcherServlet.service(new HttpServletRequestWrapper(multipartRequest), response);
multipartResolver.cleanupMultipart(multipartRequest);
assertThat(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)).isNull();
assertThat(request.getAttribute("cleanedUp")).isNotNull();
}
use of jakarta.servlet.http.HttpServletRequestWrapper in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getBodyWithWrappedRequest.
// SPR-13317
@Test
public void getBodyWithWrappedRequest() throws Exception {
byte[] bytes = "content".getBytes("UTF-8");
MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes);
this.mockRequest.addFile(part);
HttpServletRequest wrapped = new HttpServletRequestWrapper(this.mockRequest);
ServerHttpRequest request = new RequestPartServletServerHttpRequest(wrapped, "part");
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
assertThat(result).isEqualTo(bytes);
}
use of jakarta.servlet.http.HttpServletRequestWrapper in project spring-framework by spring-projects.
the class ServletWebRequestTests method decoratedNativeRequest.
@Test
public void decoratedNativeRequest() {
HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
assertThat(request.getNativeRequest()).isSameAs(decoratedRequest);
assertThat(request.getNativeRequest(ServletRequest.class)).isSameAs(decoratedRequest);
assertThat(request.getNativeRequest(HttpServletRequest.class)).isSameAs(decoratedRequest);
assertThat(request.getNativeRequest(MockHttpServletRequest.class)).isSameAs(servletRequest);
assertThat(request.getNativeRequest(MultipartRequest.class)).isNull();
assertThat(request.getNativeResponse()).isSameAs(decoratedResponse);
assertThat(request.getNativeResponse(ServletResponse.class)).isSameAs(decoratedResponse);
assertThat(request.getNativeResponse(HttpServletResponse.class)).isSameAs(decoratedResponse);
assertThat(request.getNativeResponse(MockHttpServletResponse.class)).isSameAs(servletResponse);
assertThat(request.getNativeResponse(MultipartRequest.class)).isNull();
}
Aggregations