View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  import java.io.BufferedReader;
14  import java.io.File;
15  import java.io.FileReader;
16  import java.io.FileWriter;
17  
18  /***
19   * Utility for splitting HEAD from GET/POST/PUT/DELETE requests in a standard webserver log file
20   * 
21   * @author Ole.Matzura
22   */
23  
24  public class HEADRequestRemover
25  {
26  	public static void main(String[] args) throws Exception
27  	{
28  		File in = new File( args[0] );
29  		File out = new File( args[1] );
30  		File headOut = new File( args[2] );
31  		
32  		BufferedReader reader = new BufferedReader( new FileReader( in ));
33  		FileWriter writer = new FileWriter( out );
34  		FileWriter headWriter = new FileWriter( headOut );
35  		
36  		String ln = reader.readLine();
37  		int lnCnt = 0;
38  		int headCnt = 0;
39  		
40  		while( ln != null )
41  		{
42  			lnCnt++;
43  			
44  			if( ln.indexOf( "] \"HEAD ") == -1 )
45  			{
46  				writer.write( ln );
47  				writer.write( "\r\n" );
48  			}
49  			else
50  			{
51  				headWriter.write( ln );
52  				headWriter.write( "\r\n" );
53  				headCnt++;
54  			}
55  			
56  			ln = reader.readLine();
57  		}
58  		
59  		reader.close();
60  		writer.close();
61  		headWriter.close();
62  		
63  		System.out.println( "Processed file contained " + lnCnt + " lines, extracted " + headCnt + " HEAD requests" );
64  	}
65  
66  }