mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
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,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) {
|
public static void setup(Thread thread) {
|
||||||
UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
|
UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
|
||||||
if (!(handler instanceof SilentExitExceptionHandler)) {
|
if (!(handler instanceof SilentExitExceptionHandler)) {
|
||||||
@ -58,41 +90,6 @@ class SilentExitExceptionHandler implements UncaughtExceptionHandler {
|
|||||||
throw new SilentExitException();
|
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 {
|
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 {
|
||||||
|
|
||||||
|
@ -1972,7 +1972,7 @@ packaged as an executable archive), there are some limitations in the JSP suppor
|
|||||||
* Undertow does not support JSPs.
|
* Undertow does not support JSPs.
|
||||||
|
|
||||||
* Creating a custom `error.jsp` page won't override the default view for
|
* Creating a custom `error.jsp` page won't override the default view for
|
||||||
<<boot-features-error-handling,error handling>>.
|
<<boot-features-error-handling,error handling>>.
|
||||||
|
|
||||||
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so you
|
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so you
|
||||||
can see how to set things up.
|
can see how to set things up.
|
||||||
|
@ -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…
Reference in New Issue
Block a user