HttpServletRequest httpRequest = (HttpServletRequest) request;
String parentRequestPath = httpRequest.getRequestURI().replaceAll("/[^/]*$", "");
String hostIdentifier = httpRequest.getRequestURL().toString().replaceAll(contextPath + ".*$", "");
String requestUri = hostIdentifier + parentRequestPath;
ServletOutputStream out = response.getOutputStream();
CharResponseWrapper responseWrapper = new CharResponseWrapper((HttpServletResponse) response);
chain.doFilter(request, responseWrapper);
try
{
// logger.debug("processing and replacing JNDI tokens within response.");
StringBuffer filteredResponse = streamTokeniser.replaceTokens(responseWrapper.getReader(), tokenFinder, requestUri);
byte[] filteredData = filteredResponse.toString().getBytes(response.getCharacterEncoding());
if (!response.isCommitted()) {
response.setContentLength(filteredData.length);
out.write(filteredData);
}