Example usage for org.springframework.web.server ServerWebExchange getFormData

List of usage examples for org.springframework.web.server ServerWebExchange getFormData

Introduction

In this page you can find the example usage for org.springframework.web.server ServerWebExchange getFormData.

Prototype

Mono<MultiValueMap<String, String>> getFormData();

Source Link

Document

Return the form data from the body of the request if the Content-Type is "application/x-www-form-urlencoded" or an empty map otherwise.

Usage

From source file:org.springframework.cloud.gateway.test.HttpBinCompatibleController.java

@RequestMapping(path = "/post", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<Map<String, Object>> post(ServerWebExchange exchange, @RequestBody(required = false) String body)
        throws IOException {
    HashMap<String, Object> ret = new HashMap<>();
    ret.put("headers", getHeaders(exchange));
    ret.put("data", body);
    HashMap<String, Object> form = new HashMap<>();
    ret.put("form", form);

    return exchange.getFormData().flatMap(map -> {
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
            for (String value : entry.getValue()) {
                form.put(entry.getKey(), value);
            }/*from ww w.  j ava2s  .  c o m*/
        }
        return Mono.just(ret);
    });
}