add function recording many times in a port
This commit is contained in:
parent
849961091e
commit
270c4b8d14
|
@ -112,30 +112,30 @@ public class ScriptController extends BaseController {
|
|||
null, null, null);
|
||||
}
|
||||
}
|
||||
UUID uuid = UUID.randomUUID();
|
||||
this.getScriptCapturer().startRecordServer(port.getPort(),
|
||||
buildScriptSavePath(), uuid.toString());
|
||||
|
||||
this.getScriptCapturer().startRecordServer(port.getPort());
|
||||
|
||||
return buildReponseModel(true, "", this.getScriptCapturer()
|
||||
.getIpHttpCaptureServerAdress(), port.getPort(), null, null,
|
||||
uuid.toString());
|
||||
"");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/startScriptRecording", method = {
|
||||
RequestMethod.POST, RequestMethod.GET })
|
||||
@ResponseBody
|
||||
public OperateScriptServerResponseModel startScriptRecording(
|
||||
@RequestParam int port, @RequestParam String fileNameUUID) {
|
||||
@RequestParam int port) {
|
||||
if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return buildReponseModel(false,
|
||||
"has no power for stopScriptCapture!!!", "", -1, null,
|
||||
null, null);
|
||||
}
|
||||
|
||||
this.getScriptCapturer().startRecording(port);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
this.getScriptCapturer().startRecording(port,
|
||||
buildScriptSavePath(), uuid.toString());
|
||||
|
||||
return buildReponseModel(true, "RecordServer stop", "", port, null,
|
||||
null, fileNameUUID);
|
||||
null, uuid.toString());
|
||||
}
|
||||
|
||||
private String buildScriptSavePath() {
|
||||
|
|
|
@ -53,9 +53,9 @@ public class ScriptCapturer {
|
|||
|
||||
public void startRecord(int port, String fileDir, String fileName) {
|
||||
try {
|
||||
HttpCapture httpCapture = buildACapture(port, fileDir, fileName);
|
||||
HttpCapture httpCapture = buildACapture(port);
|
||||
httpCapture.startProxyServer();
|
||||
httpCapture.startRecording();
|
||||
httpCapture.startRecording( fileDir, fileName);
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Error When start recording!");
|
||||
e1.printStackTrace();
|
||||
|
@ -64,9 +64,9 @@ public class ScriptCapturer {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void startRecordServer(int port, String fileDir, String fileName){
|
||||
public void startRecordServer(int port){
|
||||
try {
|
||||
HttpCapture httpCapture = buildACapture(port, fileDir, fileName);
|
||||
HttpCapture httpCapture = buildACapture(port);
|
||||
httpCapture.startProxyServer();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
@ -76,10 +76,10 @@ public class ScriptCapturer {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void startRecording(int port){
|
||||
public void startRecording(int port, String filePath, String fileName){
|
||||
try {
|
||||
HttpCapture httpCapture = this.getHttpCaptureMap().get(new Integer(port));
|
||||
httpCapture.startRecording();
|
||||
httpCapture.startRecording( filePath, fileName);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -88,8 +88,8 @@ public class ScriptCapturer {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private HttpCapture buildACapture(int port, String filePath, String fileName) {
|
||||
HttpCapture httpCapture = new HttpCapture(filePath, fileName, port,
|
||||
private HttpCapture buildACapture(int port) {
|
||||
HttpCapture httpCapture = new HttpCapture(port,
|
||||
HTTPCATUREGENERATOR_STRING, new JTextArea());
|
||||
this.getHttpCaptureMap().put(new Integer(port), httpCapture);
|
||||
return httpCapture;
|
||||
|
|
|
@ -72,19 +72,33 @@ public class HttpCapture {
|
|||
return this.getCurrentTest().isRecording();
|
||||
}
|
||||
|
||||
public HttpCapture(String dirPath, String fileName, int localport,
|
||||
String generator, JTextArea textArea) {
|
||||
// public HttpCapture(String dirPath, String fileName, int localport,
|
||||
// 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;
|
||||
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();
|
||||
|
@ -102,7 +116,18 @@ public class HttpCapture {
|
|||
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.resultFile.createNewFile();
|
||||
this.currentTest.setTestFile(this.resultFile);
|
||||
|
|
|
@ -238,8 +238,7 @@ public class ScriptController extends BaseController {
|
|||
@ResponseBody
|
||||
public Map<String, Object> updateScript(
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String scriptId,
|
||||
@RequestParam String scriptName,
|
||||
@RequestParam String scriptId, @RequestParam String scriptName,
|
||||
@RequestParam String runScenarioModelStr,
|
||||
@RequestParam(required = false) MultipartFile[] paramFiles) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
@ -277,17 +276,27 @@ public class ScriptController extends BaseController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("startRecording")
|
||||
@ResponseBody
|
||||
public Map<String, Object> startRecording(
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String port, @RequestParam String scriptRecordUUID) {
|
||||
return processScriptResponse(
|
||||
new HashMap<String, Object>(),
|
||||
@RequestParam String port) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel =
|
||||
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")
|
||||
@ResponseBody
|
||||
public Map<String, Object> stopRecordServer(
|
||||
|
@ -298,7 +307,7 @@ public class ScriptController extends BaseController {
|
|||
this.getScriptMessager().stopScriptRecordServer(accessToken,
|
||||
port, scriptRecordUUID));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("stopScriptRecording")
|
||||
@ResponseBody
|
||||
public Map<String, Object> stopScriptRecording(
|
||||
|
@ -306,24 +315,24 @@ public class ScriptController extends BaseController {
|
|||
@RequestParam String port, @RequestParam String scriptRecordUUID) {
|
||||
return processScriptResponse(
|
||||
new HashMap<String, Object>(),
|
||||
this.getScriptMessager().stopScriptRecording(accessToken,
|
||||
port, scriptRecordUUID));
|
||||
this.getScriptMessager().stopScriptRecording(accessToken, port,
|
||||
scriptRecordUUID));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("testRecordProxy")
|
||||
@ResponseBody
|
||||
public Map<String, Object> testRecordProxy(
|
||||
@RequestHeader HttpHeaders headers) {
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
//is from proxy
|
||||
boolean isFromProxy = Boolean.parseBoolean(headers.getFirst("FromProxy"));
|
||||
if(isFromProxy)
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
// is from proxy
|
||||
boolean isFromProxy = Boolean.parseBoolean(headers
|
||||
.getFirst("FromProxy"));
|
||||
if (isFromProxy) {
|
||||
success(map);
|
||||
}else{
|
||||
fail(map,"proxy setting error!");
|
||||
} else {
|
||||
fail(map, "proxy setting error!");
|
||||
}
|
||||
return map ;
|
||||
return map;
|
||||
}
|
||||
|
||||
@RequestMapping("saveScriptRecorded")
|
||||
|
@ -368,7 +377,7 @@ public class ScriptController extends BaseController {
|
|||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
private void updateRunScenarioModel(RunScenarioModel runScenarioModel) {
|
||||
List<BehaviorModel> behaviorModels = new LinkedList<BehaviorModel>();
|
||||
for (PageModel pageModel : runScenarioModel.getPages()) {
|
||||
|
|
|
@ -27,11 +27,11 @@ public class ScriptMessager extends MasterMessager {
|
|||
}
|
||||
|
||||
public OperateScriptServerResponseModel startRecording(
|
||||
String accessToken, String port, String fileNameUUID) {
|
||||
String accessToken, String port) {
|
||||
String url = this.getBaseUrl() + "/startScriptRecording";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("port", port);
|
||||
params.put("fileNameUUID", fileNameUUID);
|
||||
// params.put("fileNameUUID", fileNameUUID);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ button#createScript{
|
|||
<fmt:message key="startRecording" />
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary"
|
||||
onClick="stopRecording()" id=stopRecording>
|
||||
onClick="stopRecording(false)" id=stopRecording>
|
||||
<fmt:message key="stopRecording" />
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -34,7 +34,6 @@ function startRecording() {
|
|||
if (server != null) {
|
||||
$.post("startRecording", {
|
||||
port : server.port,
|
||||
scriptRecordUUID : server.fileName
|
||||
}, function(data) {
|
||||
if (!data.success) {
|
||||
$('#scriptInfo3').text(
|
||||
|
@ -43,6 +42,7 @@ function startRecording() {
|
|||
$('#startRecording').attr('disabled', false);
|
||||
}
|
||||
else {
|
||||
server.fileName = data.server.fileName;
|
||||
$('#scriptInfo3').text($.i18n.prop("stopRecordingMessage"));
|
||||
var url = $('#target-url2').val();
|
||||
window.open(url);
|
||||
|
@ -58,7 +58,7 @@ function startRecording() {
|
|||
}
|
||||
}
|
||||
|
||||
function stopRecording() {
|
||||
function stopRecording(isStopServer) {
|
||||
if (server != null) {
|
||||
$.post("stopScriptRecording", {
|
||||
port : server.port,
|
||||
|
@ -71,8 +71,11 @@ function stopRecording() {
|
|||
else {
|
||||
$('#scriptInfo3').text($.i18n.prop("stopRecord"));
|
||||
$('#fileName').show();
|
||||
stopServer();
|
||||
if(isStopServer)
|
||||
stopServer();
|
||||
startRecordingSuccess = false;
|
||||
|
||||
$('#startRecording').attr('disabled', false);
|
||||
}
|
||||
$('#stopRecording').attr('disabled', true);
|
||||
}, "json").error(function(){
|
||||
|
@ -95,6 +98,7 @@ function stopServer() {
|
|||
}
|
||||
else {
|
||||
startServerSuccess = false;
|
||||
server = null;
|
||||
}
|
||||
}, "json").error(function(){
|
||||
information($.i18n.prop('failed-connect-server'));
|
||||
|
@ -133,7 +137,7 @@ function saveScript() {
|
|||
if (data.success) {
|
||||
$("#scriptInfo3").text($.i18n.prop("saveScriptSuccess"));
|
||||
$('#fileName').hide();
|
||||
server = null;
|
||||
server.fileName="";
|
||||
} else {
|
||||
$("#scriptInfo3").text($.i18n.prop("saveScriptFail") + data.failedMessage);
|
||||
$('#fileName').hide();
|
||||
|
|
|
@ -4,14 +4,14 @@ $('.btn-setting').click(function(e) {
|
|||
});
|
||||
window.onbeforeunload = function() {
|
||||
if(startRecordingSuccess){
|
||||
stopRecording();
|
||||
stopRecording(true);
|
||||
}else if(startServerSuccess)
|
||||
stopServer();
|
||||
}
|
||||
function dismiss(container){
|
||||
$(container).modal('hide');
|
||||
if(startRecordingSuccess){
|
||||
stopRecording();
|
||||
stopRecording(true);
|
||||
$('#fileName').hide();
|
||||
}else if(startServerSuccess)
|
||||
stopServer();
|
||||
|
|
Loading…
Reference in New Issue