spring-webflux

how to get the object returned from joinPoint.proceed() with Spring AOP and WebFlux

泪湿孤枕 提交于 2019-12-12 01:16:50
问题 I have a simple aspect (see below) with @Around annotation. This aspect works when the the application don't use reactive paradigm. But when the application returns Mono or Flux doesn't works properly. I need to get the object returned from the method to generate a JSON object to use as log, generate events, etc. Here is my code that works in a non reactive classes: @Around("@annotation(simpleEvent)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, SimpleEvent simpleEvent)

WebFlux not sending data when using application/stream+json

非 Y 不嫁゛ 提交于 2019-12-11 21:22:30
问题 I have a reactive core WebClient to post to a given endpoint. The payload is a flux of Job objects and the content-type is application/stream+json Flux jobFlux = Flux.just(new Job()); Mono<JsonNode> response = localEP.post().uri( "/dev/job" ) .contentType(MediaType.APPLICATION_STREAM_JSON) .body( BodyInserters.fromObject(jobFlux)) .retrieve() .bodyToMono( JsonNode.class ); On the server end I have tried both a Spring Controller style and Spring Web Reactive FunctionHandler to process the

javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory' when using WebTestClient

佐手、 提交于 2019-12-11 17:56:31
问题 I am trying to write an integration test with WebTestClient that will only standup the controller I'm testing with a WebTestClient to make the requests. On starting a test, I get this in the console: 14:33:50.435 [main] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.9.Final 14:33:50.442 [main] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2

How print class object information in Spring Boot? Web-flux prints hash code and not class context in Spring Boot

こ雲淡風輕ζ 提交于 2019-12-11 16:13:43
问题 I'm new to Spring Boot and I bought the book for Spring Boot 2.0 by Greg Turnsquit. In chapter 1 there is a simple application in which if I take a look to http://localhost:8080/chapters URL I'll be able to see the chapter list. The error I'm having is that on the console the app prints the hashcode of the classes in the repository. In the web browser the app prints a dictionary with three empty elements. Code Example: https://github.com/learning-spring-boot/learning-spring-boot-2nd-edition

How to use Micrometer timer together with webflux endpoints

限于喜欢 提交于 2019-12-11 15:49:09
问题 IS there any simple way to use Micrometer timers with Webflux controllers? It seems that @Timed works only with non-reactive methods. For reactive it records very low time values. I found a similar question: How to use Micrometer Timer to record duration of async method (returns Mono or Flux) but the answers were too complex for such a common issue Any ideas? 回答1: If you want to measure time for Web-flux methods/calls you can then use easily metrics directly from Flux/Mono (plus configure

ServerWebExchange attributes are empty

蹲街弑〆低调 提交于 2019-12-11 15:16:39
问题 I have Spring Boot annotation based controller built on WebFlux. I implement WebFilter , inside WebFilter I invoked serverWebExchange.getAttributes() and it returned 4 attributes which is fine. But after that it stopped working and now it always returns empty attributes map. I didn't change anything in controller, but even if I did I should still get those attributes. Why it stopped working? 回答1: It works when firstly I do: this.handlerMapping.getHandler(serverWebExchange) where

Spring webflux session management

早过忘川 提交于 2019-12-11 14:53:08
问题 I am using Spring boot 2 with spring webflux running on netty. I would like to add session management without needing to have a backing database or redis server (so Spring Session doesn't seem to be a solution here). I could use WebSession in my controllers, but then I would need to enable sticky sessions on my load balancer, which I would prefer to avoid. What I would like is one of the following: Client side session like in Play framework (session is stored as a cookie and added onto each

Unable to Consume Webflux Streaming Response in React-Native client

你说的曾经没有我的故事 提交于 2019-12-11 11:52:21
问题 I've a reactive streaming api built on spring 5 webflux running on netty server with the following syntax - @RequestMapping(path = "/customer/messages/stream", method = RequestMethod.POST, produces = MediaType.APPLICATION_STREAM_JSON_VALUE) public Flux<Messages> fetchAllMessagesForCustomer(@RequestBody CustomerRequest) Now to consume this from my react-native app, I tried using fetch Api but it didn't work because of react-native issue. So I tried with good old xhr xhr.onreadystatechange =

Spring reactive streaming data from regular WebClient request

别说谁变了你拦得住时间么 提交于 2019-12-11 10:57:02
问题 Im learning new Spring WebFlux and reactive programming. I would like to create reactive API that streams some data to Angular client. Part of this data I will take from another (third party) API that does not support streams. So, as I understand I need to: Create REST stream end-point. Link some service to that. This service will call third party API every 5 seconds using WebClient. And put data to my stream. (not sure about this step) That stream is going to be returned by @RestController.

Spring Webflux annotated rest controller doesn't support ServerHttpRequest as method parameter: java.lang.NoSuchMethodException

心已入冬 提交于 2019-12-11 08:32:01
问题 Spring Boot 2.1.0/1 application packaged as war doesn't support ServerHttpRequest as input parameter in a Rest Controller, e.g: @GetMapping(produces = APPLICATION_JSON_UTF8_VALUE) public Flux<Event> findAll(ServerHttpRequest request) { return eventService.findAll(); } Log: java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.http.server.reactive.ServerHttpRequest at org.springframework.web.method.annotation.ModelAttributeMethodProcessor