0

We're moving from zuul to Spring Cloud Gateway. Storing all the request and response details in a table using pre-filter and post-filter implementation. Following is the implementation in zuul

PreFilter

public Object run() {

   RequestContext ctx = RequestContext.getCurrentContext();
   HttpServletRequest request = ctx.getRequest();
   ..get the request details
   ctx.put("REQ-LOG-ID",reqLogId);
}

PostFilter

public Object run() {
    
  RequestContext ctx = RequestContext.getCurrentContext();
  HttpServletResponse response = ctx.getResponse();
  log.info("Response : {} \n {}",response.getStatus(),response.getHeaderNames());
  String requestLogId = (String) ctx.get("REQ-LOG-ID");
  log.info("Request log Id :{}",requestLogId);
}

How to use RequestContext in Prefilter and Postfilter in Spring cloud Gateway? How to get the same request id,get the responseCode of the particular req and store it in a table? Can anyone please guide me for the implementation in Spring cloud gateway?

0