1

I am trying to define a Route using Spring's WebFlux modules. Here is my route defintion:

@Bean
public RouterFunction<?> routes(Handler handler) {
    Predicate<ServerRequest.Headers> predicate = headers -> headers.equals("clientId");
    return
            route(GET("/api/v1/client/info").and(headers(predicate)),handler::getInfo);
}

My intent here is to define an GET endPoint with a certain path and the client must provide request header called "clientId". This definition does not work when I make the call to the endPoint. However, if I take the header() part out, the call goes through. What am I missing here ? Kindly advise.

Thank you.

deepak
  • 339
  • 6
  • 16
  • 3
    An object of type ServerRequest.Headers wil never, ever be equal to an object of type String. You want to test it the ServerRequest.Headers object **has** a header **named** clientId. – JB Nizet Jun 17 '18 at 07:20

1 Answers1

0

As said in the comments: You can't compare a String to a header.
The Predicate needs to check that headers.firstHeader("clientId") is not null:

Predicate<ServerRequest.Headers> clientIdPredicate =
                headers -> headers.firstHeader("clientId") != null;
TomerBu
  • 1,483
  • 15
  • 15