APIClient variable 처리 수정

This commit is contained in:
현성필
2024-02-19 15:18:14 +09:00
parent a77c7a6965
commit 47d997866a
3 changed files with 17 additions and 17 deletions
+16 -12
View File
@@ -12,7 +12,6 @@ class APIClient {
constructor() { constructor() {
window.globals = {}; window.globals = {};
this.variables = {};
this.abortController = null; this.abortController = null;
this.contextPath = document.querySelector('meta[name="context-path"]').getAttribute('content'); this.contextPath = document.querySelector('meta[name="context-path"]').getAttribute('content');
@@ -31,8 +30,9 @@ class APIClient {
async sendAPIRequest(model, preProcessCallback, consoleOutput) { async sendAPIRequest(model, preProcessCallback, consoleOutput) {
try { try {
const updatedModel = await this.executePreRequestScript(model, consoleOutput); let variables = {};
let processedRequest = this.replacePlaceholdersWithVariables(updatedModel); const updatedModel = await this.executePreRequestScript(model, variables, consoleOutput);
let processedRequest = this.replacePlaceholdersWithVariables(updatedModel, variables);
if (preProcessCallback) { if (preProcessCallback) {
preProcessCallback(processedRequest); preProcessCallback(processedRequest);
@@ -46,7 +46,7 @@ class APIClient {
} }
const finalResponse = this.formatResponse(responseData); const finalResponse = this.formatResponse(responseData);
return this.executePostRequestScript(model.postRequestScript, finalResponse, consoleOutput).catch(error => { return this.executePostRequestScript(model.postRequestScript, variables, processedRequest, finalResponse, consoleOutput).catch(error => {
$('.toast-body').text(error); $('.toast-body').text(error);
$('.toast').toast('show'); $('.toast').toast('show');
return finalResponse; // Return the original response even if there's an error in the post-request script return finalResponse; // Return the original response even if there's an error in the post-request script
@@ -99,7 +99,7 @@ class APIClient {
} }
} }
replacePlaceholdersWithVariables(original) { replacePlaceholdersWithVariables(original, variables) {
let request = JSON.parse(JSON.stringify(original)); let request = JSON.parse(JSON.stringify(original));
let mergedVariables = {}; let mergedVariables = {};
@@ -107,8 +107,8 @@ class APIClient {
mergedVariables[key] = value; mergedVariables[key] = value;
}); });
if (this.variables) { if (variables) {
_.forEach(this.variables, (value, key) => { _.forEach(variables, (value, key) => {
mergedVariables[key] = value; mergedVariables[key] = value;
}); });
} }
@@ -139,12 +139,12 @@ class APIClient {
return request; return request;
} }
executePreRequestScript(model, consoleOutput) { executePreRequestScript(model, variables, consoleOutput) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let script = model.preRequestScript; let script = model.preRequestScript;
let resultFrame = document.getElementById('preRequest'); let resultFrame = document.getElementById('preRequest');
this.variables = {};
window.preRequestComplete = (updatedModel, error) => { window.preRequestComplete = (updatedModel, error) => {
if (error) { if (error) {
@@ -154,7 +154,7 @@ class APIClient {
} }
}; };
window.temp_variable = this.variables; window.temp_variable = variables;
window.currentRequest = model; window.currentRequest = model;
window.consoleOutput = consoleOutput; window.consoleOutput = consoleOutput;
resultFrame.srcdoc = `<script> resultFrame.srcdoc = `<script>
@@ -179,11 +179,13 @@ class APIClient {
}); });
} }
executePostRequestScript(script, response, consoleOutput) { executePostRequestScript(script, variables, request, response, consoleOutput) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let resultFrame = document.getElementById('postRequest'); let resultFrame = document.getElementById('postRequest');
window.request = request;
window.response = response; window.response = response;
window.temp_variable = this.variables; window.temp_variable = variables;
window.postRequestComplete = (response, error) => { window.postRequestComplete = (response, error) => {
if (error) { if (error) {
reject(error); reject(error);
@@ -201,7 +203,9 @@ class APIClient {
}; };
window.globals = window.parent.globals; window.globals = window.parent.globals;
window.variables = window.parent.temp_variable; window.variables = window.parent.temp_variable;
window.request = window.parent.request;
window.response = window.parent.response; window.response = window.parent.response;
try { try {
${script} ${script}
window.parent.postRequestComplete(window.response, null); window.parent.postRequestComplete(window.response, null);
-4
View File
@@ -178,7 +178,6 @@ class APITester {
</div> </div>
</div> </div>
</div> </div>
<!-- <div class="resizer" data-direction="vertical"></div>-->
<div class="api_response" style="flex: 1"> <div class="api_response" style="flex: 1">
<div class="mt-1"> <div class="mt-1">
<span>Response</span> <span>Response</span>
@@ -719,9 +718,6 @@ class APITester {
model.postRequestScript = postRequestEditor.getValue(); model.postRequestScript = postRequestEditor.getValue();
}); });
// apiRequestTabContent.find('.resizer').each(function(index, ele) {
// resizable(ele, () => {this.resizeEditor();});
// });
} }
renderResponse(tabIndex) { renderResponse(tabIndex) {
@@ -24,7 +24,7 @@ public class LoadTestGraphBuilder {
Map<String, ScenarioNode> graphData; Map<String, ScenarioNode> graphData;
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
graphData = objectMapper.readValue(data, new TypeReference<>() { graphData = objectMapper.readValue(data, new TypeReference<Map<String, ScenarioNode>>() {
}); });
return graphData; return graphData;
} }