Skip to content

Commit

Permalink
Merge pull request #7187 from payara/FISH-10055
Browse files Browse the repository at this point in the history
FISH-9957 Introduce Payara Micro Global Context Root Support
  • Loading branch information
Pandrex247 authored Mar 7, 2025
2 parents 41381f9 + 33a40cc commit f2bc336
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 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
@@ -1,7 +1,7 @@
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright (c) 2016-2020 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 @@ -102,3 +102,4 @@ showservletmappings=Shows the servlet mappings in the deployment summary message
hzpublicaddress=Sets the Public Address of the Data Grid for use where NAT translation is used (including in Docker)
hzinitialjoinwait=Set the join wait system property hazelcast.wait.seconds.before.join which is the wait time before joining the cluster
contextroot=Specifies the context root of the first deployment without a context root specified
globalcontextroot=Set the global context root of all deployed applications. This will prepend the context root for any deployed application.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018-2021] [Payara Foundation and/or its affiliates]
// Portions Copyright [2018-2025] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.web;

Expand Down Expand Up @@ -136,6 +136,14 @@ public <V> V loadMetaData(Class<V> type, DeploymentContext dc) {
if (contextRoot == null)
contextRoot = ((GenericHandler)dc.getArchiveHandler()).getDefaultApplicationNameFromArchiveName(dc.getOriginalSource());

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 @@ -239,4 +247,9 @@ void runJSPC(final DeploymentContext dc) throws DeploymentException {
throw de;
}
}

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

}

0 comments on commit f2bc336

Please sign in to comment.