spring-webflux

Spring Security Webflux. How to make ServerWebExchange return pre-authentication Principal

蓝咒 提交于 2020-06-24 16:36:14
问题 I cannot access the java.security.Principal authenticated by my CAS authentication system. serverWebExchange.getPrincipal() is allways empty. In fact this is the implementation of DefaultServerWebExchange : @Override public <T extends Principal> Mono<T> getPrincipal() { return Mono.empty(); } Another implementation of ServerWebExchange is ServerWebExchangeDecorator and its documentation says: Note: if the purpose for using a decorator is to override properties like getPrincipal() , consider

who calls subscribe on Flux or Mono in reactive webapplication

喜欢而已 提交于 2020-06-22 03:19:10
问题 I am looking at some examples of reactive web applications and i am seeing them like this @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public Mono<Person> findById(...) { return exampleService.findById(...); } @RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_EVENT_STREAM_VALUE) @ResponseBody public Flux<Person> findAll() { Flux<Person> persons = exampleService.findAll(); return persons; } When i am reading about the Mono and Flux in the

who calls subscribe on Flux or Mono in reactive webapplication

ε祈祈猫儿з 提交于 2020-06-22 03:19:07
问题 I am looking at some examples of reactive web applications and i am seeing them like this @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public Mono<Person> findById(...) { return exampleService.findById(...); } @RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_EVENT_STREAM_VALUE) @ResponseBody public Flux<Person> findAll() { Flux<Person> persons = exampleService.findAll(); return persons; } When i am reading about the Mono and Flux in the

How to log request body in spring Webflux Java

不想你离开。 提交于 2020-06-17 09:32:07
问题 I am receiving some XML payload in a POST request and want to see the payload as received for debugging purposes. Below (my custom WebFilter) code logs the URI and request headers as expected but not the request body/payload, must be something wrong with my reactive code - final ServerHttpRequest request = exchange.getRequest(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); LOGGER.info("Request: uri={}", request.getURI()); LOGGER.info("Request: headers={}", request.getHeaders()

Spring WebFlux - how to get data from DB to use in the next step

馋奶兔 提交于 2020-06-16 07:11:27
问题 I use Spring WebFlux (Project Reactor) and I'm facing the following problem: I have to get some data from db to use them to call another service - everything in one stream. How to do that? public Mono<MyObj> saveObj(Mono<MyObj> obj) { return obj .flatMap( ob-> Mono.zip( repo1.save( ...), repo2 .saveAll(...) .collectList(), repo3 .saveAll(...) .collectList()) .map(this::createSpecificObject)) .doOnNext(item-> createObjAndCallAnotherService(item)); } private void createObjAndCallAnotherService

Type interference issue with the WebFlux WebTestClient and Kotlin

孤人 提交于 2020-06-15 06:21:45
问题 I'm building a prototype for a new application using Spring Webflux and Kotlin. Spring Webflux contains a WebTestClient for unit tests. According to the documentation I should be able to test the results of a REST call like this: @Test fun getVersion_SingleResult_ContentTypeJson_StatusCodeOk_ContentEqualsVersion() { //given var version = Version("Test", "1.0") val handler = ApiHandler(version!!) val client = WebTestClient.bindToRouterFunction(ApiRoutes(handler).apiRouter()).build() //expect

Type interference issue with the WebFlux WebTestClient and Kotlin

风流意气都作罢 提交于 2020-06-15 06:18:10
问题 I'm building a prototype for a new application using Spring Webflux and Kotlin. Spring Webflux contains a WebTestClient for unit tests. According to the documentation I should be able to test the results of a REST call like this: @Test fun getVersion_SingleResult_ContentTypeJson_StatusCodeOk_ContentEqualsVersion() { //given var version = Version("Test", "1.0") val handler = ApiHandler(version!!) val client = WebTestClient.bindToRouterFunction(ApiRoutes(handler).apiRouter()).build() //expect

Spring WebFlux: Serve files from controller

£可爱£侵袭症+ 提交于 2020-06-10 03:47:08
问题 Coming from .NET and Node I really have a hard time to figure out how to transfer this blocking MVC controller to a non-blocking WebFlux annotated controller? I've understood the concepts, but fail to find the proper async Java IO method (which I would expect to return a Flux or Mono). @RestController @RequestMapping("/files") public class FileController { @GetMapping("/{fileName}") public void getFile(@PathVariable String fileName, HttpServletResponse response) { try { File file = new File

How do you set programmatically the Authentication object in Spring Security reactive applications?

允我心安 提交于 2020-06-01 05:07:27
问题 In non reactive applications we could do SecurityContextHolder.getContext().setAuthentication(authentication); to authenticate a request programmatically. What would be the equivalent with Webflux? public class ReactiveServiceAuthenticationFilter implements WebFilter { private final ReactiveAuthenticationManager authenticationManager; public ReactiveServiceAuthenticationFilter(ReactiveAuthenticationManager authenticationManager){ this.authenticationManager = authenticationManager; } @Override

Send message only to certain client using websockets with Rsocket and Spring Webflux

孤街浪徒 提交于 2020-05-24 03:28:47
问题 I am trying to use Rsocket with websocket in one of my POC projects. In my case user login is not required. I would like to send a message only to certain clients when I receive a message from another service. Basically, my flow goes like this. Service A Service B |--------| websocket |------------------| Queue based comm |---------------| | Web |----------------->| Rsocket server |--------------------->| Another | | |<-----------------| using Websocket |<---------------------| service | |---