Adding Zuul filters

We can also add custom filters in the Zuul microservice for implementing some cross-cutting concerns, such as security and rate-limiting. In the API Gateway components section, we discussed four filters—pre, post, route, and error. We can create these filters by extending the com.netflix.zuul.ZuulFilter class. We have to override filterType, filterOrder, and shouldFilter, and run methods. Let's see the following PreFilter custom filter:

package com.dineshonjava.apizuulservice.filters;import java.util.UUID;import javax.servlet.http.HttpServletRequest;import com.netflix.zuul.ZuulFilter;import com.netflix.zuul.context.RequestContext;import com.netflix.zuul.exception.ZuulException;public class PreFilter extends ZuulFilter{ ...

Get Mastering Spring Boot 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.