Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3880 Fixed JVM options as semi-colon separated list parameter #4002

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,39 +340,8 @@ private String getErrorMessage(Map<String, String> data, ActionReport ar) {
return message;
}

// Ugly, temporary hack
//"There's nothing more permanent than a temporary solution" - Russian Proverb
protected Map<String, String> processData(Map<String, String> data, boolean removeVersioning) {
Map<String, String> results = new HashMap<String, String>();
StringBuilder options = new StringBuilder();
String sep = "";
for (Map.Entry<String, String> entry : data.entrySet()) {
String key = entry.getKey();
if ("target".equals(key) || "profiler".equals(key)) {
results.put(key, entry.getValue());
} else {
options.append(sep).append(removeVersioning ? new JvmOption(key).option : key);

String value = entry.getValue();

if (key != null && !key.trim().isEmpty() && (key.startsWith("-D") || key.startsWith("-X"))) {
if (value == null) {
value = "";
} else if(value.contains("=")) {
value = value.replaceAll("=", "");
}

if (key.endsWith("=")) {
options.append(value);
} else if(!key.contains("=")) {
options.append("=").append(value);
}
}
sep = ":";
}
}

results.put("id", options.toString());
Map<String, String> results = ResourceUtil.processJvmOptions(data, removeVersioning);
if (results.get("target") == null) {
results.put("target", target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.universal.xml.MiniXmlParser.JvmOption;

import fish.payara.audit.AdminAuditService;
import fish.payara.asadmin.recorder.AsadminRecorderService;
Expand All @@ -64,6 +65,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
Expand Down Expand Up @@ -1180,4 +1182,57 @@ public static boolean isAuthorized(final ServiceLocator habitat, final Subject s
new PrivilegedLookup<AuthorizationService>(habitat, AuthorizationService.class));
return authorizationSvc.isAuthorized(subject, new URI("admin", resource, null), action);
}

/**
* Creates a new rearranged map of JVM options. Options {@code target} and {@code profiler} are forwarded 1:1. All
* other options are joined in the result map for key {@code id} and are separated by semi-colon.
*
* An input key may include a value. In such case key and value are divided by an equals sign: {@code key=value}. In
* case of an empty value the key may end with an equals sign: {@code key=}. If the value is given as part of the
* key the input value should be empty or {@code null}. A value may itself contain equals signs.
*
* Keys ending with a backslash the backslash is stripped away. This is a backwards compatibility behaviour
* addressing remains of escaped equals sign that isn't properly unescaped prior to splitting in all path.
*
* The resulting option only uses an equals sign between key and value in case the value is non-empty. This is
* independent of whether the value was extracted from the input key or input value.
*
* @param jvmOptions a set of jvm options given as key-value pairs, keys are allowed to contain values too
* @param removeVersioning set {@code true} to erase any JVM version prefix from the keys, {@code false} to keep
* keys as they are.
* @return a map where most options are joined into one expression for key {@code id}. If existing {@code target}
* and {@code profiler} keys are kept same as in input map.
*/
public static Map<String, String> processJvmOptions(Map<String, String> jvmOptions, boolean removeVersioning) {
Map<String, String> results = new HashMap<>();
StringBuilder options = new StringBuilder();
String sep = "";
for (Map.Entry<String, String> option : jvmOptions.entrySet()) {
String key = option.getKey();
if ("target".equals(key) || "profiler".equals(key)) {
results.put(key, option.getValue());
} else if (key != null && !key.trim().isEmpty()) {
int endOfKey = key.indexOf('=');
String value = null;
if (endOfKey > 0) {
value = key.substring(endOfKey + 1);
key = key.substring(0, endOfKey);
}
if (key.endsWith("\\")) {
key = key.substring(0, key.length() - 1);
}
options.append(sep);
options.append(removeVersioning ? new JvmOption(key).option : key);
if (value == null || value.trim().isEmpty()) {
value = option.getValue();
}
if (value != null && !value.trim().isEmpty()) {
options.append("=").append(value);
}
sep = ":";
}
}
results.put("id", options.toString());
return results;
}
}

This file was deleted.

Loading