use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class HttpEntityMethodProcessorTests method handleReturnValueWithETagAndETagFilter.
// SPR-13423
@Test
public void handleReturnValueWithETagAndETagFilter() throws Exception {
String eTagValue = "\"deadb33f8badf00d\"";
String content = "body";
Method method = getClass().getDeclaredMethod("handle");
MethodParameter returnType = new MethodParameter(method, -1);
FilterChain chain = (req, res) -> {
ResponseEntity<String> returnValue = ResponseEntity.ok().eTag(eTagValue).body(content);
try {
ServletWebRequest requestToUse = new ServletWebRequest((HttpServletRequest) req, (HttpServletResponse) res);
new HttpEntityMethodProcessor(Collections.singletonList(new StringHttpMessageConverter())).handleReturnValue(returnValue, returnType, mavContainer, requestToUse);
assertThat(this.servletResponse.getContentAsString()).as("Response body was cached? It should be written directly to the raw response").isEqualTo(content);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
};
this.servletRequest.setMethod("GET");
new ShallowEtagHeaderFilter().doFilter(this.servletRequest, this.servletResponse, chain);
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
assertThat(this.servletResponse.getHeader(HttpHeaders.ETAG)).isEqualTo(eTagValue);
assertThat(this.servletResponse.getContentAsString()).isEqualTo(content);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method matchWildcard.
@Test
public void matchWildcard() {
ProducesRequestCondition condition = new ProducesRequestCondition("text/*");
HttpServletRequest request = createRequest("text/plain");
assertThat(condition.getMatchingCondition(request)).isNotNull();
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class RequestMethodsRequestConditionTests method getMatchingConditionWithEmptyConditions.
@Test
public void getMatchingConditionWithEmptyConditions() {
RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
for (RequestMethod method : RequestMethod.values()) {
if (method != OPTIONS) {
HttpServletRequest request = new MockHttpServletRequest(method.name(), "");
assertThat(condition.getMatchingCondition(request)).isNotNull();
}
}
testNoMatch(condition, OPTIONS);
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class MvcUriComponentsBuilderTests method adaptRequestFromForwardedHeaders.
// SPR-16668
private void adaptRequestFromForwardedHeaders() throws Exception {
MockFilterChain chain = new MockFilterChain();
new ForwardedHeaderFilter().doFilter(this.request, new MockHttpServletResponse(), chain);
HttpServletRequest adaptedRequest = (HttpServletRequest) chain.getRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(adaptedRequest));
}
use of jakarta.servlet.http.HttpServletRequest in project spring-framework by spring-projects.
the class RequestConditionHolderTests method compareEmpty.
@Test
public void compareEmpty() {
HttpServletRequest request = new MockHttpServletRequest();
RequestConditionHolder empty = new RequestConditionHolder(null);
RequestConditionHolder empty2 = new RequestConditionHolder(null);
RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name"));
assertThat(empty.compareTo(empty2, request)).isEqualTo(0);
assertThat(notEmpty.compareTo(empty, request)).isEqualTo(-1);
assertThat(empty.compareTo(notEmpty, request)).isEqualTo(1);
}
Aggregations