Compiler warnings

This commit is contained in:
Dave Syer
2018-04-24 09:46:48 +01:00
parent ea5811fbe2
commit 2df5dcc992

View File

@@ -16,9 +16,16 @@
package org.springframework.cloud.function.web.flux; package org.springframework.cloud.function.web.flux;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
import org.springframework.cloud.function.context.catalog.FunctionInspector; import org.springframework.cloud.function.context.catalog.FunctionInspector;
import org.springframework.cloud.function.context.message.MessageUtils; import org.springframework.cloud.function.context.message.MessageUtils;
import org.springframework.cloud.function.web.flux.constants.WebRequestConstants; import org.springframework.cloud.function.web.flux.constants.WebRequestConstants;
@@ -32,15 +39,10 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest; import org.springframework.web.context.request.WebRequest;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
/** /**
* @author Dave Syer * @author Dave Syer
* @author Mark Fisher * @author Mark Fisher
@@ -67,7 +69,8 @@ public class FunctionController {
@PostMapping(path = "/**") @PostMapping(path = "/**")
@ResponseBody @ResponseBody
public ResponseEntity<Publisher<?>> post(WebRequest request, @RequestBody FluxRequest<?> body) { public ResponseEntity<Publisher<?>> post(WebRequest request,
@RequestBody FluxRequest<?> body) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Function<Flux<?>, Flux<?>> function = (Function<Flux<?>, Flux<?>>) request Function<Flux<?>, Flux<?>> function = (Function<Flux<?>, Flux<?>>) request
@@ -75,10 +78,10 @@ public class FunctionController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Consumer<Flux<?>> consumer = (Consumer<Flux<?>>) request Consumer<Flux<?>> consumer = (Consumer<Flux<?>>) request
.getAttribute(WebRequestConstants.CONSUMER, WebRequest.SCOPE_REQUEST); .getAttribute(WebRequestConstants.CONSUMER, WebRequest.SCOPE_REQUEST);
Boolean single = (Boolean) request Boolean single = (Boolean) request.getAttribute(WebRequestConstants.INPUT_SINGLE,
.getAttribute(WebRequestConstants.INPUT_SINGLE, WebRequest.SCOPE_REQUEST); WebRequest.SCOPE_REQUEST);
FluxFormRequest form = FluxFormRequest.from(request.getParameterMap()); FluxFormRequest<?, ?> form = FluxFormRequest.from(request.getParameterMap());
if (function != null) { if (function != null) {
Flux<?> flux = body.body() == null ? form.flux() : body.flux(); Flux<?> flux = body.body() == null ? form.flux() : body.flux();
@@ -92,11 +95,13 @@ public class FunctionController {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Handled POST with function"); logger.debug("Handled POST with function");
} }
return ResponseEntity.ok().body(debug ? result.log() : response(request, function, single, result)); return ResponseEntity.ok().body(
debug ? result.log() : response(request, function, single, result));
} }
if (consumer != null) { if (consumer != null) {
Flux<?> flux = body.body() == null ? form.flux().cache() : body.flux().cache(); // send a copy back to the caller Flux<?> flux = body.body() == null ? form.flux().cache()
: body.flux().cache(); // send a copy back to the caller
if (debug) { if (debug) {
flux = flux.log(); flux = flux.log();
} }
@@ -110,14 +115,17 @@ public class FunctionController {
throw new IllegalArgumentException("no such function"); throw new IllegalArgumentException("no such function");
} }
private Publisher<?> response(WebRequest request, Object handler, Boolean single, Flux<?> result) { private Publisher<?> response(WebRequest request, Object handler, Boolean single,
Flux<?> result) {
if (single != null && single && isOutputSingle(handler)) { if (single != null && single && isOutputSingle(handler)) {
request.setAttribute(WebRequestConstants.OUTPUT_SINGLE, true, WebRequest.SCOPE_REQUEST); request.setAttribute(WebRequestConstants.OUTPUT_SINGLE, true,
WebRequest.SCOPE_REQUEST);
return Mono.from(result); return Mono.from(result);
} }
request.setAttribute(WebRequestConstants.OUTPUT_SINGLE, false, WebRequest.SCOPE_REQUEST); request.setAttribute(WebRequestConstants.OUTPUT_SINGLE, false,
WebRequest.SCOPE_REQUEST);
return result; return result;
} }
@@ -143,8 +151,8 @@ public class FunctionController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Supplier<Flux<?>> supplier = (Supplier<Flux<?>>) request Supplier<Flux<?>> supplier = (Supplier<Flux<?>>) request
.getAttribute(WebRequestConstants.SUPPLIER, WebRequest.SCOPE_REQUEST); .getAttribute(WebRequestConstants.SUPPLIER, WebRequest.SCOPE_REQUEST);
String argument = (String) request String argument = (String) request.getAttribute(WebRequestConstants.ARGUMENT,
.getAttribute(WebRequestConstants.ARGUMENT, WebRequest.SCOPE_REQUEST); WebRequest.SCOPE_REQUEST);
if (function != null) { if (function != null) {
return value(function, argument); return value(function, argument);