Skip to content

Commit

Permalink
Fixes issue piranhacloud#3468 - Add --context-path support
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Jul 1, 2023
1 parent 1b97c8c commit ef5aa17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class MicroBootstrap implements Runnable {
* Stores the logger.
*/
private static final System.Logger LOGGER = System.getLogger(MicroBootstrap.class.getName());

/**
* Stores the context path.
*/
private String contextPath = "ROOT";

/**
* The HTTP port on which Piranha accepts requests
Expand Down Expand Up @@ -99,6 +104,9 @@ public void configure(String[] arguments) {

if (arguments.length > 0) {
for (int i = 0; i < arguments.length; i++) {
if (arguments[i].equals("--context-path")) {
contextPath = arguments[i + 1];
}
if (arguments[i].equals("--http-port")) {
port = Integer.parseInt(arguments[i + 1]);
}
Expand Down Expand Up @@ -143,8 +151,9 @@ public void configure(String[] arguments) {
@Override
public void run() {
MicroConfiguration configuration = new MicroConfiguration();
configuration.setPort(port);
configuration.setHttpServer(httpServer);
configuration.setContextPath(contextPath);
configuration.setPort(port);

outerDeployer = new MicroOuterDeployer(configuration.postConstruct());
outerDeployer.deploy(archive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ public Map<String, Object> toMap() {
Map<String, Object> config = new HashMap<>();
config.put("micro.port", getPort());
config.put("micro.rootIsWarName", rootIsWarName);
if (getRoot() != null) {
config.put("micro.root", getRoot());
if (getContextPath() != null) {
config.put("micro.root", getContextPath());
}
config.put("micro.http.start", httpStart);

Expand Down Expand Up @@ -328,7 +328,7 @@ public boolean isRootIsWarName() {
* Sets that the war name should be used for the root context of a web app.
*
* <p>
* Setting this to true overrides the explicit context root set via the <code>setRoot</code> method.
* Setting this to true overrides the explicit context root set via the <code>setContextPath</code> method.
*
* @param rootIsWarName whether the war name is used for the context root
*/
Expand All @@ -337,19 +337,19 @@ public void setRootIsWarName(boolean rootIsWarName) {
}

/**
* {@return the root}
* {@return the context path}
*/
public String getRoot() {
public String getContextPath() {
return root;
}

/**
* Set the root.
* Set the context path.
*
* @param root the root.
* @param contextPath the context path.
*/
public void setRoot(String root) {
this.root = root;
public void setContextPath(String contextPath) {
this.root = contextPath;
}

/**
Expand Down

0 comments on commit ef5aa17

Please sign in to comment.