Commit 11201762 by Julien Roy Committed by Dave Syer

Eureka dashboard controller path mapping can be configured or disabled

parent 8f8e738f
...@@ -12,6 +12,7 @@ import com.netflix.eureka.resources.StatusResource; ...@@ -12,6 +12,7 @@ import com.netflix.eureka.resources.StatusResource;
import com.netflix.eureka.util.StatusInfo; import com.netflix.eureka.util.StatusInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -26,12 +27,16 @@ import java.util.*; ...@@ -26,12 +27,16 @@ import java.util.*;
* @author Spencer Gibb * @author Spencer Gibb
*/ */
@Controller @Controller
@RequestMapping("${eureka.dashboard.path:/}")
public class EurekaController { public class EurekaController {
@Autowired @Value("${eureka.dashboard.path:/}")
private String dashboardPath = "";
@Autowired
ServerProperties serverProperties; ServerProperties serverProperties;
@RequestMapping(value = "/", method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public String status(HttpServletRequest request, Map<String, Object> model) { public String status(HttpServletRequest request, Map<String, Object> model) {
populateBase(request, model); populateBase(request, model);
...@@ -86,6 +91,7 @@ public class EurekaController { ...@@ -86,6 +91,7 @@ public class EurekaController {
model.put("time", new Date()); model.put("time", new Date());
model.put("basePath", basePath); model.put("basePath", basePath);
model.put("dashboardPath", dashboardPath);
populateHeader(model); populateHeader(model);
......
...@@ -3,6 +3,7 @@ package org.springframework.cloud.netflix.eureka.server; ...@@ -3,6 +3,7 @@ package org.springframework.cloud.netflix.eureka.server;
import javax.servlet.Filter; import javax.servlet.Filter;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaServerConfigBean; import org.springframework.cloud.netflix.eureka.EurekaServerConfigBean;
...@@ -26,6 +27,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer; ...@@ -26,6 +27,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
@Bean @Bean
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true)
public EurekaController eurekaController() { public EurekaController eurekaController() {
return new EurekaController(); return new EurekaController();
} }
...@@ -36,7 +38,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { ...@@ -36,7 +38,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
bean.setFilter(new ServletContainer()); bean.setFilter(new ServletContainer());
bean.setOrder(Ordered.LOWEST_PRECEDENCE); bean.setOrder(Ordered.LOWEST_PRECEDENCE);
bean.addInitParameter("com.sun.jersey.config.property.WebPageContentRegex", bean.addInitParameter("com.sun.jersey.config.property.WebPageContentRegex",
EurekaServerConfigBean.DEFAULT_PREFIX + "/(fonts|images|css)/.*"); EurekaServerConfigBean.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");
bean.addInitParameter("com.sun.jersey.config.property.packages", bean.addInitParameter("com.sun.jersey.config.property.packages",
"com.netflix.discovery;com.netflix.eureka"); "com.netflix.discovery;com.netflix.eureka");
bean.setUrlPatterns(Lists.newArrayList(EurekaServerConfigBean.DEFAULT_PREFIX bean.setUrlPatterns(Lists.newArrayList(EurekaServerConfigBean.DEFAULT_PREFIX
......
<#import "/spring.ftl" as spring />
<nav class="navbar navbar-default" role="navigation"> <nav class="navbar navbar-default" role="navigation">
<div class="container"> <div class="container">
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href="${basePath}"><span></span></a> <a class="navbar-brand" href="<@spring.url dashboardPath/>"><span></span></a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
...@@ -12,10 +13,10 @@ ...@@ -12,10 +13,10 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li> <li>
<a href="${basePath}">Home</a> <a href="<@spring.url dashboardPath/>">Home</a>
</li> </li>
<li> <li>
<a href="lastn">Last 1000 since startup</a> <a href="<@spring.url dashboardPath/>/lastn">Last 1000 since startup</a>
</li> </li>
</ul> </ul>
</div> </div>
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
<css>webjar:bootstrap/3.2.0/less/bootstrap.less</css> <css>webjar:bootstrap/3.2.0/less/bootstrap.less</css>
<css>file:${project.basedir}/src/main/wro/main.less</css> <css>file:${project.basedir}/src/main/wro/main.less</css>
<js>webjar:jquery/2.1.1/jquery.min.js</js> <js>webjar:jquery/2.1.1/jquery.min.js</js>
<js>webjar:bootstrap/3.2.0/bootstrap.js</js> <js>webjar:bootstrap/3.2.0/js/bootstrap.min.js</js>
</group> </group>
</groups> </groups>
\ No newline at end of file
...@@ -70,6 +70,13 @@ public class ApplicationContextTests { ...@@ -70,6 +70,13 @@ public class ApplicationContextTests {
} }
@Test @Test
public void jsAvailable() {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/context/eureka/js/wro.js", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
@Test
public void adminLoads() { public void adminLoads() {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
......
package org.springframework.cloud.netflix.eureka.server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.netflix.eureka.server.ApplicationContextTests.Application;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.Map;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest({ "server.port=0", "spring.application.name=eureka",
"eureka.dashboard.enabled=false" })
public class ApplicationDashboardDisabledTests {
@Value("${local.server.port}")
private int port = 0;
@Test
public void catalogLoads() {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/eureka/apps", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
@Test
public void dashboardLoads() {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/", String.class);
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
}
}
package org.springframework.cloud.netflix.eureka.server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.netflix.eureka.server.ApplicationContextTests.Application;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest({ "server.port=0", "spring.application.name=eureka",
"eureka.dashboard.path=/dashboard" })
public class ApplicationDashboardPathTests {
@Value("${local.server.port}")
private int port = 0;
@Test
public void catalogLoads() {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/eureka/apps", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
@Test
public void dashboardLoads() {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/dashboard", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
String body = entity.getBody();
// System.err.println(body);
assertTrue(body.contains("eureka/js"));
assertTrue(body.contains("eureka/css"));
// The "DS Replicas"
assertTrue(
body.contains("<a href=\"http://localhost:8761/eureka/\">localhost</a>"));
// The Home
assertTrue(
body.contains("<a href=\"/dashboard\">Home</a>"));
// The Lastn
assertTrue(
body.contains("<a href=\"/dashboard/lastn\">Last"));
}
@Test
public void cssAvailable() {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/eureka/css/wro.css", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
@Test
public void jsAvailable() {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/eureka/js/wro.js", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
}
...@@ -70,6 +70,13 @@ public class ApplicationServletPathTests { ...@@ -70,6 +70,13 @@ public class ApplicationServletPathTests {
} }
@Test @Test
public void jsAvailable() {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + port + "/servlet/eureka/js/wro.js", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}
@Test
public void adminLoads() { public void adminLoads() {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment