Skip to content

Instantly share code, notes, and snippets.

@danielbryantuk
Created May 26, 2014 10:45
Show Gist options
  • Save danielbryantuk/56e6a7b897d56fa79627 to your computer and use it in GitHub Desktop.
Save danielbryantuk/56e6a7b897d56fa79627 to your computer and use it in GitHub Desktop.
public class CorrelationHeaderFilter implements Filter {
//...
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
final HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
String currentCorrId = httpServletRequest.getHeader(RequestCorrelation.CORRELATION_ID_HEADER);
if (!currentRequestIsAsyncDispatcher(httpServletRequest)) {
if (currentCorrId == null) {
currentCorrId = UUID.randomUUID().toString();
LOGGER.info("No correlationId found in Header. Generated : " + currentCorrId);
} else {
LOGGER.info("Found correlationId in Header : " + currentCorrId);
}
RequestCorrelation.setId(currentCorrId);
}
filterChain.doFilter(httpServletRequest, servletResponse);
}
//...
private boolean currentRequestIsAsyncDispatcher(HttpServletRequest httpServletRequest) {
return httpServletRequest.getDispatcherType().equals(DispatcherType.ASYNC);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment