finish the messenger with master in web
This commit is contained in:
parent
6ad7385bbd
commit
72c1829682
|
@ -7,7 +7,6 @@ import java.io.FileReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -58,7 +57,7 @@ import com.google.gson.Gson;
|
|||
public class ScriptActionController {
|
||||
|
||||
private CommunicateWithMaster communicateWithMaster;
|
||||
private final String baseUrl = "RecordScript";
|
||||
private final String baseUrl = "script";
|
||||
private ScriptService scriptService;
|
||||
private final String BASECALLER = "ScriptActionController:";
|
||||
|
||||
|
@ -295,7 +294,7 @@ public class ScriptActionController {
|
|||
public BaseResponseModel uploadScript(
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam("script") CommonsMultipartFile script,
|
||||
@RequestParam String scriptName)
|
||||
@RequestParam String scriptName, CommonsMultipartFile[] paramFiles)
|
||||
throws CustomGenericException {
|
||||
if (script.isEmpty()) {
|
||||
return new BaseResponseModel(false, "empty file");
|
||||
|
@ -307,10 +306,12 @@ public class ScriptActionController {
|
|||
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
|
||||
.unmarshal(RunScenarioModel.class, scenarioModel);
|
||||
|
||||
|
||||
HttpResponse httpResponse = this.getCommunicateWithMaster()
|
||||
.uploadScriptWithParamFiles(accessToken, scriptName,
|
||||
runScenarioModel, paramFiles);
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel = (OperateScriptServerResponseModel) MarshalHelper
|
||||
.tryUnmarshal(OperateScriptServerResponseModel.class,
|
||||
"");
|
||||
httpResponse.getContent());
|
||||
|
||||
if (operateScriptServerResponseModel.isSuccess())
|
||||
return new BaseResponseModel(true, (Object) new String(
|
||||
|
@ -395,7 +396,8 @@ public class ScriptActionController {
|
|||
@ResponseBody
|
||||
public BaseResponseModel uploadEditScript(
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String content, @RequestParam CommonsMultipartFile[] paramFiles )
|
||||
@RequestParam String content,
|
||||
@RequestParam CommonsMultipartFile[] paramFiles)
|
||||
throws CustomGenericException {
|
||||
ScenarioModel scenarioModel = null;
|
||||
Gson gson = new Gson();
|
||||
|
@ -414,10 +416,11 @@ public class ScriptActionController {
|
|||
try {
|
||||
ObjectXmlExchange.toXml(RunScenarioModel.class, runScenarioModel);
|
||||
|
||||
HttpResponse httpResponse = this.getCommunicateWithMaster()
|
||||
HttpResponse httpResponse = this.getCommunicateWithMaster()
|
||||
.uploadScriptWithParamFiles(accessToken, scriptName,
|
||||
runScenarioModel, paramFiles);
|
||||
Logger.getLogger(ScriptActionController.class).info(httpResponse.getContent());
|
||||
runScenarioModel, paramFiles);
|
||||
Logger.getLogger(ScriptActionController.class).info(
|
||||
httpResponse.getContent());
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel = (OperateScriptServerResponseModel) MarshalHelper
|
||||
.tryUnmarshal(OperateScriptServerResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
|
@ -429,7 +432,8 @@ public class ScriptActionController {
|
|||
return new BaseResponseModel(false,
|
||||
operateScriptServerResponseModel.getFailCauseString());
|
||||
} catch (JAXBException e) {
|
||||
Logger.getLogger(ScriptActionController.class).info(ExceptionLog.getStackTrace(e));
|
||||
Logger.getLogger(ScriptActionController.class).info(
|
||||
ExceptionLog.getStackTrace(e));
|
||||
return new BaseResponseModel(false,
|
||||
"Failed:invalidated script file!");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.AgentResponseModel;
|
||||
|
||||
public class AgentManagerMessenger extends MasterMessenger {
|
||||
|
||||
public AgentManagerMessenger() {
|
||||
super(MasterAddressManamger.getMasterAddress() + "/agentManage");
|
||||
}
|
||||
|
||||
public AgentResponseModel addAgent(String accessToken,
|
||||
String agentModelContnet) {
|
||||
String url = this.getBaseUrl() + "/addAgentToPool";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPostXml(url,
|
||||
agentModelContnet, makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (AgentResponseModel) MarshalHelper.unmarshal(
|
||||
AgentResponseModel.class, httpResponse.getContent());
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public AgentResponseModel deleteAgent(String accessToken, String agentId,
|
||||
String hostName) {
|
||||
String url = this.getBaseUrl() + "/removeAgentFromPool";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("agentId", agentId);
|
||||
params.put("hostName", hostName);
|
||||
return this.getAgentResponseModel(url, params, accessToken);
|
||||
}
|
||||
|
||||
public AgentResponseModel loadAgents(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/queryAgentList";
|
||||
return this.getAgentResponseModel(url, null, accessToken);
|
||||
|
||||
}
|
||||
|
||||
private AgentResponseModel getAgentResponseModel(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (AgentResponseModel) MarshalHelper.unmarshal(
|
||||
AgentResponseModel.class, httpResponse.getContent());
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -63,6 +64,15 @@ public abstract class MasterMessenger {
|
|||
return true;
|
||||
}
|
||||
logger.info(httpResponse.getContent());
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String buildUrl(List<String> urls) {
|
||||
String url = "";
|
||||
for (String urlPart : urls) {
|
||||
url += "/" + urlPart;
|
||||
}
|
||||
return url;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||
|
@ -35,7 +39,7 @@ public class MonitorMessenger extends MasterMessenger {
|
|||
httpResponse.getContent());
|
||||
return memoryResponseModel;
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (JAXBException |IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
@ -58,7 +62,7 @@ public class MonitorMessenger extends MasterMessenger {
|
|||
.unmarshal(MonitorProcessorResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
return monitorProcessorResponseModel;
|
||||
} catch (Exception e) {
|
||||
} catch (JAXBException |IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.plugin.PluginResponseModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PluginMessenger extends MasterMessenger {
|
||||
public PluginMessenger() {
|
||||
super(MasterAddressManamger.getMasterAddress() + "/plugin");
|
||||
|
@ -14,51 +18,20 @@ public class PluginMessenger extends MasterMessenger {
|
|||
|
||||
public PluginResponseModel loadPluginUIModels(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadPluginList";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!this.validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractPluginResponseModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
return getPluginResponseModelByGet(url, null, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public PluginResponseModel loadPluginNameList(String accessToken) {
|
||||
|
||||
String url = this.getBaseUrl() + "/loadPluginNameList";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractPluginResponseModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
return getPluginResponseModelByGet(url, null, accessToken);
|
||||
}
|
||||
|
||||
public PluginResponseModel loadBehaviors(String accessToken,
|
||||
String pluginName) {
|
||||
String url = this.getBaseUrl() + "/loadBehaviors" + "/" + pluginName;
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return this.extractPluginResponseModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
return this.getPluginResponseModelByGet(url, null, accessToken);
|
||||
|
||||
}
|
||||
|
||||
|
@ -72,20 +45,36 @@ public class PluginMessenger extends MasterMessenger {
|
|||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractPluginResponseModel(httpResponse);
|
||||
} catch (Exception e) {
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public PluginResponseModel deletePlugin(String accessToken,String pluginName){
|
||||
String url=this.getBaseUrl()+"/deletePlugin"+"/"+pluginName;
|
||||
HttpResponse httpResponse=null;
|
||||
// try{
|
||||
//
|
||||
// }
|
||||
return null;
|
||||
public PluginResponseModel deletePlugin(String accessToken,
|
||||
String pluginName) {
|
||||
String url = this.getBaseUrl() + "/deletePlugin" + "/" + pluginName;
|
||||
return getPluginResponseModelByGet(url, null, accessToken);
|
||||
}
|
||||
|
||||
private PluginResponseModel getPluginResponseModelByGet(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractPluginResponseModel(httpResponse);
|
||||
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PluginResponseModel extractPluginResponseModel(
|
||||
HttpResponse httpResponse) throws JAXBException {
|
||||
return (PluginResponseModel) MarshalHelper.unmarshal(
|
||||
|
|
|
@ -1,5 +1,65 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
public class RecordPortMessenger {
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.OrganizeRecordPortResponseModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
public class RecordPortMessenger extends MasterMessenger {
|
||||
|
||||
public RecordPortMessenger() {
|
||||
super(MasterAddressManamger.getMasterAddress() + "/RecordPort");
|
||||
}
|
||||
|
||||
public OrganizeRecordPortResponseModel addPort(String accessToken,
|
||||
String port) {
|
||||
String url = this.getBaseUrl() + "/addPortToPortPool";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("port", port);
|
||||
return getOrganizeRecordPortResponseModel(url, params, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public OrganizeRecordPortResponseModel deletePort(String accessToken,
|
||||
String port) {
|
||||
String url = this.getBaseUrl() + "/removePortFromPool";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("port", port);
|
||||
return getOrganizeRecordPortResponseModel(url, params, accessToken);
|
||||
}
|
||||
|
||||
public OrganizeRecordPortResponseModel loadPorts(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadPortList";
|
||||
return getOrganizeRecordPortResponseModel(url, null, accessToken);
|
||||
}
|
||||
|
||||
private OrganizeRecordPortResponseModel getOrganizeRecordPortResponseModel(
|
||||
String url, Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractOrganizeRecordPortResponseModel(httpResponse);
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private OrganizeRecordPortResponseModel extractOrganizeRecordPortResponseModel(
|
||||
HttpResponse httpResponse) throws JAXBException {
|
||||
return (OrganizeRecordPortResponseModel) MarshalHelper.unmarshal(
|
||||
OrganizeRecordPortResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,139 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
public class ScriptMessenger {
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
@Component
|
||||
public class ScriptMessenger extends MasterMessenger {
|
||||
public ScriptMessenger() {
|
||||
super(MasterAddressManamger.getMasterAddress() + "/script");
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel startScriptRecordServer(
|
||||
String accessToken) {
|
||||
String url = this.getBaseUrl() + "/startScriptRecordServer";
|
||||
return this.getOperateScriptServerResponseModelByPost(url, null,
|
||||
accessToken);
|
||||
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel stopScriptRecordServer(
|
||||
String accessToken) {
|
||||
String url = this.getBaseUrl() + "/stopScriptRecordServer";
|
||||
return this.getOperateScriptServerResponseModelByPost(url, null,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel saveScriptRecorded(
|
||||
String accessToken, String scriptName, String port,
|
||||
String fileNameUUID) {
|
||||
|
||||
String url = this.getBaseUrl() + "/saveScriptToDB";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("scriptName", scriptName);
|
||||
params.put("port", port);
|
||||
params.put("fileNameUUID", fileNameUUID);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel uploadScript(String accessToken,
|
||||
String scriptName, String scenarioModel,
|
||||
CommonsMultipartFile[] paramFiles) {
|
||||
String url = this.getBaseUrl() + "/uploadScript" + "/" + scriptName;
|
||||
List<String> stringPart = new LinkedList<String>();
|
||||
stringPart.add(scenarioModel);
|
||||
HttpResponse httpResponse = null;
|
||||
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().postFilesMulti(
|
||||
makeAccessTockenMap(accessToken), url, "paramFiles[]",
|
||||
paramFiles, "scenarioModel", stringPart);
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (OperateScriptServerResponseModel) MarshalHelper.unmarshal(
|
||||
OperateScriptServerResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel deleteScript(String accessToken,
|
||||
String scriptId) {
|
||||
String url = this.getBaseUrl() + "/deleteScript";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("scriptId", scriptId);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel updateScript(String accessToken,
|
||||
String scriptId, String scriptContent) {
|
||||
String url = this.getBaseUrl() + "/updateScript" + "/" + scriptId;
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("content", scriptContent);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel loadScript(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadScriptList";
|
||||
return this.getOperateScriptServerResponseModelByPost(url, null,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel queryScriptById(String accessToken,
|
||||
String scriptId) {
|
||||
String url = this.getBaseUrl() + "/queryScriptById";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("scriptId", scriptId);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
public OperateScriptServerResponseModel queryScriptByName(
|
||||
String accessToken, String scriptName) {
|
||||
String url = this.getBaseUrl() + "/queryScriptByName";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("name", scriptName);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
}
|
||||
|
||||
private OperateScriptServerResponseModel getOperateScriptServerResponseModelByPost(
|
||||
String url, Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
return extractOperateScriptServerResponseModel(httpResponse);
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private OperateScriptServerResponseModel extractOperateScriptServerResponseModel(
|
||||
HttpResponse httpResponse) throws JAXBException {
|
||||
return (OperateScriptServerResponseModel) MarshalHelper.unmarshal(
|
||||
OperateScriptServerResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,207 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
public class TestPlanMessegner {
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanResponseModel;
|
||||
import org.bench4q.share.models.master.TestPlanResultModel;
|
||||
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPageBriefModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptPagesBriefModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestPlanMessegner extends MasterMessenger {
|
||||
|
||||
public TestPlanMessegner() {
|
||||
super("/testPlan");
|
||||
}
|
||||
|
||||
public TestPlanResultModel submitTestPlan(String accessToken,
|
||||
String testPlanXmlContent) {
|
||||
String url = this.getBaseUrl() + "/runTestPlanWithTestPlanModel";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPostXml(url,
|
||||
testPlanXmlContent, makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResultModel getRunningTestInfo(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/getRunningInfo";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return this.getTestPlanResultModelByPost(url, params, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanScriptBriefResultModel getScriptBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId,
|
||||
String duationBegin) {
|
||||
List<String> urlPart = createUrlPartList(testPlanId, scriptId);
|
||||
urlPart.add(duationBegin);
|
||||
String url = this.getBaseUrl() + this.buildUrl(urlPart);
|
||||
HttpResponse httpResponse = null;
|
||||
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (TestPlanScriptBriefResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanScriptBriefResultModel.class,
|
||||
httpResponse.getContent());
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ScriptBehaviorsBriefModel getScriptBehaviorsBriefResult(
|
||||
String accessToken, String testPlanId, String scriptId) {
|
||||
String url = this.getBaseUrl()
|
||||
+ this.buildUrl(createUrlPartList(testPlanId, scriptId));
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (ScriptBehaviorsBriefModel) MarshalHelper.unmarshal(
|
||||
ScriptBehaviorsBriefModel.class, httpResponse.getContent());
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ScriptPagesBriefModel getPageBriefResult(String accessToken,
|
||||
String testPlanId, String scriptId) {
|
||||
|
||||
String url = this.getBaseUrl()
|
||||
+ this.buildUrl(createUrlPartList(testPlanId, scriptId));
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (ScriptPagesBriefModel) MarshalHelper.unmarshal(
|
||||
ScriptPageBriefModel.class, httpResponse.getContent());
|
||||
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TestPlanResultModel queryTestPlanById(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/queryTestPlan" + "/" + testPlanRunId;
|
||||
return this.getTestPlanResultModelByPost(url, null, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResponseModel deleteTestPlan(String accessToken,
|
||||
String testPlanId) {
|
||||
String url = this.getBaseUrl() + "/removeTestPlanFromPool";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanId", testPlanId);
|
||||
return getTestPlanResponseModel(url, params, accessToken);
|
||||
|
||||
}
|
||||
|
||||
public TestPlanResponseModel loadTestPlans(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadTestPlans";
|
||||
return getTestPlanResponseModel(url, null, accessToken);
|
||||
}
|
||||
|
||||
public HttpResponse getTestPlanReport(String accessToken,
|
||||
String testPlanRunId) {
|
||||
String url = this.getBaseUrl() + "/getTestPlanReport";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("testPlanRunID", testPlanRunId);
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return httpResponse;
|
||||
|
||||
} catch (IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> createUrlPartList(String testPlanId, String scriptId) {
|
||||
List<String> urlParts = new LinkedList<String>();
|
||||
urlParts.add(testPlanId);
|
||||
urlParts.add(scriptId);
|
||||
return urlParts;
|
||||
}
|
||||
|
||||
private TestPlanResponseModel getTestPlanResponseModel(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResponseModel(httpResponse);
|
||||
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResultModel getTestPlanResultModelByPost(String url,
|
||||
Map<String, String> params, String accessToken) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return extractTestPlanResultModel(httpResponse);
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlanResponseModel extractTestPlanResponseModel(
|
||||
HttpResponse httpResponse) throws JAXBException {
|
||||
return (TestPlanResponseModel) MarshalHelper.unmarshal(
|
||||
TestPlanResponseModel.class, httpResponse.getContent());
|
||||
}
|
||||
|
||||
private TestPlanResultModel extractTestPlanResultModel(
|
||||
HttpResponse httpResponse) throws JAXBException {
|
||||
return (TestPlanResultModel) MarshalHelper.unmarshal(
|
||||
TestPlanResultModel.class, httpResponse.getContent());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,88 @@
|
|||
package org.bench4q.web.masterMessenger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.AuthorizeResponseModel;
|
||||
import org.bench4q.share.models.master.RegisterResponseModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class UserMessenger {
|
||||
public class UserMessenger extends MasterMessenger {
|
||||
|
||||
public UserMessenger() {
|
||||
super(MasterAddressManamger.getMasterAddress() + "/user");
|
||||
}
|
||||
|
||||
public RegisterResponseModel register(String accessToken, String userName,
|
||||
String password, String scope) {
|
||||
String url = this.getBaseUrl() + "/register";
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("userName", userName);
|
||||
params.put("password", password);
|
||||
params.put("scope", scope);
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
return null;
|
||||
}
|
||||
return (RegisterResponseModel) MarshalHelper.unmarshal(
|
||||
RegisterResponseModel.class, httpResponse.getContent());
|
||||
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public AuthorizeResponseModel adminLogin(String userName, String password) {
|
||||
String url = this.getBaseUrl() + "/adminAuthorize";
|
||||
return getAuthorizeResponseModel(null, url,
|
||||
makeParams(userName, password));
|
||||
}
|
||||
|
||||
public AuthorizeResponseModel normalLogin(String userName, String password) {
|
||||
String url = this.getBaseUrl() + "/normalAuthorize";
|
||||
|
||||
return getAuthorizeResponseModel(null, url,
|
||||
makeParams(userName, password));
|
||||
}
|
||||
|
||||
|
||||
public AuthorizeResponseModel deleteUser(String userName) {
|
||||
String url = this.getBaseUrl() + "/deleteUser" + "/" + userName;
|
||||
return getAuthorizeResponseModel(null, url, null);
|
||||
}
|
||||
|
||||
private Map<String, String> makeParams(String userName, String password) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("userName", userName);
|
||||
params.put("password", password);
|
||||
return params;
|
||||
}
|
||||
|
||||
private AuthorizeResponseModel getAuthorizeResponseModel(
|
||||
String accessToken, String url, Map<String, String> params) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPost(url, params,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (AuthorizeResponseModel) MarshalHelper.unmarshal(
|
||||
AuthorizeResponseModel.class, httpResponse.getContent());
|
||||
|
||||
} catch (JAXBException | IOException e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,9 +81,15 @@ public class CommunicateWithMaster {
|
|||
String url = masterAddress + "RecordScript/uploadScript/" + scriptName;
|
||||
List<String> stringPart = new LinkedList<String>();
|
||||
stringPart.add(MarshalHelper.tryMarshal(runScenarioModel));
|
||||
return this.getHttpRequester().postFilesMulti(
|
||||
makeAccessTockenMap(accessToken), url, "paramFiles[]",
|
||||
paramFiles, "scenarioModel", stringPart);
|
||||
try {
|
||||
return this.getHttpRequester().postFilesMulti(
|
||||
makeAccessTockenMap(accessToken), url, "paramFiles[]",
|
||||
paramFiles, "scenarioModel", stringPart);
|
||||
} catch (IOException e) {
|
||||
Logger.getLogger(CommunicateWithMaster.class).info(
|
||||
ExceptionLog.getStackTrace(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getRespnseObjectByPostXml(String accessToken, String url,
|
||||
|
|
Loading…
Reference in New Issue