spring-webflux

How to do sequence of operations and ensure one operation is complete before next one in Spring Reactor web app?

我的未来我决定 提交于 2019-12-20 11:28:40
问题 I have Spring Boot 2 web app in which I need to identify site visitor by cookie and gather page view stats. So I need to intercept every web request. The code I had to write is more complex than call back hell (the very problem Spring reactor was supposed to solve). Here is the code: package mypack.conf; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired;

Spring MVC (async) vs Spring WebFlux

你说的曾经没有我的故事 提交于 2019-12-20 09:14:25
问题 I'm trying to understand Spring WebFlux. The things I've found so far are reactive at the core, no Servlet API, no thread per request, HTTP 2, server pushes, application/stream+json. But what is the difference between asynchronous calls in Spring MVC? I mean in Spring MVC when you return Future, DefferedResult and etc you get logic in the request handler (controller method) executed in a separate thread, so you can benefit from saving thread pool resources for dispatching requests as well. So

Spring Reactive xml payload exception java.lang.IllegalStateException: Failed to resolve argument 0 of type 'reactor.core.publisher.Mono'

為{幸葍}努か 提交于 2019-12-20 05:38:18
问题 I have a spring boot application. trying to send xml payload through postman to a Post request. I get the following exception java.lang.IllegalStateException: Failed to resolve argument 0 of type 'reactor.core.publisher.Mono' on public reactor.core.publisher.Mono<com.event.gateway.rest.controller.Sir> com.event.gateway.rest.controller.WBController.hello(reactor.core.publisher.Mono<com.event.gateway.rest.controller.Sir>) at org.springframework.web.reactive.result.method.InvocableHandlerMethod

Spring Boot WebClient.Builder bean usage in traditional servlet multi threaded application

对着背影说爱祢 提交于 2019-12-20 02:54:40
问题 I would like to have a http client to call other microservice from Spring Boot not reactive application. Because of RestTemplate will be deprecated I tried to use WebClient.Builder and WebClient. Though I not sure about thread safety. Here example: @Service public class MyService{ @Autowired WebClient.Builder webClientBuilder; public VenueDTO serviceMethod(){ //!!! This is not thread safe !!! WebClient webClient = webClientBuilder.baseUrl("http://localhost:8000").build(); VenueDTO venueDTO =

Spring WebFlux: Only one connection receive subscriber allowed

梦想与她 提交于 2019-12-19 21:49:08
问题 I am writing a simple app with Spring 5 Webflux and Kotlin. I am trying to implement PUT endpoint in a following way: PUT("/confs/{id}", { val id = it.pathVariable("id") ServerResponse.ok().body(service.save(it.bodyToMono(Item::class.java)), Item::class.java) }) The trick on save is that I try to read a city name from item, resolve geo coordinates, overwrite them in original item and then save to Mongo using Spring Data Mongo Reactive repo. fun save(item: Mono<Item>): Mono<Item> { val geo =

How to enable Spring Reactive Web MVC to handle Multipart-file?

独自空忆成欢 提交于 2019-12-19 10:16:10
问题 I'm trying to use the new reactive web-mvc implementation in a spring boot 2.0 application. I'm trying to define a method which consume multipart file but do not succeed at making it working :( - I always get a 415 error. On one hand I have a controller containing the following request mapping : @RequestMapping(method = RequestMethod.POST, path = "/myPath/{param}/{param2}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseBody public Mono<Void> postFile( @RequestBody MultipartFile

How to limit the request/second with WebClient?

左心房为你撑大大i 提交于 2019-12-19 09:05:38
问题 I'm using a WebClient object to send Http Post request to a server. It's sending a huge amount of requests quite rapidly (there is about 4000 messages in a QueueChannel ). The problem is... it seems the server can't respond fast enough... so I'm getting a lot of server error 500 and connexion closed prematurely. Is there a way to limit the number of request per seconds ? Or limit the number of threads it's using ? EDIT : The Message endpoint processe message in a QueueChannel :

Spring WebFlux - ServerResponse Jackson Serializer problems

倖福魔咒の 提交于 2019-12-19 06:34:42
问题 I have a problem during sending a HTTP GET request to my web server. Here is a snippet of code which is responsible for this resource: @GetMapping("/events") public Mono<ServerResponse> getEvents() { return ServerResponse.ok() .contentType(APPLICATION_JSON) .build(); } When sending a request I am getting an exception: org.springframework.core.codec.CodecException: Type definition error: [simple type, class org.springframework.web.reactive.function.server.DefaultServerResponseBuilder

Spring WebFlux - ServerResponse Jackson Serializer problems

南笙酒味 提交于 2019-12-19 06:31:02
问题 I have a problem during sending a HTTP GET request to my web server. Here is a snippet of code which is responsible for this resource: @GetMapping("/events") public Mono<ServerResponse> getEvents() { return ServerResponse.ok() .contentType(APPLICATION_JSON) .build(); } When sending a request I am getting an exception: org.springframework.core.codec.CodecException: Type definition error: [simple type, class org.springframework.web.reactive.function.server.DefaultServerResponseBuilder

Authentication by certificate for WebFlux?

守給你的承諾、 提交于 2019-12-19 04:44:45
问题 In the regular Servlet API for Spring Boot Web, there is the .x509() of the HttpSecurity configuration. But in WebFlux's ServerHttpSecurity I can't find anything similar to it. What is the equivalent of .x509().subjectPrincipalRegex(...) in WebFlux End goal is to get the certificate subject as the username sent to ReactiveUserDetailsService . 回答1: I don't think there is a X509 filter as there was in the previous versions of spring, so you'll have to implement your own version of it.