org.apache.jmeter.protocol.http.util.accesslog
Class TCLogParser
- LogParser
Description:
Currently the parser only handles GET/POST requests. It's easy enough to add
support for other request methods by changing checkMethod. The is a complete
rewrite of a tool I wrote for myself earlier. The older algorithm was basic
and did not provide the same level of flexibility I want, so I wrote a new
one using a totally new algorithm. This implementation reads one line at a
time using BufferedReader. When it gets to the end of the file and the
sampler needs to get more requests, the parser will re-initialize the
BufferedReader. The implementation uses StringTokenizer to create tokens.
The parse algorithm is the following:
- cleans the entry by looking for backslash "\"
- looks to see if GET or POST is in the line
- tokenizes using quotes "
- finds the token with the request method
- gets the string of the token and tokenizes it using space
- finds the first token beginning with slash character
- tokenizes the string using question mark "?"
- get the path from the first token
- returns the second token and checks it for parameters
- tokenizes the string using ampersand "&"
- parses each token to name/value pairs
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.
protected String | FILENAME
|
protected Filter | FILTER - Handles to supporting classes
|
static String | GET
|
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 | decode - by default, we probably should decode the parameter values
|
protected static Logger | log
|
protected boolean | useFILE
|
boolean | checkMethod(String text) - The method checks for POST and GET 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?
|
String | cleanURL(String entry) - The method cleans the URL using the following algorithm.
|
void | close()
|
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.
|
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 Vector | parseParameters(String parameters) - Method uses StringTokenizer to convert the string into single pairs.
|
void | setDecodeParameterValues(boolean decodeparams) - by default decode is set to true. if the parameters shouldn't be
decoded, call the method with false
|
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.
|
FILENAME
protected String FILENAME
FILTER
protected Filter FILTER
Handles to supporting classes
GET
public static final String GET
POST
public static final String POST
READER
protected BufferedReader READER
RMETHOD
protected String RMETHOD
protected members *
SOURCE
protected File SOURCE
URL_PATH
protected String URL_PATH
The path to the access log file
decode
protected boolean decode
by default, we probably should decode the parameter values
log
protected static final Logger log
useFILE
protected boolean useFILE
TCLogParser
public TCLogParser()
TCLogParser
public TCLogParser(String source)
checkMethod
public boolean checkMethod(String text)
The method checks for POST and GET methods currently. The other methods
aren't supported yet.
checkParamFormat
public boolean checkParamFormat(String text)
Checks the string to see if it contains "&" and "=". If it does, return
true, so that it can be parsed.
checkURL
public boolean checkURL(String url)
Checks the string to make sure it has /path/file?name=value format. If
the string doesn't have "?", it will return false.
cleanURL
public String cleanURL(String entry)
The method cleans the URL using the following algorithm.
- check for double quotes
- check the request method
- tokenize using double quotes
- find first token containing request method
- tokenize string using space
- find first token that begins with "/"
Example Tomcat log entry:
127.0.0.1 - - [08/Jan/2003:07:03:54 -0500] "GET /addrbook/ HTTP/1.1" 200
1981
convertStringToJMRequest
public void convertStringToJMRequest(String text,
TestElement el)
Convert a single line into XML
convertStringtoNVPair
public NVPair[] convertStringtoNVPair(String stringparams)
Parse the string parameters into NVPair[] array. Once they are parsed, it
is returned. The method uses parseOneParameter(string) to convert each
pair.
decodeParameterValue
public boolean decodeParameterValue()
decode the parameter values is to true by default
- if paramter values should be decoded
parse
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.
parse
public int parse(TestElement el,
int parseCount)
parse the entire file.
parseAndConfigure
public int parseAndConfigure(int count,
TestElement el)
parse a set number of lines from the access log. Keep in mind the number
of lines parsed will depend the filter and number of lines in the log.
The method returns the actual lines parsed.
- parseAndConfigure in interface LogParser
parseLine
protected int parseLine(String line,
TestElement el)
parseLine calls the other parse methods to parse the given text.
parseOneParameter
protected NVPair parseOneParameter(String parameter)
Method expects name and value to be separated by an equal sign "=". The
method uses StringTokenizer to make a NVPair object. If there happens to
be more than one "=" sign, the others are ignored. The chance of a string
containing more than one is unlikely and would not conform to HTTP spec.
I should double check the protocol spec to make sure this is accurate.
parseParameters
protected Vector parseParameters(String parameters)
Method uses StringTokenizer to convert the string into single pairs. The
string should conform to HTTP protocol spec, which means the name/value
pairs are separated by the ampersand symbol "&". Some one could write the
querystrings by hand, but that would be round about and go against the
purpose of this utility.
setDecodeParameterValues
public void setDecodeParameterValues(boolean decodeparams)
by default decode is set to true. if the parameters shouldn't be
decoded, call the method with false
setFilter
public void setFilter(Filter filter)
Use the filter to include/exclude files in the access logs. This is
provided as a convienance and reduce the need to spend hours cleaning up
log files.
- setFilter in interface LogParser
setSourceFile
public void setSourceFile(String source)
Sets the source file.
- setSourceFile in interface LogParser
setUseParsedFile
public void setUseParsedFile(boolean file)
Calls this method to set whether or not to use the path in the log. We
may want to provide the ability to filter the log file later on. By
default, the parser uses the file in the log.
stripFile
public String stripFile(String url,
TestElement el)
Tokenize the URL into two tokens. If the URL has more than one "?", the
parse may fail. Only the first two tokens are used. The first token is
automatically parsed and set at URL_PATH.
tokenize
public StringTokenizer tokenize(String line,
String delim)
Parses the line using java.util.StringTokenizer.
line
- line to be parseddelim
- delimiter
Copyright © 1998-2010 Apache Software Foundation. All Rights Reserved.