/** * Decorate as {@link ByteBufFlux} * * @param source publisher to decorate * * @return a {@link ByteBufFlux} */ public static ByteBufFlux fromString(Publisher<? extends String> source) { return fromString(source, Charset.defaultCharset(), ByteBufAllocator.DEFAULT); }
/** * Decorate as {@link ByteBufFlux} * * @param source publisher to decorate * * @return a {@link ByteBufFlux} */ public static ByteBufFlux fromString(Publisher<? extends String> source) { return fromString(source, Charset.defaultCharset(), ByteBufAllocator.DEFAULT); }
.post() .uri(zipkinSpansUrl) .send(ByteBufFlux.fromString(Mono.just(spans))) .response() .timeout(Duration.ofSeconds(30))
.post() .uri(zipkinSpansUrl) .send(ByteBufFlux.fromString(Mono.just(spans))) .response() .timeout(Duration.ofSeconds(30))
@Test public void contentHeader() { ConnectionProvider fixed = ConnectionProvider.fixed("test", 1); HttpClient client = HttpClient.create(fixed) .wiretap(true) .headers(h -> h.add("content-length", "1")); HttpResponseStatus r = client.request(HttpMethod.GET) .uri("http://google.com") .send(ByteBufFlux.fromString(Mono.just(" "))) .responseSingle((res, buf) -> Mono.just(res.status())) .block(Duration.ofSeconds(30)); client.request(HttpMethod.GET) .uri("http://google.com") .send(ByteBufFlux.fromString(Mono.just(" "))) .responseSingle((res, buf) -> Mono.just(res.status())) .block(Duration.ofSeconds(30)); Assert.assertEquals(r, HttpResponseStatus.BAD_REQUEST); fixed.dispose(); }
private void doTestIssue186(HttpClient client) { Mono<String> content = client.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("bodysample"))) .responseContent() .aggregate() .asString(); StepVerifier.create(content) .expectComplete() .verify(Duration.ofSeconds(30)); }
.send(ByteBufFlux.fromString(Mono.just("test") .then(Mono.error(new Exception("error"))))) .responseContent() .send(ByteBufFlux.fromString(Mono.just("test"))) .responseContent() .aggregate()
.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("bodysample"))) .responseContent() .aggregate()
.post() .uri("/") .send(ByteBufFlux.fromString(Flux.just("1", "2", "3", "4", "5"))) .responseContent() .aggregate()
@Test public void disableChunkForced() { Tuple2<HttpResponseStatus, String> r = HttpClient.newConnection() .tcpConfiguration(tcpClient -> tcpClient.host("google.com")) .wiretap(true) .chunkedTransfer(false) .request(HttpMethod.GET) .uri("/unsupportedURI") .send(ByteBufFlux.fromString(Flux.just("hello"))) .responseSingle((res, conn) -> Mono.just(res.status()) .zipWith(conn.asString())) .block(Duration.ofSeconds(30)); assertThat(r).isNotNull(); Assert.assertEquals(r.getT1(), HttpResponseStatus.NOT_FOUND); }
.send(ByteBufFlux.fromString(Mono.just("bodysample") .subscriberContext(c -> { context.set(c);
@Test public void httpRespondsEmpty() { DisposableServer server = HttpServer.create() .port(0) .route(r -> r.post("/test/{param}", (req, res) -> Mono.empty())) .wiretap(true) .bindNow(); HttpClient client = HttpClient.create() .port(server.address().getPort()) .wiretap(true); Mono<ByteBuf> content = client.headers(h -> h.add("Content-Type", "text/plain")) .post() .uri("/test/World") .send(ByteBufFlux.fromString(Mono.just("Hello") .log("client-send"))) .responseContent() .log("client-received") .next() .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage())); StepVerifier.create(content) .expectComplete() .verify(Duration.ofSeconds(5000)); server.disposeNow(); }
@Test public void httpStatusCode404IsHandledByTheClient() { DisposableServer server = HttpServer.create() .port(0) .route(r -> r.post("/test", (req, res) -> res.send(req.receive() .log("server-received")))) .wiretap(true) .bindNow(); HttpClient client = HttpClient.create() .port(server.address().getPort()) .wiretap(true); Mono<Integer> content = client.headers(h -> h.add("Content-Type", "text/plain")) .request(HttpMethod.GET) .uri("/unsupportedURI") .send(ByteBufFlux.fromString(Flux.just("Hello") .log("client-send"))) .responseSingle((res, buf) -> Mono.just(res.status().code())) .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage())); StepVerifier.create(content) .expectNext(404) .verifyComplete(); server.disposeNow(); } }
.post() .uri("/") .send(ByteBufFlux.fromString(Flux.just(data))) .responseContent()) .subscribe();
private void doTestPublisherSenderOnCompleteFlushInProgress(boolean useScheduler) { DisposableServer server = HttpServer.create() .port(0) .handle((req, res) -> req.receive() .asString() .doOnNext(System.err::println) .then(res.status(200).sendHeaders().then())) .wiretap(true) .bindNow(Duration.ofSeconds(30)); Flux<String> flux = Flux.range(1, 257).map(count -> count + ""); if (useScheduler) { flux.publishOn(Schedulers.single()); } Mono<Integer> code = HttpClient.create() .port(server.address().getPort()) .wiretap(true) .post() .uri("/") .send(ByteBufFlux.fromString(flux)) .responseSingle((res, buf) -> Mono.just(res.status().code())) .log(); StepVerifier.create(code) .expectNextMatches(c -> c == 200) .expectComplete() .verify(Duration.ofSeconds(30)); server.disposeNow(); }
.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just(sb.toString()))) .responseContent() .aggregate()
.post() .uri("/test/World") .send(ByteBufFlux.fromString(Flux.just("Hello") .log("client-send"))) .responseContent()
.post() .uri("/2") .send(ByteBufFlux.fromString(Mono.just("test"))) .responseContent() .aggregate()
.post() .uri("/hi") .send(ByteBufFlux.fromString(Flux.just("1", "2", "3", "4", "5"))) .responseContent() .aggregate() .post() .uri("/hi") .send(ByteBufFlux.fromString(Flux.just("1", "2", "3", "4", "5"))) .responseContent() .aggregate()
.post() .uri("/hi") .send(ByteBufFlux.fromString(Flux.just("1", "2", "3", "4", "5"))) .responseContent() .aggregate() .post() .uri("/hi") .send(ByteBufFlux.fromString(Flux.just("1", "2", "3", "4", "5"))) .responseContent() .aggregate()