Merge branch 'master' of https://github.com/lostcharlie/Bench4Q
This commit is contained in:
commit
00c1afd5b4
|
@ -1,5 +1,6 @@
|
|||
package org.bench4q.recorder.httpcapture.generator;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ResponseHeader {
|
||||
|
@ -18,6 +19,7 @@ public class ResponseHeader {
|
|||
private String contentEncoding;
|
||||
private int contentLength;
|
||||
private String transferEncoding;
|
||||
private Charset contentCharset;
|
||||
|
||||
public int getRespCode() {
|
||||
return respCode;
|
||||
|
@ -81,4 +83,12 @@ public class ResponseHeader {
|
|||
public void setTransferEncoding(String transferEncoding) {
|
||||
this.transferEncoding = transferEncoding;
|
||||
}
|
||||
|
||||
public Charset getContentCharset() {
|
||||
return contentCharset;
|
||||
}
|
||||
|
||||
public void setContentCharset(Charset charset) {
|
||||
this.contentCharset = charset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.nio.charset.Charset;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.recorder.httpcapture.ResponseModel;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
public class ResponseParser {
|
||||
private Logger logger = Logger.getLogger(ResponseParser.class);
|
||||
|
@ -80,7 +81,7 @@ public class ResponseParser {
|
|||
}
|
||||
|
||||
private String parseContentType(HttpURLConnection httpURLConnection) {
|
||||
|
||||
|
||||
String ret = null;
|
||||
String value = httpURLConnection.getHeaderField("Content-Type");
|
||||
int pos;
|
||||
|
@ -96,14 +97,11 @@ public class ResponseParser {
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private String parseTransferEncoding(HttpURLConnection httpURLConnection) {
|
||||
|
||||
|
||||
return httpURLConnection.getHeaderField("Transfer-Encoding");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void parseResponseBody() {
|
||||
ContentDecoder contentDecoder = ContentDecoder.createDecoder(this
|
||||
.getResponseHeader().getContentEncoding());
|
||||
|
@ -119,25 +117,54 @@ public class ResponseParser {
|
|||
try {
|
||||
charset = Charset.forName(this.getResponseHeader().getCharset());
|
||||
} catch (Exception e) {
|
||||
charset = Charset.forName("utf-8");
|
||||
charset = getCharsetFromContent(contentBodyAfterDecoded);
|
||||
if(charset == null){
|
||||
charset = Charset.forName("utf-8");
|
||||
}
|
||||
this.getResponseHeader().setContentCharset(charset);
|
||||
logger.error(e, e);
|
||||
}
|
||||
this.setResponseBody(new String(contentBodyAfterDecoded, charset));
|
||||
}
|
||||
|
||||
public byte[] encodeCoent(String responseBody){
|
||||
|
||||
private Charset getCharsetFromContent(byte[] content) {
|
||||
String contentString = new String(content,
|
||||
Charset.forName("iso-8859-1")).toLowerCase();
|
||||
int pos = contentString.indexOf("charset=");
|
||||
if (pos == -1)
|
||||
return null;
|
||||
pos += 8;
|
||||
char tempChar = contentString.charAt(pos);
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
if (tempChar == '"') {
|
||||
pos++;
|
||||
}
|
||||
while ((tempChar = contentString.charAt(pos)) != '"') {
|
||||
sBuilder.append(tempChar);
|
||||
pos++;
|
||||
}
|
||||
try {
|
||||
return Charset.forName(sBuilder.toString());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encodeCoent(String responseBody) {
|
||||
ContentEncoder contentEncoder = ContentEncoder.createEncoder(this
|
||||
.getResponseHeader().getContentEncoding());
|
||||
Charset charset = null;
|
||||
try {
|
||||
charset = Charset.forName(this.getResponseHeader().getCharset());
|
||||
} catch (Exception e) {
|
||||
charset = Charset.forName("utf-8");
|
||||
charset = this.getResponseHeader().getContentCharset();
|
||||
if(charset == null)
|
||||
charset = Charset.forName("utf-8");
|
||||
logger.error(e, e);
|
||||
}
|
||||
byte[] responseBytes = responseBody.getBytes(charset);
|
||||
responseBytes = contentEncoder.encoderContent(responseBytes);
|
||||
|
||||
|
||||
return responseBytes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,10 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class ScheduleModel {
|
||||
private List<PointModel> points;
|
||||
|
||||
@XmlElementWrapper(name = "points")
|
||||
@XmlElement(name = "point")
|
||||
|
||||
public List<PointModel> getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
@ -45,22 +43,28 @@ public class ScheduleModel {
|
|||
return result;
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
public static class PointModel {
|
||||
// Time Unit is second
|
||||
private long timeInSecond;
|
||||
private int load;
|
||||
|
||||
@XmlElement
|
||||
|
||||
public PointModel() {
|
||||
}
|
||||
|
||||
public PointModel(long timeInSecond, int load) {
|
||||
this.setTimeInSecond(timeInSecond);
|
||||
this.setLoad(load);
|
||||
}
|
||||
|
||||
public long getTimeInSecond() {
|
||||
return timeInSecond;
|
||||
}
|
||||
|
||||
public void setTimeInSecond(long time) {
|
||||
this.timeInSecond = time;
|
||||
public void setTimeInSecond(long timeInSecond) {
|
||||
this.timeInSecond = timeInSecond;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getLoad() {
|
||||
return load;
|
||||
}
|
||||
|
@ -68,13 +72,5 @@ public class ScheduleModel {
|
|||
public void setLoad(int load) {
|
||||
this.load = load;
|
||||
}
|
||||
|
||||
public PointModel() {
|
||||
}
|
||||
|
||||
public PointModel(long timeInSecond, int load) {
|
||||
this.timeInSecond = timeInSecond;
|
||||
this.load = load;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class WebScriptModel {
|
|||
public WebScriptModel(int id, int load, ScheduleModel scheduleModel,
|
||||
String filterTypeMatches) {
|
||||
this.id = id;
|
||||
this.scheduleModel = scheduleModel;
|
||||
this.setScheduleModel(scheduleModel);
|
||||
this.filterTypeMatches = filterTypeMatches;
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,7 @@ public class WebScriptModel {
|
|||
this.isFilterTimer = timer;
|
||||
}
|
||||
|
||||
public ScheduleModel getScheduleModel() {
|
||||
return scheduleModel;
|
||||
}
|
||||
|
||||
public void setScheduleModel(ScheduleModel scheduleModel) {
|
||||
this.scheduleModel = scheduleModel;
|
||||
}
|
||||
|
||||
public String getFilterTypeMatches() {
|
||||
return filterTypeMatches;
|
||||
|
@ -50,4 +44,12 @@ public class WebScriptModel {
|
|||
this.filterTypeMatches = filterTypeMatches;
|
||||
}
|
||||
|
||||
public ScheduleModel getScheduleModel() {
|
||||
return scheduleModel;
|
||||
}
|
||||
|
||||
public void setScheduleModel(ScheduleModel scheduleModel) {
|
||||
this.scheduleModel = scheduleModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -91,15 +91,12 @@ select{
|
|||
border:red 2px solid;
|
||||
}
|
||||
.load-config-input{
|
||||
width:150px;
|
||||
width:70%;
|
||||
}
|
||||
.load-config-input-alert{
|
||||
width:100px;
|
||||
border:red 2px solid;
|
||||
}
|
||||
#loadConfig td{
|
||||
padding-left:50px;
|
||||
}
|
||||
.allocation-input{
|
||||
width:100px;
|
||||
}
|
||||
|
@ -114,6 +111,6 @@ select{
|
|||
width:150px;
|
||||
border:red 2px solid;
|
||||
}
|
||||
#addStep{
|
||||
margin-left:50px;
|
||||
div#test-plan-continuous{
|
||||
width:100%;
|
||||
}
|
|
@ -118,9 +118,9 @@ body {
|
|||
<tr>
|
||||
<td>
|
||||
<button id="createNewScript"
|
||||
class="btn btn-primary" onclick="startServer()" type="submit">
|
||||
class="btn btn-primary" type="submit" onclick="startServer()">
|
||||
<fmt:message key="script_jsp_recordScript" />
|
||||
</button> <a href="createScript.jsp"><button id="createScript"
|
||||
</button><a href="createScript.jsp"><button id="createScript"
|
||||
class="btn btn-primary" onclick="#" type="submit">
|
||||
<fmt:message key="home-createScript" />
|
||||
</button> </a>
|
||||
|
|
|
@ -112,6 +112,10 @@ function testRecordProxy() {
|
|||
|
||||
function saveScript() {
|
||||
var scriptName = document.getElementsByName("scriptname")[0].value;
|
||||
if (scriptName == undefined || scriptName == "") {
|
||||
information("need a script name!");
|
||||
return;
|
||||
}
|
||||
$.post("saveScriptRecorded", {
|
||||
scriptName : scriptName,
|
||||
port : server.port,
|
||||
|
@ -126,5 +130,7 @@ function saveScript() {
|
|||
$('#fileName').hide();
|
||||
}
|
||||
loadScript(table, 2);
|
||||
}).error(function(){
|
||||
information("failed to connect server");
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,7 +2,12 @@ $('.btn-setting').click(function(e) {
|
|||
e.preventDefault();
|
||||
$('#myModal').modal('show');
|
||||
});
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
if(startRecordingSuccess){
|
||||
stopRecording();
|
||||
}else if(startServerSuccess)
|
||||
stopServer();
|
||||
}
|
||||
function dismiss(container){
|
||||
$(container).modal('hide');
|
||||
if(startRecordingSuccess){
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
function ScriptModel(ID, load, warmup, cooldown, executeRange, isFilterTimer, filterTypeMatches) {
|
||||
function ScriptModel(ID, schedule, isFilterTimer, filterTypeMatches) {
|
||||
this.id = ID;
|
||||
this.load = load;
|
||||
this.warmup = warmup;
|
||||
this.executeRange = executeRange;
|
||||
this.cooldown = cooldown;
|
||||
this.scheduleModel = schedule;
|
||||
this.isFilterTimer = isFilterTimer;
|
||||
this.filterTypeMatches = filterTypeMatches;
|
||||
};
|
||||
|
|
|
@ -65,7 +65,15 @@ function getScriptId(scriptName) {
|
|||
return scriptId;
|
||||
|
||||
}
|
||||
|
||||
function getPointModelList(allocation,requireLoadArrayObj,executeRangeArrayObj){
|
||||
var pointModelList = new Array();
|
||||
for(var i=1;i< requireLoadArrayObj.length;i++){
|
||||
var realLoad = parseInt(parseInt(requireLoadArrayObj[i].value)*allocation/100);
|
||||
var pointModel = new WebPointModel(parseInt(executeRangeArrayObj[i].value),realLoad);
|
||||
pointModelList.push(pointModel);
|
||||
}
|
||||
return pointModelList;
|
||||
}
|
||||
|
||||
function start() {
|
||||
var scriptList = new Array();
|
||||
|
@ -73,17 +81,16 @@ function start() {
|
|||
ipList = getIpList();
|
||||
var input = $("#userConfig").find("tbody").find("tr").find(".allocation-input");
|
||||
var allocationList = new Array();
|
||||
var loadList = new Array();
|
||||
var requireLoad = parseInt($("#RequireLoad").val());
|
||||
var scriptList = new Array();
|
||||
var scriptIdList = new Array();
|
||||
var warmUp = parseInt($("#WarmUp").val());
|
||||
var coolDown = parseInt($("#CoolDown").val());
|
||||
var executeRange = parseInt($("#ExecuteRange").val());
|
||||
|
||||
//
|
||||
var requireLoadArrayObj = $("#test-plan-continuous").find("input[name='RequireLoad']");
|
||||
var executeRangeArrayObj = $("#test-plan-continuous").find("input[name='ExecuteRange']");
|
||||
|
||||
for ( var i = 0; i < input.length; i++)
|
||||
allocationList.push(parseInt(input[i].value));
|
||||
for ( var j = 0; j < input.length; j++)
|
||||
loadList.push(parseInt(requireLoad * allocationList[j] / 100));
|
||||
|
||||
scriptIdList = getScriptIdList();
|
||||
|
||||
var isFilterTimer = false;
|
||||
|
@ -104,8 +111,8 @@ function start() {
|
|||
filterTypeMatches = filterTypeMatches.substring(0,filterTypeMatches.length-1);
|
||||
|
||||
for ( var k = 0; k < input.length; k++){
|
||||
scriptList.push(new ScriptModel(scriptIdList[k], loadList[k], warmUp,
|
||||
coolDown, executeRange,isFilterTimer,filterTypeMatches));
|
||||
var scheduleModel = new WebScheduleModel(getPointModelList(allocationList[k],requireLoadArrayObj,executeRangeArrayObj));
|
||||
scriptList.push(new ScriptModel(scriptIdList[k],scheduleModel ,isFilterTimer,filterTypeMatches));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ function submitScript(pages,usePlugins,formData) {
|
|||
|
||||
var scriptName = $("#scriptName").val();
|
||||
if (scriptName == undefined || scriptName == "") {
|
||||
information("need a script name!")
|
||||
information("need a script name!");
|
||||
return;
|
||||
}
|
||||
var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages);
|
||||
|
|
|
@ -90,7 +90,7 @@ body {
|
|||
<td><fmt:message key="test-excuteRange" />(s)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input name="RequireLoad" class="load-config-input"
|
||||
<td width="186px"><input name="RequireLoad" class="load-config-input"
|
||||
type="text" value="10"
|
||||
onblur="loadSchedulePlot();checkLoadConfig()" /></td>
|
||||
<td width="186px"><input name="ExecuteRange" class="load-config-input"
|
||||
|
@ -108,7 +108,7 @@ body {
|
|||
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input name="RequireLoad" class="load-config-input"
|
||||
<td width="186px"><input name="RequireLoad" class="load-config-input"
|
||||
type="text" value="10"
|
||||
onblur="loadSchedulePlot();checkLoadConfig()" /></td>
|
||||
<td width="186px"><input name="ExecuteRange" class="load-config-input"
|
||||
|
|
Loading…
Reference in New Issue