KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > test > bigpost


1 /* *****************************************************************************
2  * bigpost.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10
11 package org.openlaszlo.test;
12
13 import java.io.*;
14 import java.net.Socket JavaDoc;
15
16 import org.apache.commons.httpclient.*;
17 import org.apache.commons.httpclient.methods.*;
18 import org.openlaszlo.utils.FileUtils;
19
20
21 public class bigpost {
22    static public void main (String JavaDoc args[]) {
23        Socket JavaDoc socket = null;
24        int i = 0;
25        int j = 0;
26
27        try {
28            /*
29            String surl = args[0];
30            OutputStream out = new FileOutputStream(args[1]);
31
32            PostMethod pm = new PostMethod();
33
34            int s = Integer.parseInt(args[2]);
35
36            byte bytes[] = new byte[s];
37            String big = new String(bytes);
38            pm.setParameter("junk", big);
39            pm.setParameter("lzt", "data");
40            pm.setParameter("reqtype", "POST");
41            pm.setParameter("cache", "false");
42            pm.setParameter("sendheaders", "false");
43            pm.setParameter("ccache", "false");
44            pm.setParameter("url", "http://localhost:8080/lps/build.xml");
45
46            pm.setPath(surl);
47
48            HostConfiguration hcfg = new HostConfiguration();
49            URI uri = new URI(surl);
50            hcfg.setHost(uri);
51
52            HttpClient htc = new HttpClient();
53            htc.setHostConfiguration(hcfg);
54
55            int rc = htc.executeMethod(hcfg, pm);
56            System.err.println("status: " + rc);
57            InputStream in = pm.getResponseBodyAsStream();
58            FileUtils.send(in, out);
59            out.close();
60            */

61
62          String JavaDoc host = args[0];
63          int port = Integer.parseInt(args[1]);
64          String JavaDoc uri = args[2];
65
66          OutputStream outf = new FileOutputStream(args[3]);
67          socket = new Socket JavaDoc(host, port);
68
69          System.out.println("Made socket to " + host + ":" + port);
70
71          //int length = Integer.MAX_VALUE;
72
int length = Integer.parseInt(args[4]);
73          Writer out = new OutputStreamWriter(
74             socket.getOutputStream(), "ISO-8859-1");
75          out.write("POST " + uri + " HTTP/1.1\r\n");
76          out.write("Host: " + host + ":" + port + "\r\n");
77          out.write("User-Agent: bigpost\r\n");
78          out.write("Content-type: application/x-www-form-urlencoded\r\n");
79          out.write("Content-length: " + length + "\r\n");
80          out.write("\r\n");
81          out.flush();
82          out.write("lzt=data\r\n");
83          out.write("reqtype=POST\r\n");
84          out.write("cache=false\r\n");
85          out.write("ccache=false\r\n");
86          out.write("sendheaders=false\r\n");
87          out.write("url=http://localhost:8080/lps/build.xml?x=");
88          while(true) {
89              out.write("x");
90              if (i % 1000 == 0) {
91                  out.flush();
92                  System.err.println("" + i);
93                  j = i;
94              }
95              i++;
96          }
97
98          //out.write("\r\n");
99
//out.flush();
100

101          // FileUtils.send(socket.getInputStream(), outf);
102

103        } catch (Exception JavaDoc e) {
104            System.err.println("bytes sent: " + i);
105            System.err.println("bytes flushed: " + j);
106            e.printStackTrace();
107        } finally {
108          try {
109              socket.close();
110          } catch (IOException e) {
111          }
112        }
113    }
114 }
115
Popular Tags