spring-webflux

How to create a data class implements Spring Secuirty specific UserDetails

夙愿已清 提交于 2019-12-25 08:49:51
问题 I am trying to migrate some spring-webflux sample codes to kotlin. Currently I want to convert my Spring Data Mongo sample to kotlin. There is a User , the original Data Mongo version looks: @Data @ToString @Builder @NoArgsConstructor @AllArgsConstructor @Document class User implements UserDetails { @Id private String id; private String username; private String password; @Builder.Default() private boolean active = true; @Builder.Default() private List<String> roles = new ArrayList<>();

Seemingly Random Test Failure With Maven & Spring Boot 2 When A WebFluxTest Is Introduced

流过昼夜 提交于 2019-12-25 02:26:41
问题 Environment OSX 10.13.5 Java 10.0.1 2018-04-17 Apache Maven 3.5.2 Spring Boot 2.0.3.RELEASE Maven Surefire plugin 2.22.0 Issue I have a test which reliably passes: public class TransformerTest { private final MyTransformer transformer = new MyTransformerImpl(); @Rule public final OutputCapture outputCapture = new OutputCapture(); @Test public void successShouldLogSuccessMessages() { final B result = transformer.transform(new A()); outputCapture.expect(containsString("First message"));

How to await when all Disposable elements will be finished?

此生再无相见时 提交于 2019-12-25 01:37:23
问题 Lets consider following code: List<Mono<String>> monoList= apiCall(); List<Disposable> disposableList = monoList.stream() .map(m-> m.subscribe(str-> { log.info("Mono is finished with "+ str); }) ).collect(Collectors.toList()); // I need to await here I need to await when all mono will be finished. How could I achieve it? 回答1: Not mixing different streaming APIs you could utilize side effects instead of subscriptions and await completion with then() Mono<Void> await = Flux .fromIterable

How to convert List<Mono<String>> into Flux<List<String>>?

断了今生、忘了曾经 提交于 2019-12-25 01:12:23
问题 List<Mono<String>> responses = apiCall() I would like to get Flux<String> to await all mono-s from list. How could I achieve it ? P.S. I've found similar question but I need vice versa operation https://stackoverflow.com/a/44040346/2674303 回答1: You could use Flux.mergeSequential() and Flux.collectList() Mono<List<String>> list = Flux.mergeSequential(apiCall()).collectList(); 来源: https://stackoverflow.com/questions/58913554/how-to-convert-listmonostring-into-fluxliststring

Spring Boot + Webflux + Reactive MongoDB - get document by property Id

怎甘沉沦 提交于 2019-12-25 01:08:41
问题 I'd like to find all Offer documents by Offer.ProductProperties.brand: @Document(collection = "offers") public class Offer { @Id private String id; @NotNull @DBRef private ProductProperties properties; ProductProperties: @Document(collection = "product_properties") public class ProductProperties { @Id private String id; @NotNull @NotEmpty private String brand; Service: Flux<ProductProperties> all = productPropertiesRepository.findAllByBrand(brand); List<String> productPropIds = all.toStream()

Spring DataJpaTest do not load javax.transaction.SystemException with Java 9

自作多情 提交于 2019-12-25 00:50:19
问题 I would like to test my service layer with DataJpaTest annotation. My setup is the following : SpringBoot 2.0.0-M7, JAVA 9 and pom xml : <dependencies> <!-- Compile --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId

Why is the handler for a REST endpoint being accessed twice, when accessed from a WebClient?

人走茶凉 提交于 2019-12-24 20:22:40
问题 This is a second attempt, with revised demo code that, hopefully, better illustrates the issue. The code has been stripped down to remove all elements except those demonstrating the issue being encountered. Add Note: Some additional testing was done, and the results posted as an answer (vice extending this post). It may be that this is "expected behavior", but I'm still trying to understand "the why". The code "works", in that it returns the expected information (either a String, or a list of

How to await when all http requests are finished using spring webClient?

拥有回忆 提交于 2019-12-24 19:14:01
问题 I want to execute http request for each queue element. These requests shoule be called in parallel. Also I need to await the termination of all requests. I developed the following code: List<Mono<MyResponseDTO>> monoList = queue.stream() .map(jobStatusBunch -> webClient .post() .uri("localhost:8080/api/some/url") .bodyValue(convertToRequestDto(someBean)) .retrieve() .toEntity(String.class) .filter(HttpEntity::hasBody) .map(stringResponseEntity -> { try { return objectMapper.readValue

Logging POST request body in Web Flux

怎甘沉沦 提交于 2019-12-24 18:33:50
问题 I am trying to log request body in web-flux following : webflux-demo But I end up with empty string all the time even when I pass request body. The requestBody.map does not get executed. It skips the block. What am I missing? @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if(logging.enabled()){ ServerHttpRequest request = exchange.getRequest(); System.out.println("Request body : " + getRequestBody(request)); return chain.filter(exchange); } else {

Spring Reactive: java.io.IOException: An established connection was aborted by the software in your host machine, when I close the connection

匆匆过客 提交于 2019-12-24 08:25:42
问题 Working with spring reactive application, I created a rest service which produces an event every second. The code for my rest controller is: @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public Flux<Event> getEvents() { Flux<Event> eventFlux = Flux.fromStream(Stream.generate(() -> new Event(new Random().nextLong(), "Hello Event"))); Flux<Long> emmitFlux = Flux.interval(Duration.ofSeconds(1)); return Flux.zip(eventFlux, emmitFlux).map(Tuple2::getT1); } The