Package org.apache.turbine
Class Turbine
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.apache.turbine.Turbine
-
- All Implemented Interfaces:
Serializable
,Servlet
,ServletConfig
@WebServlet(name="Turbine",urlPatterns="/app",loadOnStartup=1,initParams={@WebInitParam(name="applicationRoot",value="webContext"),@WebInitParam(name="properties",value="/WEB-INF/conf/TurbineResources.properties")}) public class Turbine extends HttpServlet
Turbine is the main servlet for the entire system. If you need to perform initialization of a service, then you should implement the Services API and let your code be initialized by it.
Turbine servlet recognizes the following initialization parameters.
properties
the path to TurbineResources.properties file used to configure Turbine, relative to the application root.configuration
the path to TurbineConfiguration.xml file used to configure Turbine from various sources, relative to the application root.applicationRoot
this parameter defaults to the web context of the servlet container. You can use this parameter to specify the directory within the server's filesystem, that is the base of your web application.
- Version:
- $Id$
- Author:
- Jon S. Stevens, Brett McLaughlin, Greg Ritter, John D. McNally, Frank Y. Kim, Rafal Krzewski, Jason van Zyl, Sean Legassick, Martin Poeschl, Henning P. Schmiedehausen, Quinton McCombs, Eric Pugh, Peter Courcoux, Thomas Vandahl
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
BASEDIR_KEY
Deprecated.static String
REDIRECTED_PATHINFO_NAME
Deprecated.
-
Constructor Summary
Constructors Constructor Description Turbine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
configure(ServletConfig config, ServletContext context)
Read the master configuration file in, configure logging and start up any early services.protected Path
configureApplication(ServletConfig config, ServletContext context)
Checks configuraton style, resolves the location of the configuration and loads it to internalConfiguration
object (configuration
).protected void
configureLogging(Path logConf)
Checks Log4j 2 Context, loads log4File, if configured and configuration is not already located.void
destroy()
TheServlet
destroy method.void
doGet(HttpServletRequest req, HttpServletResponse res)
The primary method invoked when the Turbine servlet is executed.void
doPost(HttpServletRequest req, HttpServletResponse res)
In this application doGet and doPost are the same thing.protected String
findInitParameter(ServletContext context, ServletConfig config, String name, String defaultValue)
Finds the specified servlet configuration/initialization parameter, looking first for a servlet-specific parameter, then for a global parameter, and using the provided default if not found.static String
getApplicationRoot()
Get the application root for this Turbine webapp.static File
getApplicationRootAsFile()
Get the application root for this Turbine webapp as a file object.static org.apache.commons.configuration2.Configuration
getConfiguration()
Return the current configuration with all keys includedstatic String
getContextPath()
Return the context path.static String
getDefaultInputEncoding()
Deprecated.UseDefaultSetEncodingValve
to set default encodingstatic ServerData
getDefaultServerData()
Return all the Turbine Servlet information (Server Name, Port, Scheme in a ServerData structure.static String
getRealPath(String path)
Used to get the real path of configuration and resource information.static String
getScriptName()
Get the script name.static String
getServerName()
Return the server name.static String
getServerPort()
Return the server port.static String
getServerScheme()
Return the server scheme.String
getServletInfo()
Return the servlet info.static ServletConfig
getTurbineServletConfig()
Get the servlet config for this turbine webapp.static ServletContext
getTurbineServletContext()
Get the servlet context for this turbine webapp.protected void
handleException(PipelineData pipelineData, HttpServletResponse res, Throwable t)
This method is about making sure that we catch and display errors to the screen in one fashion or another.protected void
handleHorribleException(HttpServletResponse res, Throwable t)
This method handles exception cases where no PipelineData object existsvoid
init()
This init method will load the default resources from a properties file.void
init(PipelineData data)
Initializes the services which needPipelineData
to initialize themselves (post startup).protected Path
resolveLog4j2(Path logConfPath)
Check TurbineConstants.LOG4J2_CONFIG_FILE in Turbine configuration.static void
saveServletInfo(PipelineData data)
Save some information about this servlet so that it can be utilized by object instances that do not have direct access to PipelineData.static void
setApplicationRoot(String val)
Set the application root for the webapp.static void
setTurbineServletConfig(ServletConfig config)
Set the servlet config for this turbine webapp.static void
setTurbineServletContext(ServletContext context)
Set the servlet context for this turbine webapp.-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
-
-
-
-
Field Detail
-
REDIRECTED_PATHINFO_NAME
@Deprecated public static final String REDIRECTED_PATHINFO_NAME
Deprecated.Name of path info parameter used to indicate the redirected stage of a given user's initial Turbine request- See Also:
- Constant Field Values
-
BASEDIR_KEY
@Deprecated public static final String BASEDIR_KEY
Deprecated.The base directory key @deprecated- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Turbine
public Turbine()
-
-
Method Detail
-
init
public void init() throws ServletException
This init method will load the default resources from a properties file. This method is called by init(ServletConfig config)- Overrides:
init
in classGenericServlet
- Throws:
ServletException
- a servlet exception.
-
configure
protected void configure(ServletConfig config, ServletContext context) throws Exception
Read the master configuration file in, configure logging and start up any early services.- Parameters:
config
- The Servlet Configuration supplied by the containercontext
- The Servlet Context supplied by the container- Throws:
Exception
- A problem occurred while reading the configuration or performing early startup
-
configureApplication
protected Path configureApplication(ServletConfig config, ServletContext context) throws IOException, org.apache.commons.configuration2.ex.ConfigurationException
Checks configuraton style, resolves the location of the configuration and loads it to internalConfiguration
object (configuration
). Allows reading from aCombinedConfigurationBuilder
xml configuration file.- Parameters:
config
- the Servlet Configurationcontext
- Servlet Context- Returns:
- The resolved Configuration Path
- Throws:
IOException
- if configuration path not foundorg.apache.commons.configuration2.ex.ConfigurationException
- if failed to configure
-
findInitParameter
protected String findInitParameter(ServletContext context, ServletConfig config, String name, String defaultValue)
Finds the specified servlet configuration/initialization parameter, looking first for a servlet-specific parameter, then for a global parameter, and using the provided default if not found.- Parameters:
context
- the servlet contextconfig
- configuration objectname
- name of parameterdefaultValue
- of the parameter- Returns:
- String value of the parameter
-
init
public void init(PipelineData data)
Initializes the services which needPipelineData
to initialize themselves (post startup).- Parameters:
data
- The firstGET
request.
-
getConfiguration
public static org.apache.commons.configuration2.Configuration getConfiguration()
Return the current configuration with all keys included- Returns:
- a Configuration Object
-
getServerName
public static String getServerName()
Return the server name.- Returns:
- String server name
-
getServerScheme
public static String getServerScheme()
Return the server scheme.- Returns:
- String server scheme
-
getServerPort
public static String getServerPort()
Return the server port.- Returns:
- String server port
-
getScriptName
public static String getScriptName()
Get the script name. This is the initial script name. Actually this is probably not needed any more. I'll check. jvz.- Returns:
- String initial script name.
-
getContextPath
public static String getContextPath()
Return the context path.- Returns:
- String context path
-
getDefaultServerData
public static ServerData getDefaultServerData()
Return all the Turbine Servlet information (Server Name, Port, Scheme in a ServerData structure. This is generated from the values set when initializing the Turbine and may not be correct if you're running in a clustered structure. You can provide default values in your configuration for cases where access is requied before your application is first accessed by a user. This might be used if you need a DataURI and have no RunData object handy.- Returns:
- An initialized ServerData object
-
setTurbineServletConfig
public static void setTurbineServletConfig(ServletConfig config)
Set the servlet config for this turbine webapp.- Parameters:
config
- New servlet config
-
getTurbineServletConfig
public static ServletConfig getTurbineServletConfig()
Get the servlet config for this turbine webapp.- Returns:
- ServletConfig
-
setTurbineServletContext
public static void setTurbineServletContext(ServletContext context)
Set the servlet context for this turbine webapp.- Parameters:
context
- New servlet context.
-
getTurbineServletContext
public static ServletContext getTurbineServletContext()
Get the servlet context for this turbine webapp.- Returns:
- ServletContext
-
destroy
public void destroy()
TheServlet
destroy method. InvokesServiceBroker
tear down method.- Specified by:
destroy
in interfaceServlet
- Overrides:
destroy
in classGenericServlet
-
doGet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
The primary method invoked when the Turbine servlet is executed.- Overrides:
doGet
in classHttpServlet
- Parameters:
req
- Servlet request.res
- Servlet response.- Throws:
IOException
- a servlet exception.ServletException
- a servlet exception.
-
doPost
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
In this application doGet and doPost are the same thing.- Overrides:
doPost
in classHttpServlet
- Parameters:
req
- Servlet request.res
- Servlet response.- Throws:
IOException
- a servlet exception.ServletException
- a servlet exception.
-
getServletInfo
public String getServletInfo()
Return the servlet info.- Specified by:
getServletInfo
in interfaceServlet
- Overrides:
getServletInfo
in classGenericServlet
- Returns:
- a string with the servlet information.
-
handleException
protected void handleException(PipelineData pipelineData, HttpServletResponse res, Throwable t)
This method is about making sure that we catch and display errors to the screen in one fashion or another. What happens is that it will attempt to show the error using your user defined Error Screen. If that fails, then it will resort to just displaying the error and logging it all over the place including the servlet engine log file, the Turbine log file and on the screen.- Parameters:
pipelineData
- A Turbine PipelineData object.res
- Servlet response.t
- The exception to report.
-
handleHorribleException
protected void handleHorribleException(HttpServletResponse res, Throwable t)
This method handles exception cases where no PipelineData object exists- Parameters:
res
- Servlet response.t
- The exception to report.
-
saveServletInfo
public static void saveServletInfo(PipelineData data)
Save some information about this servlet so that it can be utilized by object instances that do not have direct access to PipelineData.- Parameters:
data
- Turbine request data
-
configureLogging
protected void configureLogging(Path logConf) throws IOException
Checks Log4j 2 Context, loads log4File, if configured and configuration is not already located.- Parameters:
logConf
- Configuration file path- Throws:
IOException
- if path not found
-
resolveLog4j2
protected Path resolveLog4j2(Path logConfPath)
Check TurbineConstants.LOG4J2_CONFIG_FILE in Turbine configuration.- Parameters:
logConfPath
- configuration directory- Returns:
- Resolved log4j2
Path
or null, if not found or configured "none".
-
setApplicationRoot
public static void setApplicationRoot(String val)
Set the application root for the webapp.- Parameters:
val
- New app root.
-
getApplicationRoot
public static String getApplicationRoot()
Get the application root for this Turbine webapp.- Returns:
- String applicationRoot
-
getApplicationRootAsFile
public static File getApplicationRootAsFile()
Get the application root for this Turbine webapp as a file object.- Returns:
- File applicationRootFile
-
getRealPath
public static String getRealPath(String path)
Used to get the real path of configuration and resource information. This can be used by an app being developed in a standard CVS layout.- Parameters:
path
- path translated to the application root- Returns:
- the real path
-
getDefaultInputEncoding
@Deprecated public static String getDefaultInputEncoding()
Deprecated.UseDefaultSetEncodingValve
to set default encodingReturns the default input encoding for the servlet.- Returns:
- the default input encoding.
-
-