spring-webflux

Spring WebFlux - Content type 'application/xml' not supported for bodyType=org.springframework.web.multipart.MultipartFile

狂风中的少年 提交于 2019-12-24 07:30:37
问题 I am using spring-webflux and want to upload files .... everything works great with just spring-web but when it comes to webflux i have not a clue what's wrong . Be careful in the difference ... i am using : <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> So let's say we have the below @RestController , for Spring Web it works like charm: @PostMapping(value = "/uploadFile") public Response uploadFile(@RequestParam(

Spring boot way to marshall/demarshall XML

烂漫一生 提交于 2019-12-24 00:49:44
问题 What is the "Boot-iful" way to auto marshall/demarshall XML? My Rest controller: @RestController @Slf4j public class ProvisioningController { @RequestMapping(value = "/provisioning", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML) public void handleRequest(@RequestBody ProvisioningRequest request) { log.info("Rx request: {}", request); } } The ProvisioningRequest class is generated by Jaxb from a XSD. Posting a sample request to the rest endpoint gives the following error:

How to use the Spring WebClient with Jetty, instead of Netty?

六月ゝ 毕业季﹏ 提交于 2019-12-23 19:37:47
问题 According to the documentation it is possible to use the Spring Reactive WebClient with a different server as Netty: WebClient provides a higher level API over HTTP client libraries. By default it uses Reactor Netty but that is pluggable with a different ClientHttpConnector. However, I was not able to find a way how to do this. If I simply change the dependency from Netty to Jetty like this: compile('org.springframework.boot:spring-boot-starter-webflux') { exclude group: 'org.springframework

Downlolad and save file from ClientRequest using ExchangeFunction in Project Reactor

给你一囗甜甜゛ 提交于 2019-12-23 19:36:50
问题 I have problem with correctly saving a file after its download is complete in Project Reactor. class HttpImageClientDownloader implements ImageClientDownloader { private final ExchangeFunction exchangeFunction; HttpImageClientDownloader() { this.exchangeFunction = ExchangeFunctions.create(new ReactorClientHttpConnector()); } @Override public Mono<File> downloadImage(String url, Path destination) { ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create(url)).build();

What is the function of the @EnableWebFlux annotation

旧街凉风 提交于 2019-12-23 09:46:50
问题 I have a very simple webflux demo application with freemarker which has got following files: 1.WebFluxDemoApplication.java @SpringBootApplication public class WebFluxDemoApplication { public static void main(String[] args) { SpringApplication.run(WebFluxDemoApplication.class, args); } @Controller class HomeController { @GetMapping("/hello") public String hello() { return "index"; } } } 2.index.ftl (located under classpath:/templates) <html> <head> <title>demo</title> </head> <body></body> <

Spring Security 5 Calling OAuth2 Secured API in Application Runner results in IllegalArgumentException

你说的曾经没有我的故事 提交于 2019-12-23 08:11:30
问题 Given the following code, is it possible to call a Client Credentials secured API in an application runner? @Bean public ApplicationRunner test( WebClient.Builder builder, ClientRegistrationRepository clientRegistrationRepo, OAuth2AuthorizedClientRepository authorizedClient) { return args -> { try { var oauth2 = new ServletOAuth2AuthorizedClientExchangeFilterFunction( clientRegistrationRepo, authorizedClient); oauth2.setDefaultClientRegistrationId("test"); var response = builder .apply(oauth2

Add Exception handler for Spring Web Client

假如想象 提交于 2019-12-23 07:59:15
问题 I use this code for REST API requests. WebClient.Builder builder = WebClient.builder().baseUrl(gatewayUrl); ClientHttpConnector httpConnector = new ReactorClientHttpConnector(opt -> opt.sslContext(sslContext)); builder.clientConnector(httpConnector); How I can add connection exception handler? I would like to implement some custom logic? Is this feature easy to implement? 回答1: If I understand your question in the context of failing the connection because of SSL credentials, then you should

How to create request with parameters with webflux Webclient?

感情迁移 提交于 2019-12-23 07:39:16
问题 At backend side I have REST controller with POST method: @RequestMapping(value = "/save", method = RequestMethod.POST) public Integer save(@RequestParam String name) { //do save return 0; } How can i create request using WebClient with request parameter? WebClient.create(url).post() .uri("/save") //? .exchange() .block() .bodyToMono(Integer.class) .block(); 回答1: There are many encoding challenges when it comes to creating URIs. For more flexibility while still being right on the encoding part

WebFlux call `bodyToMono()` twice throws `IllegalStateException`

二次信任 提交于 2019-12-23 04:41:54
问题 I'm currently working on creating a logging ExchangeFilterFunction that can be used for any WebFlux WebClient to log both requests and responses. The issue I am running into is that when I attempt to log the body of the response I get the following: java.lang.IllegalStateException: Only one connection receive subscriber allowed. I understand why it's happening as Spring only allows one subscriber to the stream. My question is how can I obtain the body in two decoupled places? I have tried

WebFlux async processing

怎甘沉沦 提交于 2019-12-23 04:34:29
问题 I am trying to evaluate Spring WebFlux and advantages of reactive processing. To do so I have implemented tiny project with jetty server setup that exposes same endpoint over sync jersey, async jersey and spring web-flux. Repository can be found here https://github.com/aakhmerov/nio-test As far as I can see current implementation is not faster then synchronous processing implemented over jersey. Which makes me think that I have made some mistake in setup. Flux setup is done over annotations