Skip to content

Commit

Permalink
Merge both boot 1.x and 2.x context path properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh committed Nov 9, 2018
1 parent 9179d5d commit 29e52b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,7 @@ public Optional<List<LiveConditional>> getLiveConditionals() throws Exception {
@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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 29e52b3

Please sign in to comment.