spring-webflux

How to prevent embedded netty server from starting with spring-boot-starter-webflux?

ぃ、小莉子 提交于 2021-02-07 11:17:43
问题 I want to establish a communication between a client and server application using Springs new reactive webflux extension. For dependency management I use gradle . My build.gradle file on the server, as well as on the client side basically is: buildscript { repositories { mavenCentral() maven { url "https://repo.spring.io/snapshot" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.0.BUILD-SNAPSHOT") } } repositories { mavenCentral() maven { url "https://repo

How to use Spring Reactive WebSocket and transform it into the Flux stream?

点点圈 提交于 2021-02-06 09:27:08
问题 There is some WebSocketClient example on Spring documentation: WebSocketClient client = new ReactorNettyWebSocketClient(); client.execute("ws://localhost:8080/echo"), session -> {...}).blockMillis(5000); Im not sure how to handle stream of incomming data? Inside that block {...} . I mean: how can I filter incoming data and cast it into Flux? Here is what I want to get. @GetMapping("/stream", produces = MediaType.APPLICATION_STREAM_JSON_VALUE) public Flux<MyRecourse> getStreaming() { // get

How can I convert a Stream of Mono to Flux

不想你离开。 提交于 2021-02-05 07:55:38
问题 I have a method that try use WebClient to return a Mono @GetMapping("getMatch") public Mono<Object> getMatch(@RequestParam Long matchId) { return WebClient.create(OpenDotaConstant.BASE_URL).get() .uri("/matches/{matchId}", matchId) .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(Object.class); } It can return result that I expected. Then I try to create another method to support List as params @GetMapping("getMatches") public Flux<Object> getMatches(@RequestParam String matchesId)

Spring Webflux throws a “block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2”

人盡茶涼 提交于 2021-01-29 16:10:21
问题 I have a small issue with doing a blocking operation in Spring Webflux. I retrieve a list of article documents and from the list of article documents, i would like to update another object. When i execute the below, sometimes it works and sometimes it throws a "block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2". Could you please suggest how to fix. I dont really want to make it blocking but not sure how to proceed. There are similar threads in

How to get last redirect URL in Spring WebClient

旧时模样 提交于 2021-01-29 11:23:56
问题 A client that follows redirects can be created as follows: WebClient.builder() .clientConnector(new ReactorClientHttpConnector( HttpClient.create().followRedirect(true) )) After invoking a HEAD request on a URL, how can the final Location header be retrieved? In other words, how can we get the final URL redirected to? 回答1: It is true that HttpClient#followRedirect(true) enables the redirection. However there is also HttpClient#followRedirect(BiPredicate<HttpClientRequest,HttpClientResponse>)

How to access to request body using WebFlux and Netty HttpClient

孤街醉人 提交于 2021-01-29 10:51:29
问题 I need to calculate some kind of digest of the request body using the WebClient of Webflux and this digest must be set into a HTTP header. Using the good old Spring MVC ClientHttpRequestInterceptor is easy because the request body is provided as an array of bytes. The ExchangeFilterFunction does not provide access to the request body. The body is sent as JSon and Spring uses Jackson in order to serialize Java objects, so an option could be serialize my Object into Json and calculate the

How to set the access token once during the instanciation of the webClient in spring webflux?

风流意气都作罢 提交于 2021-01-29 10:15:38
问题 I try to use WebClient with oauth2 in spring webflux. I fetch a token from an url access token and i set it into the webclient. but i do not like to fetch this access token in every call of other secured endpoints. Means that i want to fetch it only in the first time during the instanciation of the webclient and when the access token expire. Here is the code that i am using : @Configuration public class OauthEmployeConfig{ /** ** ... String baseUrl, String accessUrl for the access token url *

How to customize the OAuth2 login redirection endpoint base uri with Spring Security Webflux

流过昼夜 提交于 2021-01-29 10:13:33
问题 Spring security in the servlet stack ( web ) allows you to customize the OAuth2 login redirection endpoint base uri in the Oauth2 authorization code grant flow as given here. I am trying to do the same for the reactive stack with Spring webflux. The github issue here mentions an authorizationRequestResolver and authenticationMatcher on the Oauth2LoginSpec that can be used to customize the base uri but I am unable to figure out how. Can someone please help me out with the configuration? 回答1:

Spring WebClient - SSL configuration

谁说胖子不能爱 提交于 2021-01-29 10:02:36
问题 Below is the old code which I am trying to replace. How can I use webclient to follow same behavior? If anyone can guide me on this it will be great. I check for code to use HostnameVerifier but i did not find any link which can help me. public void initSSL() { if (logger.isDebugEnabled()) { logger.debug("HttpBasedUrlConnection - Initializing SSL"); } // Configure truststore location for everybody final String homePath = getHomePath(); synchronized (this) { trustStorePath = homePath + "/conf

Set cache expireAfterWrite property dynamically - Caffeine and Spring WebFlux

守給你的承諾、 提交于 2021-01-29 09:41:11
问题 I am using caffeine cache to store an authorisation token that has been obtained using webClient WebFlux. I have set the expireAfterWrite to a hardcoded value in the application.yml file as follows: spring: cache: cache-names: accessTokens caffeine: spec: expireAfterWrite=100m The token is obtained using a WebClient with Spring WebFlux as below code depicts: @Autowired var cacheManager: CacheManager? = null override fun getAuthToken(): Mono<AccessToken> { val map = LinkedMultiValueMap<String,