}
}
protected PageInfo buildPage(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
// Invoke the next entity in the chain
SerializableByteArrayOutputStream out = new SerializableByteArrayOutputStream();
GenericResponseWrapper wrapper = new GenericResponseWrapper(response, out);
Map<String, Serializable> cacheableRequestAttributes = new HashMap<String, Serializable>();
// TODO: split the special include handling out into a separate method
HttpServletResponse originalResponse = null;
boolean isInclude = WebUtils.isIncludeRequest(request);
if (isInclude) {
originalResponse = WrappedResponseHolder.getWrappedResponse();
WrappedResponseHolder.setWrappedResponse(wrapper);
}
try {
List<String> attributesBefore = toList(request.getAttributeNames());
chain.doFilter(request, wrapper);
List<String> attributesAfter = toList(request.getAttributeNames());
attributesAfter.removeAll(attributesBefore);
for (String attrName : attributesAfter) {
Object value = request.getAttribute(attrName);
if (value instanceof Serializable) {
cacheableRequestAttributes.put(attrName, (Serializable)value);
}
}
}
finally {
if (isInclude) {
WrappedResponseHolder.setWrappedResponse(originalResponse);
}
}
wrapper.flush();
long timeToLiveSeconds = Integer.MAX_VALUE; // TODO cacheManager.getEhcache(context.cacheName).cacheConfiguration.timeToLiveSeconds;
String contentType = wrapper.getContentType();
if (!StringUtils.hasLength(contentType)) {
contentType = response.getContentType();
}
return new PageInfo(wrapper.getStatus(), contentType, out.toByteArray(),
false, timeToLiveSeconds, wrapper.getAllHeaders(), wrapper.getCookies(), cacheableRequestAttributes);
}