Skip to content

Commit

Permalink
FISH-10055 Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchan committed Mar 4, 2025
1 parent 5348897 commit ecbe29b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2016-2021 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2016-2025 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
Expand Down Expand Up @@ -111,6 +111,7 @@ public enum RUNTIME_OPTION {
shutdowngrace(true, new IntegerValidator(1, Integer.MAX_VALUE)),
hzinitialjoinwait(true, new IntegerValidator(0,100000)),
contextroot(true),
globalcontextroot(true),
warmup(false),
hotdeploy(false),
nohazelcast(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public class PayaraMicroImpl implements PayaraMicroBoot {
private int minHttpThreads = Integer.MIN_VALUE;
private String instanceName;
private String contextRoot;
private String globalContextRoot;
private File rootDir;
private File deploymentRoot;
private File alternateDomainXML;
Expand Down Expand Up @@ -1429,6 +1430,12 @@ else if (requestTracing[0].matches("\\D+")) {
contextRoot = "/";
}
break;
case globalcontextroot:
if (globalContextRoot != null) {
LOGGER.warning("Multiple --globalContextRoot arguments only the last one will apply");
}
globalContextRoot = value;
break;
case accessloginterval:
accessLogInterval = Integer.parseInt(value);
break;
Expand Down Expand Up @@ -1677,7 +1684,7 @@ private void deployAll() throws GlassFishException {
}
deploymentParams.add("--contextroot=" + deploymentContext);
}

addGlobalContextRootProperty(deploymentParams);
deployer.deploy(this.getClass().getClassLoader().getResourceAsStream(entry), deploymentParams.toArray(new String[0]));

deploymentCount++;
Expand Down Expand Up @@ -1737,6 +1744,7 @@ private void deployAll() throws GlassFishException {
}
deploymentParams.add("--contextroot=" + deploymentContext);
}
addGlobalContextRootProperty(deploymentParams);
deployer.deploy(deploymentURI, deploymentParams.toArray(new String[0]));

deploymentCount++;
Expand All @@ -1745,6 +1753,12 @@ private void deployAll() throws GlassFishException {
LOGGER.log(Level.INFO, "Deployed {0} archive(s)", deploymentCount);
}

private void addGlobalContextRootProperty(List<String> deploymentParams) {
if (globalContextRoot != null && !globalContextRoot.isBlank()) {
deploymentParams.add("--properties=" + "globalContextRoot="+globalContextRoot);
}
}

private ConsoleHandler configureLogger(Logger logger) {
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.ALL);
Expand Down Expand Up @@ -2329,6 +2343,7 @@ private void setArgumentsFromSystemProperties() {
showServletMappings = getBooleanProperty("payaramicro.showServletMappings", "false");
publicAddress = getProperty("payaramicro.publicAddress");
contextRoot = getProperty("payaramicro.contextRoot");
globalContextRoot = getProperty("payaramicro.globalContextRoot");

// Set the rootDir file
String rootDirFileStr = getProperty("payaramicro.rootDir");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,14 @@ public <V> V loadMetaData(Class<V> type, DeploymentContext dc) {
if (contextRoot == null)
contextRoot = ((GenericHandler)dc.getArchiveHandler()).getDefaultApplicationNameFromArchiveName(dc.getOriginalSource());


if (this.env.getRuntimeType().isMicro()) {
String globalContextRoot = getProperty("payaramicro.globalContextRoot");
if (globalContextRoot != null && !globalContextRoot.isBlank()) {
globalContextRoot = removeSlashes(globalContextRoot);
if (params.properties != null && params.properties.getProperty("globalContextRoot") != null) {
String globalContextRoot = removeSlashes(params.properties.getProperty("globalContextRoot"));
if (!globalContextRoot.isBlank()) {
contextRoot = removeSlashes(contextRoot);

contextRoot = "/" + globalContextRoot + "/" + contextRoot;
}
}

if (!contextRoot.startsWith("/")) {
contextRoot = "/" + contextRoot;
}
Expand Down Expand Up @@ -250,17 +248,8 @@ void runJSPC(final DeploymentContext dc) throws DeploymentException {
}
}

private String getProperty(String value) {
String result;
result = System.getProperty(value);
if (result == null) {
result = System.getenv(value.replace('.', '_'));
}
return result;
}

private String removeSlashes(String value) {
return value.replaceAll("^/|/$", "");
return value.replaceAll("[/]", "");
}

}

0 comments on commit ecbe29b

Please sign in to comment.