Commit c136054e authored by Phillip Webb's avatar Phillip Webb

Merge branch '1.3.x'

parents 0c1cf731 5b97981c
......@@ -148,10 +148,12 @@ public class HalBrowserMvcEndpoint extends HalJsonMvcEndpoint
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());
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 + "'");
return new TransformedResource(resource, content.getBytes(DEFAULT_CHARSET));
}
......
......@@ -89,7 +89,8 @@ public class HalBrowserMvcEndpointManagementContextPathIntegrationTests {
@Test
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(content().string(containsString("entryPoint: '/admin'")));
}
......
......@@ -64,7 +64,8 @@ public class IntegrationAutoConfiguration {
@ConditionalOnClass(EnableIntegrationMBeanExport.class)
@ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT)
@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;
......@@ -81,7 +82,8 @@ public class IntegrationAutoConfiguration {
@Override
public void setEnvironment(Environment environment) {
this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.jmx.");
this.propertyResolver = new RelaxedPropertyResolver(environment,
"spring.jmx.");
}
@Bean
......
......@@ -36,7 +36,7 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread thread, Throwable exception) {
if (exception instanceof SilentExitException) {
if (jvmWillExit(thread)) {
if (isJvmExiting(thread)) {
preventNonZeroExitCode();
}
return;
......@@ -46,19 +46,7 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
}
}
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 boolean jvmWillExit(Thread exceptionThread) {
private boolean isJvmExiting(Thread exceptionThread) {
for (Thread thread : getAllThreads()) {
if (thread != exceptionThread && thread.isAlive() && !thread.isDaemon()) {
return false;
......@@ -67,22 +55,15 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
return true;
}
protected void preventNonZeroExitCode() {
System.exit(0);
}
protected Thread[] getAllThreads() {
ThreadGroup rootThreadGroup = getRootThreadGroup();
int size = 32;
int threadCount;
Thread[] threads;
do {
size *= 2;
threads = new Thread[size];
threadCount = rootThreadGroup.enumerate(threads);
Thread[] threads = new Thread[32];
int count = rootThreadGroup.enumerate(threads);
while (count == threads.length) {
threads = new Thread[threads.length * 2];
count = rootThreadGroup.enumerate(threads);
}
while (threadCount == threads.length);
return Arrays.copyOf(threads, threadCount);
return Arrays.copyOf(threads, count);
}
private ThreadGroup getRootThreadGroup() {
......@@ -93,6 +74,22 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
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 {
}
......
......@@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
* Tests for {@link SilentExitExceptionHandler}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class SilentExitExceptionHandlerTests {
......
......@@ -2133,9 +2133,9 @@ packaged as an executable archive), there are some limitations in the JSP suppor
* Undertow does not support JSPs.
* Creating a custom `error.jsp` page won't override the default view for
<<boot-features-error-handling,error handling>>.
<<boot-features-error-handling-custom-error-pages,Custom error pages>> should be used
instead.
<<boot-features-error-handling,error handling>>,
<<boot-features-error-handling-custom-error-pages,custom error pages>> should be used
instead.
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so you
can see how to set things up.
......
......@@ -399,9 +399,9 @@ public class SpringApplicationTests {
application.setBeanNameGenerator(beanNameGenerator);
this.context = application.run();
verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator);
Object bean = this.context
Object actualGenerator = this.context
.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
assertThat(bean).isSameAs(beanNameGenerator);
assertThat(actualGenerator).isSameAs(beanNameGenerator);
}
@Test
......@@ -413,9 +413,9 @@ public class SpringApplicationTests {
application.setBeanNameGenerator(beanNameGenerator);
this.context = application.run();
verify(application.getLoader()).setBeanNameGenerator(beanNameGenerator);
Object bean = this.context
Object actualGenerator = this.context
.getBean(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
assertThat(bean).isSameAs(beanNameGenerator);
assertThat(actualGenerator).isSameAs(beanNameGenerator);
}
@Test
......
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