001: /* *****************************************************************************
002: * bigpost.java
003: * ****************************************************************************/
004:
005: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
007: * Use is subject to license terms. *
008: * J_LZ_COPYRIGHT_END *********************************************************/
009:
010: package org.openlaszlo.test;
011:
012: import java.io.*;
013: import java.net.Socket;
014:
015: import org.apache.commons.httpclient.*;
016: import org.apache.commons.httpclient.methods.*;
017: import org.openlaszlo.utils.FileUtils;
018:
019: public class bigpost {
020: static public void main(String args[]) {
021: Socket socket = null;
022: int i = 0;
023: int j = 0;
024:
025: try {
026: /*
027: String surl = args[0];
028: OutputStream out = new FileOutputStream(args[1]);
029:
030: PostMethod pm = new PostMethod();
031:
032: int s = Integer.parseInt(args[2]);
033:
034: byte bytes[] = new byte[s];
035: String big = new String(bytes);
036: pm.setParameter("junk", big);
037: pm.setParameter("lzt", "data");
038: pm.setParameter("reqtype", "POST");
039: pm.setParameter("cache", "false");
040: pm.setParameter("sendheaders", "false");
041: pm.setParameter("ccache", "false");
042: pm.setParameter("url", "http://localhost:8080/lps/build.xml");
043:
044: pm.setPath(surl);
045:
046: HostConfiguration hcfg = new HostConfiguration();
047: URI uri = new URI(surl);
048: hcfg.setHost(uri);
049:
050: HttpClient htc = new HttpClient();
051: htc.setHostConfiguration(hcfg);
052:
053: int rc = htc.executeMethod(hcfg, pm);
054: System.err.println("status: " + rc);
055: InputStream in = pm.getResponseBodyAsStream();
056: FileUtils.send(in, out);
057: out.close();
058: */
059:
060: String host = args[0];
061: int port = Integer.parseInt(args[1]);
062: String uri = args[2];
063:
064: OutputStream outf = new FileOutputStream(args[3]);
065: socket = new Socket(host, port);
066:
067: System.out.println("Made socket to " + host + ":" + port);
068:
069: //int length = Integer.MAX_VALUE;
070: int length = Integer.parseInt(args[4]);
071: Writer out = new OutputStreamWriter(socket
072: .getOutputStream(), "ISO-8859-1");
073: out.write("POST " + uri + " HTTP/1.1\r\n");
074: out.write("Host: " + host + ":" + port + "\r\n");
075: out.write("User-Agent: bigpost\r\n");
076: out
077: .write("Content-type: application/x-www-form-urlencoded\r\n");
078: out.write("Content-length: " + length + "\r\n");
079: out.write("\r\n");
080: out.flush();
081: out.write("lzt=data\r\n");
082: out.write("reqtype=POST\r\n");
083: out.write("cache=false\r\n");
084: out.write("ccache=false\r\n");
085: out.write("sendheaders=false\r\n");
086: out.write("url=http://localhost:8080/lps/build.xml?x=");
087: while (true) {
088: out.write("x");
089: if (i % 1000 == 0) {
090: out.flush();
091: System.err.println("" + i);
092: j = i;
093: }
094: i++;
095: }
096:
097: //out.write("\r\n");
098: //out.flush();
099:
100: // FileUtils.send(socket.getInputStream(), outf);
101:
102: } catch (Exception e) {
103: System.err.println("bytes sent: " + i);
104: System.err.println("bytes flushed: " + j);
105: e.printStackTrace();
106: } finally {
107: try {
108: socket.close();
109: } catch (IOException e) {
110: }
111: }
112: }
113: }
|