add function recording many times in a port

This commit is contained in:
hmm 2014-09-09 09:40:49 +08:00
parent 849961091e
commit 270c4b8d14
8 changed files with 95 additions and 57 deletions

View File

@ -112,30 +112,30 @@ public class ScriptController extends BaseController {
null, null, null); null, null, null);
} }
} }
UUID uuid = UUID.randomUUID();
this.getScriptCapturer().startRecordServer(port.getPort(), this.getScriptCapturer().startRecordServer(port.getPort());
buildScriptSavePath(), uuid.toString());
return buildReponseModel(true, "", this.getScriptCapturer() return buildReponseModel(true, "", this.getScriptCapturer()
.getIpHttpCaptureServerAdress(), port.getPort(), null, null, .getIpHttpCaptureServerAdress(), port.getPort(), null, null,
uuid.toString()); "");
} }
@RequestMapping(value = "/startScriptRecording", method = { @RequestMapping(value = "/startScriptRecording", method = {
RequestMethod.POST, RequestMethod.GET }) RequestMethod.POST, RequestMethod.GET })
@ResponseBody @ResponseBody
public OperateScriptServerResponseModel startScriptRecording( public OperateScriptServerResponseModel startScriptRecording(
@RequestParam int port, @RequestParam String fileNameUUID) { @RequestParam int port) {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) { if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false, return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null, "has no power for stopScriptCapture!!!", "", -1, null,
null, null); null, null);
} }
UUID uuid = UUID.randomUUID();
this.getScriptCapturer().startRecording(port); this.getScriptCapturer().startRecording(port,
buildScriptSavePath(), uuid.toString());
return buildReponseModel(true, "RecordServer stop", "", port, null, return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID); null, uuid.toString());
} }
private String buildScriptSavePath() { private String buildScriptSavePath() {

View File

@ -53,9 +53,9 @@ public class ScriptCapturer {
public void startRecord(int port, String fileDir, String fileName) { public void startRecord(int port, String fileDir, String fileName) {
try { try {
HttpCapture httpCapture = buildACapture(port, fileDir, fileName); HttpCapture httpCapture = buildACapture(port);
httpCapture.startProxyServer(); httpCapture.startProxyServer();
httpCapture.startRecording(); httpCapture.startRecording( fileDir, fileName);
} catch (IOException e1) { } catch (IOException e1) {
System.out.println("Error When start recording!"); System.out.println("Error When start recording!");
e1.printStackTrace(); e1.printStackTrace();
@ -64,9 +64,9 @@ public class ScriptCapturer {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
public void startRecordServer(int port, String fileDir, String fileName){ public void startRecordServer(int port){
try { try {
HttpCapture httpCapture = buildACapture(port, fileDir, fileName); HttpCapture httpCapture = buildACapture(port);
httpCapture.startProxyServer(); httpCapture.startProxyServer();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -76,10 +76,10 @@ public class ScriptCapturer {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void startRecording(int port){ public void startRecording(int port, String filePath, String fileName){
try { try {
HttpCapture httpCapture = this.getHttpCaptureMap().get(new Integer(port)); HttpCapture httpCapture = this.getHttpCaptureMap().get(new Integer(port));
httpCapture.startRecording(); httpCapture.startRecording( filePath, fileName);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -88,8 +88,8 @@ public class ScriptCapturer {
e.printStackTrace(); e.printStackTrace();
} }
} }
private HttpCapture buildACapture(int port, String filePath, String fileName) { private HttpCapture buildACapture(int port) {
HttpCapture httpCapture = new HttpCapture(filePath, fileName, port, HttpCapture httpCapture = new HttpCapture(port,
HTTPCATUREGENERATOR_STRING, new JTextArea()); HTTPCATUREGENERATOR_STRING, new JTextArea());
this.getHttpCaptureMap().put(new Integer(port), httpCapture); this.getHttpCaptureMap().put(new Integer(port), httpCapture);
return httpCapture; return httpCapture;

View File

@ -72,19 +72,33 @@ public class HttpCapture {
return this.getCurrentTest().isRecording(); return this.getCurrentTest().isRecording();
} }
public HttpCapture(String dirPath, String fileName, int localport, // public HttpCapture(String dirPath, String fileName, int localport,
String generator, JTextArea textArea) { // String generator, JTextArea textArea) {
// this.localport = localport;
// System.out.println(dirPath + System.getProperty("file.separator")
// + fileName + ".xml");
//
// File file = new File(dirPath);
// if (!file.exists()) {
// file.mkdirs();
// }
//
// this.resultFile = new File(dirPath
// + System.getProperty("file.separator") + fileName + ".xml");
// this.config = Config.getConfig();
// try {
// this.config.completeInit();
// this.proxy = new ProxyServer(this.localport);
// } catch (Exception e) {
// e.printStackTrace();
// }
// this.currentTest = new Test(this.proxy, new Bench4qTestScriptAdapter(
// new RunScenarioModel()), generator);
// }
public HttpCapture(int localport, String generator, JTextArea textArea) {
this.localport = localport; this.localport = localport;
System.out.println(dirPath + System.getProperty("file.separator")
+ fileName + ".xml");
File file = new File(dirPath);
if (!file.exists()) {
file.mkdirs();
}
this.resultFile = new File(dirPath
+ System.getProperty("file.separator") + fileName + ".xml");
this.config = Config.getConfig(); this.config = Config.getConfig();
try { try {
this.config.completeInit(); this.config.completeInit();
@ -102,7 +116,18 @@ public class HttpCapture {
this.executorService.execute(this.proxy); this.executorService.execute(this.proxy);
} }
public void startRecording() throws IOException, Utils.UserException { public void startRecording(String dirPath, String fileName)
throws IOException, Utils.UserException {
System.out.println(dirPath + System.getProperty("file.separator")
+ fileName + ".xml");
File file = new File(dirPath);
if (!file.exists()) {
file.mkdirs();
}
this.resultFile = new File(dirPath
+ System.getProperty("file.separator") + fileName + ".xml");
this.currentTest.startRecording(); this.currentTest.startRecording();
this.resultFile.createNewFile(); this.resultFile.createNewFile();
this.currentTest.setTestFile(this.resultFile); this.currentTest.setTestFile(this.resultFile);

View File

@ -238,8 +238,7 @@ public class ScriptController extends BaseController {
@ResponseBody @ResponseBody
public Map<String, Object> updateScript( public Map<String, Object> updateScript(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@RequestParam String scriptId, @RequestParam String scriptId, @RequestParam String scriptName,
@RequestParam String scriptName,
@RequestParam String runScenarioModelStr, @RequestParam String runScenarioModelStr,
@RequestParam(required = false) MultipartFile[] paramFiles) { @RequestParam(required = false) MultipartFile[] paramFiles) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
@ -277,17 +276,27 @@ public class ScriptController extends BaseController {
} }
} }
@RequestMapping("startRecording") @RequestMapping("startRecording")
@ResponseBody @ResponseBody
public Map<String, Object> startRecording( public Map<String, Object> startRecording(
@ModelAttribute("accessToken") String accessToken, @ModelAttribute("accessToken") String accessToken,
@RequestParam String port, @RequestParam String scriptRecordUUID) { @RequestParam String port) {
return processScriptResponse( Map<String, Object> map = new HashMap<String, Object>();
new HashMap<String, Object>(), OperateScriptServerResponseModel operateScriptServerResponseModel =
this.getScriptMessager().startRecording(accessToken, this.getScriptMessager().startRecording(accessToken,
port, scriptRecordUUID)); port);
if (operateScriptServerResponseModel.isSuccess()) {
map = success(map);
map.put("server", operateScriptServerResponseModel);
return map;
} else {
map = fail(map,
operateScriptServerResponseModel.getFailCauseString());
return map;
}
} }
@RequestMapping("stopRecordServer") @RequestMapping("stopRecordServer")
@ResponseBody @ResponseBody
public Map<String, Object> stopRecordServer( public Map<String, Object> stopRecordServer(
@ -298,7 +307,7 @@ public class ScriptController extends BaseController {
this.getScriptMessager().stopScriptRecordServer(accessToken, this.getScriptMessager().stopScriptRecordServer(accessToken,
port, scriptRecordUUID)); port, scriptRecordUUID));
} }
@RequestMapping("stopScriptRecording") @RequestMapping("stopScriptRecording")
@ResponseBody @ResponseBody
public Map<String, Object> stopScriptRecording( public Map<String, Object> stopScriptRecording(
@ -306,24 +315,24 @@ public class ScriptController extends BaseController {
@RequestParam String port, @RequestParam String scriptRecordUUID) { @RequestParam String port, @RequestParam String scriptRecordUUID) {
return processScriptResponse( return processScriptResponse(
new HashMap<String, Object>(), new HashMap<String, Object>(),
this.getScriptMessager().stopScriptRecording(accessToken, this.getScriptMessager().stopScriptRecording(accessToken, port,
port, scriptRecordUUID)); scriptRecordUUID));
} }
@RequestMapping("testRecordProxy") @RequestMapping("testRecordProxy")
@ResponseBody @ResponseBody
public Map<String, Object> testRecordProxy( public Map<String, Object> testRecordProxy(
@RequestHeader HttpHeaders headers) { @RequestHeader HttpHeaders headers) {
Map<String,Object> map = new HashMap<String,Object>(); Map<String, Object> map = new HashMap<String, Object>();
//is from proxy // is from proxy
boolean isFromProxy = Boolean.parseBoolean(headers.getFirst("FromProxy")); boolean isFromProxy = Boolean.parseBoolean(headers
if(isFromProxy) .getFirst("FromProxy"));
{ if (isFromProxy) {
success(map); success(map);
}else{ } else {
fail(map,"proxy setting error!"); fail(map, "proxy setting error!");
} }
return map ; return map;
} }
@RequestMapping("saveScriptRecorded") @RequestMapping("saveScriptRecorded")
@ -368,7 +377,7 @@ public class ScriptController extends BaseController {
return map; return map;
} }
private void updateRunScenarioModel(RunScenarioModel runScenarioModel) { private void updateRunScenarioModel(RunScenarioModel runScenarioModel) {
List<BehaviorModel> behaviorModels = new LinkedList<BehaviorModel>(); List<BehaviorModel> behaviorModels = new LinkedList<BehaviorModel>();
for (PageModel pageModel : runScenarioModel.getPages()) { for (PageModel pageModel : runScenarioModel.getPages()) {

View File

@ -27,11 +27,11 @@ public class ScriptMessager extends MasterMessager {
} }
public OperateScriptServerResponseModel startRecording( public OperateScriptServerResponseModel startRecording(
String accessToken, String port, String fileNameUUID) { String accessToken, String port) {
String url = this.getBaseUrl() + "/startScriptRecording"; String url = this.getBaseUrl() + "/startScriptRecording";
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("port", port); params.put("port", port);
params.put("fileNameUUID", fileNameUUID); // params.put("fileNameUUID", fileNameUUID);
return this.getOperateScriptServerResponseModelByPost(url, params, return this.getOperateScriptServerResponseModelByPost(url, params,
accessToken); accessToken);
} }

View File

@ -208,7 +208,7 @@ button#createScript{
<fmt:message key="startRecording" /> <fmt:message key="startRecording" />
</button> </button>
<button type="button" class="btn btn-primary" <button type="button" class="btn btn-primary"
onClick="stopRecording()" id=stopRecording> onClick="stopRecording(false)" id=stopRecording>
<fmt:message key="stopRecording" /> <fmt:message key="stopRecording" />
</button> </button>
</div> </div>

View File

@ -34,7 +34,6 @@ function startRecording() {
if (server != null) { if (server != null) {
$.post("startRecording", { $.post("startRecording", {
port : server.port, port : server.port,
scriptRecordUUID : server.fileName
}, function(data) { }, function(data) {
if (!data.success) { if (!data.success) {
$('#scriptInfo3').text( $('#scriptInfo3').text(
@ -43,6 +42,7 @@ function startRecording() {
$('#startRecording').attr('disabled', false); $('#startRecording').attr('disabled', false);
} }
else { else {
server.fileName = data.server.fileName;
$('#scriptInfo3').text($.i18n.prop("stopRecordingMessage")); $('#scriptInfo3').text($.i18n.prop("stopRecordingMessage"));
var url = $('#target-url2').val(); var url = $('#target-url2').val();
window.open(url); window.open(url);
@ -58,7 +58,7 @@ function startRecording() {
} }
} }
function stopRecording() { function stopRecording(isStopServer) {
if (server != null) { if (server != null) {
$.post("stopScriptRecording", { $.post("stopScriptRecording", {
port : server.port, port : server.port,
@ -71,8 +71,11 @@ function stopRecording() {
else { else {
$('#scriptInfo3').text($.i18n.prop("stopRecord")); $('#scriptInfo3').text($.i18n.prop("stopRecord"));
$('#fileName').show(); $('#fileName').show();
stopServer(); if(isStopServer)
stopServer();
startRecordingSuccess = false; startRecordingSuccess = false;
$('#startRecording').attr('disabled', false);
} }
$('#stopRecording').attr('disabled', true); $('#stopRecording').attr('disabled', true);
}, "json").error(function(){ }, "json").error(function(){
@ -95,6 +98,7 @@ function stopServer() {
} }
else { else {
startServerSuccess = false; startServerSuccess = false;
server = null;
} }
}, "json").error(function(){ }, "json").error(function(){
information($.i18n.prop('failed-connect-server')); information($.i18n.prop('failed-connect-server'));
@ -133,7 +137,7 @@ function saveScript() {
if (data.success) { if (data.success) {
$("#scriptInfo3").text($.i18n.prop("saveScriptSuccess")); $("#scriptInfo3").text($.i18n.prop("saveScriptSuccess"));
$('#fileName').hide(); $('#fileName').hide();
server = null; server.fileName="";
} else { } else {
$("#scriptInfo3").text($.i18n.prop("saveScriptFail") + data.failedMessage); $("#scriptInfo3").text($.i18n.prop("saveScriptFail") + data.failedMessage);
$('#fileName').hide(); $('#fileName').hide();

View File

@ -4,14 +4,14 @@ $('.btn-setting').click(function(e) {
}); });
window.onbeforeunload = function() { window.onbeforeunload = function() {
if(startRecordingSuccess){ if(startRecordingSuccess){
stopRecording(); stopRecording(true);
}else if(startServerSuccess) }else if(startServerSuccess)
stopServer(); stopServer();
} }
function dismiss(container){ function dismiss(container){
$(container).modal('hide'); $(container).modal('hide');
if(startRecordingSuccess){ if(startRecordingSuccess){
stopRecording(); stopRecording(true);
$('#fileName').hide(); $('#fileName').hide();
}else if(startServerSuccess) }else if(startServerSuccess)
stopServer(); stopServer();