From 9a948c67e1716d903562543912606daf413d45f9 Mon Sep 17 00:00:00 2001 From: Nicolas Adment <39568358+nadment@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:18:27 +0100 Subject: [PATCH] Remote Work Configurations Won't Work Because of Turkish Characters #3356 Force sending/receiving XML to UTF-8 --- .../src/main/java/org/apache/hop/server/HopServer.java | 10 ++++++---- .../org/apache/hop/www/RegisterPipelineServlet.java | 6 +++--- .../org/apache/hop/www/RegisterWorkflowServlet.java | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/engine/src/main/java/org/apache/hop/server/HopServer.java b/engine/src/main/java/org/apache/hop/server/HopServer.java index eeef474a114..24450295426 100644 --- a/engine/src/main/java/org/apache/hop/server/HopServer.java +++ b/engine/src/main/java/org/apache/hop/server/HopServer.java @@ -513,8 +513,8 @@ public String constructUrl(IVariables variables, String serviceAndArguments) HttpPost buildSendXmlMethod(IVariables variables, byte[] content, String service) throws Exception { - String encoding = Const.getEnvironmentVariable("file.encoding", Const.XML_ENCODING); - return buildSendMethod(variables, content, encoding, service, "text/xml"); + String encoding = Const.XML_ENCODING; + return buildSendMethod(variables, content, encoding, service, "text/xml"); } // Method is defined as package-protected in order to be accessible by unit tests @@ -542,7 +542,7 @@ HttpPost buildSendMethod( public String sendXml(IVariables variables, String xml, String service) throws Exception { String encoding = getXmlEncoding(xml); HttpPost method = - buildSendMethod(variables, xml.getBytes(encoding), encoding, service, "text/xml"); + buildSendMethod(variables, xml.getBytes(encoding), encoding, service, "text/xml"); try { return executeAuth(variables, method); } finally { @@ -579,7 +579,8 @@ private String getXmlEncoding(String xml) { if (matcher.find()) { return matcher.group(); } - return Const.getEnvironmentVariable("file.encoding", Const.XML_ENCODING); + + return Const.XML_ENCODING; } /** Throws if not ok */ @@ -1348,3 +1349,4 @@ public void setPropertiesMasterName(String propertiesMasterName) { this.propertiesMasterName = propertiesMasterName; } } + diff --git a/engine/src/main/java/org/apache/hop/www/RegisterPipelineServlet.java b/engine/src/main/java/org/apache/hop/www/RegisterPipelineServlet.java index 724ce16469e..8b4af9fad59 100644 --- a/engine/src/main/java/org/apache/hop/www/RegisterPipelineServlet.java +++ b/engine/src/main/java/org/apache/hop/www/RegisterPipelineServlet.java @@ -24,10 +24,10 @@ import org.apache.hop.pipeline.PipelineMeta; import org.apache.hop.pipeline.engine.IPipelineEngine; import org.json.simple.parser.ParseException; - +import java.io.IOException; +import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; @HopServerServlet(id = "registerPipeline", name = "Add a pipeline to the server") public class RegisterPipelineServlet extends BaseWorkflowServlet { @@ -48,7 +48,7 @@ WebResult generateBody( IVariables variables) throws IOException, HopException, HopException, ParseException { - final String xml = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); + final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8); // Parse the XML, create a pipeline configuration PipelineConfiguration pipelineConfiguration = PipelineConfiguration.fromXml(xml); diff --git a/engine/src/main/java/org/apache/hop/www/RegisterWorkflowServlet.java b/engine/src/main/java/org/apache/hop/www/RegisterWorkflowServlet.java index c6d059dbd6d..a47eb619c61 100644 --- a/engine/src/main/java/org/apache/hop/www/RegisterWorkflowServlet.java +++ b/engine/src/main/java/org/apache/hop/www/RegisterWorkflowServlet.java @@ -24,10 +24,10 @@ import org.apache.hop.workflow.WorkflowMeta; import org.apache.hop.workflow.engine.IWorkflowEngine; import org.json.simple.parser.ParseException; - +import java.io.IOException; +import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; @HopServerServlet(id = "registerWorkflow", name = "Add a workflow to the server") public class RegisterWorkflowServlet extends BaseWorkflowServlet { @@ -48,7 +48,7 @@ WebResult generateBody( IVariables variables) throws IOException, HopException, HopException, ParseException { - final String xml = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); + final String xml = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8); // Parse the XML, create a workflow configuration WorkflowConfiguration workflowConfiguration = WorkflowConfiguration.fromXml(xml, variables);