HttpSequenceHandle.java
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.ecar.apm.http.client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.client.CookieStore;
import org.apache.http.impl.client.BasicCookieStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ecar.apm.model.HttpRequest;
import com.ecar.apm.model.HttpRequestLog;
import com.ecar.apm.model.HttpSequence;
import com.ecar.apm.model.HttpSequenceLog;
import com.github.pagehelper.StringUtil;
public class HttpSequenceHandle {
protected static final Logger LOGGER = LoggerFactory.getLogger(HttpClientHandler.class);
private HttpSequence httpSequence;
public HashMap<String,String> variables = new HashMap<String,String>();
public ArrayList<HttpRequestLog> httpRequestLogList = new ArrayList<HttpRequestLog>();
public HttpSequenceLog httpSequenceLog;
public HttpSequenceHandle(HttpSequence httpSequence) {
this.httpSequence = httpSequence;
}
//cookie保存
CookieStore cookieStore=new BasicCookieStore();
public void execute(){
List<HttpRequest> requests = httpSequence.getHttpRequest();
for(HttpRequest request : requests){
HttpClientHandler handle = new HttpClientHandler(request,this);
HttpRequestLog requestLog = handle.execute();
requestLog.setPguid(request.getGuid());
requestLog.setPpguid(httpSequence.getGuid());
httpRequestLogList.add(requestLog);
}
handleLog();
}
private void handleLog(){
httpSequenceLog = new HttpSequenceLog();
StringBuffer tempLog = new StringBuffer();
long costTime = 0l;
for(HttpRequestLog log : httpRequestLogList){
costTime += log.getCostTime();
if(StringUtil.isNotEmpty(log.getLog())){
if(tempLog.length() != 0){
tempLog.append("\r\n");
}
tempLog.append(log.getLog());
}
}
httpSequenceLog.setPguid(httpSequence.getGuid());
httpSequenceLog.setCostTime(costTime);
httpSequenceLog.setLog(tempLog.toString());
httpSequenceLog.setStatus(StringUtil.isEmpty(tempLog.toString()));
}
public void setVariables(String key, String value){
variables.put(key, value);
}
public String getVariables(String val){
for (String variableName : variables.keySet()) {
if(variableName.equals(val)){
return variables.get(variableName);
}
}
return null;
}
}