Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: raining/client/SBHttpClient.java


1   /*
2    * $Author: rahul_kumar $
3    * $Id: SBHttpClient.java,v 1.6 2003/10/08 16:41:44 rahul_kumar Exp $
4    *
5    * Copyright (C) 2003 Rahul Kumar. All rights reserved.
6    * 
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2.1 of the License, or (at your option) any later version.
11   * 
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   * 
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22   
23  package raining.client;
24  import raining.core.*;
25  import java.net.URL;
26  import org.apache.commons.cli.*;
27  import java.io.*;
28  import java.util.*;
29  
30  /**
31   * An HTTPClient that extends the basic HTTPClient, with the ability to
32   * generate loads.
33   *
34   *  FOr Testing or loading :
35   *  - how many concurrent connections (A)
36   *  - how long to keep hitting URL
37   *  - any pause between A's
38   *  - max hits
39   *
40   *
41   */
42  
43  public class SBHttpClient extends HttpClient {
44  
45  public static int totalsent = 0;
46  public static int totalrcvd = 0;
47  
48      public static void main (String args[]){ 
49  
50          String urlarray[] = null;
51          String filename = null;
52  
53          // Looks like this wont get used by classes that use a
54          // SBHttpClient!
55  
56          ClientParser clp = new ClientParser(args, "SBHttpClient");
57          Options options = clp.getOptions();
58          options.addOption( "x", "load", true, "how many urls to keep bytes read for" );
59          clp.setOptionProcessor( new OptionProcessor(){
60                  public void processOpt( Option obj ,String opt, String longOpt, String value){
61                  if (opt.equals("x")){
62                  load = Integer.parseInt(value) ;
63                  if (load > 0)
64                  SBHttpClient.setLoadArray( load );
65                  }
66                  }
67                  });
68  
69          clp.parse();
70  
71          urlarray = clp.getUrlArray();
72          // the following gets still need to be moved off, this is adding
73          // to the work one has to do, even after using clp.
74          useProxy = clp.getUseProxy();
75          if (useProxy){
76              HttpClient.setProxy(clp.getProxyServer(), clp.getProxyPort());
77  
78              if (clp.getProxyAuth() != null)
79                  HttpClient.setProxyAuthString(clp.getProxyAuth());
80              else
81                  System.err.println(  "warning: Auth String not passed for connecting to proxy !");
82          } // proxy settings
83  
84  
85  
86          try {
87              // START WORK
88              //
89              if (urlarray.length >0){
90                  for( int i = 0; i < urlarray.length; i++ ){ 
91                     SBHttpClient h = new SBHttpClient (urlarray[i]);
92                     h.push();
93                  }
94              }
95              NioSocket.stopWhenIdle(true);
96              //NioSocket.setDebug(true);
97              NioSocket.start();
98          } catch (Exception exc) { System.err.println( " Http 21 EXC:"+ exc.toString()); exc.printStackTrace(); } 
99  
100     }
101 
102     static int bytesread[] = null;
103     static int load = 0;
104     public static void setLoadArray (int mload){
105         bytesread = new int[ mload ];
106         load = mload;
107     }
108     public static int[] getLoadArray () {
109         return bytesread;
110     }
111 
112     /** Constructor that takes absolute URL and splits it.
113      * e.g. http://www.benegal.net/
114      */
115     public SBHttpClient (String Url) throws java.net.MalformedURLException, java.io.IOException, Exception {
116         super(Url);
117         totalsent++;
118     }
119     /** Constructor to be used if you have created a GETString already.
120      * this is required if you wish to blast one URL with many
121      * connections.
122      */
123     public SBHttpClient () throws java.io.IOException, Exception {
124         super();
125         totalsent++;
126     }
127 
128     //public static final char DOTCHAR = '.';
129 
130     public void handle_read_complete(String mdata){
131         totalrcvd++;
132     }
133 
134 
135 } // end of class
136 
137 
138