|
Apache JMeter | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.jmeter.protocol.http.util.accesslog.TCLogParser
public class TCLogParser
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:
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.
Field Summary | |
---|---|
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.apache.log.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 Summary | |
---|---|
TCLogParser()
|
|
TCLogParser(String source)
|
Method Summary | |
---|---|
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? |
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. |
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. 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.log.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
Constructor Detail |
---|
public TCLogParser()
public TCLogParser(String source)
source
- name of the source fileMethod Detail |
---|
public 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)
setFilter
in interface LogParser
filter
- Filter
to be used while reading the log linespublic void setSourceFile(String source)
setSourceFile
in interface LogParser
source
- 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 LogParser
count
- number of lines to readel
- TestElement
to read lines into
protected int parse(BufferedReader breader, TestElement el, int parseCount)
breader
- BufferedReader
to read lines fromel
- TestElement
to read lines intoparseCount
- number of lines to read
protected int parseLine(String line, TestElement el)
line
- single line to be parsedel
- TestElement
in which the line will be added
public 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 extracted
public boolean checkMethod(String text)
POST
, GET
and HEAD
methods currently.
The other methods aren't supported yet.
text
- text to be checked for HTTP method
true
if method is supported, false
otherwisepublic String stripFile(String url, TestElement el)
URL_PATH
.
url
- url which should be stripped from parametersel
- TestElement
to parse url into
null
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 parameters
true
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 be convertedel
- HTTPSamplerBase
which consumes the text
public NVPair[] convertStringtoNVPair(String stringparams)
stringparams
- String with parameters to be parsed
NVPair
sprotected NVPair parseOneParameter(String parameter)
parameter
- to be parsed
NVPair
with the parsed name and value of the parameterprotected List<String> parseParameters(String parameters)
parameters
- string to be parsed
public StringTokenizer tokenize(String line, String delim)
line
- line to be parseddelim
- delimiter
line
and delim
public void close()
LogParser
close
in interface LogParser
|
Apache JMeter | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |