jet.servlet
Class JetServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by jet.servlet.JetServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
JetFilter, ScratchBoard

public class JetServlet
extends javax.servlet.http.HttpServlet

The servlet - the core class of the jet turbine

Author:
Markus.Meisters@web.de
See Also:
Serialized Form

Field Summary
protected  ObjectPool actionpool
          The jet definitions from config file
protected  net.sf.ehcache.Cache cache
           
private  java.lang.String contextPath
          the context path of the webapp
private  java.util.HashMap debug
           
private static JetInjector defaultInjector
           
private  java.lang.String encoding
           
static java.lang.String INCOMING_FILTERNAME
           
protected  ObjectPool jetInternalObjectPool
          Holds the object pool for jetcontext
private  java.util.concurrent.locks.Lock lock
           
private  java.lang.String[] locs
          Localizer files/urls readed - you can specify more than one in config
private  org.apache.log4j.Logger log
          logger object
private  MessageProvider provider
          Localizer provider used
private  FilteredQueue<QueuedAction> queue
          Queue for incoming requests
private  java.util.concurrent.locks.Lock queueLock
           
private  java.util.HashMap refresh
          Holds the regex which hosts etc. are allowed to use refresh
private  java.util.concurrent.locks.Lock refreshLock
           
private  javax.servlet.ServletConfig servletConfig
          the servlet config object
private  javax.servlet.ServletContext servletContext
          the servlet context object
private  freemarker.ext.servlet.ServletContextHashModel servletContextHashModel
          freemarker servletcontexthashmodel
protected  Jetdefs servletjetdefs
          The jet definitions from config file
private  java.util.HashMap status
          Holds the regex which hosts etc. are allowed to use status
private  freemarker.ext.jsp.TaglibFactory taglibs
          freemarker taglib support
private  freemarker.template.Configuration templateEngine
          The template engine used
private  java.lang.ThreadGroup workerthreadgroup
           
 
Constructor Summary
JetServlet()
           
 
Method Summary
private static java.lang.String createID(javax.servlet.http.HttpServletRequest request, boolean sessionAware)
           
 void destroy()
          This method is called if the servlet/server shut down here we have to cleanup resources etc.
protected  void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles the HTTP DELETE method.
private  void doFirstQueuedAction(JetContext context, QueuedAction qaction)
           
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles the HTTP GET method.
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles the HTTP POST method.
protected  void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles the HTTP PUT method.
private  void doQueuedActions(JetContext context, javax.servlet.http.HttpServletResponse response, QueuedAction qaction)
           
 java.lang.String getContextPath()
          Method to return the context path
 java.lang.String getEncoding()
          Returns the encoding to use
 Jetdefs getJetdefs()
          Returns the Jetdefs readed from config
 java.util.TreeMap getLocalizedMessagesFor(java.util.Locale locale)
          Method to retriev localized messages as hashmap
static java.lang.String getMapAsLocaliser(java.lang.String parentKey, java.util.Map map)
          Method to get debug print for localiser
 byte[] getResource(java.lang.String resourceName)
          gets the a file/resource
 javax.servlet.ServletConfig getServletConfig()
           
 javax.servlet.ServletContext getServletContext()
           
 freemarker.ext.servlet.ServletContextHashModel getServletContextHashModel()
          Method returning a hashstructur needed for taglb support in freemarker templates
 java.lang.String getServletInfo()
          Returns a short description of the servlet.
 freemarker.ext.jsp.TaglibFactory getTaglibs()
          Method returning the tagib support object from freemarkers
 freemarker.template.Configuration getTemplateEngine()
          returns the template engine
static java.lang.String getTimeStamp()
          returns a simple timestamp - used for debug prints
 void init(javax.servlet.ServletConfig config)
          Method to initialize the jet turbine
protected  void initCache()
          Method to initialize the ehcache - initialze only if not aready done
 boolean isDebug(java.lang.String host)
          indicates if the servlet allows debug modus in jetcontext
 boolean isRefresh(java.lang.String host)
          indicates if the servlet allows refresh modus in jetcontext
 boolean isStatus(java.lang.String host)
          indicates if the servlet allows status modus in jetcontext
private  void printStatusInformation(javax.servlet.http.HttpServletResponse response)
          Method du print status information about the jet caches and pools
protected  void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Processes requests for both HTTP GET and POST methods.
protected  void refreshAll()
          refreshs all caches etc.
protected  void refreshLocalizers()
          refreshs the localizer cache
protected  void refreshResourceCache()
          refresh resource cache
protected  void refreshTemplateEngine()
          refreshs template engine.
private  void setContextPath(java.lang.String val)
          Method to set the context path
private  void setDebug(java.lang.String regex)
          Set if debug is allowed
private  void setJetdefs(Jetdefs jetdefs)
          Set the Jetdefs to use
private  void setRefresh(java.lang.String regex)
          Set if refrsh is allowed
private  void setStatus(java.lang.String regex)
          Set if status is allowed
private  void setTemplateEngine(freemarker.template.Configuration aTemplateEngine)
          Set the template engine to use
 
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.log4j.Logger log
logger object


jetInternalObjectPool

protected ObjectPool jetInternalObjectPool
Holds the object pool for jetcontext


templateEngine

private freemarker.template.Configuration templateEngine
The template engine used


servletjetdefs

protected Jetdefs servletjetdefs
The jet definitions from config file


actionpool

protected ObjectPool actionpool
The jet definitions from config file


queue

private FilteredQueue<QueuedAction> queue
Queue for incoming requests


INCOMING_FILTERNAME

public static final java.lang.String INCOMING_FILTERNAME
See Also:
Constant Field Values

workerthreadgroup

private java.lang.ThreadGroup workerthreadgroup

debug

private java.util.HashMap debug

status

private java.util.HashMap status
Holds the regex which hosts etc. are allowed to use status


refresh

private java.util.HashMap refresh
Holds the regex which hosts etc. are allowed to use refresh


servletContext

private javax.servlet.ServletContext servletContext
the servlet context object


servletConfig

private javax.servlet.ServletConfig servletConfig
the servlet config object


locs

private java.lang.String[] locs
Localizer files/urls readed - you can specify more than one in config


provider

private MessageProvider provider
Localizer provider used


contextPath

private java.lang.String contextPath
the context path of the webapp


taglibs

private freemarker.ext.jsp.TaglibFactory taglibs
freemarker taglib support


servletContextHashModel

private freemarker.ext.servlet.ServletContextHashModel servletContextHashModel
freemarker servletcontexthashmodel


lock

private java.util.concurrent.locks.Lock lock

refreshLock

private java.util.concurrent.locks.Lock refreshLock

queueLock

private java.util.concurrent.locks.Lock queueLock

encoding

private java.lang.String encoding

cache

protected net.sf.ehcache.Cache cache

defaultInjector

private static final JetInjector defaultInjector
Constructor Detail

JetServlet

public JetServlet()
Method Detail

setContextPath

private final void setContextPath(java.lang.String val)
Method to set the context path


getContextPath

public final java.lang.String getContextPath()
Method to return the context path


processRequest

protected final void processRequest(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response)
                             throws javax.servlet.ServletException,
                                    java.io.IOException
Processes requests for both HTTP GET and POST methods.

Parameters:
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

doFirstQueuedAction

private void doFirstQueuedAction(JetContext context,
                                 QueuedAction qaction)
                          throws java.io.IOException
Throws:
java.io.IOException

doQueuedActions

private void doQueuedActions(JetContext context,
                             javax.servlet.http.HttpServletResponse response,
                             QueuedAction qaction)
                      throws java.io.IOException
Throws:
java.io.IOException

createID

private static final java.lang.String createID(javax.servlet.http.HttpServletRequest request,
                                               boolean sessionAware)

printStatusInformation

private void printStatusInformation(javax.servlet.http.HttpServletResponse response)
                             throws java.io.IOException
Method du print status information about the jet caches and pools

Throws:
java.io.IOException

getServletContext

public javax.servlet.ServletContext getServletContext()
Specified by:
getServletContext in interface javax.servlet.ServletConfig
Overrides:
getServletContext in class javax.servlet.GenericServlet

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Method to initialize the jet turbine

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - servlet config
Throws:
javax.servlet.ServletException

getLocalizedMessagesFor

public java.util.TreeMap getLocalizedMessagesFor(java.util.Locale locale)
Method to retriev localized messages as hashmap

Parameters:
locale - the locale to localize

getMapAsLocaliser

public static java.lang.String getMapAsLocaliser(java.lang.String parentKey,
                                                 java.util.Map map)
Method to get debug print for localiser

Parameters:
parentKey - parent key
map - map
Returns:
String the buffer holding key/values

doGet

protected final void doGet(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Handles the HTTP GET method.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected final void doPost(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws javax.servlet.ServletException,
                            java.io.IOException
Handles the HTTP POST method.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

doDelete

protected final void doDelete(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              java.io.IOException
Handles the HTTP DELETE method.

Overrides:
doDelete in class javax.servlet.http.HttpServlet
Parameters:
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

doPut

protected final void doPut(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Handles the HTTP PUT method.

Overrides:
doPut in class javax.servlet.http.HttpServlet
Parameters:
request - servlet request
response - servlet response
Throws:
javax.servlet.ServletException
java.io.IOException

getServletInfo

public java.lang.String getServletInfo()
Returns a short description of the servlet.

Specified by:
getServletInfo in interface javax.servlet.Servlet
Overrides:
getServletInfo in class javax.servlet.GenericServlet

getJetdefs

public final Jetdefs getJetdefs()
Returns the Jetdefs readed from config

Returns:
JetDefs

setJetdefs

private void setJetdefs(Jetdefs jetdefs)
Set the Jetdefs to use

Parameters:
jetdefs - jetdefs

getEncoding

public java.lang.String getEncoding()
Returns the encoding to use

Returns:
encoding

getTemplateEngine

public final freemarker.template.Configuration getTemplateEngine()
returns the template engine

Returns:
Configuration template engine

setTemplateEngine

private void setTemplateEngine(freemarker.template.Configuration aTemplateEngine)
Set the template engine to use


getTimeStamp

public static final java.lang.String getTimeStamp()
returns a simple timestamp - used for debug prints


isDebug

public final boolean isDebug(java.lang.String host)
indicates if the servlet allows debug modus in jetcontext

Returns:
boolean debug allowed?

setDebug

private final void setDebug(java.lang.String regex)
Set if debug is allowed


isStatus

public final boolean isStatus(java.lang.String host)
indicates if the servlet allows status modus in jetcontext

Returns:
boolean status allowed?

setStatus

private final void setStatus(java.lang.String regex)
Set if status is allowed


isRefresh

public final boolean isRefresh(java.lang.String host)
indicates if the servlet allows refresh modus in jetcontext

Returns:
boolean refresh allowed?

setRefresh

private final void setRefresh(java.lang.String regex)
Set if refrsh is allowed


refreshAll

protected void refreshAll()
                   throws java.io.IOException
refreshs all caches etc.

Throws:
java.io.IOException

refreshTemplateEngine

protected void refreshTemplateEngine()
refreshs template engine.


refreshLocalizers

protected void refreshLocalizers()
refreshs the localizer cache


refreshResourceCache

protected void refreshResourceCache()
                             throws java.io.IOException
refresh resource cache

Throws:
java.io.IOException

getResource

public byte[] getResource(java.lang.String resourceName)
                   throws java.io.IOException,
                          javax.servlet.ServletException
gets the a file/resource

Parameters:
resourceName - file name
Throws:
java.io.IOException
javax.servlet.ServletException

destroy

public void destroy()
This method is called if the servlet/server shut down here we have to cleanup resources etc.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

getServletContextHashModel

public freemarker.ext.servlet.ServletContextHashModel getServletContextHashModel()
Method returning a hashstructur needed for taglb support in freemarker templates

Returns:
ServletContextHashModel hashmodel

getTaglibs

public freemarker.ext.jsp.TaglibFactory getTaglibs()
Method returning the tagib support object from freemarkers

Returns:
TaglibFactory

initCache

protected void initCache()
Method to initialize the ehcache - initialze only if not aready done


getServletConfig

public javax.servlet.ServletConfig getServletConfig()
Specified by:
getServletConfig in interface javax.servlet.Servlet
Overrides:
getServletConfig in class javax.servlet.GenericServlet