Search in sources :

Example 36 with ServletServerHttpResponse

use of org.springframework.http.server.ServletServerHttpResponse in project spring-framework by spring-projects.

the class AbstractHttpRequestTests method resetResponse.

protected void resetResponse() {
    this.servletResponse = new MockHttpServletResponse();
    this.response = new ServletServerHttpResponse(this.servletResponse);
}
Also used : ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse)

Example 37 with ServletServerHttpResponse

use of org.springframework.http.server.ServletServerHttpResponse in project spring-framework by spring-projects.

the class DefaultCorsProcessor method processRequest.

@Override
@SuppressWarnings("resource")
public boolean processRequest(@Nullable CorsConfiguration config, HttpServletRequest request, HttpServletResponse response) throws IOException {
    Collection<String> varyHeaders = response.getHeaders(HttpHeaders.VARY);
    if (!varyHeaders.contains(HttpHeaders.ORIGIN)) {
        response.addHeader(HttpHeaders.VARY, HttpHeaders.ORIGIN);
    }
    if (!varyHeaders.contains(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD)) {
        response.addHeader(HttpHeaders.VARY, HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD);
    }
    if (!varyHeaders.contains(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS)) {
        response.addHeader(HttpHeaders.VARY, HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
    }
    if (!CorsUtils.isCorsRequest(request)) {
        return true;
    }
    if (response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN) != null) {
        logger.trace("Skip: response already contains \"Access-Control-Allow-Origin\"");
        return true;
    }
    boolean preFlightRequest = CorsUtils.isPreFlightRequest(request);
    if (config == null) {
        if (preFlightRequest) {
            rejectRequest(new ServletServerHttpResponse(response));
            return false;
        } else {
            return true;
        }
    }
    return handleInternal(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response), config, preFlightRequest);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse)

Example 38 with ServletServerHttpResponse

use of org.springframework.http.server.ServletServerHttpResponse in project spring-framework by spring-projects.

the class RequestResponseBodyMethodProcessor method handleReturnValue.

@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException {
    mavContainer.setRequestHandled(true);
    ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
    ServletServerHttpResponse outputMessage = createOutputMessage(webRequest);
    // Try even with null return value. ResponseBodyAdvice could get involved.
    writeWithMessageConverters(returnValue, returnType, inputMessage, outputMessage);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse)

Example 39 with ServletServerHttpResponse

use of org.springframework.http.server.ServletServerHttpResponse in project spring-framework by spring-projects.

the class AbstractMessageConverterMethodProcessor method writeWithMessageConverters.

/**
 * Writes the given return value to the given web request. Delegates to
 * {@link #writeWithMessageConverters(Object, MethodParameter, ServletServerHttpRequest, ServletServerHttpResponse)}
 */
protected <T> void writeWithMessageConverters(T value, MethodParameter returnType, NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException {
    ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
    ServletServerHttpResponse outputMessage = createOutputMessage(webRequest);
    writeWithMessageConverters(value, returnType, inputMessage, outputMessage);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse)

Example 40 with ServletServerHttpResponse

use of org.springframework.http.server.ServletServerHttpResponse in project spring-framework by spring-projects.

the class ObjectToStringHttpMessageConverterTests method setup.

@BeforeEach
public void setup() {
    ConversionService conversionService = new DefaultConversionService();
    this.converter = new ObjectToStringHttpMessageConverter(conversionService);
    this.servletResponse = new MockHttpServletResponse();
    this.response = new ServletServerHttpResponse(this.servletResponse);
}
Also used : ConversionService(org.springframework.core.convert.ConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)40 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)22 ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)7 Test (org.junit.jupiter.api.Test)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 IOException (java.io.IOException)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)5 MediaType (org.springframework.http.MediaType)4 ResponseEntity (org.springframework.http.ResponseEntity)4 HashMap (java.util.HashMap)3 List (java.util.List)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 HttpHeaders (org.springframework.http.HttpHeaders)3 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)3 ServletException (jakarta.servlet.ServletException)2 ServletRequest (jakarta.servlet.ServletRequest)2