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

      public class Turbine
      extends HttpServlet

  Turbine is the main servlet for the entire system. It is `final` because you should not ever need to subclass this servlet. If you need to perform initialization of a service, then you should implement the Services API and let your code be initialized by it. If you need to override something in the `doGet()` or `doPost()` methods, edit the TurbineResources.properties file and specify your own classes there.

  Turbine servlet recognizes the following initialization parameters.

  - `properties` the path to TurbineResources.properties file used by the default implementation of `ResourceService`, relative to the application root.
  - `basedir` this parameter is used only if your application server does not support web applications, or the or does not support `ServletContext.getRealPath(String)` method correctly. You can use this parameter to specify the directory within the server's filesystem, that is the base of your web application.
  Version:
    $Id: Turbine.java 1709648 2015-10-20 17:08:10Z tv $
  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 and Description
    --- | ---
    `static String` | `BASEDIR_KEY` The base directory key
    `static String` | `REDIRECTED_PATHINFO_NAME` Name of path info parameter used to indicate the redirected stage of a given user's initial Turbine request

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Turbine()`

  - ### Method Summary

    Methods
    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 void` | `configureLogging()` Configure the logging facilities of Turbine
    `protected void` | `createRuntimeDirectories(ServletContext context, ServletConfig config)` Create any directories that might be needed during runtime.
    `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 org.apache.commons.configuration.Configuration` | `getConfiguration()` Return the current configuration with all keys included
    `static String` | `getContextPath()` Return the context path.
    `String` | `getDefaultInputEncoding()` Returns the default input encoding for the servlet.
    `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.
    `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).
    `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`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### REDIRECTED_PATHINFO_NAME

          public static final String REDIRECTED_PATHINFO_NAME

      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

          public static final String BASEDIR_KEY

      The base directory key
      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 class `GenericServlet`
      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 container
        `context` - The Servlet Context supplied by the container
      Throws:
        `Exception` - A problem occurred while reading the configuration or performing early startup

    - #### configureLogging

          protected void configureLogging()
                                   throws IOException

      Configure the logging facilities of Turbine
      Throws:
        `IOException` - if the configuration file handling fails.

    - #### createRuntimeDirectories

          protected void createRuntimeDirectories(ServletContext context,
                                      ServletConfig config)

      Create any directories that might be needed during runtime. Right now this includes:
      - The directory to write the log files to (relative to the web application root), or `null` for the default of `/logs`. The directory is specified via the `TurbineConstants.LOGGING_ROOT_KEY` parameter.
      Parameters:
        `context` - Global initialization parameters.
        `config` - Initialization parameters specific to the Turbine servlet.

    - #### 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.

    - #### init

          public void init(PipelineData data)

      Initializes the services which need `PipelineData` to initialize themselves (post startup).
      Parameters:
        `data` - The first `GET` request.

    - #### getConfiguration

          public static org.apache.commons.configuration.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()

      The `Servlet` destroy method. Invokes `ServiceBroker` tear down method.
      Specified by:
        `destroy` in interface `Servlet`
      Overrides:
        `destroy` in class `GenericServlet`

    - #### doGet

          public void doGet(HttpServletRequest req,
                   HttpServletResponse res)
                     throws IOException,
                            ServletException

      The primary method invoked when the Turbine servlet is executed.
      Overrides:
        `doGet` in class `HttpServlet`
      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 class `HttpServlet`
      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 interface `Servlet`
      Overrides:
        `getServletInfo` in class `GenericServlet`
      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.

    - #### 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

    - #### 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. This concept was started in 3.0 and will allow an app to be developed from a standard CVS layout. With a simple switch the app will work fully within the servlet container for deployment.
      Returns:
        String applicationRoot

    - #### 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

          public String getDefaultInputEncoding()

      Returns the default input encoding for the servlet.
      Returns:
        the default input encoding.

Copyright © 2000-2015 The Apache Software Foundation. All Rights Reserved.