@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.Modifier and Type | Field and Description |
---|---|
static String |
BASEDIR_KEY
Deprecated.
|
static String |
REDIRECTED_PATHINFO_NAME
Deprecated.
|
Constructor and Description |
---|
Turbine() |
Modifier and Type | Method and 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 internal
Configuration object
(configuration ). |
protected void |
configureLogging(Path logConf)
Checks Log4j 2 Context, loads log4File, if configured and configuration
is not already located.
|
void |
destroy()
The
Servlet 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 included
|
static String |
getContextPath()
Return the context path.
|
static String |
getDefaultInputEncoding()
Deprecated.
Use
DefaultSetEncodingValve
to set default encoding |
static 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 exists
|
void |
init()
This init method will load the default resources from a properties file.
|
void |
init(PipelineData data)
Initializes the services which need
PipelineData 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.
|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
@Deprecated public static final String REDIRECTED_PATHINFO_NAME
@Deprecated public static final String BASEDIR_KEY
public Turbine()
public void init() throws ServletException
init
in class GenericServlet
ServletException
- a servlet exception.protected void configure(ServletConfig config, ServletContext context) throws Exception
config
- The Servlet Configuration supplied by the containercontext
- The Servlet Context supplied by the containerException
- A problem occurred while reading the configuration or
performing early startupprotected Path configureApplication(ServletConfig config, ServletContext context) throws IOException, org.apache.commons.configuration2.ex.ConfigurationException
Configuration
object
(configuration
).config
- the Servlet Configurationcontext
- Servlet ContextIOException
- if configuration path not foundorg.apache.commons.configuration2.ex.ConfigurationException
- if failed to configureprotected String findInitParameter(ServletContext context, ServletConfig config, String name, String defaultValue)
context
- the servlet contextconfig
- configuration objectname
- name of parameterdefaultValue
- of the parameterpublic void init(PipelineData data)
PipelineData
to
initialize themselves (post startup).data
- The first GET
request.public static org.apache.commons.configuration2.Configuration getConfiguration()
public static String getServerName()
public static String getServerScheme()
public static String getServerPort()
public static String getScriptName()
public static String getContextPath()
public static ServerData getDefaultServerData()
public static void setTurbineServletConfig(ServletConfig config)
config
- New servlet configpublic static ServletConfig getTurbineServletConfig()
public static void setTurbineServletContext(ServletContext context)
context
- New servlet context.public static ServletContext getTurbineServletContext()
public void destroy()
Servlet
destroy method. Invokes
ServiceBroker
tear down method.destroy
in interface Servlet
destroy
in class GenericServlet
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
doGet
in class HttpServlet
req
- Servlet request.res
- Servlet response.IOException
- a servlet exception.ServletException
- a servlet exception.public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
doPost
in class HttpServlet
req
- Servlet request.res
- Servlet response.IOException
- a servlet exception.ServletException
- a servlet exception.public String getServletInfo()
getServletInfo
in interface Servlet
getServletInfo
in class GenericServlet
protected void handleException(PipelineData pipelineData, HttpServletResponse res, Throwable t)
pipelineData
- A Turbine PipelineData object.res
- Servlet response.t
- The exception to report.protected void handleHorribleException(HttpServletResponse res, Throwable t)
res
- Servlet response.t
- The exception to report.public static void saveServletInfo(PipelineData data)
data
- Turbine request dataprotected void configureLogging(Path logConf) throws IOException
logConf
- Configuration file pathIOException
- if path not foundprotected Path resolveLog4j2(Path logConfPath)
logConfPath
- configuration directoryPath
or null, if not found or configured
"none".public static void setApplicationRoot(String val)
val
- New app root.public static String getApplicationRoot()
public static File getApplicationRootAsFile()
public static String getRealPath(String path)
path
- path translated to the application root@Deprecated public static String getDefaultInputEncoding()
DefaultSetEncodingValve
to set default encodingCopyright © 2000–2019 The Apache Software Foundation. All rights reserved.