diff --git a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java index 0d36ba88b..cd345e60f 100644 --- a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java +++ b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/AbstractSpringBootApp.java @@ -397,7 +397,19 @@ public abstract class AbstractSpringBootApp implements SpringBootApp { @Override public String getContextPath() throws Exception { String environment = getEnvironment(); - return environment != null ? ContextPath.getContextPath(environment) : null; + String bootVersion = null; + // Boot 1.x + Object result = getActuatorDataFromAttribute(getObjectName("type=Endpoint,name=requestMappingEndpoint"), "Data"); + if (result != null) { + bootVersion = "1.x"; + } + + // Boot 2.x + result = getActuatorDataFromOperation(getObjectName("type=Endpoint,name=Mappings"), "mappings"); + if (result != null) { + bootVersion = "2.x"; + } + return bootVersion != null && environment != null ? ContextPath.getContextPath(bootVersion, environment) : null; } /** diff --git a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/ContextPath.java b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/ContextPath.java index 124e9ab7b..a387df8f2 100644 --- a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/ContextPath.java +++ b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/ContextPath.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.springframework.ide.vscode.commons.boot.app.cli; +import java.util.Collection; import java.util.Set; import org.json.JSONArray; @@ -18,21 +19,36 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ide.vscode.commons.util.StringUtil; +import com.google.common.collect.ImmutableList; + public class ContextPath { protected static Logger logger = LoggerFactory.getLogger(ContextPath.class); - public static final String[] CONTEXTPATH = { "server.context-path", "server.contextPath", "SERVER_CONTEXT_PATH", - "server.servlet.context-path", "server.servlet.contextPath", "SERVER_SERVLET_CONTEXT_PATH" }; + public static final Collection BOOT_1X_CONTEXTPATH = ImmutableList.of("server.context-path", + "server.contextPath"); - public static String getContextPath(String environment) { + public static final Collection BOOT_2X_CONTEXTPATH = ImmutableList.of("server.servlet.context-path", + "server.servlet.contextPath"); + + public static String getContextPath(String bootVersion, String environment) { if (environment != null) { JSONObject env = new JSONObject(environment); - for (String prop : CONTEXTPATH) { - String contextPath = findContextPath(env, prop); - if (StringUtil.hasText(contextPath)) { - return contextPath; + + Collection contextPathProperties = null; + if ("1.x".equals(bootVersion)) { + contextPathProperties = BOOT_1X_CONTEXTPATH; + } else if ("2.x".equals(bootVersion)) { + contextPathProperties = BOOT_2X_CONTEXTPATH; + } + + if (contextPathProperties != null) { + for (String prop : contextPathProperties) { + String contextPath = findContextPath(env, prop); + if (StringUtil.hasText(contextPath)) { + return contextPath; + } } } }