|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectValveBase
com.lamatek.valves.DBAccessLogValve
public class DBAccessLogValve
This class performs a similar function to the org.apache.catalina.valves.AccessLogValve class in that it logs each access for the Context in which it is defined. However this logger will log accesses to a database, rather than a text file. Defining a DBAccessLogValve is very similar to defining a standard AccessLogValve, using the same pattern setup, however the user must specify database & connection properties, rather than text file properties. (i.e.)
<Valve className="com.lamatek.valves.DBAccessLogValve"
pattern="%h,%H,%m,%U%q,%p,%s,%b,%D,%t,%v,%{Referer}i,%{User-Agent}i" resolveHosts="true"
tableName="access_log"
columnNames="remote_host,protocol,method,request,port,http_status,bytes,process_time,date,website,referer,useragent"
resource="jdbc/sql"
lookup="java:/comp/env"
/>
The following attributes are allowed (bold are required):
| Attribute | Values |
|---|---|
| className | This value must be com.lamatek.valves.DBAccessLogValve |
| pattern | This attribute defines which values are to be stored. This must be a comma separated list of markers. See below for a complete list of available markers. |
| columnNames | This is a comma separated list of column names within the target database table. Each name must be valid and exist in the database, and must accept text (all data is stored as text for compatibility). The number of columnNames MUST match the number of markers listed in the pattern attribute and must be specified in the same order. |
| tableName | The name of the table that is to receive the access data. |
| resource | This value is used for Connection Pool environments and is the name of the resource to use to grab connections. If this value is specified, any values for driver, url, username and password are ignored and are not required. |
| lookup | Used for Connection Pool environments. This is the JNDI lookup name for the resource. If not specified, java:/comp/env will be used. |
| driver | For non-pooled environments. This is the fully qualified class name for the JDBC driver used to make connections. Required for non-pooled environments. |
| url | For non-pooled environments. This is the connection URL for the desired target table. Required for non-pooled environments. |
| username | For non-pooled environments. This is a valid username with permissions to the target table. Required for non-pooled environments. |
| password | For non-pooled environments. This is the password for the specified username. Required for non-pooled environments. |
| resolveHosts | Set to true to convert the IP address of the remote host into the corresponding host name via a DNS lookup. Set to false to skip this lookup, and report the remote IP address instead. |
Values for the pattern attribute are made up of literal text strings, combined with pattern identifiers prefixed by the "%" character to cause replacement by the corresponding variable value from the current request and response. The following pattern codes are supported:
%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if resolveHosts is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.)
%p - Local port on which this request was received
%q - Query string (prepended with a '?' if it exists)
%r - First line of the request (method and request URI)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else '-'
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis
%T - Time taken to process the request, in seconds
There is also support to write information from the cookie, incoming header, the Session or something else in the ServletRequest. It is modeled after the apache syntax:
%{xxx}i for incoming headers
%{xxx}c for a specific cookie
%{xxx}r xxx is an attribute in the ServletRequest
%{xxx}s xxx is an attribute in the HttpSession
The shorthand pattern name common (which is also the default) corresponds to %h %l %u %t "%r" %s %b".
The shorthand pattern name combined appends the values of the Referer and User-Agent headers, each in double quotes, to the common pattern described in the previous paragraph.
| Field Summary | |
|---|---|
protected static java.lang.String |
info
|
protected LifecycleSupport |
lifecycle
|
protected static java.lang.String[] |
months
|
| Constructor Summary | |
|---|---|
DBAccessLogValve()
Creates a new DBAccessLogValve with default values. |
|
| Method Summary | |
|---|---|
void |
addLifecycleListener(LifecycleListener listener)
Adds a LifeCycleListener. |
LifecycleListener[] |
findLifecycleListeners()
Returns all registered LifecycleListeners. |
java.lang.String |
getColumnNames()
Returns the comma separated list of column names that correlates to the current pattern. |
java.lang.String |
getCondition()
Returns the conditional String for this instance. |
java.lang.String |
getDriver()
Returns the currently assigned driver classname. |
java.lang.String |
getInfo()
|
java.lang.String |
getLookup()
Returns the JNDI lookup name for the resource specified. |
java.lang.String |
getPassword()
Returns the database password currently assigned. |
java.lang.String |
getPattern()
Returns the pattern currently used by this instance. |
java.lang.String |
getResource()
Gets the resource name for connection pooling environments from which database connections are pulled. |
java.lang.String |
getTableName()
Returns the table name where accesses are being logged. |
java.lang.String |
getUrl()
Returns the url to the database that contains the logging table. |
java.lang.String |
getUsername()
Returns the database username currently assigned. |
void |
invoke(Request request,
Response response,
ValveContext context)
This method is called by Context anytime an access is made. |
boolean |
isResolveHosts()
Reports if IP resolution is enabled. |
protected void |
log(java.lang.String message,
java.util.Date date)
This message performs the database logging functionality. |
void |
removeLifecycleListener(LifecycleListener listener)
Unregisters the given LifecycleListener. |
void |
setColumnNames(java.lang.String columnNames)
Sets the current column names within the specified table. |
void |
setCondition(java.lang.String condition)
Sets the conditional String for this instance. |
void |
setDriver(java.lang.String driver)
Sets the JDBC driver classname. |
void |
setLookup(java.lang.String lookup)
Sets the JNDI lookup name to locate the current resource. |
void |
setPassword(java.lang.String password)
Sets the password to use for database access. |
void |
setPattern(java.lang.String pattern)
Sets the pattern for this instance, which determines which access data will be logged. |
void |
setResolveHosts(boolean resolveHosts)
Denotes whether to attempt to resolve IPs to host names. |
void |
setResource(java.lang.String resource)
Sets the resource name for connection pooling environments from which database connections should be pulled. |
void |
setTableName(java.lang.String tableName)
Sets the table name where access data should be stored. |
void |
setUrl(java.lang.String url)
Sets database url that contains the logging table.. |
void |
setUsername(java.lang.String username)
Sets the usernamed to use for database access. |
void |
start()
Prepares for the beginning of active use of the public methods of this component |
void |
stop()
Gracefully terminate the active use of the public methods of this component. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final java.lang.String info
protected LifecycleSupport lifecycle
protected static final java.lang.String[] months
| Constructor Detail |
|---|
public DBAccessLogValve()
| Method Detail |
|---|
public java.lang.String getInfo()
public java.lang.String getPattern()
public void setPattern(java.lang.String pattern)
pattern - The pattern to use.public void setResolveHosts(boolean resolveHosts)
resolveHosts - True to attempt to resolve to DNS names, or false
to report IP addresses.public boolean isResolveHosts()
public java.lang.String getCondition()
public void setCondition(java.lang.String condition)
condition - The conditional request parameter.
public void invoke(Request request,
Response response,
ValveContext context)
throws java.io.IOException,
ServletException
context - The ValveContext for this instance.request - The Request being logged.response - The Response for this request.
java.io.IOException
ServletException
protected void log(java.lang.String message,
java.util.Date date)
message - The comma delimted list of values to log.date - The date of the request being logged.public void addLifecycleListener(LifecycleListener listener)
listener - The LifecycleListener to be notified.public LifecycleListener[] findLifecycleListeners()
public void removeLifecycleListener(LifecycleListener listener)
listener - The LifeCycleListener to remove.
public void start()
throws LifecycleException
LifecycleException
public void stop()
throws LifecycleException
LifecycleExceptionpublic java.lang.String getDriver()
public void setDriver(java.lang.String driver)
driver - The fully qualified classname for the JDBC driver to use.public java.lang.String getPassword()
public void setPassword(java.lang.String password)
password - The password to use for database access.public java.lang.String getResource()
public void setResource(java.lang.String resource)
resource - The resource name to pull connections from.public java.lang.String getTableName()
public void setTableName(java.lang.String tableName)
tableName - The table name.public java.lang.String getUrl()
public void setUrl(java.lang.String url)
url - The database url to connect to.public java.lang.String getLookup()
public void setLookup(java.lang.String lookup)
lookup - The JNDI lookup name for the current resource.public java.lang.String getColumnNames()
public void setColumnNames(java.lang.String columnNames)
columnNames - The comma separated list of table column names.public java.lang.String getUsername()
public void setUsername(java.lang.String username)
username - The username to use for database access.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||