Merge pull request #4045 from its-fpereira/BAEL-1505
BAEL-1505: Spring WebFlux Filters Refatoring
This commit is contained in:
commit
13a1ddcfc2
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.reactive.filter;
|
||||
package com.baeldung.reactive.filters;
|
||||
|
||||
import org.springframework.web.reactive.function.server.HandlerFilterFunction;
|
||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
||||
|
@ -8,10 +8,10 @@ import reactor.core.publisher.Mono;
|
|||
|
||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||
|
||||
public class ExampleHandlerFilterFunction implements HandlerFilterFunction {
|
||||
public class ExampleHandlerFilterFunction implements HandlerFilterFunction<ServerResponse, ServerResponse> {
|
||||
|
||||
@Override
|
||||
public Mono filter(ServerRequest serverRequest, HandlerFunction handlerFunction) {
|
||||
public Mono<ServerResponse> filter(ServerRequest serverRequest, HandlerFunction<ServerResponse> handlerFunction) {
|
||||
if (serverRequest.pathVariable("name").equalsIgnoreCase("test")) {
|
||||
return ServerResponse.status(FORBIDDEN).build();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.reactive.filter;
|
||||
package com.baeldung.reactive.filters;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.reactive.handler;
|
||||
package com.baeldung.reactive.filters;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
|
@ -8,9 +8,9 @@ import reactor.core.publisher.Mono;
|
|||
import static org.springframework.web.reactive.function.server.ServerResponse.ok;
|
||||
|
||||
@Component
|
||||
public class PlayerHandler {
|
||||
class PlayerHandler {
|
||||
|
||||
public Mono<ServerResponse> getName(ServerRequest request) {
|
||||
Mono<ServerResponse> getName(ServerRequest request) {
|
||||
Mono<String> name = Mono.just(request.pathVariable("name"));
|
||||
return ok().body(name, String.class);
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.baeldung.reactive.router;
|
||||
package com.baeldung.reactive.filters;
|
||||
|
||||
import com.baeldung.reactive.filter.ExampleHandlerFilterFunction;
|
||||
import com.baeldung.reactive.handler.PlayerHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.server.RouterFunction;
|
||||
|
@ -17,6 +15,6 @@ public class PlayerRouter {
|
|||
public RouterFunction<ServerResponse> route(PlayerHandler playerHandler) {
|
||||
return RouterFunctions
|
||||
.route(GET("/players/{name}"), playerHandler::getName)
|
||||
.filter(new ExampleHandlerFilterFunction()::filter);
|
||||
.filter(new ExampleHandlerFilterFunction());
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.reactive.controller;
|
||||
package com.baeldung.reactive.filters;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.reactive.handler;
|
||||
package com.baeldung.reactive.filters;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.reactive.controller;
|
||||
package com.baeldung.reactive.filters;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
Loading…
Reference in New Issue