Skip to content

Commit

Permalink
Merge pull request #945 from AdoptOpenJDK/setting_http_agent_for_ows
Browse files Browse the repository at this point in the history
OWS-631: Fix properties defined in Jnlp not passed to application
  • Loading branch information
sclassen authored Jun 7, 2024
2 parents c139a18 + a2ab17b commit 5d1ddc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/net/sourceforge/jnlp/JNLPFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected JNLPFile() {

final String httpAgent = getResources().getPropertiesMap().get(HTTP_AGENT);
// Do not set http.agent in stage 2 as it can be set from the vmarg to the jvm
if (! StringUtils.isBlank(httpAgent) && !"true".equalsIgnoreCase(System.getenv(ApplicationInstance.IGNORE_JNLP_RESOURCE_PROPERTIES))) {
if (! StringUtils.isBlank(httpAgent) && !"true".equalsIgnoreCase(System.getenv(ApplicationInstance.IGNORE_HTTP_AGENT_PROPERTY))) {
System.setProperty(HTTP_AGENT, httpAgent);
if (!HttpURLConnection.userAgent.contains(httpAgent)) {
LOG.warn("Cannot set HTTP User-Agent as a connection has been opened before reading the JNLP file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.sourceforge.jnlp.runtime;

import net.adoptopenjdk.icedteaweb.JavaSystemPropertiesConstants;
import net.adoptopenjdk.icedteaweb.jnlp.element.resource.ExtensionDesc;
import net.adoptopenjdk.icedteaweb.jnlp.element.resource.PropertyDesc;
import net.adoptopenjdk.icedteaweb.jnlp.element.security.SecurityDesc;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class ApplicationInstance {

private static final String DEPLOYMENT_SYSPROP = "deployment.javaws";
private static final String DEPLOYMENT_SYSPROP_VALUE = "IcedTea-Web";
public static final String IGNORE_JNLP_RESOURCE_PROPERTIES = "ignoreJnlpResourceProperties";
public static final String IGNORE_HTTP_AGENT_PROPERTY = "ignoreHttpAgentProperty";

// todo: should attempt to unload the environment variables
// installed by the application.
Expand Down Expand Up @@ -143,9 +144,6 @@ private void installEnvironment() {
}

private void setSystemPropertiesFromJnlp() {
if ("true".equalsIgnoreCase(System.getenv(IGNORE_JNLP_RESOURCE_PROPERTIES))) {
return;
}
final List<PropertyDesc> props = collectPropertiesFromJnlpHierarchy(new ArrayList<>(), file);

if (!(props.size() == 0)) {
Expand All @@ -158,8 +156,11 @@ private void setSystemPropertiesFromJnlp() {

final PrivilegedAction<Object> setPropertiesAction = () -> {
for (PropertyDesc propDesc : props) {
LOG.debug("Setting System Property {} with value {}", propDesc.getKey(), propDesc.getValue());
System.setProperty(propDesc.getKey(), propDesc.getValue());
if (!propDesc.getKey().equals(JavaSystemPropertiesConstants.HTTP_AGENT)) {
setSystemProperty(propDesc);
} else if (!"true".equalsIgnoreCase(System.getenv(ApplicationInstance.IGNORE_HTTP_AGENT_PROPERTY))) {
setSystemProperty(propDesc);
}
}
return null;
};
Expand All @@ -169,6 +170,11 @@ private void setSystemPropertiesFromJnlp() {
}
}

private void setSystemProperty(PropertyDesc propDesc) {
LOG.debug("Setting System Property {} with value {}", propDesc.getKey(), propDesc.getValue());
System.setProperty(propDesc.getKey(), propDesc.getValue());
}

/**
* Returns the jnlpfile on which is this application based
* @return JNLP file for this task.
Expand Down

0 comments on commit 5d1ddc8

Please sign in to comment.