@Override public Mono<MultiValueMap<String, String>> formData() { return this.exchange.getFormData(); }
@Override public Mono<MultiValueMap<String, String>> formData() { return this.exchange.getFormData(); }
@Override public Mono<MultiValueMap<String, String>> getFormData() { return getDelegate().getFormData(); }
@Override public Mono<MultiValueMap<String, String>> getFormData() { return getDelegate().getFormData(); }
/** * Transform an HTTP POST into another method based on {@code methodParamName}. * @param exchange the current server exchange * @param chain provides a way to delegate to the next filter * @return {@code Mono<Void>} to indicate when request processing is complete */ @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getMethod() != HttpMethod.POST) { return chain.filter(exchange); } return exchange.getFormData() .map(formData -> { String method = formData.getFirst(this.methodParamName); return StringUtils.hasLength(method) ? mapExchange(exchange, method) : exchange; }) .flatMap(chain::filter); }
/** * Transform an HTTP POST into another method based on {@code methodParamName}. * @param exchange the current server exchange * @param chain provides a way to delegate to the next filter * @return {@code Mono<Void>} to indicate when request processing is complete */ @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getMethod() != HttpMethod.POST) { return chain.filter(exchange); } return exchange.getFormData() .map(formData -> { String method = formData.getFirst(this.methodParamName); return StringUtils.hasLength(method) ? mapExchange(exchange, method) : exchange; }) .flatMap(chain::filter); }
@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); } } return Mono.just(ret); }); }
/** * Combine query params and form data for multipart form data from the body * of the request into a {@code Map<String, Object>} of values to use for * data binding purposes. * @param exchange the current exchange * @return a {@code Mono} with the values to bind * @see org.springframework.http.server.reactive.ServerHttpRequest#getQueryParams() * @see ServerWebExchange#getFormData() * @see ServerWebExchange#getMultipartData() */ public static Mono<Map<String, Object>> extractValuesToBind(ServerWebExchange exchange) { MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams(); Mono<MultiValueMap<String, String>> formData = exchange.getFormData(); Mono<MultiValueMap<String, Part>> multipartData = exchange.getMultipartData(); return Mono.zip(Mono.just(queryParams), formData, multipartData) .map(tuple -> { Map<String, Object> result = new TreeMap<>(); tuple.getT1().forEach((key, values) -> addBindValue(result, key, values)); tuple.getT2().forEach((key, values) -> addBindValue(result, key, values)); tuple.getT3().forEach((key, values) -> addBindValue(result, key, values)); return result; }); }
/** * Combine query params and form data for multipart form data from the body * of the request into a {@code Map<String, Object>} of values to use for * data binding purposes. * @param exchange the current exchange * @return a {@code Mono} with the values to bind * @see org.springframework.http.server.reactive.ServerHttpRequest#getQueryParams() * @see ServerWebExchange#getFormData() * @see ServerWebExchange#getMultipartData() */ public static Mono<Map<String, Object>> extractValuesToBind(ServerWebExchange exchange) { MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams(); Mono<MultiValueMap<String, String>> formData = exchange.getFormData(); Mono<MultiValueMap<String, Part>> multipartData = exchange.getMultipartData(); return Mono.zip(Mono.just(queryParams), formData, multipartData) .map(tuple -> { Map<String, Object> result = new TreeMap<>(); tuple.getT1().forEach((key, values) -> addBindValue(result, key, values)); tuple.getT2().forEach((key, values) -> addBindValue(result, key, values)); tuple.getT3().forEach((key, values) -> addBindValue(result, key, values)); return result; }); }
private Mono<?> extractReadableRequestBody(ServerWebExchange exchange) { MediaType contentType = exchange.getRequest() .getHeaders() .getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) { return exchange.getFormData(); } else if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType)) { return exchange.getMultipartData(); } else { return readRequestBody(exchange, contentType); } }
/** * Fetches a user by email */ @PostMapping("/users/fetch-by-email") public Mono<U> fetchUserByEmail(ServerWebExchange exchange) { log.debug("Fetching user by email ... "); return lemonReactiveService.fetchUserByEmail(exchange.getFormData()); }
/** * The forgot Password feature */ @PostMapping("/forgot-password") @ResponseStatus(HttpStatus.NO_CONTENT) public Mono<Void> forgotPassword(ServerWebExchange exchange) { log.debug("Received forgot password request ... " ); return lemonReactiveService.forgotPassword(exchange.getFormData()); }
@Override @Deprecated public Mono<Authentication> apply(ServerWebExchange exchange) { return exchange.getFormData() .map( data -> createAuthentication(data)); }
@Override public Mono<Authentication> apply(ServerWebExchange serverWebExchange) { return serverWebExchange.getFormData() .map( data -> createAuthentication(data)); }
@Override public Mono<MultiValueMap<String, String>> getFormData() { return getDelegate().getFormData(); }
/** * Verifies current-user */ @PostMapping("/users/{id}/verification") public Mono<UserDto> verifyUser( @PathVariable ID id, ServerWebExchange exchange) { log.debug("Verifying user ..."); return userWithToken(lemonReactiveService.verifyUser(id, exchange.getFormData()), exchange.getResponse()); }
/** * Changes the email */ @PostMapping("/users/{userId}/email") public Mono<UserDto> changeEmail( @PathVariable ID userId, ServerWebExchange exchange) { log.debug("Changing email of user ..."); return userWithToken(lemonReactiveService.changeEmail( userId, exchange.getFormData()), exchange.getResponse()); }
@PostMapping(path = "/**", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) @ResponseBody public Mono<ResponseEntity<?>> form(ServerWebExchange request) { FunctionWrapper wrapper = wrapper(request); return request.getFormData().doOnSuccess(params -> wrapper.params(params)) .then(Mono.defer(() -> processor.post(wrapper, null, false))); }
@PostMapping(path = "/**", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) @ResponseBody public Mono<ResponseEntity<?>> form(ServerWebExchange request) { FunctionWrapper wrapper = wrapper(request); return request.getFormData().doOnSuccess(params -> wrapper.params(params)) .then(Mono.defer(() -> processor.post(wrapper, null, false))); }
private Mono<Boolean> containsValidCsrfToken(ServerWebExchange exchange, CsrfToken expected) { return exchange.getFormData() .flatMap(data -> Mono.justOrEmpty(data.getFirst(expected.getParameterName()))) .switchIfEmpty(Mono.justOrEmpty(exchange.getRequest().getHeaders().getFirst(expected.getHeaderName()))) .map(actual -> actual.equals(expected.getToken())); }