public class TCLogParser extends Object implements LogParser
The parse algorithm is the following:
Extending this class is fairly simple. Most access logs use the same format starting from the request method. Therefore, changing the implementation of cleanURL(string) method should be sufficient to support new log formats. Tomcat uses common log format, so any webserver that uses the format should work with this parser. Servers that are known to use non standard formats are IIS and Netscape.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
decode
by default, we probably should decode the parameter values
|
protected String |
FILENAME |
protected Filter |
FILTER
Handles to supporting classes
|
static String |
GET |
static String |
HEAD |
protected static org.slf4j.Logger |
log |
static String |
POST |
protected BufferedReader |
READER |
protected String |
RMETHOD
protected members *
|
protected File |
SOURCE |
protected String |
URL_PATH
The path to the access log file
|
protected boolean |
useFILE |
| Constructor and Description |
|---|
TCLogParser() |
TCLogParser(String source) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
checkMethod(String text)
The method checks for
POST, GET and HEAD methods currently. |
boolean |
checkParamFormat(String text)
Checks the string to see if it contains "&" and "=".
|
boolean |
checkURL(String url)
Checks the string to make sure it has
/path/file?name=value format. |
String |
cleanURL(String entry)
The method cleans the URL using the following algorithm.
|
void |
close()
close the any streams or readers.
|
void |
convertStringToJMRequest(String text,
TestElement el)
Convert a single line into XML
|
NVPair[] |
convertStringtoNVPair(String stringparams)
Parse the string parameters into NVPair[] array.
|
boolean |
decodeParameterValue()
decode the parameter values is to true by default
|
protected int |
parse(BufferedReader breader,
TestElement el,
int parseCount)
The method is responsible for reading each line, and breaking out of the
while loop if a set number of lines is given.
Note: empty lines will not be counted |
int |
parse(TestElement el,
int parseCount)
parse the entire file.
|
int |
parseAndConfigure(int count,
TestElement el)
parse a set number of lines from the access log.
|
protected int |
parseLine(String line,
TestElement el)
parseLine calls the other parse methods to parse the given text.
|
protected NVPair |
parseOneParameter(String parameter)
Method expects name and value to be separated by an equal sign "=".
|
protected List<String> |
parseParameters(String parameters)
Method uses StringTokenizer to convert the string into single pairs.
|
void |
setDecodeParameterValues(boolean decodeparams)
by default decode is set to true.
|
void |
setFilter(Filter filter)
Use the filter to include/exclude files in the access logs.
|
void |
setSourceFile(String source)
Sets the source file.
|
void |
setUseParsedFile(boolean file)
Calls this method to set whether or not to use the path in the log.
|
String |
stripFile(String url,
TestElement el)
Tokenize the URL into two tokens.
|
StringTokenizer |
tokenize(String line,
String delim)
Parses the line using java.util.StringTokenizer.
|
protected static final org.slf4j.Logger log
public static final String GET
public static final String POST
public static final String HEAD
protected String RMETHOD
protected String URL_PATH
protected boolean useFILE
protected File SOURCE
protected String FILENAME
protected BufferedReader READER
protected Filter FILTER
protected boolean decode
public TCLogParser()
public TCLogParser(String source)
source - name of the source filepublic void setDecodeParameterValues(boolean decodeparams)
decodeparams - flag whether parameters should be decodedpublic boolean decodeParameterValue()
true if parameter values should be decoded, false otherwisepublic void setUseParsedFile(boolean file)
file - flag whether to use the path from the logpublic void setFilter(Filter filter)
public void setSourceFile(String source)
setSourceFile in interface LogParsersource - name of the source filepublic int parse(TestElement el, int parseCount)
el - TestElement to read the lines intoparseCount - number of max lines to read-1 if an error occurred while readingpublic int parseAndConfigure(int count,
TestElement el)
parseAndConfigure in interface LogParsercount - number of lines to readel - TestElement to read lines intoprotected int parse(BufferedReader breader, TestElement el, int parseCount)
breader - BufferedReader to read lines fromel - TestElement to read lines intoparseCount - number of lines to readprotected int parseLine(String line, TestElement el)
line - single line to be parsedel - TestElement in which the line will be addedpublic String cleanURL(String entry)
127.0.0.1 - - [08/Jan/2003:07:03:54 -0500] "GET /addrbook/ HTTP/1.1" 200 1981
would result in the extracted url /addrbook/
entry - line from which the url is to be extractedpublic boolean checkMethod(String text)
POST, GET and HEAD methods currently.
The other methods aren't supported yet.text - text to be checked for HTTP methodtrue if method is supported, false otherwisepublic String stripFile(String url, TestElement el)
url - url which should be stripped from parametersel - TestElement to parse url intonull when none where foundpublic boolean checkURL(String url)
/path/file?name=value format. If
the string doesn't contains a "?", it will return false.url - url to check for parameterstrue if url contains a ?,
false otherwisepublic boolean checkParamFormat(String text)
true, so that it can be parsed.text - text to be checked for & and =true if text contains both &
and =, false otherwisepublic void convertStringToJMRequest(String text, TestElement el)
text - to be convertedel - HTTPSamplerBase which consumes the textpublic NVPair[] convertStringtoNVPair(String stringparams)
stringparams - String with parameters to be parsedNVPairsprotected NVPair parseOneParameter(String parameter)
parameter - to be parsedNVPair with the parsed name and value of the parameterprotected List<String> parseParameters(String parameters)
parameters - string to be parsedpublic StringTokenizer tokenize(String line, String delim)
line - line to be parseddelim - delimiterline and delimCopyright © 1998-2021 Apache Software Foundation. All Rights Reserved.