add stoprecording and stopproxyserver api

This commit is contained in:
hmm 2014-09-02 15:06:17 +08:00
parent 3349e5e0dc
commit fb2a04fd68
7 changed files with 69 additions and 7 deletions

View File

@ -161,7 +161,7 @@ public class ScriptController extends BaseController {
null, null);
}
this.getScriptCapturer().stopCurrentRecord(port);
this.getScriptCapturer().stopProxyServer(port);
synchronized (PORT_LOCK) {
this.getPortPoolService().backPort(port);
}
@ -170,6 +170,23 @@ public class ScriptController extends BaseController {
null, fileNameUUID);
}
@RequestMapping(value = "/stopScriptRecording", method = {
RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public OperateScriptServerResponseModel stopScriptRecording(
@RequestParam int port, @RequestParam String fileNameUUID) {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null,
null, null);
}
this.getScriptCapturer().stopRecording(port);
return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID);
}
@RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody

View File

@ -95,7 +95,7 @@ public class ScriptCapturer {
return httpCapture;
}
public void stopCurrentRecord(int port) {
public void stopRecording(int port){
try {
HttpCapture httpCapture = this.getHttpCaptureMap().get(
new Integer(port));
@ -104,6 +104,18 @@ public class ScriptCapturer {
}
assert (httpCapture.isRecording());
httpCapture.stopRecording();
} catch (Exception e1) {
System.out.println("Error When stop recording!");
e1.printStackTrace();
}
}
public void stopProxyServer(int port) {
try {
HttpCapture httpCapture = this.getHttpCaptureMap().get(
new Integer(port));
if (httpCapture == null) {
return;
}
httpCapture.shutProxyServer();
this.getHttpCaptureMap().remove(new Integer(port));
} catch (Exception e1) {
@ -111,4 +123,20 @@ public class ScriptCapturer {
e1.printStackTrace();
}
}
// public void stopCurrentRecord(int port) {
// try {
// HttpCapture httpCapture = this.getHttpCaptureMap().get(
// new Integer(port));
// if (httpCapture == null) {
// return;
// }
// assert (httpCapture.isRecording());
// httpCapture.stopRecording();
// httpCapture.shutProxyServer();
// this.getHttpCaptureMap().remove(new Integer(port));
// } catch (Exception e1) {
// System.out.println("Error When stop recording!");
// e1.printStackTrace();
// }
// }
}

View File

@ -6,7 +6,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
@ -300,6 +299,17 @@ public class ScriptController extends BaseController {
port, scriptRecordUUID));
}
@RequestMapping("stopScriptRecording")
@ResponseBody
public Map<String, Object> stopScriptRecording(
@ModelAttribute("accessToken") String accessToken,
@RequestParam String port, @RequestParam String scriptRecordUUID) {
return processScriptResponse(
new HashMap<String, Object>(),
this.getScriptMessager().stopScriptRecording(accessToken,
port, scriptRecordUUID));
}
@RequestMapping("testRecordProxy")
@ResponseBody
public Map<String, Object> testRecordProxy(

View File

@ -17,7 +17,6 @@ import org.bench4q.share.helper.ExceptionLog;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.bench4q.share.models.master.ScriptHandleModel;
import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanModel;

View File

@ -46,6 +46,16 @@ public class ScriptMessager extends MasterMessager {
accessToken);
}
public OperateScriptServerResponseModel stopScriptRecording(
String accessToken, String port, String fileNameUUID) {
String url = this.getBaseUrl() + "/stopScriptRecording";
Map<String, String> params = new HashMap<String, String>();
params.put("port", port);
params.put("fileNameUUID", fileNameUUID);
return this.getOperateScriptServerResponseModelByPost(url, params,
accessToken);
}
public OperateScriptServerResponseModel saveScriptRecorded(
String accessToken, String scriptName, String port,
String fileNameUUID) {

View File

@ -1,7 +1,5 @@
package org.bench4q.web.model;
import java.util.ArrayList;
import java.util.List;
public class WebScriptModel {

View File

@ -143,7 +143,7 @@ body {
</div>
<div class="modal-body">
<p id="scriptInfo"><fmt:message key="startServer" /></p>
<input autofocus class="input" id="target-url" name="target-url" type="url" value="http://">
<input class="input" id="target-url" name="target-url" type="url" value="http://">
</div>
<div class="modal-footer">