This commit is contained in:
daisyonly 2014-09-02 14:40:15 +08:00
commit 3672d3d101
13 changed files with 225 additions and 239 deletions

View File

@ -129,6 +129,16 @@ public abstract class TestBase {
final Scenario scenario, int poolSize, PluginManager pluginManager) {
ScenarioContext scenarioContext = ScenarioContext.buildScenarioContextWithoutScenario(
testId, poolSize, pluginManager);
return scenarioContext.addScenrio(scenario, Schedule.build(new ScheduleModel()), new Date().getTime());
return scenarioContext.addScenrio(scenario, Schedule.build(buildScheduleModel()), new Date().getTime());
}
public static ScheduleModel buildScheduleModel(){
ScheduleModel scheduleModel = new ScheduleModel();
List<PointModel> points = new LinkedList<ScheduleModel.PointModel>();
points.add(new PointModel(0, 0));
points.add(new PointModel(20 * 1000, 20));
points.add(new PointModel(60 * 1000, 20));
scheduleModel.setPoints(points);
return scheduleModel;
}
}

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import org.apache.commons.httpclient.ChunkedOutputStream;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.log4j.Logger;
@ -115,12 +116,12 @@ public class RequestHandler implements Runnable {
int BUF_SIZE = rs < ss ? ss : rs;
byte[] buf = new byte[BUF_SIZE];
try{
initClientServerConnections(this.clientSocket);
}catch(SilentException e){
try {
initClientServerConnections(this.clientSocket);
} catch (SilentException e) {
return;
}
this.header.buildRequestHeader(serverConnection);
log.trace("set request header");
byte[] requestBody;
@ -149,9 +150,9 @@ public class RequestHandler implements Runnable {
log.trace("wrote " + Integer.toString(len) + " bytes");
num += len;
}
//close send request to remote server
serverOut.flush();
serverOut.close();
// close send request to remote server
serverOut.flush();
serverOut.close();
requestBody = this.buffer.toByteArray();
log.trace("transferred rest of request body");
} else {
@ -160,11 +161,12 @@ public class RequestHandler implements Runnable {
}
this.clientSocket.shutdownInput();
this.serverIn = serverConnection.getInputStream();
synchronized (mutex) {
// this.proxyServer.processRequest(this.header, requestBody);
// log.trace("processed request");
// this.proxyServer.processRequest(this.header,
// requestBody);
// log.trace("processed request");
this.buffer.reset();
int len;
@ -182,7 +184,7 @@ public class RequestHandler implements Runnable {
try {
this.clientOut.write(changeHeaderToByte(
serverConnection.getHeaderFields(),
responseModel.getResponse().length));
responseModel));
this.clientOut.write(responseModel.getResponse());
} catch (SocketException e) {
@ -208,7 +210,7 @@ public class RequestHandler implements Runnable {
}
private byte[] changeHeaderToByte(Map<String, List<String>> headerMap,
int responseLen) {
ResponseModel responseModel) {
StringBuilder sb = new StringBuilder();
for (String key : headerMap.keySet()) {
@ -216,20 +218,45 @@ public class RequestHandler implements Runnable {
sb.append(changeList2String(headerMap.get(key)) + "\r\n");
continue;
}
if (key.equals("Transfer-Encoding")) {
if(key.equals("Content-Length") && headerMap.get(key).get(0).equals("-1")){
sb.append("Content-Length: "+responseModel.getResponse().length +"\r\n");
continue;
}
if (key.equals("Transfer-Encoding") && headerMap.get(key).get(0).equals("chunked")) {
responseModel.setResponse(buildResponseBodyToChunked(responseModel.getResponse()));
}
sb.append(key + ": " + changeList2String(headerMap.get(key))
+ "\r\n");
}
// change response length
if (headerMap.get("Content-Length") == null) {
sb.append("Content-Length: " + responseLen).append("\r\n");
}
sb.append("\r\n");
return sb.toString().getBytes();
}
private byte[] buildResponseBodyToChunked(byte[] responseBytes) {
ChunkedOutputStream chunkedOutputStream = null;
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
chunkedOutputStream = new ChunkedOutputStream(byteArrayOutputStream);
chunkedOutputStream.write(responseBytes,0,responseBytes.length);
chunkedOutputStream.finish();
chunkedOutputStream.flush();
return byteArrayOutputStream.toByteArray();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(chunkedOutputStream != null){
try {
chunkedOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return responseBytes;
}
private String changeList2String(List<String> headers) {
if (headers == null)
return "";

View File

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.ChunkedInputStream;
import org.apache.commons.httpclient.ChunkedOutputStream;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.log4j.Logger;
import org.bench4q.recorder.httpcapture.ResponseModel;
@ -71,29 +72,6 @@ public class ResponseParser {
return result;
}
private String preprocess(String respString) {
return respString.toLowerCase();
}
private String parseContentLength(Map<String, List<String>> map) {
List<String> values = map.get("Content-Length:");
if (values != null) {
return values.get(0);
}
return "-1";
}
private String parseContentEncoding(Map<String, List<String>> map) {
String ret = "";
List<String> values = map.get("Content-Encoding:");
if (values != null) {
return values.get(0);
}
return null;
}
private String parseCharset(HttpURLConnection httpURLConnection) {
String ret = null;
@ -129,39 +107,7 @@ public class ResponseParser {
return httpURLConnection.getHeaderField("Transfer-Encoding");
}
private byte[] buildResponseBody() {
ByteArrayInputStream in = new ByteArrayInputStream(this.getResponse(),
0, this.getResponse().length);
ChunkedInputStream chunkedIS = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
chunkedIS = new ChunkedInputStream(in);
int tempByte;
while ((tempByte = chunkedIS.read()) != -1) {
out.write(tempByte);
}
return out.toByteArray();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (chunkedIS != null) {
chunkedIS.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
private void parseResponseBody() {
ContentDecoder contentDecoder = ContentDecoder.createDecoder(this
@ -194,6 +140,9 @@ public class ResponseParser {
charset = Charset.forName("utf-8");
logger.error(e, e);
}
return contentEncoder.encoderContent(responseBody.getBytes(charset));
byte[] responseBytes = responseBody.getBytes(charset);
responseBytes = contentEncoder.encoderContent(responseBytes);
return responseBytes;
}
}

View File

@ -18,59 +18,59 @@ import org.junit.Test;
public class Test_RequestHandler {
private static final int PORT = 8910;
@Test
public void test() {
try {
ProxyServer proxyServer = new ProxyServer(PORT);
Bench4qCodeGenerator observer = new Bench4qCodeGenerator(
new Bench4qTestScriptAdapter(new RunScenarioModel()));
proxyServer.addObserver(observer);
RequestHandler requestHandler = new RequestHandler(proxyServer,
proxyServer.getServerSocket().accept());
requestHandler.run();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void test2() {
new SendRequest().run();
}
private static class SendRequest implements Runnable {
private HttpClient httpClient = new HttpClient();
@SuppressWarnings("deprecation")
public void run() {
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setProxy("127.0.0.1", PORT);
httpClient.setHostConfiguration(hostConfiguration);
// CustomGetMethod get = new CustomGetMethod("http://www.baidu.com");
GetMethod get = new GetMethod("http://www.baidu.com");
try {
get.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
get.addRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
get.addRequestHeader("Cache-Control", "max-age=0");
get.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
get.addRequestHeader("Cookie","__zpspc=188.1.1409195668.1409195668.1%234%7C%7C%7C%7C%7C; BDUSS=E45eXUtamxkY2JUbS12ZjFUSmJPbWdmUU13Ri1ZVHlzWWx2S1B3YXRxRVNUU1pVQVFBQUFBJCQAAAAAAAAAAAEAAAAOfOsxd29uYW5ndW8xMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLA~lMSwP5Tc; cflag=65535%3A1; BD_UPN=123143; BD_HOME=1; BAIDUID=12B697CB05FD662D2CA4416FF118FCD8:FG=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; BD_CK_SAM=1; H_PS_PSSID=8307_5228_1466_7800_8235_8488_8057_6506_6017_8251_7607_7799_8483_8457_8167_8509_8435_8382_8114; BD_HOME=1");
int statusCode = this.httpClient.executeMethod(get);
System.out.println(statusCode);
System.out.println(new String(get.getResponseBody(),Charset.forName("utf-8")));
} catch (URIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// @Test
// public void test() {
// try {
// ProxyServer proxyServer = new ProxyServer(PORT);
// Bench4qCodeGenerator observer = new Bench4qCodeGenerator(
// new Bench4qTestScriptAdapter(new RunScenarioModel()));
// proxyServer.addObserver(observer);
// RequestHandler requestHandler = new RequestHandler(proxyServer,
// proxyServer.getServerSocket().accept());
// requestHandler.run();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
// @Test
// public void test2() {
// new SendRequest().run();
// }
//
// private static class SendRequest implements Runnable {
// private HttpClient httpClient = new HttpClient();
//
// @SuppressWarnings("deprecation")
// public void run() {
// HostConfiguration hostConfiguration = new HostConfiguration();
// hostConfiguration.setProxy("127.0.0.1", PORT);
// httpClient.setHostConfiguration(hostConfiguration);
//// CustomGetMethod get = new CustomGetMethod("http://www.baidu.com");
// GetMethod get = new GetMethod("http://www.baidu.com");
//
// try {
// get.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
// get.addRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
// get.addRequestHeader("Cache-Control", "max-age=0");
// get.addRequestHeader("Accept-Encoding", "gzip,deflate,sdch");
// get.addRequestHeader("Cookie","__zpspc=188.1.1409195668.1409195668.1%234%7C%7C%7C%7C%7C; BDUSS=E45eXUtamxkY2JUbS12ZjFUSmJPbWdmUU13Ri1ZVHlzWWx2S1B3YXRxRVNUU1pVQVFBQUFBJCQAAAAAAAAAAAEAAAAOfOsxd29uYW5ndW8xMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABLA~lMSwP5Tc; cflag=65535%3A1; BD_UPN=123143; BD_HOME=1; BAIDUID=12B697CB05FD662D2CA4416FF118FCD8:FG=1; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; BD_CK_SAM=1; H_PS_PSSID=8307_5228_1466_7800_8235_8488_8057_6506_6017_8251_7607_7799_8483_8457_8167_8509_8435_8382_8114; BD_HOME=1");
//
// int statusCode = this.httpClient.executeMethod(get);
// System.out.println(statusCode);
// System.out.println(new String(get.getResponseBody(),Charset.forName("utf-8")));
// } catch (URIException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (HttpException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// }
//
// }
}

View File

@ -117,6 +117,7 @@ addIp=Add IP
testPlanName=Test Plan Name
plugin_jsp_addNewPlugin=Add a new plug-in
plugin_jsp_chooseBehaviors=Choose the behaviors of plug-in
plugin_jsp_chooseFilter=Choose the filter of behaviors
plugin_jsp_removeAll=Remove All
plugin_jsp_remove=Remove
plugin_jsp_cancel=Cancel
@ -132,6 +133,7 @@ plugin_jsp_scriptName=Script Name:
plugin_jsp_insertBefore=Insert Before
plugin_jsp_insertAfter=Insert After
plugin_jsp_clear=Clear
plugin_jsp_filter=Filter
plugin_jsp_insertChild=Insert Child
plugin_jsp_addPage=Add Page
script_jsp_makeScript=ScriptEdit
@ -207,4 +209,6 @@ testExecuteTime=Execute Time
startServerFail=Fail to start record server:
stopTestPlan=Stop Test
stop=Stop
testProxySettings=testProxySettings
testProxySettings=testProxySettings
startRecording=startRecording
startrecording=start recording to generate a script or upload a script to server

View File

@ -118,6 +118,7 @@ startTest=\u5F00\u59CB\u6D4B\u8BD5
testPlanName=\u6D4B\u8BD5\u540D\u79F0
plugin_jsp_addNewPlugin=\u6DFB\u52A0\u4E00\u4E2A\u65B0\u7684\u63D2\u4EF6
plugin_jsp_chooseBehaviors=\u9009\u62E9\u63D2\u4EF6\u7684\u52A8\u4F5C
plugin_jsp_chooseFilter=\u9009\u62e9\u8981\u8fc7\u6ee4\u7684\u884c\u4e3a
plugin_jsp_removeAll=\u5168\u90E8\u79FB\u9664
plugin_jsp_remove=\u79FB\u9664
plugin_jsp_cancel=\u53D6\u6D88
@ -134,6 +135,7 @@ plugin_jsp_insertBefore=\u524D\u5BFC\u5165
plugin_jsp_insertAfter=\u540E\u5BFC\u5165
plugin_jsp_insertChild=\u63D2\u5165
plugin_jsp_clear=\u6E05\u7A7A
plugin_jsp_filter=\u8fc7\u6ee4
plugin_jsp_addPage=\u52A0\u9875
script_jsp_makeScript=\u811A\u672C\u7F16\u8F91
script_jsp_recordScript=\u5F55\u5236\u811A\u672C
@ -208,4 +210,6 @@ startServer=\u70B9\u51FB\u542F\u52A8\u670D\u52A1\u5F55\u5236\u811A\u672C\u6216\u
testExecuteTime=\u6267\u884C\u65F6\u95F4
stopTestPlan=\u505C\u6B62\u6D4B\u8BD5
stop=\u505C\u6B62
testProxySettings=\u6d4b\u8bd5Proxy\u8bbe\u7f6e
testProxySettings=\u6d4b\u8bd5Proxy\u8bbe\u7f6e
startRecording=\u5f00\u59cb\u5f55\u5236
startrecording=\u70b9\u51fb\u5f00\u59cb\u5f55\u5236\u5f55\u5236\u811a\u672c

View File

@ -45,4 +45,6 @@ stopRecord=The script recording has been stopped, please input the script name a
saveScriptSuccess=Save successfully.
saveScriptFail=Fail to save script.
plugin_jsp_addPage=Add Page
stopTestPlan_fail=Stop running test plan fail
stopTestPlan_fail=Stop running test plan fail
RecordingScript=Recording Script
stopRecord=click stop server to stop recording script

View File

@ -41,4 +41,6 @@ stopRecord=\u505C\u6B62\u811A\u672C\u5F55\u5236\uFF0C\u8BF7\u8F93\u5165\u811A\u6
saveScriptSuccess=\u4FDD\u5B58\u6210\u529F\u3002
saveScriptFail=\u4FDD\u5B58\u811A\u672C\u5931\u8D25
plugin_jsp_addPage=\u52A0\u9875
stopTestPlan_fail=\u505C\u6B62\u8FD0\u884C\u6D4B\u8BD5\u8BA1\u5212\u5931\u8D25
stopTestPlan_fail=\u505C\u6B62\u8FD0\u884C\u6D4B\u8BD5\u8BA1\u5212\u5931\u8D25
RecordingScript=\u6b63\u5728\u5f55\u5236\u811a\u672c
stopRecord=\u70b9\u51fb\u505c\u6b62\u670d\u52a1\u5668\u505c\u6b62\u5f55\u5236\u811a\u672c

View File

@ -155,13 +155,6 @@ body {
<fmt:message key="uploadScript" />
</button>
</div>
<div id="fileName" style="display: none" class="modal-footer">
<input class="input-mini" name="scriptname"></input>
<button type="button" class="btn btn-primary"
onClick="saveScript()">
<fmt:message key="savefile" />
</button>
</div>
</div>
<div class="modal hide fade" id="mySecondModal">
@ -185,13 +178,6 @@ body {
<fmt:message key="plugin_jsp_cancel" />
</button>
</div>
<div id="fileName" style="display: none" class="modal-footer">
<input class="input-mini" name="scriptname"></input>
<button type="button" class="btn btn-primary"
onClick="saveScript()">
<fmt:message key="savefile" />
</button>
</div>
</div>
<div class="modal hide fade" id="myThirdModal">

View File

@ -70,6 +70,7 @@ function stopServer() {
}
else {
$('#stopServer').attr('disabled', false);
$('#fileName').show();
$('#scriptInfo3').text(
$.i18n.prop("stopRecord")
@ -136,7 +137,7 @@ function testRecordProxy() {
$('#scriptInfo3').text(
$.i18n.prop("RecordingScript"));
//$('#startServer').attr('disabled', true);
$('#stopServer').attr('disabled', true);
//$('#stopServer').attr('disabled', true);
} else {
$('#scriptInfo2').html(
$.i18n.prop("ProxySettingError") + data.failedMessage);
@ -157,7 +158,11 @@ function startRecording() {
$('#startRecording').attr('disabled', true);
}
else {
window.open('http://www.baidu.com/')
$('#scriptInfo3').text($.i18n.prop("stopRecord"));
var url = $('#target-url').val();
window.open(url);
$('#stopServer').attr('disabled', false);
$('#startRecording').attr('disabled', true);
}
}, "json");
} else {

View File

@ -1,4 +1,5 @@
var script = new Array();
var filter = new Array();
$(document).ready(function() {
$.post("loadScripts", {}, function(data) {
if (!data.success) {
@ -23,6 +24,53 @@ $(document).ready(function() {
$(document).ready(function() {
loadSchedulePlot();
});
function createFilter(){
$.post("loadFilterTypeList", {}, function(data) {
if(!data.success){
information(data.failedMessage);
return;
}else{
$('#selectFilter').show();
data = data.filterTypeList;
for ( var i = 0; i < data.length; i++)
filter.push(data[i]);
for( var j = 0; j < filter.length; j++){
var textNode = document.createTextNode(filter[j]);
var checkboxNode = document.createElement("input");
checkboxNode.setAttribute("type", "checkbox");
checkboxNode.setAttribute("name", "filterList");
checkboxNode.setAttribute("id", "filterList"+j);
checkboxNode.appendChild(textNode);
/* var line = $("<div style='cursor:pointer;'>");
line.click(function(){
document.getElementById(id).checked = true;
})
var input = $("<input type='radio' name="+name+" id="+id+">");
input.attr("value",value);
input.attr("text",text);
var span = $("<label for="+id+" style='cursor:pointer;'>");
span.html(text);
line.append(input);
line.append(span);
line.addClass("line");
*/
$('#filterList').append(checkboxNode);
}
}
});
}
$("#selectFilter #ok").click(function() {
$("#selectFilter").hide();
});
$("#selectFilter #cancel").click(function() {
$("#selectFilter").hide();
});
function toggleTestExecutionPlan() {
$("#loadTestExecutionPlan").slideToggle();
$('#loadConfigMessage').attr("class", "hide");

View File

@ -151,14 +151,14 @@ body {
</select></td>
<td><input type="checkbox" name="staticResources"
<!-- <td><input type="checkbox" name="staticResources"
value="false" data-toggle="tooltip" data-placement="left"
title=<fmt:message key="staticTip" />> <fmt:message
key="filterStatic" /></td>
<td><input type="checkbox" name="timer" value="false"
data-toggle="tooltip" data-placement="left"
title=<fmt:message key="timeTip" />> <fmt:message
key="filterTime" /><br></td>
key="filterTime" /><br></td> -->
<td><a href="#" class="button" onClick="viewScript(this)"><img
src="images/script_edit.png" alt="Add"> <fmt:message
key="test-editScript" /></a></td>
@ -183,7 +183,27 @@ body {
onClick="createNewScript()">
<fmt:message key="test_jsp_makeNewScript" />
</button>
<button type="submit" class="btn btn-primary" id="createFilter"
onClick="createFilter()">
<fmt:message key="plugin_jsp_filter" />
</button>
<div class="modal hide" id="selectFilter">
<!-- <div class="modal-header">
<h3><fmt:message key="plugin_jsp_addNewPlugin" /></h3>
</div> -->
<div class="modal-body">
<div class="inset scroll" id="filterList"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-width" id="ok">
<fmt:message key="plugin_jsp_finish" />
</button>
<button type="button" class="btn btn-primary btn-width" id="cancel">
<fmt:message key="plugin_jsp_cancel" />
</button>
</div>
</div>
<div id="userConfigMessage" class="hide">all input can not
be empty and must be greater than zero!</div>
</div>