Java Doc for TCLogParser.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » http » util » accesslog » 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 » Testing » jakarta jmeter » org.apache.jmeter.protocol.http.util.accesslog 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.jmeter.protocol.http.util.accesslog.TCLogParser

All known Subclasses:   org.apache.jmeter.protocol.http.util.accesslog.SharedTCLogParser,
TCLogParser
public class TCLogParser implements LogParser(Code)
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:

  1. cleans the entry by looking for backslash "\"
  2. looks to see if GET or POST is in the line
  3. tokenizes using quotes "
  4. finds the token with the request method
  5. gets the string of the token and tokenizes it using space
  6. finds the first token beginning with slash character
  7. tokenizes the string using question mark "?"
  8. get the path from the first token
  9. returns the second token and checks it for parameters
  10. tokenizes the string using ampersand "&"
  11. 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.



Field Summary
protected  StringFILENAME
    
protected  FilterFILTER
    
final public static  StringGET
    
final public static  StringPOST
    
protected  BufferedReaderREADER
    
protected  StringRMETHOD
    
protected  FileSOURCE
    
protected  StringURL_PATH
    
protected  booleandecode
    
static  Loggerlog
    
protected  booleanuseFILE
    

Constructor Summary
public  TCLogParser()
    
public  TCLogParser(String source)
    

Method Summary
public  booleancheckMethod(String text)
     The method checks for POST and GET methods currently.
public  booleancheckParamFormat(String text)
     Checks the string to see if it contains "&" and "=".
public  booleancheckURL(String url)
     Checks the string to make sure it has /path/file?name=value format.
public  StringcleanURL(String entry)
     The method cleans the URL using the following algorithm.
public  voidclose()
    
public  voidconvertStringToJMRequest(String text, TestElement el)
    
public  NVPair[]convertStringtoNVPair(String stringparams)
     Parse the string parameters into NVPair[] array.
public  booleandecodeParameterValue()
    
public  FileopenFile(String filename)
     Creates a new File object.
public  intparse(TestElement el, int parseCount)
     parse the entire file.
protected  intparse(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.
public  intparseAndConfigure(int count, TestElement el)
     parse a set number of lines from the access log.
protected  intparseLine(String line, TestElement el)
     parseLine calls the other parse methods to parse the given text.
protected  NVPairparseOneParameter(String parameter)
     Method expects name and value to be separated by an equal sign "=".
protected  VectorparseParameters(String parameters)
     Method uses StringTokenizer to convert the string into single pairs.
public  voidsetDecodeParameterValues(boolean decodeparams)
     by default decode is set to true.
public  voidsetFilter(Filter filter)
     Use the filter to include/exclude files in the access logs.
public  voidsetSourceFile(String source)
     Sets the source file.
public  voidsetUseParsedFile(boolean file)
     Calls this method to set whether or not to use the path in the log.
public  StringstripFile(String url, TestElement el)
     Tokenize the URL into two tokens.
public  StringTokenizertokenize(String line, String delim)
     Parses the line using java.util.StringTokenizer.

Field Detail
FILENAME
protected String FILENAME(Code)



FILTER
protected Filter FILTER(Code)
Handles to supporting classes



GET
final public static String GET(Code)



POST
final public static String POST(Code)



READER
protected BufferedReader READER(Code)



RMETHOD
protected String RMETHOD(Code)
protected members *



SOURCE
protected File SOURCE(Code)



URL_PATH
protected String URL_PATH(Code)
The path to the access log file



decode
protected boolean decode(Code)
by default, we probably should decode the parameter values



log
static Logger log(Code)



useFILE
protected boolean useFILE(Code)




Constructor Detail
TCLogParser
public TCLogParser()(Code)



TCLogParser
public TCLogParser(String source)(Code)

Parameters:
  source -




Method Detail
checkMethod
public boolean checkMethod(String text)(Code)
The method checks for POST and GET methods currently. The other methods aren't supported yet.
Parameters:
  text - if method is supported



checkParamFormat
public boolean checkParamFormat(String text)(Code)
Checks the string to see if it contains "&" and "=". If it does, return true, so that it can be parsed.
Parameters:
  text - boolean



checkURL
public boolean checkURL(String url)(Code)
Checks the string to make sure it has /path/file?name=value format. If the string doesn't have "?", it will return false.
Parameters:
  url - boolean



cleanURL
public String cleanURL(String entry)(Code)
The method cleans the URL using the following algorithm.
  1. check for double quotes
  2. check the request method
  3. tokenize using double quotes
  4. find first token containing request method
  5. tokenize string using space
  6. 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


Parameters:
  entry - cleaned url




close
public void close()(Code)



convertStringToJMRequest
public void convertStringToJMRequest(String text, TestElement el)(Code)
Convert a single line into XML
Parameters:
  text -



convertStringtoNVPair
public NVPair[] convertStringtoNVPair(String stringparams)(Code)
Parse the string parameters into NVPair[] array. Once they are parsed, it is returned. The method uses parseOneParameter(string) to convert each pair.
Parameters:
  stringparams -



decodeParameterValue
public boolean decodeParameterValue()(Code)
decode the parameter values is to true by default if paramter values should be decoded



openFile
public File openFile(String filename)(Code)
Creates a new File object.
Parameters:
  filename -



parse
public int parse(TestElement el, int parseCount)(Code)
parse the entire file. boolean success/failure



parse
protected int parse(BufferedReader breader, TestElement el, int parseCount)(Code)
The method is responsible for reading each line, and breaking out of the while loop if a set number of lines is given.
Parameters:
  breader -



parseAndConfigure
public int parseAndConfigure(int count, TestElement el)(Code)
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.
Parameters:
  count - lines parsed



parseLine
protected int parseLine(String line, TestElement el)(Code)
parseLine calls the other parse methods to parse the given text.
Parameters:
  line -



parseOneParameter
protected NVPair parseOneParameter(String parameter)(Code)
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.
Parameters:
  parameter - to be parsed NVPair



parseParameters
protected Vector parseParameters(String parameters)(Code)
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.
Parameters:
  parameters - Vector



setDecodeParameterValues
public void setDecodeParameterValues(boolean decodeparams)(Code)
by default decode is set to true. if the parameters shouldn't be decoded, call the method with false
Parameters:
  decodeparams -



setFilter
public void setFilter(Filter filter)(Code)
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.
Parameters:
  filter -



setSourceFile
public void setSourceFile(String source)(Code)
Sets the source file.
Parameters:
  source -



setUseParsedFile
public void setUseParsedFile(boolean file)(Code)
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.
Parameters:
  file -



stripFile
public String stripFile(String url, TestElement el)(Code)
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.
Parameters:
  url - String parameters



tokenize
public StringTokenizer tokenize(String line, String delim)(Code)
Parses the line using java.util.StringTokenizer.
Parameters:
  line - line to be parsed
Parameters:
  delim - delimiter StringTokenizer



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.