pull/6203/head
Phillip Webb 9 years ago
parent 9d194c2d43
commit 5b97981c87

@ -148,10 +148,12 @@ public class HalBrowserMvcEndpoint extends HalJsonMvcEndpoint
return resource; return resource;
} }
private Resource replaceInitialLink(String contextPath, Resource resource) throws IOException { private Resource replaceInitialLink(String contextPath, Resource resource)
throws IOException {
byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream()); byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
String content = new String(bytes, DEFAULT_CHARSET); String content = new String(bytes, DEFAULT_CHARSET);
String initial = contextPath + getManagementServletContext().getContextPath() + getPath(); String initial = contextPath + getManagementServletContext().getContextPath()
+ getPath();
content = content.replace("entryPoint: '/'", "entryPoint: '" + initial + "'"); content = content.replace("entryPoint: '/'", "entryPoint: '" + initial + "'");
return new TransformedResource(resource, content.getBytes(DEFAULT_CHARSET)); return new TransformedResource(resource, content.getBytes(DEFAULT_CHARSET));
} }

@ -92,7 +92,8 @@ public class HalBrowserMvcEndpointManagementContextPathIntegrationTests {
@Test @Test
public void actuatorBrowserHtml() throws Exception { public void actuatorBrowserHtml() throws Exception {
this.mockMvc.perform(get("/admin/browser.html").accept(MediaType.APPLICATION_JSON)) this.mockMvc
.perform(get("/admin/browser.html").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(containsString("entryPoint: '/admin'"))); .andExpect(content().string(containsString("entryPoint: '/admin'")));
} }

@ -90,8 +90,8 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/browser.html", HttpMethod.GET, "http://localhost:" + this.port + "/spring/actuator/browser.html",
new HttpEntity<Void>(null, headers), String.class); HttpMethod.GET, new HttpEntity<Void>(null, headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertEquals(HttpStatus.OK, entity.getStatusCode());
assertTrue("Wrong body: " + entity.getBody(), assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains("entryPoint: '/spring/actuator'")); entity.getBody().contains("entryPoint: '/spring/actuator'"));

@ -64,7 +64,8 @@ public class IntegrationAutoConfiguration {
@ConditionalOnClass(EnableIntegrationMBeanExport.class) @ConditionalOnClass(EnableIntegrationMBeanExport.class)
@ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT) @ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT)
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
protected static class IntegrationJmxConfiguration implements EnvironmentAware, BeanFactoryAware { protected static class IntegrationJmxConfiguration
implements EnvironmentAware, BeanFactoryAware {
private BeanFactory beanFactory; private BeanFactory beanFactory;
@ -81,7 +82,8 @@ public class IntegrationAutoConfiguration {
@Override @Override
public void setEnvironment(Environment environment) { public void setEnvironment(Environment environment) {
this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.jmx."); this.propertyResolver = new RelaxedPropertyResolver(environment,
"spring.jmx.");
} }
@Bean @Bean

@ -36,7 +36,7 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
@Override @Override
public void uncaughtException(Thread thread, Throwable exception) { public void uncaughtException(Thread thread, Throwable exception) {
if (exception instanceof SilentExitException) { if (exception instanceof SilentExitException) {
if (jvmWillExit(thread)) { if (isJvmExiting(thread)) {
preventNonZeroExitCode(); preventNonZeroExitCode();
} }
return; return;
@ -46,19 +46,7 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
} }
} }
public static void setup(Thread thread) { private boolean isJvmExiting(Thread exceptionThread) {
UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
if (!(handler instanceof SilentExitExceptionHandler)) {
handler = new SilentExitExceptionHandler(handler);
thread.setUncaughtExceptionHandler(handler);
}
}
public static void exitCurrentThread() {
throw new SilentExitException();
}
private boolean jvmWillExit(Thread exceptionThread) {
for (Thread thread : getAllThreads()) { for (Thread thread : getAllThreads()) {
if (thread != exceptionThread && thread.isAlive() && !thread.isDaemon()) { if (thread != exceptionThread && thread.isAlive() && !thread.isDaemon()) {
return false; return false;
@ -67,22 +55,15 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
return true; return true;
} }
protected void preventNonZeroExitCode() {
System.exit(0);
}
protected Thread[] getAllThreads() { protected Thread[] getAllThreads() {
ThreadGroup rootThreadGroup = getRootThreadGroup(); ThreadGroup rootThreadGroup = getRootThreadGroup();
int size = 32; Thread[] threads = new Thread[32];
int threadCount; int count = rootThreadGroup.enumerate(threads);
Thread[] threads; while (count == threads.length) {
do { threads = new Thread[threads.length * 2];
size *= 2; count = rootThreadGroup.enumerate(threads);
threads = new Thread[size];
threadCount = rootThreadGroup.enumerate(threads);
} }
while (threadCount == threads.length); return Arrays.copyOf(threads, count);
return Arrays.copyOf(threads, threadCount);
} }
private ThreadGroup getRootThreadGroup() { private ThreadGroup getRootThreadGroup() {
@ -93,6 +74,22 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
return candidate; return candidate;
} }
protected void preventNonZeroExitCode() {
System.exit(0);
}
public static void setup(Thread thread) {
UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
if (!(handler instanceof SilentExitExceptionHandler)) {
handler = new SilentExitExceptionHandler(handler);
thread.setUncaughtExceptionHandler(handler);
}
}
public static void exitCurrentThread() {
throw new SilentExitException();
}
private static class SilentExitException extends RuntimeException { private static class SilentExitException extends RuntimeException {
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import static org.junit.Assert.fail;
* Tests for {@link SilentExitExceptionHandler}. * Tests for {@link SilentExitExceptionHandler}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson
*/ */
public class SilentExitExceptionHandlerTests { public class SilentExitExceptionHandlerTests {

@ -397,10 +397,9 @@ public class SpringApplicationTests {
application.setBeanNameGenerator(beanNameGenerator); application.setBeanNameGenerator(beanNameGenerator);
this.context = application.run(); this.context = application.run();
verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator);
assertThat( Object actualGenerator = this.context
this.context .getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR), assertThat(actualGenerator, sameInstance((Object) beanNameGenerator));
sameInstance((Object) beanNameGenerator));
} }
@Test @Test
@ -412,10 +411,9 @@ public class SpringApplicationTests {
application.setBeanNameGenerator(beanNameGenerator); application.setBeanNameGenerator(beanNameGenerator);
this.context = application.run(); this.context = application.run();
verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator); verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator);
assertThat( Object actualGenerator = this.context
this.context .getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR), assertThat(actualGenerator, sameInstance((Object) beanNameGenerator));
sameInstance((Object) beanNameGenerator));
} }
@Test @Test

Loading…
Cancel
Save