Created
May 26, 2014 10:45
-
-
Save danielbryantuk/56e6a7b897d56fa79627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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