From 29e52b38aeb97ed0f0d61feb46a8a855b3c092e8 Mon Sep 17 00:00:00 2001 From: nsingh Date: Thu, 8 Nov 2018 17:44:56 -0800 Subject: [PATCH] Merge both boot 1.x and 2.x context path properties --- .../boot/app/cli/AbstractSpringBootApp.java | 14 +--------- .../commons/boot/app/cli/ContextPath.java | 26 +++++-------------- 2 files changed, 8 insertions(+), 32 deletions(-) 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 cd345e60f..0d36ba88b 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,19 +397,7 @@ public abstract class AbstractSpringBootApp implements SpringBootApp { @Override public String getContextPath() throws Exception { String environment = getEnvironment(); - 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; + return environment != null ? ContextPath.getContextPath(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 8162a6411..3fbabcf49 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 @@ -22,29 +22,17 @@ public class ContextPath { protected static Logger logger = LoggerFactory.getLogger(ContextPath.class); - public static final String[] BOOT_1X_CONTEXTPATH = { "server.context-path", "server.contextPath", - "SERVER_CONTEXT_PATH" }; - public static final String[] BOOT_2X_CONTEXTPATH = { "server.servlet.context-path", "server.servlet.contextPath", - "SERVER_SERVLET_CONTEXT_PATH" }; + 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 String getContextPath(String bootVersion, String environment) { + public static String getContextPath(String environment) { if (environment != null) { JSONObject env = new JSONObject(environment); - - String[] 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; - } + for (String prop : CONTEXTPATH) { + String contextPath = findContextPath(env, prop); + if (StringUtil.hasText(contextPath)) { + return contextPath; } } }