Search in sources :

Example 1 with UndertowHttpServer

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

the class ZeroCopyIntegrationTests method zeroCopy.

@ParameterizedHttpServerTest
void zeroCopy(HttpServer httpServer) throws Exception {
    assumeTrue(httpServer instanceof ReactorHttpServer || httpServer instanceof UndertowHttpServer, "Zero-copy does not support Servlet");
    startServer(httpServer);
    URI url = new URI("http://localhost:" + port);
    RequestEntity<?> request = RequestEntity.get(url).build();
    ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
    assertThat(response.hasBody()).isTrue();
    assertThat(response.getHeaders().getContentLength()).isEqualTo(springLogoResource.contentLength());
    assertThat(response.getBody().length).isEqualTo(springLogoResource.contentLength());
    assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.IMAGE_PNG);
}
Also used : ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) RestTemplate(org.springframework.web.client.RestTemplate) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) URI(java.net.URI)

Example 2 with UndertowHttpServer

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

the class AbstractWebSocketIntegrationTests method arguments.

static Stream<Object[]> arguments() throws IOException {
    WebSocketClient[] clients = new WebSocketClient[] { new TomcatWebSocketClient(), new JettyWebSocketClient(), new ReactorNettyWebSocketClient(), new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY)) };
    Map<HttpServer, Class<?>> servers = new LinkedHashMap<>();
    servers.put(new TomcatHttpServer(TMP_DIR.getAbsolutePath(), WsContextListener.class), TomcatConfig.class);
    servers.put(new JettyHttpServer(), JettyConfig.class);
    servers.put(new ReactorHttpServer(), ReactorNettyConfig.class);
    servers.put(new UndertowHttpServer(), UndertowConfig.class);
    // Try each client once against each server..
    Flux<WebSocketClient> f1 = Flux.fromArray(clients).concatMap(c -> Mono.just(c).repeat(servers.size() - 1));
    Flux<Map.Entry<HttpServer, Class<?>>> f2 = Flux.fromIterable(servers.entrySet()).repeat(clients.length - 1).share();
    return Flux.zip(f1, f2.map(Map.Entry::getKey), f2.map(Map.Entry::getValue)).map(Tuple3::toArray).toStream();
}
Also used : WsContextListener(org.apache.tomcat.websocket.server.WsContextListener) ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) ReactorNettyWebSocketClient(org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient) TomcatWebSocketClient(org.springframework.web.reactive.socket.client.TomcatWebSocketClient) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) WebSocketClient(org.springframework.web.reactive.socket.client.WebSocketClient) ReactorNettyWebSocketClient(org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient) TomcatWebSocketClient(org.springframework.web.reactive.socket.client.TomcatWebSocketClient) UndertowWebSocketClient(org.springframework.web.reactive.socket.client.UndertowWebSocketClient) JettyWebSocketClient(org.springframework.web.reactive.socket.client.JettyWebSocketClient) LinkedHashMap(java.util.LinkedHashMap) JettyWebSocketClient(org.springframework.web.reactive.socket.client.JettyWebSocketClient) TomcatHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer) ReactorHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.ReactorHttpServer) HttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer) JettyHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) TomcatHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.TomcatHttpServer) UndertowWebSocketClient(org.springframework.web.reactive.socket.client.UndertowWebSocketClient) OptionMap(org.xnio.OptionMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JettyHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.JettyHttpServer)

Example 3 with UndertowHttpServer

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

the class MultipartIntegrationTests method transferTo.

@ParameterizedHttpServerTest
void transferTo(HttpServer httpServer) throws Exception {
    // TODO Determine why Undertow fails: https://github.com/spring-projects/spring-framework/issues/25310
    assumeFalse(httpServer instanceof UndertowHttpServer, "Undertow currently fails with transferTo");
    startServer(httpServer);
    Flux<String> result = webClient.post().uri("/transferTo").bodyValue(generateBody()).retrieve().bodyToFlux(String.class);
    StepVerifier.create(result).consumeNextWith(filename -> verifyContents(Paths.get(filename), new ClassPathResource("foo.txt", MultipartHttpMessageReader.class))).consumeNextWith(filename -> verifyContents(Paths.get(filename), new ClassPathResource("logo.png", getClass()))).verifyComplete();
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) FilePart(org.springframework.http.codec.multipart.FilePart) FormFieldPart(org.springframework.http.codec.multipart.FormFieldPart) StepVerifier(reactor.test.StepVerifier) WebHttpHandlerBuilder(org.springframework.web.server.adapter.WebHttpHandlerBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClassPathResource(org.springframework.core.io.ClassPathResource) WebClient(org.springframework.web.reactive.function.client.WebClient) RequestPart(org.springframework.web.bind.annotation.RequestPart) DispatcherHandler(org.springframework.web.reactive.DispatcherHandler) HttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer) RequestBody(org.springframework.web.bind.annotation.RequestBody) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) EnableWebFlux(org.springframework.web.reactive.config.EnableWebFlux) Part(org.springframework.http.codec.multipart.Part) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) Schedulers(reactor.core.scheduler.Schedulers) MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) AbstractHttpHandlerIntegrationTests(org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpHandlerIntegrationTests) Path(java.nio.file.Path) Resource(org.springframework.core.io.Resource) PostMapping(org.springframework.web.bind.annotation.PostMapping) Files(java.nio.file.Files) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) HttpHandler(org.springframework.http.server.reactive.HttpHandler) Paths(java.nio.file.Paths) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) ResponseEntity(org.springframework.http.ResponseEntity) Bean(org.springframework.context.annotation.Bean) FileCopyUtils(org.springframework.util.FileCopyUtils) UndertowHttpServer(org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

UndertowHttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.UndertowHttpServer)3 HttpServer (org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 WsContextListener (org.apache.tomcat.websocket.server.WsContextListener)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assumptions.assumeFalse (org.junit.jupiter.api.Assumptions.assumeFalse)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1