Search in sources :

Example 1 with ReactorHttpServer

use of org.springframework.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class HttpServerTests method setUp.

@Before
public void setUp() throws Exception {
    HttpHandler httpHandler = RouterFunctions.toHttpHandler(route(GET("/test"), request -> ServerResponse.ok().body(Mono.just("It works!"), String.class)));
    this.server = new ReactorHttpServer();
    this.server.setHandler(httpHandler);
    this.server.afterPropertiesSet();
    this.server.start();
    this.client = WebTestClient.bindToServer().baseUrl("http://localhost:" + this.server.getPort()).build();
}
Also used : WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) HttpHandler(org.springframework.http.server.reactive.HttpHandler) ReactorHttpServer(org.springframework.http.server.reactive.bootstrap.ReactorHttpServer) ServerResponse(org.springframework.web.reactive.function.server.ServerResponse) After(org.junit.After) RouterFunctions(org.springframework.web.reactive.function.server.RouterFunctions) GET(org.springframework.web.reactive.function.server.RequestPredicates.GET) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Before(org.junit.Before) RouterFunctions.route(org.springframework.web.reactive.function.server.RouterFunctions.route) HttpHandler(org.springframework.http.server.reactive.HttpHandler) ReactorHttpServer(org.springframework.http.server.reactive.bootstrap.ReactorHttpServer) Before(org.junit.Before)

Example 2 with ReactorHttpServer

use of org.springframework.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class ZeroCopyIntegrationTests method zeroCopy.

@Test
public void zeroCopy() throws Exception {
    // Zero-copy only does not support servlet
    assumeTrue(server instanceof ReactorHttpServer || server instanceof UndertowHttpServer);
    RestTemplate restTemplate = new RestTemplate();
    RequestEntity<?> request = RequestEntity.get(new URI("http://localhost:" + port)).build();
    ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
    Resource logo = new ClassPathResource("spring.png", ZeroCopyIntegrationTests.class);
    assertTrue(response.hasBody());
    assertEquals(logo.contentLength(), response.getHeaders().getContentLength());
    assertEquals(logo.contentLength(), response.getBody().length);
    assertEquals(MediaType.IMAGE_PNG, response.getHeaders().getContentType());
}
Also used : ReactorHttpServer(org.springframework.http.server.reactive.bootstrap.ReactorHttpServer) RestTemplate(org.springframework.web.client.RestTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) UndertowHttpServer(org.springframework.http.server.reactive.bootstrap.UndertowHttpServer) URI(java.net.URI) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 3 with ReactorHttpServer

use of org.springframework.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class ContextPathIntegrationTests method setup.

@Before
public void setup() throws Exception {
    AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext();
    context1.register(WebApp1Config.class);
    context1.refresh();
    AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext();
    context2.register(WebApp2Config.class);
    context2.refresh();
    HttpHandler webApp1Handler = DispatcherHandler.toHttpHandler(context1);
    HttpHandler webApp2Handler = DispatcherHandler.toHttpHandler(context2);
    this.server = new ReactorHttpServer();
    this.server.registerHttpHandler("/webApp1", webApp1Handler);
    this.server.registerHttpHandler("/webApp2", webApp2Handler);
    this.server.afterPropertiesSet();
    this.server.start();
}
Also used : HttpHandler(org.springframework.http.server.reactive.HttpHandler) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ReactorHttpServer(org.springframework.http.server.reactive.bootstrap.ReactorHttpServer) Before(org.junit.Before)

Example 4 with ReactorHttpServer

use of org.springframework.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class ErrorHandlerIntegrationTests method returnValue.

@Test
public void returnValue() throws Exception {
    // TODO: fix Reactor
    assumeFalse(server instanceof ReactorHttpServer);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
    ResponseEntity<String> response = restTemplate.getForEntity(new URI("http://localhost:" + port + "/returnValue"), String.class);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
Also used : ReactorHttpServer(org.springframework.http.server.reactive.bootstrap.ReactorHttpServer) RestTemplate(org.springframework.web.client.RestTemplate) URI(java.net.URI) Test(org.junit.Test)

Example 5 with ReactorHttpServer

use of org.springframework.http.server.reactive.bootstrap.ReactorHttpServer in project spring-framework by spring-projects.

the class ErrorHandlerIntegrationTests method response.

@Test
public void response() throws Exception {
    // TODO: fix Reactor
    assumeFalse(server instanceof ReactorHttpServer);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
    ResponseEntity<String> response = restTemplate.getForEntity(new URI("http://localhost:" + port + "/response"), String.class);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
Also used : ReactorHttpServer(org.springframework.http.server.reactive.bootstrap.ReactorHttpServer) RestTemplate(org.springframework.web.client.RestTemplate) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ReactorHttpServer (org.springframework.http.server.reactive.bootstrap.ReactorHttpServer)6 Test (org.junit.Test)4 URI (java.net.URI)3 RestTemplate (org.springframework.web.client.RestTemplate)3 Before (org.junit.Before)2 HttpHandler (org.springframework.http.server.reactive.HttpHandler)2 UndertowHttpServer (org.springframework.http.server.reactive.bootstrap.UndertowHttpServer)2 After (org.junit.After)1 Parameters (org.junit.runners.Parameterized.Parameters)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 JettyHttpServer (org.springframework.http.server.reactive.bootstrap.JettyHttpServer)1 RxNettyHttpServer (org.springframework.http.server.reactive.bootstrap.RxNettyHttpServer)1 TomcatHttpServer (org.springframework.http.server.reactive.bootstrap.TomcatHttpServer)1 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)1 GET (org.springframework.web.reactive.function.server.RequestPredicates.GET)1 RouterFunctions (org.springframework.web.reactive.function.server.RouterFunctions)1 RouterFunctions.route (org.springframework.web.reactive.function.server.RouterFunctions.route)1 ServerResponse (org.springframework.web.reactive.function.server.ServerResponse)1