Java Doc for JDBCAccessLogValve.java in  » Sevlet-Container » tomcat-catalina » org » apache » catalina » valves » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Sevlet Container » tomcat catalina » org.apache.catalina.valves 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.catalina.valves.ValveBase
      org.apache.catalina.valves.JDBCAccessLogValve

JDBCAccessLogValve
final public class JDBCAccessLogValve extends ValveBase implements Lifecycle(Code)

This Tomcat extension logs server access directly to a database, and can be used instead of the regular file-based access log implemented in AccessLogValve. To use, copy into the server/classes directory of the Tomcat installation and configure in server.xml as:

 <Valve className="AccessLogDBValve"
 driverName="your_jdbc_driver"
 connectionURL="your_jdbc_url"
 pattern="combined" resolveHosts="false"
 />
 

Many parameters can be configured, such as the database connection (with driverName and connectionURL), the table name (tableName) and the field names (corresponding to the get/set method names). The same options as AccessLogValve are supported, such as resolveHosts and pattern ("common" or "combined" only).

When Tomcat is started, a database connection (with autoReconnect option) is created and used for all the log activity. When Tomcat is shutdown, the database connection is closed. This logger can be used at the level of the Engine context (being shared by all the defined hosts) or the Host context (one instance of the logger per host, possibly using different databases).

The database table can be created with the following command:

 CREATE TABLE access (
 id INT UNSIGNED AUTO_INCREMENT NOT NULL,
 ts TIMESTAMP NOT NULL,
 remoteHost CHAR(15) NOT NULL,
 user CHAR(15),
 timestamp TIMESTAMP NOT NULL,
 virtualHost VARCHAR(64) NOT NULL,
 method VARCHAR(8) NOT NULL,
 query VARCHAR(255) NOT NULL,
 status SMALLINT UNSIGNED NOT NULL,
 bytes INT UNSIGNED NOT NULL,
 referer VARCHAR(128),
 userAgent VARCHAR(128),
 PRIMARY KEY (id),
 INDEX (ts),
 INDEX (remoteHost),
 INDEX (virtualHost),
 INDEX (query),
 INDEX (userAgent)
 );
 

If the table is created as above, its name and the field names don't need to be defined.

If the request method is "common", only these fields are used: remoteHost, user, timeStamp, query, status, bytes

TO DO: provide option for excluding logging of certain MIME types.


author:
   Andre de Jesus
author:
   Peter Rossbach


Field Summary
protected  StringconnectionName
     The connection username to use when trying to connect to the database.
protected  StringconnectionPassword
     The connection URL to use when trying to connect to the database.
protected  Driverdriver
     Instance of the JDBC Driver class we use as a connection factory.
protected static  Stringinfo
     The descriptive information about this implementation.
protected  LifecycleSupportlifecycle
     The lifecycle event support for this component.

Constructor Summary
public  JDBCAccessLogValve()
     Class constructor.

Method Summary
public  voidaddLifecycleListener(LifecycleListener listener)
     Adds a Lifecycle listener.
protected  voidclose()
     Close the specified database connection.
public  LifecycleListener[]findLifecycleListeners()
     Get the lifecycle listeners associated with this lifecycle.
public  StringgetConnectionName()
     Return the username to use to connect to the database.
public  StringgetConnectionPassword()
     Return the password to use to connect to the database.
public  longgetCurrentTimeMillis()
    
public  voidinvoke(Request request, Response response, ValveContext context)
     This method is invoked by Tomcat on each query.
protected  voidlog(String message)
    
protected  voidlog(String message, Throwable throwable)
    
protected  voidopen()
     Open (if necessary) and return a database connection for use by this AccessLogValve.
public  voidremoveLifecycleListener(LifecycleListener listener)
     Removes a Lifecycle listener.
public  voidsetBytesField(String bytesField)
     Sets the name of the field containing the number of bytes returned.
public  voidsetConnectionName(String connectionName)
     Set the username to use to connect to the database.
public  voidsetConnectionPassword(String connectionPassword)
     Set the password to use to connect to the database.
public  voidsetConnectionURL(String connectionURL)
     Sets the JDBC URL for the database where the log is stored.
public  voidsetDriverName(String driverName)
     Sets the database driver name.
public  voidsetMethodField(String methodField)
     Sets the name of the field containing the HTTP request method.
public  voidsetPattern(String pattern)
     Sets the logging pattern.
public  voidsetQueryField(String queryField)
     Sets the name of the field containing the URL part of the HTTP query.
public  voidsetRefererField(String refererField)
     Sets the name of the field containing the referer.
public  voidsetRemoteHostField(String remoteHostField)
     Sets the name of the field containing the remote host.
public  voidsetResolveHosts(String resolveHosts)
     Determines whether IP host name resolution is done.
public  voidsetStatusField(String statusField)
     Sets the name of the field containing the HTTP response status code.
public  voidsetTableName(String tableName)
     Sets the name of the table where the logs are stored.
public  voidsetTimestampField(String timestampField)
     Sets the name of the field containing the server-determined timestamp.
public  voidsetUserAgentField(String userAgentField)
     Sets the name of the field containing the user agent.
public  voidsetUserField(String userField)
     Sets the name of the field containing the remote user name.
public  voidsetVirtualHostField(String virtualHostField)
     Sets the name of the field containing the virtual host information (this is in fact the server name).
public  voidstart()
     Invoked by Tomcat on startup.
public  voidstop()
     Invoked by tomcat on shutdown.

Field Detail
connectionName
protected String connectionName(Code)
The connection username to use when trying to connect to the database.



connectionPassword
protected String connectionPassword(Code)
The connection URL to use when trying to connect to the database.



driver
protected Driver driver(Code)
Instance of the JDBC Driver class we use as a connection factory.



info
protected static String info(Code)
The descriptive information about this implementation.



lifecycle
protected LifecycleSupport lifecycle(Code)
The lifecycle event support for this component.




Constructor Detail
JDBCAccessLogValve
public JDBCAccessLogValve()(Code)
Class constructor. Initializes the fields with the default values. The defaults are:
 driverName = null;
 connectionURL = null;
 tableName = "access";
 remoteHostField = "remoteHost";
 userField = "user";
 timestampField = "timestamp";
 virtualHostField = "virtualHost";
 methodField = "method";
 queryField = "query";
 statusField = "status";
 bytesField = "bytes";
 refererField = "referer";
 userAgentField = "userAgent";
 pattern = "common";
 resolveHosts = false;
 




Method Detail
addLifecycleListener
public void addLifecycleListener(LifecycleListener listener)(Code)
Adds a Lifecycle listener.
Parameters:
  listener - The listener to add.



close
protected void close()(Code)
Close the specified database connection.



findLifecycleListeners
public LifecycleListener[] findLifecycleListeners()(Code)
Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.



getConnectionName
public String getConnectionName()(Code)
Return the username to use to connect to the database.



getConnectionPassword
public String getConnectionPassword()(Code)
Return the password to use to connect to the database.



getCurrentTimeMillis
public long getCurrentTimeMillis()(Code)



invoke
public void invoke(Request request, Response response, ValveContext context) throws IOException, ServletException(Code)
This method is invoked by Tomcat on each query.
Parameters:
  request - The Request object.
Parameters:
  response - The Response object.
Parameters:
  context - The ValveContext object.
exception:
  IOException - Should not be thrown.
exception:
  ServletException - Database SQLException is wrapped in a ServletException.



log
protected void log(String message)(Code)
Log a message on the Logger associated with our Container (if any)
Parameters:
  message - Message to be logged



log
protected void log(String message, Throwable throwable)(Code)
Log a message on the Logger associated with our Container (if any)
Parameters:
  message - Message to be logged
Parameters:
  throwable - Associated exception



open
protected void open() throws SQLException(Code)
Open (if necessary) and return a database connection for use by this AccessLogValve.
exception:
  SQLException - if a database error occurs



removeLifecycleListener
public void removeLifecycleListener(LifecycleListener listener)(Code)
Removes a Lifecycle listener.
Parameters:
  listener - The listener to remove.



setBytesField
public void setBytesField(String bytesField)(Code)
Sets the name of the field containing the number of bytes returned.
Parameters:
  bytesField - The name of the returned bytes field.



setConnectionName
public void setConnectionName(String connectionName)(Code)
Set the username to use to connect to the database.
Parameters:
  connectionName - Username



setConnectionPassword
public void setConnectionPassword(String connectionPassword)(Code)
Set the password to use to connect to the database.
Parameters:
  connectionPassword - User password



setConnectionURL
public void setConnectionURL(String connectionURL)(Code)
Sets the JDBC URL for the database where the log is stored.
Parameters:
  connectionURL - The JDBC URL of the database.



setDriverName
public void setDriverName(String driverName)(Code)
Sets the database driver name.
Parameters:
  driverName - The complete name of the database driver class.



setMethodField
public void setMethodField(String methodField)(Code)
Sets the name of the field containing the HTTP request method.
Parameters:
  methodField - The name of the HTTP request method field.



setPattern
public void setPattern(String pattern)(Code)
Sets the logging pattern. The patterns supported correspond to the file-based "common" and "combined". These are translated into the use of tables containing either set of fields.

TO DO: more flexible field choices.


Parameters:
  pattern - The name of the logging pattern.



setQueryField
public void setQueryField(String queryField)(Code)
Sets the name of the field containing the URL part of the HTTP query.
Parameters:
  queryField - The name of the field containing the URL part of the HTTP query.



setRefererField
public void setRefererField(String refererField)(Code)
Sets the name of the field containing the referer.
Parameters:
  refererField - The referer field name.



setRemoteHostField
public void setRemoteHostField(String remoteHostField)(Code)
Sets the name of the field containing the remote host.
Parameters:
  remoteHostField - The name of the remote host field.



setResolveHosts
public void setResolveHosts(String resolveHosts)(Code)
Determines whether IP host name resolution is done.
Parameters:
  resolveHosts - "true" or "false", if host IP resolution is desired or not.



setStatusField
public void setStatusField(String statusField)(Code)
Sets the name of the field containing the HTTP response status code.
Parameters:
  statusField - The name of the HTTP response status code field.



setTableName
public void setTableName(String tableName)(Code)
Sets the name of the table where the logs are stored.
Parameters:
  tableName - The name of the table.



setTimestampField
public void setTimestampField(String timestampField)(Code)
Sets the name of the field containing the server-determined timestamp.
Parameters:
  timestampField - The name of the server-determined timestamp field.



setUserAgentField
public void setUserAgentField(String userAgentField)(Code)
Sets the name of the field containing the user agent.
Parameters:
  userAgentField - The name of the user agent field.



setUserField
public void setUserField(String userField)(Code)
Sets the name of the field containing the remote user name.
Parameters:
  userField - The name of the remote user field.



setVirtualHostField
public void setVirtualHostField(String virtualHostField)(Code)
Sets the name of the field containing the virtual host information (this is in fact the server name).
Parameters:
  virtualHostField - The name of the virtual host field.



start
public void start() throws LifecycleException(Code)
Invoked by Tomcat on startup. The database connection is set here.
exception:
  LifecycleException - Can be thrown on lifecycle inconsistencies or on database errors (as a wrapped SQLException).



stop
public void stop() throws LifecycleException(Code)
Invoked by tomcat on shutdown. The database connection is closed here.
exception:
  LifecycleException - Can be thrown on lifecycle inconsistencies or on database errors (as a wrapped SQLException).



Fields inherited from org.apache.catalina.valves.ValveBase
protected Container container(Code)(Java Doc)
protected ObjectName controller(Code)(Java Doc)
protected int debug(Code)(Java Doc)
protected String domain(Code)(Java Doc)
protected static String info(Code)(Java Doc)
protected MBeanServer mserver(Code)(Java Doc)
protected ObjectName oname(Code)(Java Doc)
final protected static StringManager sm(Code)(Java Doc)

Methods inherited from org.apache.catalina.valves.ValveBase
public ObjectName createObjectName(String domain, ObjectName parent) throws MalformedObjectNameException(Code)(Java Doc)
public Container getContainer()(Code)(Java Doc)
public ObjectName getContainerName()(Code)(Java Doc)
public ObjectName getController()(Code)(Java Doc)
public int getDebug()(Code)(Java Doc)
public String getDomain()(Code)(Java Doc)
public String getInfo()(Code)(Java Doc)
public ObjectName getObjectName()(Code)(Java Doc)
public ObjectName getParentName(ObjectName valveName)(Code)(Java Doc)
abstract public void invoke(Request request, Response response, ValveContext context) throws IOException, ServletException(Code)(Java Doc)
public void postDeregister()(Code)(Java Doc)
public void postRegister(Boolean registrationDone)(Code)(Java Doc)
public void preDeregister() throws Exception(Code)(Java Doc)
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception(Code)(Java Doc)
public void setContainer(Container container)(Code)(Java Doc)
public void setController(ObjectName controller)(Code)(Java Doc)
public void setDebug(int debug)(Code)(Java Doc)
public void setObjectName(ObjectName oname)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.