if (pathInfo.startsWith(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX))
{
final String resourceReferenceKey = pathInfo.substring(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX.length());
Resource resource = null;
boolean externalCall = !Application.exists();
try
{
// if called externally (i.e. WicketServlet) we need to set the thread local here
// AND clean it up at the end of the request
if (externalCall)
{
Application.set(webApplication);
}
// Try to find shared resource
resource = webApplication.getSharedResources().get(resourceReferenceKey);
// If resource found and it is cacheable
if ((resource != null) && resource.isCacheable())
{
// first check the char encoding for getting the parameters
checkCharacterEncoding(servletRequest);
final WebRequest request = webApplication.newWebRequest(servletRequest);
// make the session available.
Session.findOrCreate(request, new WebResponse());
// Set parameters from servlet request
resource.setParameters(request.getParameterMap());
// Get resource stream
IResourceStream stream = resource.getResourceStream();
// Get last modified time from stream
Time time = stream.lastModifiedTime();
try
{
stream.close();
}
catch (IOException e)
{
// ignore
}
return time != null ? time.getMilliseconds() : -1;
}
}
catch (AbortException e)
{
return -1;
}
finally
{
if (resource != null)
{
resource.setParameters(null);
}
if (externalCall)
{
// Clean up thread local application if this was an external call
// (if not, doFilter will clean it up)