Polish
This commit is contained in:
parent
466ed469eb
commit
d17b7c8195
|
|
@ -22,7 +22,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration properties for some health properties
|
* Configuration properties for some health properties
|
||||||
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
|
* @since 1.2.0
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties("health.status")
|
@ConfigurationProperties("health.status")
|
||||||
public class HealthIndicatorAutoConfigurationProperties {
|
public class HealthIndicatorAutoConfigurationProperties {
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,8 @@ public class ManagementSecurityAutoConfiguration {
|
||||||
List<String> ignored = SpringBootWebSecurityConfiguration
|
List<String> ignored = SpringBootWebSecurityConfiguration
|
||||||
.getIgnored(this.security);
|
.getIgnored(this.security);
|
||||||
if (!this.management.getSecurity().isEnabled()) {
|
if (!this.management.getSecurity().isEnabled()) {
|
||||||
ignored.addAll(Arrays.asList(getEndpointPaths(
|
ignored.addAll(Arrays
|
||||||
this.endpointHandlerMapping)));
|
.asList(getEndpointPaths(this.endpointHandlerMapping)));
|
||||||
}
|
}
|
||||||
if (ignored.contains("none")) {
|
if (ignored.contains("none")) {
|
||||||
ignored.remove("none");
|
ignored.remove("none");
|
||||||
|
|
@ -227,11 +227,10 @@ public class ManagementSecurityAutoConfiguration {
|
||||||
http.exceptionHandling().authenticationEntryPoint(entryPoint());
|
http.exceptionHandling().authenticationEntryPoint(entryPoint());
|
||||||
paths = this.server.getPathsArray(paths);
|
paths = this.server.getPathsArray(paths);
|
||||||
http.requestMatchers().antMatchers(paths);
|
http.requestMatchers().antMatchers(paths);
|
||||||
// @formatter:off
|
String[] endpointPaths = this.server.getPathsArray(getEndpointPaths(
|
||||||
http.authorizeRequests()
|
this.endpointHandlerMapping, false));
|
||||||
.antMatchers(this.server.getPathsArray(getEndpointPaths(this.endpointHandlerMapping, false))).access("permitAll()")
|
http.authorizeRequests().antMatchers(endpointPaths).access("permitAll()")
|
||||||
.anyRequest().hasRole(this.management.getSecurity().getRole());
|
.anyRequest().hasRole(this.management.getSecurity().getRole());
|
||||||
// @formatter:on
|
|
||||||
http.httpBasic();
|
http.httpBasic();
|
||||||
|
|
||||||
// No cookies for management endpoints by default
|
// No cookies for management endpoints by default
|
||||||
|
|
|
||||||
|
|
@ -36,20 +36,19 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
|
||||||
|
|
||||||
private final HealthIndicator healthIndicator;
|
private final HealthIndicator healthIndicator;
|
||||||
|
|
||||||
private long ttl = 1000;
|
private long timeToLive = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Time to live for cached result. If accessed anonymously, we might need to cache the
|
* Time to live for cached result. If accessed anonymously, we might need to cache the
|
||||||
* result of this endpoint to prevent a DOS attack.
|
* result of this endpoint to prevent a DOS attack.
|
||||||
*
|
|
||||||
* @return time to live in milliseconds (default 1000)
|
* @return time to live in milliseconds (default 1000)
|
||||||
*/
|
*/
|
||||||
public long getTtl() {
|
public long getTimeToLive() {
|
||||||
return ttl;
|
return this.timeToLive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTtl(long ttl) {
|
public void setTimeToLive(long ttl) {
|
||||||
this.ttl = ttl;
|
this.timeToLive = ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,9 @@ package org.springframework.boot.actuate.endpoint.mvc;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
@ -52,7 +53,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
||||||
public class EndpointHandlerMapping extends RequestMappingHandlerMapping implements
|
public class EndpointHandlerMapping extends RequestMappingHandlerMapping implements
|
||||||
ApplicationContextAware {
|
ApplicationContextAware {
|
||||||
|
|
||||||
private final Map<String, MvcEndpoint> endpoints = new HashMap<String, MvcEndpoint>();
|
private final Map<String, MvcEndpoint> endpoints;
|
||||||
|
|
||||||
private String prefix = "";
|
private String prefix = "";
|
||||||
|
|
||||||
|
|
@ -64,15 +65,21 @@ public class EndpointHandlerMapping extends RequestMappingHandlerMapping impleme
|
||||||
* @param endpoints
|
* @param endpoints
|
||||||
*/
|
*/
|
||||||
public EndpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
|
public EndpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
|
||||||
HashMap<String, MvcEndpoint> map = (HashMap<String, MvcEndpoint>) this.endpoints;
|
this.endpoints = buildEndpointsMap(endpoints);
|
||||||
for (MvcEndpoint endpoint : endpoints) {
|
|
||||||
map.put(endpoint.getPath(), endpoint);
|
|
||||||
}
|
|
||||||
// By default the static resource handler mapping is LOWEST_PRECEDENCE - 1
|
// By default the static resource handler mapping is LOWEST_PRECEDENCE - 1
|
||||||
// and the RequestMappingHandlerMapping is 0 (we ideally want to be before both)
|
// and the RequestMappingHandlerMapping is 0 (we ideally want to be before both)
|
||||||
setOrder(-100);
|
setOrder(-100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, MvcEndpoint> buildEndpointsMap(
|
||||||
|
Collection<? extends MvcEndpoint> endpoints) {
|
||||||
|
Map<String, MvcEndpoint> map = new LinkedHashMap<String, MvcEndpoint>();
|
||||||
|
for (MvcEndpoint endpoint : endpoints) {
|
||||||
|
map.put(endpoint.getPath(), endpoint);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
super.afterPropertiesSet();
|
super.afterPropertiesSet();
|
||||||
|
|
|
||||||
|
|
@ -101,29 +101,26 @@ public class HealthMvcEndpoint implements MvcEndpoint {
|
||||||
@RequestMapping
|
@RequestMapping
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object invoke(Principal principal) {
|
public Object invoke(Principal principal) {
|
||||||
|
if (!this.delegate.isEnabled()) {
|
||||||
if (!delegate.isEnabled()) {
|
|
||||||
// Shouldn't happen because the request mapping should not be registered
|
// Shouldn't happen because the request mapping should not be registered
|
||||||
return new ResponseEntity<Map<String, String>>(Collections.singletonMap(
|
return new ResponseEntity<Map<String, String>>(Collections.singletonMap(
|
||||||
"message", "This endpoint is disabled"), HttpStatus.NOT_FOUND);
|
"message", "This endpoint is disabled"), HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
Health health = getHealth(principal);
|
Health health = getHealth(principal);
|
||||||
Status status = health.getStatus();
|
Status status = health.getStatus();
|
||||||
if (this.statusMapping.containsKey(status.getCode())) {
|
if (this.statusMapping.containsKey(status.getCode())) {
|
||||||
return new ResponseEntity<Health>(health, this.statusMapping.get(status
|
return new ResponseEntity<Health>(health, this.statusMapping.get(status
|
||||||
.getCode()));
|
.getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return health;
|
return health;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Health getHealth(Principal principal) {
|
private Health getHealth(Principal principal) {
|
||||||
Health health = useCachedValue(principal) ? cached : (Health) delegate.invoke();
|
Health health = (useCachedValue(principal) ? this.cached : (Health) this.delegate
|
||||||
|
.invoke());
|
||||||
// Not too worried about concurrent access here, the worst that can happen is the
|
// Not too worried about concurrent access here, the worst that can happen is the
|
||||||
// odd extra call to delegate.invoke()
|
// odd extra call to delegate.invoke()
|
||||||
cached = health;
|
this.cached = health;
|
||||||
if (!secure(principal)) {
|
if (!secure(principal)) {
|
||||||
// If not secure we only expose the status
|
// If not secure we only expose the status
|
||||||
health = Health.status(health.getStatus()).build();
|
health = Health.status(health.getStatus()).build();
|
||||||
|
|
@ -137,12 +134,12 @@ public class HealthMvcEndpoint implements MvcEndpoint {
|
||||||
|
|
||||||
private boolean useCachedValue(Principal principal) {
|
private boolean useCachedValue(Principal principal) {
|
||||||
long currentAccess = System.currentTimeMillis();
|
long currentAccess = System.currentTimeMillis();
|
||||||
if (cached == null || secure(principal)
|
if (this.cached == null || secure(principal)
|
||||||
|| currentAccess - lastAccess > delegate.getTtl()) {
|
|| (currentAccess - this.lastAccess) > this.delegate.getTimeToLive()) {
|
||||||
lastAccess = currentAccess;
|
this.lastAccess = currentAccess;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return cached != null;
|
return this.cached != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ public class ConfigurationPropertiesReportEndpointTests extends
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testKeySanitization() throws Exception {
|
public void testKeySanitization() throws Exception {
|
||||||
ConfigurationPropertiesReportEndpoint report = getEndpointBean();
|
ConfigurationPropertiesReportEndpoint report = getEndpointBean();
|
||||||
report.setKeysToSanitize(new String[] { "property" });
|
report.setKeysToSanitize("property");
|
||||||
Map<String, Object> properties = report.invoke();
|
Map<String, Object> properties = report.invoke();
|
||||||
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
|
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
|
||||||
.get("testProperties")).get("properties");
|
.get("testProperties")).get("properties");
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.endpoint.mvc;
|
package org.springframework.boot.actuate.endpoint.mvc;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
@ -33,10 +28,16 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.authority.AuthorityUtils;
|
import org.springframework.security.core.authority.AuthorityUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.BDDMockito.given;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link HealthMvcEndpoint}.
|
* Tests for {@link HealthMvcEndpoint}.
|
||||||
*
|
*
|
||||||
* @author Christian Dupuis
|
* @author Christian Dupuis
|
||||||
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
public class HealthMvcEndpointTests {
|
public class HealthMvcEndpointTests {
|
||||||
|
|
||||||
|
|
@ -92,7 +93,7 @@ public class HealthMvcEndpointTests {
|
||||||
public void secure() {
|
public void secure() {
|
||||||
given(this.endpoint.invoke()).willReturn(
|
given(this.endpoint.invoke()).willReturn(
|
||||||
new Health.Builder().up().withDetail("foo", "bar").build());
|
new Health.Builder().up().withDetail("foo", "bar").build());
|
||||||
Object result = this.mvc.invoke(user);
|
Object result = this.mvc.invoke(this.user);
|
||||||
assertTrue(result instanceof Health);
|
assertTrue(result instanceof Health);
|
||||||
assertTrue(((Health) result).getStatus() == Status.UP);
|
assertTrue(((Health) result).getStatus() == Status.UP);
|
||||||
assertEquals("bar", ((Health) result).getDetails().get("foo"));
|
assertEquals("bar", ((Health) result).getDetails().get("foo"));
|
||||||
|
|
@ -100,25 +101,25 @@ public class HealthMvcEndpointTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void secureNotCached() {
|
public void secureNotCached() {
|
||||||
given(this.endpoint.getTtl()).willReturn(10000L);
|
given(this.endpoint.getTimeToLive()).willReturn(10000L);
|
||||||
given(this.endpoint.invoke()).willReturn(
|
given(this.endpoint.invoke()).willReturn(
|
||||||
new Health.Builder().up().withDetail("foo", "bar").build());
|
new Health.Builder().up().withDetail("foo", "bar").build());
|
||||||
Object result = this.mvc.invoke(user);
|
Object result = this.mvc.invoke(this.user);
|
||||||
assertTrue(result instanceof Health);
|
assertTrue(result instanceof Health);
|
||||||
assertTrue(((Health) result).getStatus() == Status.UP);
|
assertTrue(((Health) result).getStatus() == Status.UP);
|
||||||
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
|
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
|
||||||
result = this.mvc.invoke(user);
|
result = this.mvc.invoke(this.user);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Health health = (Health) ((ResponseEntity<Health>) result).getBody();
|
Health health = ((ResponseEntity<Health>) result).getBody();
|
||||||
assertTrue(health.getStatus() == Status.DOWN);
|
assertTrue(health.getStatus() == Status.DOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unsecureCached() {
|
public void unsecureCached() {
|
||||||
given(this.endpoint.getTtl()).willReturn(10000L);
|
given(this.endpoint.getTimeToLive()).willReturn(10000L);
|
||||||
given(this.endpoint.invoke()).willReturn(
|
given(this.endpoint.invoke()).willReturn(
|
||||||
new Health.Builder().up().withDetail("foo", "bar").build());
|
new Health.Builder().up().withDetail("foo", "bar").build());
|
||||||
Object result = this.mvc.invoke(user);
|
Object result = this.mvc.invoke(this.user);
|
||||||
assertTrue(result instanceof Health);
|
assertTrue(result instanceof Health);
|
||||||
assertTrue(((Health) result).getStatus() == Status.UP);
|
assertTrue(((Health) result).getStatus() == Status.UP);
|
||||||
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
|
given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @since 1.2.0
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "spring.mail")
|
@ConfigurationProperties(prefix = "spring.mail")
|
||||||
public class MailProperties {
|
public class MailProperties {
|
||||||
|
|
@ -43,7 +44,7 @@ public class MailProperties {
|
||||||
private Map<String, String> properties = new HashMap<String, String>();
|
private Map<String, String> properties = new HashMap<String, String>();
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return host;
|
return this.host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHost(String host) {
|
public void setHost(String host) {
|
||||||
|
|
@ -51,7 +52,7 @@ public class MailProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getPort() {
|
public Integer getPort() {
|
||||||
return port;
|
return this.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPort(Integer port) {
|
public void setPort(Integer port) {
|
||||||
|
|
@ -59,7 +60,7 @@ public class MailProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return this.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsername(String username) {
|
public void setUsername(String username) {
|
||||||
|
|
@ -67,7 +68,7 @@ public class MailProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return this.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
|
|
@ -75,7 +76,7 @@ public class MailProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultEncoding() {
|
public String getDefaultEncoding() {
|
||||||
return defaultEncoding;
|
return this.defaultEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultEncoding(String defaultEncoding) {
|
public void setDefaultEncoding(String defaultEncoding) {
|
||||||
|
|
@ -83,7 +84,7 @@ public class MailProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getProperties() {
|
public Map<String, String> getProperties() {
|
||||||
return properties;
|
return this.properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.mail;
|
package org.springframework.boot.autoconfigure.mail;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.activation.MimeType;
|
import javax.activation.MimeType;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
|
|
||||||
|
|
@ -38,15 +38,17 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
*
|
*
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @sicne 1.2.0
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({MimeMessage.class, MimeType.class})
|
@ConditionalOnClass({ MimeMessage.class, MimeType.class })
|
||||||
@ConditionalOnProperty(prefix = "spring.mail", value = "host")
|
@ConditionalOnProperty(prefix = "spring.mail", value = "host")
|
||||||
@ConditionalOnMissingBean(MailSender.class)
|
@ConditionalOnMissingBean(MailSender.class)
|
||||||
@EnableConfigurationProperties(MailProperties.class)
|
@EnableConfigurationProperties(MailProperties.class)
|
||||||
public class MailSenderAutoConfiguration {
|
public class MailSenderAutoConfiguration {
|
||||||
|
|
||||||
@Autowired MailProperties properties;
|
@Autowired
|
||||||
|
MailProperties properties;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JavaMailSender mailSender() {
|
public JavaMailSender mailSender() {
|
||||||
|
|
@ -58,13 +60,10 @@ public class MailSenderAutoConfiguration {
|
||||||
sender.setUsername(this.properties.getUsername());
|
sender.setUsername(this.properties.getUsername());
|
||||||
sender.setPassword(this.properties.getPassword());
|
sender.setPassword(this.properties.getPassword());
|
||||||
sender.setDefaultEncoding(this.properties.getDefaultEncoding());
|
sender.setDefaultEncoding(this.properties.getDefaultEncoding());
|
||||||
Map<String,String> properties = this.properties.getProperties();
|
if (!this.properties.getProperties().isEmpty()) {
|
||||||
if (!properties.isEmpty()) {
|
Properties properties = new Properties();
|
||||||
Properties javaMailProperties= new Properties();
|
properties.putAll(this.properties.getProperties());
|
||||||
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
sender.setJavaMailProperties(properties);
|
||||||
javaMailProperties.setProperty(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
sender.setJavaMailProperties(javaMailProperties);
|
|
||||||
}
|
}
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
|
||||||
|
|
||||||
private void storeErrorAttributes(HttpServletRequest request, Exception ex) {
|
private void storeErrorAttributes(HttpServletRequest request, Exception ex) {
|
||||||
request.setAttribute(ERROR_ATTRIBUTE, ex);
|
request.setAttribute(ERROR_ATTRIBUTE, ex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -122,7 +121,8 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object message = getAttribute(requestAttributes, "javax.servlet.error.message");
|
Object message = getAttribute(requestAttributes, "javax.servlet.error.message");
|
||||||
if ((message != null || errorAttributes.get("message") == null) && !(error instanceof BindingResult)) {
|
if ((message != null || errorAttributes.get("message") == null)
|
||||||
|
&& !(error instanceof BindingResult)) {
|
||||||
errorAttributes.put("message", message == null ? "No message available"
|
errorAttributes.put("message", message == null ? "No message available"
|
||||||
: message);
|
: message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import org.junit.After;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
@ -28,7 +27,8 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link MailSenderAutoConfiguration}.
|
* Tests for {@link MailSenderAutoConfiguration}.
|
||||||
|
|
@ -53,7 +53,8 @@ public class MailSenderAutoConfigurationTests {
|
||||||
public void smtpHostSet() {
|
public void smtpHostSet() {
|
||||||
String host = "192.168.1.234";
|
String host = "192.168.1.234";
|
||||||
load(EmptyConfig.class, "spring.mail.host:" + host);
|
load(EmptyConfig.class, "spring.mail.host:" + host);
|
||||||
JavaMailSenderImpl bean = (JavaMailSenderImpl) context.getBean(JavaMailSender.class);
|
JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context
|
||||||
|
.getBean(JavaMailSender.class);
|
||||||
assertEquals(host, bean.getHost());
|
assertEquals(host, bean.getHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,8 +62,10 @@ public class MailSenderAutoConfigurationTests {
|
||||||
public void smptHostWithSettings() {
|
public void smptHostWithSettings() {
|
||||||
String host = "192.168.1.234";
|
String host = "192.168.1.234";
|
||||||
load(EmptyConfig.class, "spring.mail.host:" + host, "spring.mail.port:42",
|
load(EmptyConfig.class, "spring.mail.host:" + host, "spring.mail.port:42",
|
||||||
"spring.mail.username:john", "spring.mail.password:secret", "spring.mail.default-encoding:ISO-9");
|
"spring.mail.username:john", "spring.mail.password:secret",
|
||||||
JavaMailSenderImpl bean = (JavaMailSenderImpl) context.getBean(JavaMailSender.class);
|
"spring.mail.default-encoding:ISO-9");
|
||||||
|
JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context
|
||||||
|
.getBean(JavaMailSender.class);
|
||||||
assertEquals(host, bean.getHost());
|
assertEquals(host, bean.getHost());
|
||||||
assertEquals(42, bean.getPort());
|
assertEquals(42, bean.getPort());
|
||||||
assertEquals("john", bean.getUsername());
|
assertEquals("john", bean.getUsername());
|
||||||
|
|
@ -72,29 +75,31 @@ public class MailSenderAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void smptHostWithJavaMailProperties() {
|
public void smptHostWithJavaMailProperties() {
|
||||||
load(EmptyConfig.class, "spring.mail.host:localhost", "spring.mail.properties.mail.smtp.auth:true");
|
load(EmptyConfig.class, "spring.mail.host:localhost",
|
||||||
JavaMailSenderImpl bean = (JavaMailSenderImpl) context.getBean(JavaMailSender.class);
|
"spring.mail.properties.mail.smtp.auth:true");
|
||||||
|
JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context
|
||||||
|
.getBean(JavaMailSender.class);
|
||||||
assertEquals("true", bean.getJavaMailProperties().get("mail.smtp.auth"));
|
assertEquals("true", bean.getJavaMailProperties().get("mail.smtp.auth"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void smtpHostNotSet() {
|
public void smtpHostNotSet() {
|
||||||
load(EmptyConfig.class);
|
load(EmptyConfig.class);
|
||||||
assertEquals(0, context.getBeansOfType(JavaMailSender.class).size());
|
assertEquals(0, this.context.getBeansOfType(JavaMailSender.class).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mailSenderBackOff() {
|
public void mailSenderBackOff() {
|
||||||
load(ManualMailConfiguration.class, "spring.mail.host:smtp.acme.org",
|
load(ManualMailConfiguration.class, "spring.mail.host:smtp.acme.org",
|
||||||
"spring.mail.user:user", "spring.mail.password:secret");
|
"spring.mail.user:user", "spring.mail.password:secret");
|
||||||
JavaMailSenderImpl bean = (JavaMailSenderImpl) context.getBean(JavaMailSender.class);
|
JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context
|
||||||
|
.getBean(JavaMailSender.class);
|
||||||
assertNull(bean.getUsername());
|
assertNull(bean.getUsername());
|
||||||
assertNull(bean.getPassword());
|
assertNull(bean.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void load(Class<?> config, String... environment) {
|
private void load(Class<?> config, String... environment) {
|
||||||
this.context = doLoad(new Class<?>[] {config}, environment);
|
this.context = doLoad(new Class<?>[] { config }, environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext doLoad(Class<?>[] configs,
|
private AnnotationConfigApplicationContext doLoad(Class<?>[] configs,
|
||||||
|
|
@ -119,5 +124,7 @@ public class MailSenderAutoConfigurationTests {
|
||||||
JavaMailSender customMailSender() {
|
JavaMailSender customMailSender() {
|
||||||
return new JavaMailSenderImpl();
|
return new JavaMailSenderImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,8 @@ public class DefaultErrorAttributesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullMessage() throws Exception {
|
public void nullMessage() throws Exception {
|
||||||
this.request.setAttribute("javax.servlet.error.exception", new RuntimeException());
|
this.request
|
||||||
|
.setAttribute("javax.servlet.error.exception", new RuntimeException());
|
||||||
this.request.setAttribute("javax.servlet.error.message", "Test");
|
this.request.setAttribute("javax.servlet.error.message", "Test");
|
||||||
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(
|
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(
|
||||||
this.requestAttributes, false);
|
this.requestAttributes, false);
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,7 @@ content into your application; rather pick only the properties that you need.
|
||||||
endpoints.health.id=health
|
endpoints.health.id=health
|
||||||
endpoints.health.sensitive=false
|
endpoints.health.sensitive=false
|
||||||
endpoints.health.enabled=true
|
endpoints.health.enabled=true
|
||||||
|
endpoints.health.time-to-live=1000
|
||||||
endpoints.info.id=info
|
endpoints.info.id=info
|
||||||
endpoints.info.sensitive=false
|
endpoints.info.sensitive=false
|
||||||
endpoints.info.enabled=true
|
endpoints.info.enabled=true
|
||||||
|
|
|
||||||
|
|
@ -1567,7 +1567,6 @@ would only ever be a development time trick probably).
|
||||||
To use Spring Loaded with the Maven command line, just add it as a dependency in the
|
To use Spring Loaded with the Maven command line, just add it as a dependency in the
|
||||||
Spring Boot plugin declaration, e.g.
|
Spring Boot plugin declaration, e.g.
|
||||||
|
|
||||||
.pom.xml
|
|
||||||
[source,xml,indent=0]
|
[source,xml,indent=0]
|
||||||
----
|
----
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|
@ -1583,9 +1582,11 @@ Spring Boot plugin declaration, e.g.
|
||||||
</plugin>
|
</plugin>
|
||||||
----
|
----
|
||||||
|
|
||||||
This normally works pretty well with Eclipse and IntelliJ as long as
|
This normally works pretty well with Eclipse and IntelliJ as long as they have their
|
||||||
they have their build configuration aligned with the Maven defaults
|
build configuration aligned with the Maven defaults (Eclipse m2e does this out of the
|
||||||
(Eclipse m2e does this out of the box).
|
box).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[howto-reload-springloaded-gradle-and-intellij]]
|
[[howto-reload-springloaded-gradle-and-intellij]]
|
||||||
==== Configuring Spring Loaded for use with Gradle and IntelliJ
|
==== Configuring Spring Loaded for use with Gradle and IntelliJ
|
||||||
|
|
|
||||||
|
|
@ -94,26 +94,30 @@ Here is an example "`hello world`" web application written in Groovy:
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
Then
|
To compile and run the application type:
|
||||||
|
|
||||||
|
[indent=0,subs="verbatim,quotes,attributes"]
|
||||||
----
|
----
|
||||||
$ spring run hello.groovy
|
$ spring run hello.groovy
|
||||||
----
|
----
|
||||||
|
|
||||||
To pass command line arguments to the application, you need to use a
|
To pass command line arguments to the application, you need to use a `--` to separate
|
||||||
"--" to separate them from the "spring" command arguments, e.g.
|
them from the "`spring`" command arguments, e.g.
|
||||||
|
|
||||||
|
[indent=0,subs="verbatim,quotes,attributes"]
|
||||||
----
|
----
|
||||||
$ spring run hello.groovy -- --server.port=9000
|
$ spring run hello.groovy -- --server.port=9000
|
||||||
----
|
----
|
||||||
|
|
||||||
and to set JVM command line arguments you can use the `JAVA_OPTS`
|
To set JVM command line arguments you can use the `JAVA_OPTS` environment variable, e.g.
|
||||||
environment variable, e.g.
|
|
||||||
|
|
||||||
|
[indent=0,subs="verbatim,quotes,attributes"]
|
||||||
----
|
----
|
||||||
$ JAVA_OPTS=-Xmx1024m spring run hello.groovy
|
$ JAVA_OPTS=-Xmx1024m spring run hello.groovy
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[cli-install-uninstall]]
|
[[cli-install-uninstall]]
|
||||||
=== Adding dependencies to the CLI
|
=== Adding dependencies to the CLI
|
||||||
You can add dependencies to the CLI using the `install` command. The command takes one
|
You can add dependencies to the CLI using the `install` command. The command takes one
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,8 @@ public class SampleActuatorApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSecureHealth() throws Exception {
|
public void testSecureHealth() throws Exception {
|
||||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()).getForEntity(
|
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||||
"http://localhost:" + this.port + "/health", String.class);
|
.getForEntity("http://localhost:" + this.port + "/health", 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("\"hello\":1"));
|
entity.getBody().contains("\"hello\":1"));
|
||||||
|
|
|
||||||
|
|
@ -112,13 +112,11 @@ public class VcapApplicationListener implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||||
|
|
||||||
ConfigurableEnvironment environment = event.getEnvironment();
|
ConfigurableEnvironment environment = event.getEnvironment();
|
||||||
if (!environment.containsProperty(VCAP_APPLICATION)
|
if (!environment.containsProperty(VCAP_APPLICATION)
|
||||||
&& !environment.containsProperty(VCAP_SERVICES)) {
|
&& !environment.containsProperty(VCAP_SERVICES)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
addWithPrefix(properties, getPropertiesFromApplication(environment),
|
addWithPrefix(properties, getPropertiesFromApplication(environment),
|
||||||
"vcap.application.");
|
"vcap.application.");
|
||||||
|
|
@ -130,12 +128,10 @@ public class VcapApplicationListener implements
|
||||||
propertySources.addAfter(
|
propertySources.addAfter(
|
||||||
CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
|
CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
|
||||||
new PropertiesPropertySource("vcap", properties));
|
new PropertiesPropertySource("vcap", properties));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
propertySources.addFirst(new PropertiesPropertySource("vcap", properties));
|
propertySources.addFirst(new PropertiesPropertySource("vcap", properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWithPrefix(Properties properties, Properties other, String prefix) {
|
private void addWithPrefix(Properties properties, Properties other, String prefix) {
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.builder;
|
package org.springframework.boot.builder;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -43,6 +34,15 @@ import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link SpringApplicationBuilder}.
|
* Tests for {@link SpringApplicationBuilder}.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.cloudfoundry;
|
package org.springframework.boot.cloudfoundry;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||||
|
|
@ -26,6 +23,9 @@ import org.springframework.boot.test.EnvironmentTestUtils;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link VcapApplicationListener}.
|
* Tests for {@link VcapApplicationListener}.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue