use of cn.taketoday.web.reactive.function.client.WebClient in project today-infrastructure by TAKETODAY.
the class BodyInserters method fromProducer.
/**
* Inserter to write the given producer of value(s) which must be a {@link Publisher}
* or another producer adaptable to a {@code Publisher} via
* {@link ReactiveAdapterRegistry}.
* <p>Alternatively, consider using the {@code body} shortcuts on
* {@link WebClient WebClient} and
* {@link cn.taketoday.web.reactive.function.server.ServerResponse ServerResponse}.
*
* @param <T> the type of the body
* @param producer the source of body value(s).
* @param elementClass the class of values to be produced
* @return the inserter to write a producer
* @since 4.0
*/
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromProducer(T producer, Class<?> elementClass) {
Assert.notNull(producer, "'producer' must not be null");
Assert.notNull(elementClass, "'elementClass' must not be null");
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(producer.getClass());
Assert.notNull(adapter, "'producer' type is unknown to ReactiveAdapterRegistry");
return (message, context) -> writeWithMessageWriters(message, context, producer, ResolvableType.fromClass(elementClass), adapter);
}
use of cn.taketoday.web.reactive.function.client.WebClient in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method noCompressionForResponseWithInvalidContentType.
@Test
void noCompressionForResponseWithInvalidContentType() {
Compression compression = new Compression();
compression.setEnabled(true);
compression.setMimeTypes(new String[] { "application/json" });
WebClient client = prepareCompressionTest(compression, "test~plain");
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
assertResponseIsNotCompressed(response);
}
use of cn.taketoday.web.reactive.function.client.WebClient in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method compressionOfResponseToGetRequest.
@Test
protected void compressionOfResponseToGetRequest() {
WebClient client = prepareCompressionTest();
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
assertResponseIsCompressed(response);
}
use of cn.taketoday.web.reactive.function.client.WebClient in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method testClientAuthSuccess.
protected void testClientAuthSuccess(Ssl sslConfiguration, ReactorClientHttpConnector clientConnector) {
AbstractReactiveWebServerFactory factory = getFactory();
factory.setSsl(sslConfiguration);
this.webServer = factory.getWebServer(new EchoHandler());
this.webServer.start();
WebClient client = WebClient.builder().baseUrl("https://localhost:" + this.webServer.getPort()).clientConnector(clientConnector).build();
Mono<String> result = client.post().uri("/test").contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromValue("Hello World")).retrieve().bodyToMono(String.class);
assertThat(result.block(Duration.ofSeconds(30))).isEqualTo("Hello World");
}
use of cn.taketoday.web.reactive.function.client.WebClient in project today-infrastructure by TAKETODAY.
the class AbstractReactiveWebServerFactoryTests method noCompressionForSmallResponse.
@Test
void noCompressionForSmallResponse() {
Compression compression = new Compression();
compression.setEnabled(true);
compression.setMinResponseSize(DataSize.ofBytes(3001));
WebClient client = prepareCompressionTest(compression);
ResponseEntity<Void> response = client.get().retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
assertResponseIsNotCompressed(response);
}
Aggregations