Merge branch 'master' of gitea.release11.com:R11/release11-tools into widlam/refactor/issue#201

This commit is contained in:
2023-05-25 14:59:43 +02:00
15 changed files with 68 additions and 41 deletions

View File

@@ -9,11 +9,11 @@ import Parser
app = Flask(__name__)
CORS(app)
cors = CORS(app, resource={
r"/*":{
"origins":"*"
}
})
# cors = CORS(app, resource={
# r"/*":{
# "origins":"*"
# }
# })
def process_xml(request: request, type: str) -> str:
"""Function to process

View File

@@ -1,8 +1,7 @@
package com.r11.tools.controller;
import com.google.gson.Gson;
import com.google.gson.*;
//import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.r11.tools.controller.internal.GlobalControllerManifest;
import com.r11.tools.controller.internal.HandlerType;
import com.r11.tools.controller.internal.RestController;
@@ -11,6 +10,9 @@ import spark.Request;
import spark.Response;
import org.apache.logging.log4j.Logger;
import java.util.List;
import java.util.Map;
@GlobalControllerManifest(path = "/json")
public class JsonController implements RestController {
@@ -32,9 +34,7 @@ public class JsonController implements RestController {
JsonObject responseJson = new JsonObject();
try {
JsonObject requestJson = this.gson.fromJson(request.body(), JsonObject.class);
response.status(200);
Object requestJson = this.gson.fromJson(request.body(), Object.class);
responseJson.addProperty("data", this.prettyGson.toJson(requestJson));
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
@@ -61,7 +61,7 @@ public class JsonController implements RestController {
JsonObject responseJson = new JsonObject();
try {
JsonObject requestJson = this.prettyGson.fromJson(request.body(), JsonObject.class);
Object requestJson = this.prettyGson.fromJson(request.body(), Object.class);
response.status(200);

View File

@@ -2,7 +2,7 @@ const tools = new Map();
/**
* Get address of Mock Services
*
*
* @function
* @name getMockHost
* @kind function
@@ -30,7 +30,14 @@ function init() {
tools.set("mock", "tools/mock.html");
changeActiveTools('XML');
loadLastPage();
var toolUrl = window.location.search.substring(1);
if (toolUrl == "")
loadLastPage();
else if (tools.has(toolUrl))
changeTool(toolUrl);
else
loadLastPage();
}
/**
@@ -81,6 +88,7 @@ function changeTool(tool) {
const url = tools.get(tool);
localStorage.setItem("lastPage", tool);
document.getElementById("iframe").src = url;
document.location.search = tool;
}
/**

View File

@@ -2,7 +2,7 @@ var clientUUID = '';
var advancedDisplayed = false;
var json = {};
var jsonIndex = 0;
var host = window.location.protocol + "//" + window.location.hostname + ":8097";
var host = window.location.protocol + "//" + window.location.hostname + "/mock";
const C_UUID = 'mock-uuid';
const C_ADV = 'advanced-mode';

View File

@@ -78,7 +78,8 @@ function showHeadersHistory(record){
}
async function formatJSON(json) {
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting";
const backend = "java";
const address = window.location.protocol + "//" + window.location.hostname + "/" + backend + "/json/formatting";
var init = {
body: json,
@@ -98,7 +99,8 @@ async function formatJSON(json) {
}
async function formatXML(xml) {
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify";
const backend = "libxml";
const address = window.location.protocol + "//" + window.location.hostname + "/" + backend + "/prettify";
var data = {
data: xml,
process: "",
@@ -140,7 +142,7 @@ function showRequestBody(element){
});
break;
}
case "application/xml":{
case "application/xml": {
formatXML(historyRequestBody).then(function(result) {
if (result.status == "OK") {
popupContent.innerText = result.result;

View File

@@ -76,7 +76,7 @@ function clearDataField() {
*/
function fillDefaultXML(element) {
if (element.classList.contains("active")) {
const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086";
const serverAddress = window.location.protocol + "//" + window.location.hostname;
clearDefaultContent(document.getElementById("xmlArea"), "Insert XML here");
fetch(serverAddress + "/assets/samples/sampleXml.xml")
.then(response => response.text())
@@ -100,7 +100,7 @@ function fillDefaultXML(element) {
* @returns {void}
*/
function fillDefaultXSD(){
const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086";
const serverAddress = window.location.protocol + "//" + window.location.hostname;
fetch(serverAddress + "/assets/samples/sampleXSD.xsd")
.then( response => response.text() )
.then( (XSDSchema) => {
@@ -126,7 +126,7 @@ function fillDefaultXSD(){
* @returns {void}
*/
function fillDefaultXSLT() {
const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086";
const serverAddress = window.location.protocol + "//" + window.location.hostname;
fetch(serverAddress + "/assets/samples/XSLTTemplate.xslt")
.then( response => response.text() )
.then( (XSTLTemplate) => {
@@ -277,9 +277,9 @@ function performRequest(endpoint, checkXML, checkTransform) {
var xmlData = document.getElementById(sourceId).innerText.trim();
var transformData = document.getElementById(transformId).innerText.trim();
var port = 8081;
var backend = "java";
if (getProcessor() == "libxml") {
port = 8082;
backend = "libxml";
}
var empty = false;
@@ -293,7 +293,7 @@ function performRequest(endpoint, checkXML, checkTransform) {
empty = true;
}
if (!empty) {
restRequest(port, endpoint, xmlData, transformData).then(function (result) {
restRequest(backend, endpoint, xmlData, transformData).then(function (result) {
document.getElementById("resultArea").innerText = result.result;
highlightSyntax("resultArea");
document.getElementById("procinfo").innerText = ' Computed using ' + result.processor;
@@ -333,7 +333,7 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId) {
const sourceElement = document.getElementById(sourceId);
const targetElement = document.getElementById(targetId);
const infoElement = document.getElementById("formatinfo");
const port = 8082;
const backend = "libxml";
var xmlData = sourceElement.innerText.trim();
var empty = false;
@@ -344,7 +344,7 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId) {
}
if (!empty) {
restRequest(port, endpoint, xmlData, "").then(function (result) {
restRequest(backend, endpoint, xmlData, "").then(function (result) {
if (result.status == "OK") {
targetElement.innerText = result.result.trim();
highlightSyntax(targetElement.id);
@@ -374,16 +374,15 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId) {
* @function
* @name restRequest
* @kind function
* @param {any} port of target service
* @param {any} backend target backend
* @param {any} endpoint of target service
* @param {any} xmlData XML that will be sent
* @param {any} transformData data used to transform given XML
* @returns {Promise<any>}
*/
async function restRequest(port, endpoint, xmlData, transformData) {
const escapeChar = "specialEscapeChar";
async function restRequest(backend, endpoint, xmlData, transformData) {
const addr = window.location.protocol + "//" + window.location.hostname + ":" + port + "/" + endpoint;
const addr = window.location.protocol + "//" + window.location.hostname + "/" + backend + "/" + endpoint;
if (defaultStrings.includes(xmlData)) {
xmlData = "<empty/>";

View File

@@ -12,8 +12,26 @@ server {
add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
}
location /java/ {
proxy_pass http://xmltools-backend:8081/;
proxy_set_header Host $host;
}
location /libxml/ {
proxy_pass http://xmltools-libxml-backend/;
proxy_set_header Host $host;
}
location /mock/ {
proxy_pass http://xmltools-mocked-services:8097/;
proxy_set_header Host $host;
proxy_set_header Content-Type $http_content_type;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;

View File

@@ -31,7 +31,7 @@
<button class="action-button active" id="clearXMLButton" style="padding: 3px 10px;"
onclick="clearJsonData()">Clear</button>
<button class="action-button active" id="defaultXMLButton" style="padding: 3px 10px;"
onclick="insertDefaultJson()">Insert default XML</button>
onclick="insertDefaultJson()">Insert default JSON</button>
</div>
</div>
<pre>

View File

@@ -1,3 +1,3 @@
url = "http://localhost:5000/minimize"
url = "http://localhost/libxml/minimize"
data = "@minimize.json"
request = POST

View File

@@ -1,3 +1,3 @@
url = "http://localhost:5000/prettify"
url = "http://localhost:5000/libxml/prettify"
data = "@prettify.json"
request = POST

View File

@@ -1,4 +1,4 @@
#url = "localhost:8081/xpath"
url = "localhost:5000/xpath"
url = "localhost/java/xpath"
#url = "localhost/libxml/xpath"
request = "POST"
data = "@data.json"

View File

@@ -1,4 +1,4 @@
#url = "localhost:8081/xpath"
url = "localhost:5000/xpath"
url = "localhost/java/xpath"
#url = "localhost/libxml/xpath"
request = "POST"
data = "@dataNS.json"

View File

@@ -1,4 +1,4 @@
#url = "http://localhost:8081/xsd"
url = "http://localhost:5000/xsd"
url = "localhost/java/xsd"
#url = "localhost/libxml/xsd"
data = "@xsd.json"
request = POST

View File

@@ -1,4 +1,4 @@
#url = "http://localhost:8081/xslt"
url = "http://localhost:5000/xslt"
url = "localhost/java/xslt"
#url = "localhost/libxml/xslt"
data = "@xslt.json"
request = POST

View File

@@ -10,7 +10,7 @@ services:
container_name: xmltools-frontend
image: xmltools-frontend
ports:
- 8086:80
- 80:80
xmltools-backend:
build: ./Backend/tools-services