IBM RPM系统是WEB之上包装的非文本方式传输数据的系统。
为了开展性能测试,如何构造有效的网络包成为第一个坎。用YATT 嗅探器截获之前的通信包,保存为req.log。
然后借用JAVA 里面HttpURLConnection 发送、接收数据,经测试通过。
import java.io.*;
import java.net.HttpURLConnection;
import java.util.Map;
import java.net.URL;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public class RpmSender {
public static void main(String[] args) {
try {
String log_dir = "D:\\rpm\\record2\\";
int bufferlen =20480;
URL url = new URL("http://rpm.alibaba-inc.com:9080/webapp/IBMRPM/PMOServlet.wss");
//URL url = new URL("http://10.0.32.123:8081/IBMRPM/PMOServlet.wss");
OutputStream ōut = null;
InputStream is = null;
HttpURLConnection httpConnection = null;
for (int i = 1; i <= 16; i++) {
httpConnection = (HttpURLConnection) url
.openConnection();
httpConnection.setRequestProperty("Content-Type",
"application/octet-stream");
httpConnection.setRequestProperty("Accept", "text/html, */*");
httpConnection.setRequestProperty("Pragma", "no-cache");
httpConnection.setRequestProperty("Keep-Alive", "Y");
httpConnection.setRequestProperty("Accept-Encoding",
"deflate, identity");
httpConnection.setRequestProperty("Zip", "D");
httpConnection.setRequestProperty("User-Agent", "IBMRPM");
httpConnection.setRequestProperty("Method", "POST");
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
out = new BufferedOutputStream(httpConnection.getOutputStream());
String reqfile = i + "_req.log";
String resultfile = "result_" + i + "_reponse.log";
FileInputStream fstream = new FileInputStream(log_dir + reqfile);
String charset = "UTF-8"; //GBK,ISO-8859-1,GB2312,UTF-8
byte[] ōutput = new byte[bufferlen];
int readbyte = fstream.read(output);
System.out.println(readbyte);
//httpConnection.setRequestProperty("Content-Length",new
// Integer(readbyte).toString() );
out.write(output, 0, readbyte);
out.flush();
byte[] buffer = new byte[bufferlen * 3];
byte[] tmp = new byte[bufferlen];
int length;
int total_len = 0;
is = httpConnection.getInputStream();
while ((length = is.read(tmp)) > -1) {
System.arraycopy(tmp, 0, buffer, total_len, length);
total_len += length;
}
System.out.println(total_len);
Inflater decompresser = new Inflater();
decompresser.setInput(buffer, 0, total_len);
byte[] result = new byte[4096];
int resultLength = decompresser.inflate(result);
decompresser.end();
FileOutputStream fout = new FileOutputStream(log_dir
+ resultfile);
fout.write(result, 0, resultLength);
fout.close();
// Decode the bytes into a String
// String ōutputString = new String(result);
String ōutputString = new String(result, 0, resultLength,
charset); //"UTF-8");
System.out.println(outputString);
out.close();
is.close();
httpConnection.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}