Skip to content

Instantly share code, notes, and snippets.

@AdrianoJS
Created April 12, 2023 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdrianoJS/e230c7427049f961f3cda5999d203e6b to your computer and use it in GitHub Desktop.
Save AdrianoJS/e230c7427049f961f3cda5999d203e6b to your computer and use it in GitHub Desktop.
package no.embriq.api.gateway.filter;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.HttpStatusCode;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import static java.nio.charset.StandardCharsets.UTF_8;
@Component
public class PingFilter extends AbstractGatewayFilterFactory<Object> {
private static final String DEFAULT_RESPONSE = """
{
"status": "UP",
"applicationName": "api-gateway"
}
""";
@Override
public GatewayFilter apply(final Object ignored) {
return ((exchange, chain) -> {
var response = exchange.getResponse();
var buffer = response.bufferFactory().wrap(DEFAULT_RESPONSE.getBytes(UTF_8));
response.setStatusCode(HttpStatusCode.valueOf(200));
return response.writeWith(Flux.just(buffer));
});
}
@Override
public String name() {
return "PingFilter";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment