Package org.openbravo.base
Class HttpBaseServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.openbravo.base.HttpBaseServlet
-
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
,ConnectionProvider
- Direct Known Subclasses:
CheckCleanCache
,HttpSecureAppServlet
,Login
,LoginHandler
,ServletGoBack
,SessionActive
,ShowImageLogo
public class HttpBaseServlet extends javax.servlet.http.HttpServlet implements ConnectionProvider
This class is intended to be extended by the HttpSecureAppServlet and provides methods for basic management of request/response, database connections, transactions, FOP rendering, and others that do not require authentication. It is loaded upon startup of the application server.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ConfigParameters
globalParameters
protected org.apache.logging.log4j.Logger
log4j
protected ConnectionProvider
myPool
protected String
strDefaultServlet
static String
strDireccion
protected String
strReplaceWith
protected String
strReplaceWithFull
XmlEngine
xmlEngine
-
Constructor Summary
Constructors Constructor Description HttpBaseServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Redirects all HTTP GET requests to be handled by the doPost method of the extending class.void
doGetCall(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
doPostCall(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected String
getBaseDesignPath(String language)
Returns the absolute path to the correct language subfolder within the context's src-loc folder.CallableStatement
getCallableStatement(String strSql)
Returns a prepared callable statement for the specified strSql based on the connection retrieved from the default pool of connections.CallableStatement
getCallableStatement(String poolName, String strSql)
Returns a prepared callable statement for the specified strSql based on the connection retrieved from the poolName.CallableStatement
getCallableStatement(Connection conn, String strSql)
Returns a prepared callable statement for the specified strSql based on the connection conn provided.Connection
getConnection()
Retrieves an open autocommit connection from the connection pool managed by this class.protected String
getPoolStatus()
Not implemented yet.PreparedStatement
getPreparedStatement(String strSql)
Returns a PreparedStatement object that contains the specified strSql prepared on top of a connection retrieved from a default connection pool.PreparedStatement
getPreparedStatement(String poolName, String strSql)
Returns a PreparedStatement object that contains the specified strSql prepared on top of a connection retrieved from the poolName pool of connections.PreparedStatement
getPreparedStatement(Connection conn, String strSql)
Returns a PreparedStatement object that contains the specified strSql prepared on top of the connection conn passed to the method.String
getRDBMS()
Return the bbdd.rdbms property defined within the config/Openbravo.properties configuration file.String
getServletInfo()
Statement
getStatement()
Returns a Statement object for sending SQL statements to the database based on a connection retrieved from the default pool of connections.Statement
getStatement(String poolName)
Returns a Statement object for sending SQL statements to the database based on a connection retrieved from the poolName.Statement
getStatement(Connection conn)
Returns a Statement object for sending SQL statements to the database based on the connection conn provided.String
getStatus()
Connection
getTransactionConnection()
Retrieves an open connection that is not automatically commited from the connection pool managed by this class.void
init(javax.servlet.ServletConfig config)
Loads basic configuration settings that this class and all that extend it require to function properly.void
initialize(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Initialization of basic servlet variables required by subsequent operations of this class and the ones that extend it.void
releaseCallableStatement(CallableStatement callableStatement)
Closes the prepared callableStatement and releases the connection on top of which this callable statement was prepared.void
releaseCommitConnection(Connection conn)
First commit the connection specified and then store it back into the pool of available connections managed by this class.void
releasePreparedStatement(PreparedStatement preparedStatement)
Closes the preparedStatement and releases the connection on top of which this statement was prepared.void
releaseRollbackConnection(Connection conn)
First rollback the connection specified and then store it back into the pool of available connections managed by this class.void
releaseStatement(Statement statement)
Closes the statement and releases the connection back into the pool.void
releaseTransactionalPreparedStatement(PreparedStatement preparedStatement)
Only closes the preparedStatement since it is probably part of a series of statements that use the same connection.void
releaseTransactionalStatement(Statement statement)
Only closes the statement since it is probably part of a series of statements that use the same connection.void
service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
A dispatcher method that calls the initialization upon every request to the servlet before it hands over the final dispatchment to the HttpServlet base class.void
serviceInitialized(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Called by the HttpSecureAppServlet within its service() method to indirectly call the service() method of the HttpServlet base class because HttpBaseServlet.service() is then replaced by the HttpSecureAppServlets one.-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
-
Methods inherited from class javax.servlet.GenericServlet
destroy, 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
-
Methods inherited from interface org.openbravo.database.ConnectionProvider
destroy
-
-
-
-
Field Detail
-
myPool
protected ConnectionProvider myPool
-
strDireccion
public static String strDireccion
-
strReplaceWith
protected String strReplaceWith
-
strReplaceWithFull
protected String strReplaceWithFull
-
strDefaultServlet
protected String strDefaultServlet
-
xmlEngine
public XmlEngine xmlEngine
-
log4j
protected org.apache.logging.log4j.Logger log4j
-
globalParameters
protected ConfigParameters globalParameters
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig config)
Loads basic configuration settings that this class and all that extend it require to function properly. Also instantiates XmlEngine object. This method is called upon load of the class, which is configured to be loaded upon start of the application server. See also web.xml (load-on-startup).- Specified by:
init
in interfacejavax.servlet.Servlet
- Overrides:
init
in classjavax.servlet.GenericServlet
-
initialize
public void initialize(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Initialization of basic servlet variables required by subsequent operations of this class and the ones that extend it. Normally called within the service() method of this class.- Parameters:
request
- HttpServletRequest object where details of the HTTP request are.response
- HttpServletResponse object where the response will be written and returned to the user.- Throws:
IOException
javax.servlet.ServletException
-
serviceInitialized
public void serviceInitialized(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Called by the HttpSecureAppServlet within its service() method to indirectly call the service() method of the HttpServlet base class because HttpBaseServlet.service() is then replaced by the HttpSecureAppServlets one.- Parameters:
request
- HttpServletRequest object where details of the HTTP request are.response
- HttpServletResponse object where the response will be written and returned to the user.- Throws:
IOException
javax.servlet.ServletException
-
service
public void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
A dispatcher method that calls the initialization upon every request to the servlet before it hands over the final dispatchment to the HttpServlet base class.- Overrides:
service
in classjavax.servlet.http.HttpServlet
- Parameters:
request
- HttpServletRequest object where details of the HTTP request are.response
- HttpServletResponse object where the response will be written and returned to the user.- Throws:
IOException
javax.servlet.ServletException
-
getBaseDesignPath
protected String getBaseDesignPath(String language)
Returns the absolute path to the correct language subfolder within the context's src-loc folder.- Parameters:
language
- String specifying the language folder required, e.g. es_ES- Returns:
- String with the absolute path on the local drive.
-
doGet
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Redirects all HTTP GET requests to be handled by the doPost method of the extending class.- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Parameters:
request
- HttpServletRequest object where details of the HTTP request are.response
- HttpServletResponse object where the response will be written and returned to the user.- Throws:
IOException
javax.servlet.ServletException
-
doGetCall
public void doGetCall(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
- Throws:
Exception
-
doPostCall
public void doPostCall(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
- Throws:
Exception
-
getConnection
public Connection getConnection() throws NoConnectionAvailableException
Retrieves an open autocommit connection from the connection pool managed by this class.- Specified by:
getConnection
in interfaceConnectionProvider
- Returns:
- A Connection object containing the open connection.
- Throws:
NoConnectionAvailableException
-
getRDBMS
public String getRDBMS()
Return the bbdd.rdbms property defined within the config/Openbravo.properties configuration file. This property defines the type of the database (ORACLE or POSTGRES).- Specified by:
getRDBMS
in interfaceConnectionProvider
- Returns:
- String containing the database type (ORACLE or POSTGRES).
-
getTransactionConnection
public Connection getTransactionConnection() throws NoConnectionAvailableException, SQLException
Retrieves an open connection that is not automatically commited from the connection pool managed by this class.- Specified by:
getTransactionConnection
in interfaceConnectionProvider
- Returns:
- A Connection object containing the open connection
- Throws:
NoConnectionAvailableException
SQLException
-
releaseCommitConnection
public void releaseCommitConnection(Connection conn) throws SQLException
First commit the connection specified and then store it back into the pool of available connections managed by this class.- Specified by:
releaseCommitConnection
in interfaceConnectionProvider
- Parameters:
conn
- The Connection object required to be committed and stored back into the pool.- Throws:
SQLException
-
releaseRollbackConnection
public void releaseRollbackConnection(Connection conn) throws SQLException
First rollback the connection specified and then store it back into the pool of available connections managed by this class.- Specified by:
releaseRollbackConnection
in interfaceConnectionProvider
- Parameters:
conn
- The Connection object required to be rolled back and stored back into the pool.- Throws:
SQLException
-
getPreparedStatement
public PreparedStatement getPreparedStatement(String poolName, String strSql) throws Exception
Returns a PreparedStatement object that contains the specified strSql prepared on top of a connection retrieved from the poolName pool of connections.- Specified by:
getPreparedStatement
in interfaceConnectionProvider
- Parameters:
poolName
- The name of the pool to retrieve the connection from.strSql
- The SQL statement to prepare.- Returns:
- PreparedStatement object with the strSql prepared.
- Throws:
Exception
-
getPreparedStatement
public PreparedStatement getPreparedStatement(String strSql) throws Exception
Returns a PreparedStatement object that contains the specified strSql prepared on top of a connection retrieved from a default connection pool.- Specified by:
getPreparedStatement
in interfaceConnectionProvider
- Parameters:
strSql
- The SQL statement to prepare.- Returns:
- PreparedStatement object with the strSql prepared.
- Throws:
Exception
-
getPreparedStatement
public PreparedStatement getPreparedStatement(Connection conn, String strSql) throws SQLException
Returns a PreparedStatement object that contains the specified strSql prepared on top of the connection conn passed to the method.- Specified by:
getPreparedStatement
in interfaceConnectionProvider
- Parameters:
conn
- The Connection object containing the connection.strSql
- The SQL statement to prepare.- Returns:
- PreparedStatement object with the strSql prepared.
- Throws:
SQLException
-
releasePreparedStatement
public void releasePreparedStatement(PreparedStatement preparedStatement) throws SQLException
Closes the preparedStatement and releases the connection on top of which this statement was prepared.- Specified by:
releasePreparedStatement
in interfaceConnectionProvider
- Parameters:
preparedStatement
- Object containing prepared statement to release.- Throws:
SQLException
-
getStatement
public Statement getStatement(String poolName) throws Exception
Returns a Statement object for sending SQL statements to the database based on a connection retrieved from the poolName.- Specified by:
getStatement
in interfaceConnectionProvider
- Parameters:
poolName
- The name of the pool to retrieve the connection from.- Returns:
- Prepared Statement object requested.
- Throws:
Exception
-
getStatement
public Statement getStatement() throws Exception
Returns a Statement object for sending SQL statements to the database based on a connection retrieved from the default pool of connections.- Specified by:
getStatement
in interfaceConnectionProvider
- Returns:
- Prepared Statement object requested.
- Throws:
Exception
-
getStatement
public Statement getStatement(Connection conn) throws SQLException
Returns a Statement object for sending SQL statements to the database based on the connection conn provided.- Specified by:
getStatement
in interfaceConnectionProvider
- Returns:
- Prepared Statement object requested.
- Throws:
SQLException
-
releaseStatement
public void releaseStatement(Statement statement) throws SQLException
Closes the statement and releases the connection back into the pool.- Specified by:
releaseStatement
in interfaceConnectionProvider
- Parameters:
statement
- Object containing the statement to release.- Throws:
SQLException
-
releaseTransactionalStatement
public void releaseTransactionalStatement(Statement statement) throws SQLException
Only closes the statement since it is probably part of a series of statements that use the same connection. The connection must be then closed manually after all statements have been closed.- Specified by:
releaseTransactionalStatement
in interfaceConnectionProvider
- Parameters:
statement
- Object containing the statement to release.- Throws:
SQLException
-
releaseTransactionalPreparedStatement
public void releaseTransactionalPreparedStatement(PreparedStatement preparedStatement) throws SQLException
Only closes the preparedStatement since it is probably part of a series of statements that use the same connection. The connection must be then closed manually after all statements have been closed.- Specified by:
releaseTransactionalPreparedStatement
in interfaceConnectionProvider
- Parameters:
preparedStatement
- Object containing the prepared statement to release.- Throws:
SQLException
-
getCallableStatement
public CallableStatement getCallableStatement(String poolName, String strSql) throws Exception
Returns a prepared callable statement for the specified strSql based on the connection retrieved from the poolName.- Specified by:
getCallableStatement
in interfaceConnectionProvider
- Parameters:
poolName
- The name of the pool to retrieve the connection from.strSql
- The callable SQL statement to prepare.- Returns:
- CallableStatement object with the strSql prepared.
- Throws:
SQLException
Exception
-
getCallableStatement
public CallableStatement getCallableStatement(String strSql) throws Exception
Returns a prepared callable statement for the specified strSql based on the connection retrieved from the default pool of connections.- Specified by:
getCallableStatement
in interfaceConnectionProvider
- Parameters:
strSql
- The callable SQL statement to prepare.- Returns:
- CallableStatement object with the strSql prepared.
- Throws:
Exception
-
getCallableStatement
public CallableStatement getCallableStatement(Connection conn, String strSql) throws SQLException
Returns a prepared callable statement for the specified strSql based on the connection conn provided.- Specified by:
getCallableStatement
in interfaceConnectionProvider
- Parameters:
conn
- The Connection object containing the connection.strSql
- The callable SQL statement to prepare.- Returns:
- CallableStatement object with the strSql prepared.
- Throws:
SQLException
-
releaseCallableStatement
public void releaseCallableStatement(CallableStatement callableStatement) throws SQLException
Closes the prepared callableStatement and releases the connection on top of which this callable statement was prepared.- Specified by:
releaseCallableStatement
in interfaceConnectionProvider
- Parameters:
callableStatement
- Object containing prepared callable statement to release.- Throws:
SQLException
-
getPoolStatus
protected String getPoolStatus()
Not implemented yet.- Returns:
- String with "Status unavailable" or "Not implemented yet"
-
getStatus
public String getStatus()
- Specified by:
getStatus
in interfaceConnectionProvider
-
getServletInfo
public String getServletInfo()
- Specified by:
getServletInfo
in interfacejavax.servlet.Servlet
- Overrides:
getServletInfo
in classjavax.servlet.GenericServlet
-
-