org.hippoecm.hst.servlet
Class ResourceServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.hippoecm.hst.servlet.ResourceServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ResourceServlet
extends javax.servlet.http.HttpServlet

Serves resources from either web application or classpath.

A typical configuration is to set classpath resource path and map a servlet path to this servlet.

<servlet> <servlet-name>ExampleResourceServlet</servlet-name> <servlet-class>org.hippoecm.hst.servlet.ResourceServlet</servlet-class> <init-param> <param-name>jarPathPrefix</param-name> <param-value>/META-INF/example/myapp/skin</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>ExampleResourceServlet</servlet-name> <url-pattern>/myapp/skin/*</url-pattern> </servlet-mapping>

With the configuration above, requests by paths, "/myapp/skin/*", will be served by ExampleResourceServlet, which reads the target resource from the configured classpath resource path, "/META-INF/example/myapp/skin". For example, if the request path info is "/myapp/skin/example.png", then the servlet will find the corresponding classpath resource, "classpath:META-INF/example/myapp/skin/example.png", to serve the request.

The following init parameters are available:

Init parameter name Description Example value Default value
jarPathPrefix Classpath resource path prefix META-INF/example/myapp/skin META-INF
cacheTimeout Millisecond value to set cache control HTTP headers: 'Expires' and 'Cache-Control'. These cache control HTTP headers will be written only if this value is greater than zero. Otherwise, the cache control HTTP headers are not written. 0 31556926
gzipEnabled Flag to enable/disable gzip encoded response for specified mimeTypes, which can be configured by 'compressedMimeTypes' init parameter. false true
webResourceEnabled Flag to enable/disable to read resources from the servlet context on web application resources. If this is enabled, then the servlet will try to read a resource from the web application first by the request path info. false true
jarResourceEnabled Flag to enable/disable to read resources from the classpath resources. If this is enabled, then the servlet will try to read a resource from the classpath. false true
allowedResourcePaths Sets resource path regex patterns which are allowed to serve by this servlet.
 ^/.\*\.js,
 ^/.\*\.css, 
 ^/.\*\.png, 
 ^/.\*\.gif, 
 ^/.\*\.ico, 
 ^/.\*\.jpg, 
 ^/.\*\.jpeg, 
 ^/.\*\.swf,
 ^/.\*\.txt
     
 ^/.\*\.js,
 ^/.\*\.css, 
 ^/.\*\.png, 
 ^/.\*\.gif, 
 ^/.\*\.ico, 
 ^/.\*\.jpg, 
 ^/.\*\.jpeg, 
 ^/.\*\.swf
     
mimeTypes Sets mimeType mappings to override (or add) from the default mimeType mappings of the web application. If a proper mimeType is not found by this mapping, then it will look up a mimeType from the web application.
 .css = text/css,
 .js = text/javascript,
 .gif = image/gif,
 .png = image/png,
 .ico = image/vnd.microsoft.icon,
 .jpg = image/jpeg,
 .jpeg = image/jpeg,
 .swf = application/x-shockwave-flash,
 .txt = text/plain
     
 .css = text/css,
 .js = text/javascript,
 .gif = image/gif,
 .png = image/png,
 .ico = image/vnd.microsoft.icon,
 .jpg = image/jpeg,
 .jpeg = image/jpeg,
 .swf = application/x-shockwave-flash
     
compressedMimeTypes Sets mimeTypes which can be compressed to serve the resource by this servlet. If a resource is in this kind of mimeTypes, then the servlet will write a compressed response in gzip encoding.
 text/.*,
 application/json
     
 text/.*
     

See Also:
Serialized Form

Constructor Summary
ResourceServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void init()
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceServlet

public ResourceServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException


Copyright © 2008-2012 Hippo. All Rights Reserved.