From ff9621cbb3b395887dfdb5ea958986e331426358 Mon Sep 17 00:00:00 2001 From: NotedSalmon Date: Thu, 8 Aug 2024 14:43:38 +0100 Subject: [PATCH 1/4] FISH-9196 DBControl now has a charset UTF_8 --- .../com/sun/enterprise/admin/cli/optional/DBControl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java index 2a4fa9863f8..058ce75af70 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2017 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2017-2024] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -44,6 +44,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import com.sun.enterprise.util.io.FileUtils; import org.glassfish.api.admin.CommandException; @@ -84,7 +85,7 @@ protected DBControl(final String dbCommand, final String dbHost, final String db } // Redirect stdout and stderr to a file - try (PrintStream printStream = new PrintStream(new FileOutputStream(dbLog, true), true)) { + try (PrintStream printStream = new PrintStream(new FileOutputStream(dbLog, true), true, StandardCharsets.UTF_8)) { System.setOut(printStream); System.setErr(printStream); } From 3fe0de7d80cfe06261394002dcb6b946e025729a Mon Sep 17 00:00:00 2001 From: NotedSalmon Date: Thu, 8 Aug 2024 17:14:41 +0100 Subject: [PATCH 2/4] FISH-9196 GFLauncher changed to use UTF_8 encoding --- .../java/com/sun/enterprise/admin/launcher/GFLauncher.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java b/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java index 0e03b82fa34..87e6d588f92 100644 --- a/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java +++ b/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java @@ -56,6 +56,7 @@ import com.sun.enterprise.util.io.FileUtils; import fish.payara.admin.launcher.PayaraDefaultJvmOptions; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.logging.Level; import java.util.regex.Matcher; @@ -608,7 +609,7 @@ private void writeSecurityTokens(Process sp) throws GFLauncherException, IOExcep OutputStreamWriter osw = null; BufferedWriter bw = null; try { - osw = new OutputStreamWriter(os); + osw = new OutputStreamWriter(os, StandardCharsets.UTF_8); bw = new BufferedWriter(osw); for (String token : info.securityTokens) { bw.write(token); @@ -910,7 +911,7 @@ private Optional getConfiguredJdkVersion(String javaExePath) throws Runtime r = Runtime.getRuntime(); Process p = r.exec(javaExePath + " -version"); p.waitFor(); - try (BufferedReader b = new BufferedReader(new InputStreamReader(p.getErrorStream()))) { + try (BufferedReader b = new BufferedReader(new InputStreamReader(p.getErrorStream(), StandardCharsets.UTF_8))) { String line; while ((line = b.readLine()) != null) { Matcher m = JAVA_VERSION_PATTERN.matcher(line); From 6b577bb345ffb5b8fe7110f4212ea6a03cd40c05 Mon Sep 17 00:00:00 2001 From: NotedSalmon Date: Thu, 8 Aug 2024 17:15:18 +0100 Subject: [PATCH 3/4] FISH-9196 RemoteAdminCommand changed to use UTF_8 encoding --- .../enterprise/admin/remote/RemoteAdminCommand.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java index d2e44e1313d..5712f81c232 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2017-2018] [Payara Foundation and/or its affiliates] +// Portions Copyright [2017-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.admin.remote; @@ -63,6 +63,7 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.Iterator; @@ -931,8 +932,8 @@ private void doHttpCommand(String uriString, String httpMethod, } catch (Exception e) { logger.log(Level.FINER, "doHttpCommand: exception", e); ByteArrayOutputStream buf = new ByteArrayOutputStream(); - e.printStackTrace(new PrintStream(buf)); - logger.finer(buf.toString()); + e.printStackTrace(new PrintStream(buf, true, UTF_8)); + logger.finer(buf.toString(UTF_8)); throw new CommandException(e); } } while (shouldTryCommandAgain); @@ -1123,7 +1124,7 @@ private StringBuilder addPasswordOption(StringBuilder uriString, String name, St passwordOptions .append(name) .append('=') - .append(URLEncoder.encode(new String(Base64.getMimeEncoder().encode(option.getBytes()), UTF_8), "UTF-8")); + .append(URLEncoder.encode(new String(Base64.getMimeEncoder().encode(option.getBytes(UTF_8)), UTF_8), "UTF-8")); return uriString; } @@ -1341,7 +1342,7 @@ private CommandModel parseMetadata(InputStream in, StringBuilder errors) { FileUtils.copy(in, baos, 0); } catch (IOException ex) { } in = new ByteArrayInputStream(baos.toByteArray()); - String response = baos.toString(); + String response = baos.toString(UTF_8); logger.finer("------- RAW METADATA RESPONSE ---------"); logger.finer(response); logger.finer("------- RAW METADATA RESPONSE ---------"); From a4c133071fcc3aee852244cb394e445cfcd0c68c Mon Sep 17 00:00:00 2001 From: NotedSalmon Date: Fri, 9 Aug 2024 17:02:12 +0100 Subject: [PATCH 4/4] FISH-9196 settings autoflushed to false, keeping default behaviour --- .../java/com/sun/enterprise/admin/cli/optional/DBControl.java | 2 +- .../com/sun/enterprise/admin/remote/RemoteAdminCommand.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java index 058ce75af70..72d67edd8c1 100644 --- a/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java +++ b/appserver/admin/cli-optional/src/main/java/com/sun/enterprise/admin/cli/optional/DBControl.java @@ -85,7 +85,7 @@ protected DBControl(final String dbCommand, final String dbHost, final String db } // Redirect stdout and stderr to a file - try (PrintStream printStream = new PrintStream(new FileOutputStream(dbLog, true), true, StandardCharsets.UTF_8)) { + try (PrintStream printStream = new PrintStream(new FileOutputStream(dbLog, true), false, StandardCharsets.UTF_8)) { System.setOut(printStream); System.setErr(printStream); } diff --git a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java index 5712f81c232..93df64eda0c 100644 --- a/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java +++ b/nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteAdminCommand.java @@ -63,7 +63,6 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.net.UnknownHostException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.Iterator; @@ -932,7 +931,7 @@ private void doHttpCommand(String uriString, String httpMethod, } catch (Exception e) { logger.log(Level.FINER, "doHttpCommand: exception", e); ByteArrayOutputStream buf = new ByteArrayOutputStream(); - e.printStackTrace(new PrintStream(buf, true, UTF_8)); + e.printStackTrace(new PrintStream(buf, false, UTF_8)); logger.finer(buf.toString(UTF_8)); throw new CommandException(e); }