Source:
<code>public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { long startTime = System.currentTimeMillis(); TeeHttpServletRequest req = new TeeHttpServletRequest( (HttpServletRequest) request); TeeHttpServletResponse resp = new TeeHttpServletResponse( (HttpServletResponse) response); try { MDC.put("requestType", "req"); String requestUUID = UUID.randomUUID().toString(); MDC.put("requestUuid", requestUUID); String correlationId = ""; Enumeration<String> headerNames = (Enumeration<String>) ((HttpServletRequest) request) .getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); if ("X-Correlation-ID".equalsIgnoreCase(name)) { correlationId = ((HttpServletRequest) request).getHeader(name); } } <START> if (correlationId.matches("^([a-zA-Z0-9-])*$") && <END> correlationId.length() <= CORRELATION_ID_LENGTH) { MDC.put(CSID, correlationId); } else if (!StringUtils.isBlank(correlationId)) { log.info("Correlation Id must contain alphanumeric characters or hypens and " + "be or fewer characters in length.", CORRELATION_ID_LENGTH); } req.setAttribute("requestUuid", requestUUID); resp.setHeader(customHeaderName, requestUUID); if (log.isDebugEnabled()) { log.debug("{}", ServletLogger.logRequest(req)); } else { log.info("{}", ServletLogger.logBasicRequestInfo(req)); } chain.doFilter(req, resp); if (log.isDebugEnabled()) { log.debug("{}", ServletLogger.logResponse(resp, startTime)); } else { log.info("{}", ServletLogger.logBasicResponseInfo(resp, startTime)); } resp.finish(); } finally { MDC.clear(); } }</code><technical_language>good. note is regex match empty string. If desirable, a + instead of *. I merge</technical_language>

Target:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { long startTime = System.currentTimeMillis(); TeeHttpServletRequest req = new TeeHttpServletRequest( (HttpServletRequest) request); TeeHttpServletResponse resp = new TeeHttpServletResponse( (HttpServletResponse) response); try { MDC.put("requestType", "req"); String requestUUID = UUID.randomUUID().toString(); MDC.put("requestUuid", requestUUID); String correlationId = ""; Enumeration<String> headerNames = (Enumeration<String>) ((HttpServletRequest) request) .getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); if ("X-Correlation-ID".equalsIgnoreCase(name)) { correlationId = ((HttpServletRequest) request).getHeader(name); } } if (correlationId.matches("^([a-zA-Z0-9-])+$") && correlationId.length() <= CORRELATION_ID_LENGTH) { MDC.put(CSID, correlationId); } else if (!StringUtils.isBlank(correlationId)) { log.info("Correlation Id must contain alphanumeric characters or hypens and " + "be or fewer characters in length.", CORRELATION_ID_LENGTH); } req.setAttribute("requestUuid", requestUUID); resp.setHeader(customHeaderName, requestUUID); if (log.isDebugEnabled()) { log.debug("{}", ServletLogger.logRequest(req)); } else { log.info("{}", ServletLogger.logBasicRequestInfo(req)); } chain.doFilter(req, resp); if (log.isDebugEnabled()) { log.debug("{}", ServletLogger.logResponse(resp, startTime)); } else { log.info("{}", ServletLogger.logBasicResponseInfo(resp, startTime)); } resp.finish(); } finally { MDC.clear(); } }