Skip to content

Commit 21ecb48

Browse files
authored
Merge branch 'main' into feature/logging-improvements
2 parents f59b01b + d934af2 commit 21ecb48

File tree

21 files changed

+790
-96
lines changed

21 files changed

+790
-96
lines changed

client/src/com/mirth/connect/client/ui/OSXAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ protected static Object getApplication() throws Exception {
278278
return macOSXApplication;
279279
}
280280

281+
@SuppressWarnings("removal")
281282
protected static void setHandler(InvocationHandler adapter, String interfaceName, String applicationSetter) throws Exception {
282283
Class<?> handlerInterface = Class.forName(interfaceName);
283284
Object handlerImpl = Proxy.newProxyInstance(AccessController.doPrivileged(ReflectionHelper.getClassLoaderPA(handlerInterface)), new Class[] {

client/src/com/mirth/connect/client/ui/panels/connectors/ConnectorSettingsPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public final <T> T getServlet(final Class<T> servletInterface, final String work
197197
* A custom error message to display if an exception occurs during connector service
198198
* invocation
199199
*/
200-
@SuppressWarnings("unchecked")
200+
@SuppressWarnings({"removal", "unchecked"})
201201
public final <T> T getServlet(final Class<T> servletInterface, final String workerDisplayText, final String errorText, final ResponseHandler responseHandler, final String workerId) {
202202
return (T) Proxy.newProxyInstance(AccessController.doPrivileged(ReflectionHelper.getClassLoaderPA(servletInterface)), new Class[] {
203203
servletInterface }, new InvocationHandler() {

server/basedir-includes/oieserver

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
#!/usr/bin/env bash
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
# SPDX-FileCopyrightText: 2025 Tony Germano and Mitch Gaffigan
5+
#
6+
7+
# =============================================================================
8+
# Open Integration Engine Server Launcher Script
9+
#
10+
# Description:
11+
# This script is the main launcher for the Open Integration Engine (OIE)
12+
# server. It prepares the Java environment and executes the server launcher
13+
# JAR file.
14+
#
15+
# The script automatically finds a compatible Java runtime (version 17+ by
16+
# default) by searching for a valid executable in the following priority order:
17+
# 1. The OIE_JAVA_PATH environment variable.
18+
# 2. The -java-cmd directive in the oieserver.vmoptions file or included
19+
# .vmoptions files. Must specify the path to the 'java' executable.
20+
# This is the preferred way to declare the desired version for running
21+
# the server and can be overridden by OIE_JAVA_PATH. Can be a relative
22+
# path from the location of this script.
23+
# 3. The JAVA_HOME environment variable.
24+
# 4. The 'java' command available in the system's PATH.
25+
#
26+
# It also parses the 'oieserver.vmoptions' file to configure JVM options,
27+
# system properties (-D...), and classpath modifications.
28+
#
29+
# Usage:
30+
# ./oieserver.sh [app-arguments]
31+
#
32+
# All [app-arguments] are passed directly to the underlying Java application
33+
# (com.mirth.connect.server.launcher.MirthLauncher).
34+
#
35+
# Configuration via Environment Variables:
36+
# OIE_JAVA_PATH - (Highest priority) Set the full path to the 'java'
37+
# executable to be used. Can be a relative path from the
38+
# location of this script or a tilde path
39+
# (e.g., ~/path/to/java).
40+
# JAVA_HOME - Set the path to the root of a Java installation. The
41+
# script will look for 'bin/java' within this path.
42+
# =============================================================================
43+
44+
APP_ARGS=("$@")
45+
MIN_JAVA_VERSION=17
46+
47+
# Set OIE_HOME to the script directory
48+
OIE_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
49+
# The engine expects it's working directory to be OIE_HOME
50+
if ! cd "$OIE_HOME"; then
51+
echo "Error: Could not change to the OIE_HOME directory: $OIE_HOME" >&2
52+
exit 1
53+
fi
54+
LAUNCHER_JAR="$OIE_HOME/mirth-server-launcher.jar"
55+
CLASSPATH="$LAUNCHER_JAR"
56+
VMOPTIONS=()
57+
# This will hold the validated path to the Java executable. It is intentionally left empty for now.
58+
FINAL_JAVA_CMD=""
59+
# This will temporarily hold the result from parsing the vmoptions file.
60+
VMOPTIONS_JAVA_CMD=""
61+
VMOPTIONS_JAVA_CMD_FILE=""
62+
63+
64+
# --- Function to resolve a path to a canonical absolute path ---
65+
# Resolves a given path, handling tilde, relative, and '..' components.
66+
# @param $1: The path to resolve.
67+
# @echo: The resolved, canonical absolute path.
68+
resolve_canonical_path() {
69+
local path_to_resolve="$1"
70+
71+
# Explicitly handle tilde expansion first
72+
path_to_resolve=$(sed -E "s,^~(/|$),${HOME}\1," <<< "$path_to_resolve")
73+
74+
# If the path is not absolute, assume it's relative to OIE_HOME
75+
if [[ ! "$path_to_resolve" =~ ^/ ]]; then
76+
path_to_resolve="$OIE_HOME/$path_to_resolve"
77+
fi
78+
79+
# Use cd and pwd to resolve '..' and '.' components for a canonical path.
80+
if [[ -d "$(dirname "$path_to_resolve")" ]]; then
81+
echo "$(cd "$(dirname "$path_to_resolve")" && pwd)/$(basename "$path_to_resolve")"
82+
else
83+
echo "$path_to_resolve"
84+
fi
85+
}
86+
87+
# --- Function to expand environment variable in a string ---
88+
# @param $1: The line to expand
89+
# @echo: The expanded line
90+
expand_line_variables() {
91+
local line="$1"
92+
local result_line=""
93+
94+
# This loop consumes the line from left to right, preventing recursive expansion.
95+
while [[ "$line" =~ (\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}) ]]; do
96+
# Append the text before the match to our result.
97+
result_line+="${line%%"${BASH_REMATCH[0]}"*}"
98+
99+
# Get the variable name and its value.
100+
local var_name="${BASH_REMATCH[2]}"
101+
# Use indirect expansion to get the variable's value. Do not replace if not set.
102+
if [[ -n "${!var_name+x}" ]]; then
103+
local var_value="${!var_name}"
104+
result_line+="$var_value"
105+
else
106+
result_line+="${BASH_REMATCH[0]}"
107+
fi
108+
109+
# Update the line to be only the portion *after* the match.
110+
line="${line#*"${BASH_REMATCH[0]}"}"
111+
done
112+
113+
# Append any remaining part of the line after the last match and return.
114+
echo "$result_line$line"
115+
}
116+
117+
# --- Function to validate Java version ---
118+
# Checks if a given command points to a Java executable of the required minimum version.
119+
# @param $1: The java command or path to check
120+
# @return: 0 on success (is valid), 1 on failure.
121+
is_valid_java_version() {
122+
local java_cmd="$1"
123+
124+
# Check if the command is found and is executable
125+
if ! command -v "$java_cmd" &> /dev/null || ! [[ -x "$(command -v "$java_cmd")" ]]; then
126+
return 1
127+
fi
128+
129+
# Execute 'java -version' and capture the output from stderr
130+
# Example output: openjdk version "17.0.2" 2022-07-19
131+
local version_output
132+
version_output=$("$java_cmd" -version 2>&1)
133+
134+
# Check if the version command succeeded
135+
if [[ $? -ne 0 ]]; then
136+
return 1
137+
fi
138+
139+
# Extract the major version number. This works for formats like "1.8.0" and "17.0.2".
140+
local major_version
141+
major_version=$(echo "$version_output" | head -n 1 | cut -d '"' -f 2 | cut -d '.' -f 1)
142+
143+
# Check if the extracted version is a number and meets the minimum requirement
144+
if [[ "$major_version" =~ ^[0-9]+$ ]] && [[ "$major_version" -ge "$MIN_JAVA_VERSION" ]]; then
145+
return 0 # Success
146+
else
147+
return 1 # Failure
148+
fi
149+
}
150+
151+
# Set Java options by parsing the vmoptions file
152+
parse_vmoptions() {
153+
local file="$1"
154+
155+
if [[ ! -f "$file" ]]; then
156+
echo "Warning: VM options file not found: $file" >&2
157+
return 1
158+
fi
159+
160+
# Read the file line by line
161+
while IFS= read -r line; do
162+
# Trim leading/trailing whitespace
163+
line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
164+
165+
# Skip empty lines and comments
166+
if [[ -z "$line" || "$line" =~ ^# ]]; then
167+
continue
168+
fi
169+
170+
line=$(expand_line_variables "$line")
171+
172+
# Check for -include-options directive
173+
if [[ "$line" =~ ^-include-options[[:space:]]+(.+) ]]; then
174+
local included_file="${BASH_REMATCH[1]}"
175+
# Resolve relative paths
176+
if [[ ! "$included_file" =~ ^/ ]]; then # Not an absolute path
177+
included_file="$(dirname "$file")/$included_file"
178+
fi
179+
# Recursively call parse_vmoptions for the included file
180+
parse_vmoptions "$included_file"
181+
elif [[ "$line" =~ ^-classpath[[:space:]]+(.+) ]]; then
182+
# Handle -classpath directive
183+
CLASSPATH="${BASH_REMATCH[1]}"
184+
elif [[ "$line" =~ ^-classpath/a[[:space:]]+(.+) ]]; then
185+
# Handle -classpath/a directive (append to existing classpath)
186+
CLASSPATH="${CLASSPATH}:${BASH_REMATCH[1]}"
187+
elif [[ "$line" =~ ^-classpath/p[[:space:]]+(.+) ]]; then
188+
# Handle -classpath/p directive (prepend to existing classpath)
189+
CLASSPATH="${BASH_REMATCH[1]}:${CLASSPATH}"
190+
elif [[ "$line" =~ ^-java-cmd[[:space:]]+(.+) ]]; then
191+
# Handle -java-cmd directive
192+
# Store the path and the file it was found in. Validation is deferred.
193+
VMOPTIONS_JAVA_CMD=$(resolve_canonical_path "${BASH_REMATCH[1]}")
194+
VMOPTIONS_JAVA_CMD_FILE="$file"
195+
else
196+
# Add the option to the accumulated string
197+
VMOPTIONS+=("$line")
198+
fi
199+
done < "$file"
200+
return 0
201+
}
202+
203+
# --- Main Logic ---
204+
205+
# 1. Recursively parse the VM options file to populate vmoptions variables.
206+
parse_vmoptions "$OIE_HOME/oieserver.vmoptions"
207+
208+
# 2. Ensure the launcher JAR is always in the classpath.
209+
case "$CLASSPATH" in
210+
*"$LAUNCHER_JAR"*)
211+
# It's already there, do nothing.
212+
;;
213+
*)
214+
# Prepend the launcher JAR if a custom classpath was provided.
215+
echo "Info: Prepending mirth-server-launcher.jar to the classpath."
216+
CLASSPATH="$LAUNCHER_JAR:$CLASSPATH"
217+
;;
218+
esac
219+
220+
# 3. Discover the Java executable using the documented priority order.
221+
222+
# Check OIE_JAVA_PATH (fail-fast on invalid).
223+
if [[ -n "$OIE_JAVA_PATH" ]]; then
224+
resolved_path=$(resolve_canonical_path "$OIE_JAVA_PATH")
225+
if is_valid_java_version "$resolved_path"; then
226+
echo "Info: Found suitable java version specified by the OIE_JAVA_PATH environment variable"
227+
FINAL_JAVA_CMD="$resolved_path"
228+
else
229+
echo "Error: '$resolved_path' is specified by the OIE_JAVA_PATH environment variable, which is not a valid Java executable of at least version $MIN_JAVA_VERSION. Exiting." >&2
230+
exit 1
231+
fi
232+
fi
233+
234+
# Check -java-cmd from vmoptions (fail-fast on invalid, only if not already found).
235+
if [[ -z "$FINAL_JAVA_CMD" ]] && [[ -n "$VMOPTIONS_JAVA_CMD" ]]; then
236+
if is_valid_java_version "$VMOPTIONS_JAVA_CMD"; then
237+
echo "Info: Found suitable java version specified by the -java-cmd directive in '$VMOPTIONS_JAVA_CMD_FILE'"
238+
FINAL_JAVA_CMD="$VMOPTIONS_JAVA_CMD"
239+
else
240+
echo "Error: '$VMOPTIONS_JAVA_CMD' is specified by the -java-cmd directive in '$VMOPTIONS_JAVA_CMD_FILE', which is not a valid Java executable of at least version $MIN_JAVA_VERSION. Exiting." >&2
241+
exit 1
242+
fi
243+
fi
244+
245+
# Check JAVA_HOME (no fail-fast).
246+
if [[ -z "$FINAL_JAVA_CMD" ]] && [[ -d "$JAVA_HOME" ]]; then
247+
java_home_path="$JAVA_HOME/bin/java"
248+
if is_valid_java_version "$java_home_path"; then
249+
echo "Info: Found suitable java version specified by the JAVA_HOME environment variable"
250+
FINAL_JAVA_CMD="$java_home_path"
251+
else
252+
echo "Warning: '$java_home_path' is specified by the JAVA_HOME environment variable, which is not a valid Java executable of at least version $MIN_JAVA_VERSION. Ignoring." >&2
253+
fi
254+
fi
255+
256+
# Check system PATH (no fail-fast).
257+
if [[ -z "$FINAL_JAVA_CMD" ]]; then
258+
if is_valid_java_version "java"; then
259+
echo "Info: Found suitable java version in the PATH"
260+
FINAL_JAVA_CMD="java"
261+
else
262+
echo "Warning: 'java' does not exist in your PATH or is not a valid Java executable of at least version $MIN_JAVA_VERSION." >&2
263+
fi
264+
fi
265+
266+
# 4. Final check for a valid Java path before execution.
267+
if [[ -z "$FINAL_JAVA_CMD" ]]; then
268+
echo "Error: Could not find a Java ${MIN_JAVA_VERSION}+ installation." >&2
269+
echo "Please configure -java-cmd in conf/custom.vmoptions, set OIE_JAVA_PATH, set JAVA_HOME, or ensure 'java' in your PATH is version ${MIN_JAVA_VERSION} or higher." >&2
270+
exit 1
271+
fi
272+
273+
JAVA_OPTS=("${VMOPTIONS[@]}"
274+
"-cp" "$CLASSPATH"
275+
"com.mirth.connect.server.launcher.MirthLauncher"
276+
"${APP_ARGS[@]}")
277+
278+
# Launch Open Integration Engine (as this PID with exec)
279+
echo "Starting Open Integration Engine..."
280+
echo "$FINAL_JAVA_CMD ${JAVA_OPTS[*]}"
281+
exec "$FINAL_JAVA_CMD" "${JAVA_OPTS[@]}"

0 commit comments

Comments
 (0)