Search in sources :

Example 61 with ServletServerHttpRequest

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

the class HttpRestartServerTests method sendClassLoaderFiles.

@Test
public void sendClassLoaderFiles() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    ClassLoaderFiles files = new ClassLoaderFiles();
    files.addFile("name", new ClassLoaderFile(Kind.ADDED, new byte[0]));
    byte[] bytes = serialize(files);
    request.setContent(bytes);
    this.server.handle(new ServletServerHttpRequest(request), new ServletServerHttpResponse(response));
    verify(this.delegate).updateAndRestart(this.filesCaptor.capture());
    assertThat(this.filesCaptor.getValue().getFile("name")).isNotNull();
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClassLoaderFiles(org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ClassLoaderFile(org.springframework.boot.devtools.restart.classloader.ClassLoaderFile) Test(org.junit.Test)

Example 62 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest 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 63 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest 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 64 with ServletServerHttpRequest

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

the class HttpPutFormContentFilter method doFilterInternal.

@Override
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    if (("PUT".equals(request.getMethod()) || "PATCH".equals(request.getMethod())) && isFormContentType(request)) {
        HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {

            @Override
            public InputStream getBody() throws IOException {
                return request.getInputStream();
            }
        };
        MultiValueMap<String, String> formParameters = formConverter.read(null, inputMessage);
        HttpServletRequest wrapper = new HttpPutFormContentRequestWrapper(request, formParameters);
        filterChain.doFilter(wrapper, response);
    } else {
        filterChain.doFilter(request, response);
    }
}
Also used : HttpInputMessage(org.springframework.http.HttpInputMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest)

Aggregations

ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)64 Test (org.junit.Test)33 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)29 HttpRequest (org.springframework.http.HttpRequest)20 ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Before (org.junit.Before)8 ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 HttpInputMessage (org.springframework.http.HttpInputMessage)5 ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)4 MediaType (org.springframework.http.MediaType)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)2 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1