Changed process time to backend.
This commit is contained in:
@@ -24,35 +24,53 @@ public class JsonController implements RestController {
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/formatting")
|
||||
public void formatting(Request request, Response response) {
|
||||
long startProcess = System.currentTimeMillis();
|
||||
JsonObject responseJson = new JsonObject();
|
||||
|
||||
try {
|
||||
JsonObject jsonObject = this.gson.fromJson(request.body(), JsonObject.class);
|
||||
JsonObject requestJson = this.gson.fromJson(request.body(), JsonObject.class);
|
||||
|
||||
response.status(200);
|
||||
response.body(this.prettyGson.toJson(jsonObject));
|
||||
|
||||
responseJson.addProperty("data", this.prettyGson.toJson(requestJson));
|
||||
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
|
||||
|
||||
response.body(this.prettyGson.toJson(responseJson));
|
||||
} catch (Exception e) {
|
||||
response.status(500);
|
||||
Throwable cause = e.getCause();
|
||||
if (cause == null) {
|
||||
response.body(e.getMessage());
|
||||
} else {
|
||||
response.body(cause.getMessage());
|
||||
}
|
||||
|
||||
response.status(500);
|
||||
|
||||
responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage());
|
||||
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
|
||||
|
||||
response.body(this.prettyGson.toJson(responseJson));
|
||||
}
|
||||
}
|
||||
|
||||
@ScopedControllerManifest(method = HandlerType.POST, path = "/minimize")
|
||||
public void minimize(Request request, Response response) {
|
||||
long startProcess = System.currentTimeMillis();
|
||||
JsonObject responseJson = new JsonObject();
|
||||
|
||||
try {
|
||||
JsonObject jsonObject = this.prettyGson.fromJson(request.body(), JsonObject.class);
|
||||
JsonObject requestJson = this.prettyGson.fromJson(request.body(), JsonObject.class);
|
||||
|
||||
response.status(200);
|
||||
response.body(this.gson.toJson(jsonObject));
|
||||
|
||||
responseJson.addProperty("data", this.gson.toJson(requestJson));
|
||||
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
|
||||
|
||||
response.body(this.gson.toJson(responseJson));
|
||||
} catch (Exception e) {
|
||||
response.status(500);
|
||||
Throwable cause = e.getCause();
|
||||
if (cause == null) {
|
||||
response.body(e.getMessage());
|
||||
} else {
|
||||
response.body(cause.getMessage());
|
||||
}
|
||||
|
||||
response.status(500);
|
||||
|
||||
responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage());
|
||||
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
|
||||
|
||||
response.body(this.prettyGson.toJson(responseJson));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
function formatAndValidateJson(errorElement) {
|
||||
const input = document.querySelector('#jsonBlock');
|
||||
const processInfo = document.getElementById(errorElement);
|
||||
const start = new Date();
|
||||
|
||||
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
|
||||
|
||||
@@ -10,22 +9,22 @@ function formatAndValidateJson(errorElement) {
|
||||
body: input.textContent
|
||||
})
|
||||
.then(async (response) => {
|
||||
const promise = response.json();
|
||||
if (!response.ok) {
|
||||
throw Error(await response.text());
|
||||
throw Error(await promise);
|
||||
}
|
||||
|
||||
return response.text();
|
||||
return promise;
|
||||
})
|
||||
.then((data) => {
|
||||
input.innerText = data;
|
||||
input.innerText = data.data;
|
||||
processInfo.innerText = "";
|
||||
hljs.highlightElement(input);
|
||||
|
||||
const end = new Date();
|
||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
||||
})
|
||||
.catch((error) => {
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
@@ -34,7 +33,6 @@ function minimizeJson(errorElement) {
|
||||
const input = document.querySelector('#jsonBlock');
|
||||
const processInfo = document.getElementById(errorElement);
|
||||
|
||||
const start = new Date();
|
||||
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize"
|
||||
|
||||
fetch(address, {
|
||||
@@ -42,22 +40,22 @@ function minimizeJson(errorElement) {
|
||||
body: input.textContent
|
||||
})
|
||||
.then(async (response) => {
|
||||
const promise = response.json();
|
||||
if (!response.ok) {
|
||||
throw Error(await response.text());
|
||||
throw Error(await promise);
|
||||
}
|
||||
|
||||
return response.text();
|
||||
return promise;
|
||||
})
|
||||
.then((data) => {
|
||||
input.innerText = data;
|
||||
input.innerText = data.data;
|
||||
processInfo.innerText = "";
|
||||
hljs.highlightElement(input);
|
||||
|
||||
const end = new Date();
|
||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
|
||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
||||
})
|
||||
.catch((error) => {
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
|
||||
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user