diff --git a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java index 9fac94307df..7c8f4a4699a 100644 --- a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java +++ b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/cmd/options/RUNTIME_OPTION.java @@ -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 @@ -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); diff --git a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java index 0b45f1064c2..79210c438b6 100644 --- a/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java +++ b/appserver/extras/payara-micro/payara-micro-core/src/main/java/fish/payara/micro/impl/PayaraMicroImpl.java @@ -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; @@ -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; @@ -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++; @@ -1737,6 +1744,7 @@ private void deployAll() throws GlassFishException { } deploymentParams.add("--contextroot=" + deploymentContext); } + addGlobalContextRootProperty(deploymentParams); deployer.deploy(deploymentURI, deploymentParams.toArray(new String[0])); deploymentCount++; @@ -1745,6 +1753,12 @@ private void deployAll() throws GlassFishException { LOGGER.log(Level.INFO, "Deployed {0} archive(s)", deploymentCount); } + private void addGlobalContextRootProperty(List deploymentParams) { + if (globalContextRoot != null && !globalContextRoot.isBlank()) { + deploymentParams.add("--properties=" + "globalContextRoot="+globalContextRoot); + } + } + private ConsoleHandler configureLogger(Logger logger) { ConsoleHandler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.ALL); @@ -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"); diff --git a/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/WebDeployer.java b/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/WebDeployer.java index 9bde642edba..bfae6740056 100644 --- a/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/WebDeployer.java +++ b/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/WebDeployer.java @@ -136,16 +136,14 @@ public V loadMetaData(Class 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; } @@ -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("[/]", ""); } }