import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
import java.net.*;
import java.lang.String;
public class HttpSender {
private static String lineSeperator = System.getProperty("line.separator");
/**
* @param args0: total args1 thread count
*/
public static void main(String[] args) throws Exception{
String help = "Usage: HttpSender [options] http://hostname[:port]/path\n" +
"Options:\n" +
" --help Help message\n" +
" -c Concurrent threads\n" +
" -n Number of total requests\n" +
" -h Header of http request\n" +
" -f File to read url lists\n" +
" -r [1/0]:1 random, 0 iterative\n" +
" -i dynamic to get vip from dns\n" +
" -p Print response header\n";
//some Parameters to read from arg:
int threadCount = 1;
long totalEachThread = 1;
long LastThreadRequest = 0;
long totalRequest = 1;
boolean printHeader = false;
String urlFile = null;
String cUrl = null;
int random = 0;
boolean changVip = false;
String getVipLocalInfo = "";
ArrayList<String> headerArray = new ArrayList<String>();
ArrayList<String> urlArray = new ArrayList<String>();
Hashtable<Integer, Integer> totalResCode = new Hashtable<Integer, Integer>();
Hashtable<String, Integer> totalExcep = new Hashtable<String, Integer>();
// process args:
if(args.length == 1){
if(args[0].contains("http") == true)
cUrl = args[0];
else{
System.out.println(help);
return;
}
}
else if (args.length == 2 || args.length == 0) {
System.out.println(help);
return;
}
else {
int n = 0;
while ( n < args.length ){
if (args[n].contentEquals("-c") && args[n+1] != null){
threadCount = Integer.valueOf(args[n+1]);
n = n + 2;
}
else if (args[n].contentEquals("-f") && args[n+1] != null){
urlFile = args[n+1];
n = n + 2;
}
else if (args[n].contentEquals("-n") && args[n+1] != null){
totalRequest = Long.valueOf(args[n+1]);
n = n + 2;
}
else if (args[n].contentEquals("-h") && args[n+1] != null){
headerArray.add(args[n+1]);
n = n + 2;
}
else if (args[n].contentEquals("-r") && args[n+1] != null){
random = Integer.valueOf(args[n+1]);
n = n + 2;
}
else if (args[n].contains("http") == true){
cUrl = args[n];
n = n + 1;
}
else if (args[n].contentEquals("-p")){
printHeader = true;
n = n + 1;
}
else if (args[n].contentEquals("-i")){
changVip = true;
n = n + 1;
}
else {
System.out.println(help);
return;
}
}
}
System.out.println("...Start...\n");
/*处理命令行接收的cUrl*/
if (cUrl != null && urlFile != null){
System.out.println("urlFile & url conflict");
System.out.println(help);
return;
}
/*添加获取vip处理*/
if(changVip == true){
getVipLocalInfo = readLocalNetInfo();
System.out.println(getVipLocalInfo);
System.out.println(getLocalVip(getVipLocalInfo));
}
if(cUrl != null && urlFile == null){
urlArray = splitRegrexString(cUrl);
}
totalEachThread = totalRequest / threadCount;
// * 如果提供urlFile,则从文件里读取URL,忽略<url>参数
if(urlFile != null && (!urlFile.isEmpty())){
FileReader fr = new FileReader(urlFile);
BufferedReader br = new BufferedReader(fr);
String urlLine = br.readLine();
while (urlLine != null) {
urlArray.add(urlLine);
urlLine = br.readLine();
}
br.close();
fr.close();
}
/*文件处理完毕*/
ArrayList<String> rtArray = new ArrayList<String>();
ArrayList<SendThread> threadArray = new ArrayList<SendThread>();
SendThread t = null;
Date threadStart = new Date();
for(int tc = 0; tc < (threadCount - 1); tc ++){
t = new SendThread(tc, totalEachThread, rtArray,urlArray,random, headerArray, printHeader);
t.start();
threadArray.add(t);
}
//for the last thread when 100%3=1
LastThreadRequest = totalEachThread + totalRequest % threadCount;
t = new SendThread(threadCount, LastThreadRequest, rtArray,urlArray,random, headerArray, printHeader);
t.start();
threadArray.add(t);
//Wait for all thread died
for(int j=0; j<threadArray.size(); j++){
threadArray.get(j).join();
}
Date threadEnd = new Date();
long totalResponse = 0;
double averRT = 0;
double totalQPS = 0;
double totalCostTime = (double) (threadEnd.getTime() - threadStart.getTime())/1000;
Hashtable<Integer, Integer> tmpResCode = new Hashtable<Integer, Integer>();
Hashtable<String, Integer> tmpThreadExcep = new Hashtable<String, Integer>();
Integer tmpCode = 0;
Integer tmpValue = 0;
String tmpExcep = null;
//thread process
for(int j=0; j<threadArray.size(); j++) try {
averRT += threadArray.get(j).getRT();
totalQPS += threadArray.get(j).getQPS();
totalResponse += threadArray.get(j).getResponse();
tmpResCode = threadArray.get(j).getResCode();
Iterator<Integer> it = tmpResCode.keySet().iterator();
while(it.hasNext()) {
tmpCode = it.next();
if(totalResCode.containsKey(tmpCode)){
tmpValue = totalResCode.get(tmpCode) + tmpResCode.get(tmpCode);
totalResCode.put(tmpCode, tmpValue);
}
else {
tmpValue = tmpResCode.get(tmpCode);
totalResCode.put(tmpCode, tmpValue);
}
}
tmpThreadExcep = threadArray.get(j).getThreadExcep();
Iterator<String> is = tmpThreadExcep.keySet().iterator();
while(is.hasNext()){
tmpExcep = is.next();
if(totalExcep.containsKey(tmpExcep)) {
tmpValue = totalExcep.get(tmpExcep) + tmpThreadExcep.get(tmpExcep);
totalExcep.put(tmpExcep,tmpValue);
}
else {
tmpValue = tmpThreadExcep.get(tmpExcep);
totalExcep.put(tmpExcep,tmpValue);
}
}
} catch (Exception e) {
e.printStackTrace();
}
if(threadArray.size() > 0){
averRT = averRT/threadArray.size();
}
java.text.DecimalFormat rtDF=new java.text.DecimalFormat("#.###");
java.text.DecimalFormat qpsDF=new java.text.DecimalFormat("#");
System.out.println(String.format("Avg RT: %1$1sms\nTotal QPS: %2$1s\nCost Time: %3$1ss\n",
rtDF.format(averRT),qpsDF.format(totalQPS),rtDF.format(totalCostTime)));
//print response code
Iterator<Integer> it = totalResCode.keySet().iterator();
System.out.println("Response Code:");
while(it.hasNext()) {
tmpCode = it.next();
System.out.println(String.format("%1$-6d %2$-6d",tmpCode, totalResCode.get(tmpCode)));
}
//print exception
System.out.println("\nException:");
Iterator<String> is = totalExcep.keySet().iterator();
while(is.hasNext()){
tmpExcep = is.next();
System.out.println(String.format("%1$-16s: %2$-5d", tmpExcep, totalExcep.get(tmpExcep)));
}
System.out.println("\n...Finish...");
return;
}
/*
*处理URL中的正则表达式
*[a-b]/[c-d]
*[a-b]/c
*a/[b-c]
*a/b
*/
public static ArrayList<String> splitRegrexString(String regexString) {
ArrayList<String> elements = new ArrayList<String>();
int need = regexString.indexOf("]");
int left = regexString.indexOf("/[");
int ab = regexString.indexOf("]/");
int fIndex1 = regexString.indexOf("[");
int fIndex2 = regexString.indexOf("]",fIndex1);
int fIndex3 = regexString.indexOf('-',fIndex1);
int oIndex1 = regexString.indexOf('[', fIndex1 + 1);
int oIndex2 = regexString.indexOf(']', fIndex2 + 1);
int oIndex3 = regexString.indexOf('-', fIndex3 + 1);
if( need == -1){
elements.add(regexString);
}
else if(left == -1){
elements.add(regexString);
}
else if(fIndex1 != -1 && fIndex2 != -1 && fIndex3 != -1 && oIndex1 != -1 && oIndex2 != -1 && oIndex3 != -1) {
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
httpsender.gz (43个子文件)
httpsender
src
SendThread.java 5KB
global
Result.java 2KB
Global.java 9KB
ProgressTimer.java 517B
MD5.java 627B
http
SendThread.java 5KB
HttpSender.java 2KB
Response.java 910B
HttpRequest.java 3KB
HttpSender.java 12KB
httpSender 630B
lib
commons-codec-1.4.jar 57KB
.svn
tmp
props
prop-base
text-base
props
all-wcprops 882B
entries 1KB
prop-base
commons-logging-1.1.1.jar.svn-base 53B
httpmime-4.1.jar.svn-base 53B
httpclient-4.1.jar.svn-base 53B
httpcore-4.1.jar.svn-base 53B
commons-codec-1.4.jar.svn-base 53B
httpclient-cache-4.1.jar.svn-base 53B
text-base
commons-logging-1.1.1.jar.svn-base 59KB
httpmime-4.1.jar.svn-base 26KB
httpclient-4.1.jar.svn-base 342KB
httpcore-4.1.jar.svn-base 177KB
commons-codec-1.4.jar.svn-base 57KB
httpclient-cache-4.1.jar.svn-base 103KB
httpclient-cache-4.1.jar 103KB
commons-logging-1.1.1.jar 59KB
httpcore-4.1.jar 177KB
httpmime-4.1.jar 26KB
httpclient-4.1.jar 342KB
httpsender 635B
bin
HttpSender.class 11KB
global
Result.class 3KB
MD5.class 1KB
Global.class 9KB
ProgressTimer.class 1KB
http
HttpSender.class 2KB
Response.class 1KB
HttpRequest.class 4KB
SendThread.class 6KB
httpSender 630B
SendThread.class 6KB
共 43 条
- 1
资源评论
- qinshouchusheng2016-05-24window下貌似没有用啊
qq_28024575
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Проекты и скрипты.zip
- 公开整理-中国各省市级信用体系建设匹配数据集(2010-2024).xls
- [한빛미디어]“与파스트다和파스썬”전체소스코드저장소입니다 .zip
- 汽车行业车载网络安全认证协议 UDS Service 29 解析与应用
- .raw 文件打开方式.pdf
- 760964449620474KivaIxaBeltAllRiderSeries_1.1_apkcombo.com.apk
- 开源的跨平台计算机视觉库opencv-4.10.0-windows
- qt-opensource-windows-x86-msvc2013-5.6.3.rar
- 基于 crossbeam-channel + JNI 实现 Java 与 Rust 的消息传递
- 酒店管理客房管理系统源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功