Merge branch '1.3.x'

This commit is contained in:
Phillip Webb 2016-06-20 18:50:00 -07:00
commit c136054e69
7 changed files with 51 additions and 48 deletions

View File

@ -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));
}

View File

@ -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'")));
}

View File

@ -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

View File

@ -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,6 +46,38 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
}
}
private boolean isJvmExiting(Thread exceptionThread) {
for (Thread thread : getAllThreads()) {
if (thread != exceptionThread && thread.isAlive() && !thread.isDaemon()) {
return false;
}
}
return true;
}
protected Thread[] getAllThreads() {
ThreadGroup rootThreadGroup = getRootThreadGroup();
Thread[] threads = new Thread[32];
int count = rootThreadGroup.enumerate(threads);
while (count == threads.length) {
threads = new Thread[threads.length * 2];
count = rootThreadGroup.enumerate(threads);
}
return Arrays.copyOf(threads, count);
}
private ThreadGroup getRootThreadGroup() {
ThreadGroup candidate = Thread.currentThread().getThreadGroup();
while (candidate.getParent() != null) {
candidate = candidate.getParent();
}
return candidate;
}
protected void preventNonZeroExitCode() {
System.exit(0);
}
public static void setup(Thread thread) {
UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
if (!(handler instanceof SilentExitExceptionHandler)) {
@ -58,41 +90,6 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
throw new SilentExitException();
}
private boolean jvmWillExit(Thread exceptionThread) {
for (Thread thread : getAllThreads()) {
if (thread != exceptionThread && thread.isAlive() && !thread.isDaemon()) {
return false;
}
}
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);
}
while (threadCount == threads.length);
return Arrays.copyOf(threads, threadCount);
}
private ThreadGroup getRootThreadGroup() {
ThreadGroup candidate = Thread.currentThread().getThreadGroup();
while (candidate.getParent() != null) {
candidate = candidate.getParent();
}
return candidate;
}
private static class SilentExitException extends RuntimeException {
}

View File

@ -27,6 +27,7 @@ import static org.junit.Assert.fail;
* Tests for {@link SilentExitExceptionHandler}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class SilentExitExceptionHandlerTests {

View File

@ -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.

View File

@ -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