Search in sources :

Example 26 with ServletServerHttpResponse

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

the class HttpTunnelServerTests method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    this.server = new HttpTunnelServer(this.serverConnection);
    given(this.serverConnection.open(anyInt())).willAnswer(new Answer<ByteChannel>() {

        @Override
        public ByteChannel answer(InvocationOnMock invocation) throws Throwable {
            MockServerChannel channel = HttpTunnelServerTests.this.serverChannel;
            channel.setTimeout((Integer) invocation.getArguments()[0]);
            return channel;
        }
    });
    this.servletRequest = new MockHttpServletRequest();
    this.servletRequest.setAsyncSupported(true);
    this.servletResponse = new MockHttpServletResponse();
    this.request = new ServletServerHttpRequest(this.servletRequest);
    this.response = new ServletServerHttpResponse(this.servletResponse);
    this.serverChannel = new MockServerChannel();
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ByteChannel(java.nio.channels.ByteChannel) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 27 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(CorsConfiguration config, HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (!CorsUtils.isCorsRequest(request)) {
        return true;
    }
    ServletServerHttpResponse serverResponse = new ServletServerHttpResponse(response);
    if (responseHasCors(serverResponse)) {
        logger.debug("Skip CORS processing: response already contains \"Access-Control-Allow-Origin\" header");
        return true;
    }
    ServletServerHttpRequest serverRequest = new ServletServerHttpRequest(request);
    if (WebUtils.isSameOrigin(serverRequest)) {
        logger.debug("Skip CORS processing: request is from same origin");
        return true;
    }
    boolean preFlightRequest = CorsUtils.isPreFlightRequest(request);
    if (config == null) {
        if (preFlightRequest) {
            rejectRequest(serverResponse);
            return false;
        } else {
            return true;
        }
    }
    return handleInternal(serverRequest, serverResponse, config, preFlightRequest);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse)

Example 28 with ServletServerHttpResponse

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

the class ObjectToStringHttpMessageConverterTests method setUp.

@Before
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.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Aggregations

ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)28 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)18 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Before (org.junit.Before)6 Test (org.junit.Test)6 ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)6 ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 ResponseEntity (org.springframework.http.ResponseEntity)3 ServletRequest (javax.servlet.ServletRequest)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpHeaders (org.springframework.http.HttpHeaders)2 MediaType (org.springframework.http.MediaType)2 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)2 HandshakeFailureException (org.springframework.web.socket.server.HandshakeFailureException)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ByteChannel (java.nio.channels.ByteChannel)1