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;
import com.netflix.eureka.util.StatusInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -26,12 +27,16 @@ import java.util.*;
* @author Spencer Gibb
*/
@Controller
@RequestMapping("${eureka.dashboard.path:/}")
public class EurekaController {
@Value("${eureka.dashboard.path:/}")
private String dashboardPath = "";
@Autowired
ServerProperties serverProperties;
@RequestMapping(value = "/", method = RequestMethod.GET)
@RequestMapping(method = RequestMethod.GET)
public String status(HttpServletRequest request, Map<String, Object> model) {
populateBase(request, model);
......@@ -86,6 +91,7 @@ public class EurekaController {
model.put("time", new Date());
model.put("basePath", basePath);
model.put("dashboardPath", dashboardPath);
populateHeader(model);
......
......@@ -3,6 +3,7 @@ package org.springframework.cloud.netflix.eureka.server;
import javax.servlet.Filter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaServerConfigBean;
......@@ -26,6 +27,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
@Bean
@ConditionalOnProperty(prefix = "eureka.dashboard", name = "enabled", matchIfMissing = true)
public EurekaController eurekaController() {
return new EurekaController();
}
......@@ -36,7 +38,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
bean.setFilter(new ServletContainer());
bean.setOrder(Ordered.LOWEST_PRECEDENCE);
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",
"com.netflix.discovery;com.netflix.eureka");
bean.setUrlPatterns(Lists.newArrayList(EurekaServerConfigBean.DEFAULT_PREFIX
......
<#import "/spring.ftl" as spring />
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<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">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
......@@ -12,10 +13,10 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="${basePath}">Home</a>
<a href="<@spring.url dashboardPath/>">Home</a>
</li>
<li>
<a href="lastn">Last 1000 since startup</a>
<a href="<@spring.url dashboardPath/>/lastn">Last 1000 since startup</a>
</li>
</ul>
</div>
......
......@@ -3,6 +3,6 @@
<css>webjar:bootstrap/3.2.0/less/bootstrap.less</css>
<css>file:${project.basedir}/src/main/wro/main.less</css>
<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>
</groups>
\ No newline at end of file
......@@ -70,6 +70,13 @@ public class ApplicationContextTests {
}
@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() {
@SuppressWarnings("rawtypes")
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 {
}
@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() {
@SuppressWarnings("rawtypes")
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