Numerous changes to actuator
Numerous changes to the actuator project, including: - Specific Endpoint interface - Spring MVC/Enpoint adapter - Management server context changes - Consistent auto-configuration class naming - Auto-configuration ordering - Javadoc, code formatting and testspull/2/merge
parent
dd69d0f660
commit
8c347fc99b
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.springframework.bootstrap.actuate.properties.EndpointsProperties;
|
|
||||||
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
|
||||||
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for service apps.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@Import({ ActuatorWebConfiguration.class, MetricRepositoryConfiguration.class,
|
|
||||||
ErrorConfiguration.class, TraceFilterConfiguration.class,
|
|
||||||
MetricFilterConfiguration.class, AuditConfiguration.class })
|
|
||||||
public class ActuatorAutoConfiguration {
|
|
||||||
|
|
||||||
// ServerProperties has to be declared in a non-conditional bean, so that it gets
|
|
||||||
// added to the context early enough
|
|
||||||
|
|
||||||
@EnableConfigurationProperties
|
|
||||||
public static class ServerPropertiesConfiguration {
|
|
||||||
|
|
||||||
@ConditionalOnMissingBean(ManagementServerProperties.class)
|
|
||||||
@Bean(name = "org.springframework.bootstrap.actuate.properties.ManagementServerProperties")
|
|
||||||
public ManagementServerProperties managementServerProperties() {
|
|
||||||
return new ManagementServerProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(EndpointsProperties.class)
|
|
||||||
public EndpointsProperties endpointsProperties() {
|
|
||||||
return new EndpointsProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
|
||||||
|
|
||||||
import org.springframework.bootstrap.autoconfigure.web.WebMvcAutoConfiguration.WebMvcConfiguration;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
|
||||||
import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link WebMvcConfiguration} for actuator.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
|
||||||
@Configuration
|
|
||||||
public class ActuatorWebConfiguration extends DelegatingWebMvcConfiguration {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
||||||
addDefaultHttpMessageConverters(converters);
|
|
||||||
for (HttpMessageConverter<?> converter : converters) {
|
|
||||||
if (converter instanceof MappingJackson2HttpMessageConverter) {
|
|
||||||
MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
|
|
||||||
jacksonConverter.getObjectMapper().disable(
|
|
||||||
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.configureMessageConverters(converters);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Conditional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A bean with this annotation will only be instantiated in the management context,
|
|
||||||
* whether that is the current context or a child context. Using this feature makes it
|
|
||||||
* easy to have a single set of configuration beans for both contexts and be able to
|
|
||||||
* switch the management features to a child context externally. Very useful if (for
|
|
||||||
* instance) you want management endpoints but open, or differently secured public facing
|
|
||||||
* endpoints.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Conditional(OnManagementContextCondition.class)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
|
||||||
public @interface ConditionalOnManagementContext {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import javax.servlet.Servlet;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.Endpoint;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.mvc.EndpointHandlerAdapter;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.mvc.EndpointHandlerMapping;
|
||||||
|
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
||||||
|
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.autoconfigure.web.WebMvcAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.context.annotation.AutoConfigureAfter;
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||||
|
import org.springframework.bootstrap.properties.ServerProperties;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.event.ContextClosedEvent;
|
||||||
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link EnableAutoConfiguration Auto-configuration} to enable Spring MVC to handle
|
||||||
|
* {@link Endpoint} requests. If the {@link ManagementServerProperties} specifies a
|
||||||
|
* different port to {@link ServerProperties} a new child context is created, otherwise it
|
||||||
|
* is assumed that endpoint requests will be mapped and handled via an already registered
|
||||||
|
* {@link DispatcherServlet}.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
||||||
|
@AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||||
|
ManagementServerPropertiesAutoConfiguration.class })
|
||||||
|
public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||||
|
ApplicationListener<ContextRefreshedEvent> {
|
||||||
|
|
||||||
|
private static final Integer DISABLED_PORT = Integer.valueOf(0);
|
||||||
|
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private ServerProperties serverProperties = new ServerProperties();
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private ManagementServerProperties managementServerProperties = new ManagementServerProperties();
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public EndpointHandlerMapping endpointHandlerMapping() {
|
||||||
|
EndpointHandlerMapping mapping = new EndpointHandlerMapping();
|
||||||
|
mapping.setDisabled(ManagementServerPort.get(this.applicationContext) != ManagementServerPort.SAME);
|
||||||
|
mapping.setPrefix(this.managementServerProperties.getContextPath());
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public EndpointHandlerAdapter endpointHandlerAdapter() {
|
||||||
|
return new EndpointHandlerAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext)
|
||||||
|
throws BeansException {
|
||||||
|
this.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||||
|
if (event.getApplicationContext() == this.applicationContext) {
|
||||||
|
if (ManagementServerPort.get(this.applicationContext) == ManagementServerPort.DIFFERENT) {
|
||||||
|
createChildManagementContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createChildManagementContext() {
|
||||||
|
|
||||||
|
final AnnotationConfigEmbeddedWebApplicationContext childContext = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||||
|
childContext.setParent(this.applicationContext);
|
||||||
|
childContext.setId(this.applicationContext.getId() + ":management");
|
||||||
|
|
||||||
|
// Register the ManagementServerChildContextConfiguration first followed
|
||||||
|
// by various specific AutoConfiguration classes. NOTE: The child context
|
||||||
|
// is intentionally not completely auto-configured.
|
||||||
|
childContext.register(EndpointWebMvcChildContextConfiguration.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
EmbeddedServletContainerAutoConfiguration.class);
|
||||||
|
|
||||||
|
// Ensure close on the parent also closes the child
|
||||||
|
if (this.applicationContext instanceof ConfigurableApplicationContext) {
|
||||||
|
((ConfigurableApplicationContext) this.applicationContext)
|
||||||
|
.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ContextClosedEvent event) {
|
||||||
|
if (event.getApplicationContext() == EndpointWebMvcAutoConfiguration.this.applicationContext) {
|
||||||
|
childContext.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
childContext.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum ManagementServerPort {
|
||||||
|
|
||||||
|
DISABLE, SAME, DIFFERENT;
|
||||||
|
|
||||||
|
public static ManagementServerPort get(BeanFactory beanFactory) {
|
||||||
|
|
||||||
|
ServerProperties serverProperties;
|
||||||
|
try {
|
||||||
|
serverProperties = beanFactory.getBean(ServerProperties.class);
|
||||||
|
} catch (NoSuchBeanDefinitionException ex) {
|
||||||
|
serverProperties = new ServerProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
ManagementServerProperties managementServerProperties;
|
||||||
|
try {
|
||||||
|
managementServerProperties = beanFactory
|
||||||
|
.getBean(ManagementServerProperties.class);
|
||||||
|
} catch (NoSuchBeanDefinitionException ex) {
|
||||||
|
managementServerProperties = new ManagementServerProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DISABLED_PORT.equals(managementServerProperties.getPort())) {
|
||||||
|
return DISABLE;
|
||||||
|
}
|
||||||
|
return managementServerProperties.getPort() == null
|
||||||
|
|| serverProperties.getPort() == managementServerProperties.getPort() ? SAME
|
||||||
|
: DIFFERENT;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.beans.factory.HierarchicalBeanFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.mvc.EndpointHandlerAdapter;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.mvc.EndpointHandlerMapping;
|
||||||
|
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConditionalOnBean;
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
||||||
|
import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory;
|
||||||
|
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer;
|
||||||
|
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.annotation.web.EnableWebSecurity;
|
||||||
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
import org.springframework.web.servlet.HandlerAdapter;
|
||||||
|
import org.springframework.web.servlet.HandlerMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for triggered from {@link EndpointWebMvcAutoConfiguration} when a new
|
||||||
|
* {@link EmbeddedServletContainer} running on a different port is required.
|
||||||
|
*
|
||||||
|
* @see EndpointWebMvcAutoConfiguration
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class EndpointWebMvcChildContextConfiguration implements
|
||||||
|
EmbeddedServletContainerCustomizer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ManagementServerProperties managementServerProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
|
||||||
|
factory.setPort(this.managementServerProperties.getPort());
|
||||||
|
factory.setAddress(this.managementServerProperties.getAddress());
|
||||||
|
factory.setContextPath(this.managementServerProperties.getContextPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DispatcherServlet dispatcherServlet() {
|
||||||
|
DispatcherServlet dispatcherServlet = new DispatcherServlet();
|
||||||
|
|
||||||
|
// Ensure the parent configuration does not leak down to us
|
||||||
|
dispatcherServlet.setDetectAllHandlerAdapters(false);
|
||||||
|
dispatcherServlet.setDetectAllHandlerExceptionResolvers(false);
|
||||||
|
dispatcherServlet.setDetectAllHandlerMappings(false);
|
||||||
|
dispatcherServlet.setDetectAllViewResolvers(false);
|
||||||
|
|
||||||
|
return dispatcherServlet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HandlerMapping handlerMapping() {
|
||||||
|
return new EndpointHandlerMapping();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HandlerAdapter handlerAdapter() {
|
||||||
|
return new EndpointHandlerAdapter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass({ EnableWebSecurity.class, Filter.class })
|
||||||
|
public static class EndpointWebMvcChildContextSecurityConfiguration {
|
||||||
|
|
||||||
|
// FIXME reuse of security filter here is not good. What if totally different
|
||||||
|
// security config is required. Perhaps we can just drop it on the management
|
||||||
|
// port?
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(name = "springSecurityFilterChain")
|
||||||
|
public Filter springSecurityFilterChain(HierarchicalBeanFactory beanFactory) {
|
||||||
|
BeanFactory parent = beanFactory.getParentBeanFactory();
|
||||||
|
return parent.getBean("springSecurityFilterChain", Filter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.env.EnvEndpoint;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for /metrics endpoint.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
|
||||||
@ConditionalOnMissingBean({ EnvEndpoint.class })
|
|
||||||
public class EnvConfiguration {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConfigurableEnvironment environment;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public EnvEndpoint envEndpoint() {
|
|
||||||
return new EnvEndpoint(this.environment);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.health.HealthEndpoint;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.health.HealthIndicator;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.health.VanillaHealthIndicator;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for /health endpoint.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
|
||||||
@ConditionalOnMissingBean({ HealthEndpoint.class })
|
|
||||||
public class HealthConfiguration {
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private HealthIndicator<? extends Object> healthIndicator = new VanillaHealthIndicator();
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public HealthEndpoint<? extends Object> healthEndpoint() {
|
|
||||||
return new HealthEndpoint<Object>(this.healthIndicator);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,161 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.bootstrap.actuate.autoconfigure.ManagementAutoConfiguration.RememberManagementConfiguration;
|
|
||||||
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
|
||||||
import org.springframework.bootstrap.autoconfigure.web.EmbeddedContainerCustomizerConfiguration;
|
|
||||||
import org.springframework.bootstrap.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
|
||||||
import org.springframework.bootstrap.properties.ServerProperties;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.context.ApplicationListener;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Condition;
|
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
|
||||||
import org.springframework.context.annotation.Conditional;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.context.event.ContextClosedEvent;
|
|
||||||
import org.springframework.context.event.ContextRefreshedEvent;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@Conditional(RememberManagementConfiguration.class)
|
|
||||||
@Import(ManagementEndpointsRegistration.class)
|
|
||||||
public class ManagementAutoConfiguration implements ApplicationContextAware {
|
|
||||||
|
|
||||||
public static final String MEMO_BEAN_NAME = ManagementAutoConfiguration.class
|
|
||||||
.getName() + ".MEMO";
|
|
||||||
|
|
||||||
private ApplicationContext parent;
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ServerProperties configuration = new ServerProperties();
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ManagementServerProperties management = new ManagementServerProperties();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationContext(ApplicationContext applicationContext)
|
|
||||||
throws BeansException {
|
|
||||||
this.parent = applicationContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ApplicationListener<ContextClosedEvent> managementContextClosedListener() {
|
|
||||||
return new ApplicationListener<ContextClosedEvent>() {
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(ContextClosedEvent event) {
|
|
||||||
if (event.getSource() != ManagementAutoConfiguration.this.parent) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ManagementAutoConfiguration.this.context != null) {
|
|
||||||
ManagementAutoConfiguration.this.context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ApplicationListener<ContextRefreshedEvent> managementContextRefeshedListener() {
|
|
||||||
|
|
||||||
return new ApplicationListener<ContextRefreshedEvent>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
|
||||||
|
|
||||||
if (event.getSource() != ManagementAutoConfiguration.this.parent) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ManagementAutoConfiguration.this.configuration.getPort() != ManagementAutoConfiguration.this.management
|
|
||||||
.getPort()) {
|
|
||||||
AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext();
|
|
||||||
context.setParent(ManagementAutoConfiguration.this.parent);
|
|
||||||
context.register(assembleConfigClasses(ManagementAutoConfiguration.this.parent));
|
|
||||||
context.refresh();
|
|
||||||
ManagementAutoConfiguration.this.context = context;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class RememberManagementConfiguration implements Condition {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
|
||||||
Environment environment = context.getEnvironment();
|
|
||||||
int serverPort = environment.getProperty("server.port", Integer.class, 8080);
|
|
||||||
int managementPort = environment.getProperty("management.port",
|
|
||||||
Integer.class, serverPort);
|
|
||||||
if (!context.getBeanFactory().containsSingleton(MEMO_BEAN_NAME)) {
|
|
||||||
context.getBeanFactory().registerSingleton(MEMO_BEAN_NAME,
|
|
||||||
managementPort > 0);
|
|
||||||
}
|
|
||||||
return managementPort > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Class<?>[] assembleConfigClasses(BeanFactory parent) {
|
|
||||||
|
|
||||||
// Some basic context configuration that all child context need
|
|
||||||
ArrayList<Class<?>> configs = new ArrayList<Class<?>>(Arrays.<Class<?>> asList(
|
|
||||||
EmbeddedContainerCustomizerConfiguration.class,
|
|
||||||
ManagementServerConfiguration.class, ErrorConfiguration.class));
|
|
||||||
|
|
||||||
String managementContextBeanName = OnManagementContextCondition.class.getName();
|
|
||||||
|
|
||||||
// Management context only beans pulled in from the deferred list in the parent
|
|
||||||
// context
|
|
||||||
if (parent.containsBean(managementContextBeanName)) {
|
|
||||||
String[] names = parent.getBean(managementContextBeanName, String[].class);
|
|
||||||
for (String name : names) {
|
|
||||||
try {
|
|
||||||
configs.add(ClassUtils.forName(name,
|
|
||||||
ManagementAutoConfiguration.this.parent.getClassLoader()));
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
throw new BeanCreationException(managementContextBeanName,
|
|
||||||
"Class not found: " + name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return configs.toArray(new Class<?>[configs.size()]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.metrics.MetricsEndpoint;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.metrics.PublicMetrics;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.metrics.VanillaPublicMetrics;
|
|
||||||
import org.springframework.bootstrap.actuate.metrics.MetricRepository;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for /metrics endpoint.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
|
||||||
@ConditionalOnMissingBean({ MetricsEndpoint.class })
|
|
||||||
public class MetricsConfiguration {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MetricRepository repository;
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private PublicMetrics metrics;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public MetricsEndpoint metricsEndpoint() {
|
|
||||||
if (this.metrics == null) {
|
|
||||||
this.metrics = new VanillaPublicMetrics(this.repository);
|
|
||||||
}
|
|
||||||
return new MetricsEndpoint(this.metrics);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionLogUtils;
|
|
||||||
import org.springframework.context.annotation.Condition;
|
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A condition that can determine if the bean it applies to is in the management context
|
|
||||||
* (the application context with the management endpoints).
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
* @see ConditionalOnManagementContext
|
|
||||||
*/
|
|
||||||
public class OnManagementContextCondition implements Condition {
|
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(OnManagementContextCondition.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
|
||||||
|
|
||||||
String checking = ConditionLogUtils.getPrefix(logger, metadata);
|
|
||||||
|
|
||||||
Environment environment = context.getEnvironment();
|
|
||||||
int serverPort = environment.getProperty("server.port", Integer.class, 8080);
|
|
||||||
int managementPort = environment.getProperty("management.port", Integer.class,
|
|
||||||
serverPort);
|
|
||||||
|
|
||||||
// If there is no management context, the decision is easy (match=false)
|
|
||||||
boolean managementEnabled = managementPort > 0;
|
|
||||||
|
|
||||||
// The management context is the same as the parent context
|
|
||||||
boolean managementContextInParent = serverPort == managementPort;
|
|
||||||
|
|
||||||
// The current context is a child context with a management server
|
|
||||||
boolean managementChildContext = context.getBeanFactory().getBeanNamesForType(
|
|
||||||
ManagementServerConfiguration.class).length > 0;
|
|
||||||
|
|
||||||
// The management auto configuration either hasn't been added yet or has been
|
|
||||||
// added to the context and it is enabled
|
|
||||||
boolean containsManagementBeans = !context.getBeanFactory().containsSingleton(
|
|
||||||
ManagementAutoConfiguration.MEMO_BEAN_NAME)
|
|
||||||
|| (Boolean) context.getBeanFactory().getSingleton(
|
|
||||||
ManagementAutoConfiguration.MEMO_BEAN_NAME);
|
|
||||||
|
|
||||||
boolean result = managementEnabled
|
|
||||||
&& ((managementContextInParent && containsManagementBeans) || managementChildContext);
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
if (!managementEnabled) {
|
|
||||||
logger.debug(checking + "Management context is disabled");
|
|
||||||
} else {
|
|
||||||
logger.debug(checking + "Management context is in parent: "
|
|
||||||
+ managementContextInParent + " (management.port="
|
|
||||||
+ managementPort + ", server.port=" + serverPort + ")");
|
|
||||||
logger.debug(checking + "In management child context: "
|
|
||||||
+ managementChildContext);
|
|
||||||
logger.debug(checking + "In management parent context: "
|
|
||||||
+ containsManagementBeans);
|
|
||||||
logger.debug(checking + "Finished matching and result is matches="
|
|
||||||
+ result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result && metadata instanceof AnnotationMetadata) {
|
|
||||||
Collection<String> beanClasses = getManagementContextClasses(context
|
|
||||||
.getBeanFactory());
|
|
||||||
beanClasses.add(((AnnotationMetadata) metadata).getClassName());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Collection<String> getManagementContextClasses(
|
|
||||||
ConfigurableListableBeanFactory beanFactory) {
|
|
||||||
String name = OnManagementContextCondition.class.getName();
|
|
||||||
if (!beanFactory.containsSingleton(name)) {
|
|
||||||
beanFactory.registerSingleton(name, new HashSet<String>());
|
|
||||||
}
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Collection<String> result = (Collection<String>) beanFactory.getSingleton(name);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.trace.WebRequestLoggingFilter;
|
|
||||||
import org.springframework.bootstrap.actuate.trace.InMemoryTraceRepository;
|
|
||||||
import org.springframework.bootstrap.actuate.trace.TraceRepository;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for /trace endpoint.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class TraceFilterConfiguration {
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private TraceRepository traceRepository = new InMemoryTraceRepository();
|
|
||||||
|
|
||||||
@ConditionalOnMissingBean(TraceRepository.class)
|
|
||||||
@Configuration
|
|
||||||
protected static class TraceRepositoryConfiguration {
|
|
||||||
@Bean
|
|
||||||
public TraceRepository traceRepository() {
|
|
||||||
return new InMemoryTraceRepository();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
|
||||||
protected static class WebRequestLoggingFilterConfiguration {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TraceRepository traceRepository;
|
|
||||||
|
|
||||||
@Value("${management.dump_requests:false}")
|
|
||||||
private boolean dumpRequests;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WebRequestLoggingFilter webRequestLoggingFilter(BeanFactory beanFactory) {
|
|
||||||
|
|
||||||
WebRequestLoggingFilter filter = new WebRequestLoggingFilter(
|
|
||||||
this.traceRepository);
|
|
||||||
filter.setDumpRequests(this.dumpRequests);
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base for {@link Endpoint} implementations.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public abstract class AbstractEndpoint<T> implements Endpoint<T> {
|
||||||
|
|
||||||
|
private static final MediaType[] NO_MEDIA_TYPES = new MediaType[0];
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Pattern(regexp = "/[^/]*", message = "Path must start with /")
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
private boolean sensitive;
|
||||||
|
|
||||||
|
public AbstractEndpoint(String path) {
|
||||||
|
this(path, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractEndpoint(String path, boolean sensitive) {
|
||||||
|
this.path = path;
|
||||||
|
this.sensitive = sensitive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPath() {
|
||||||
|
return this.path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSensitive() {
|
||||||
|
return this.sensitive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensitive(boolean sensitive) {
|
||||||
|
this.sensitive = sensitive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaType[] getProduces() {
|
||||||
|
return NO_MEDIA_TYPES;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An endpoint that can be used to expose useful information to operations. Usually
|
||||||
|
* exposed via Spring MVC but could also be exposed using some other technique.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
public interface Endpoint<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the path of the endpoint. Must start with '/' and should not include
|
||||||
|
* wildcards.
|
||||||
|
*/
|
||||||
|
String getPath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the endpoint is sensitive, i.e. may return data that the average user
|
||||||
|
* should not see. Mappings can use this as a security hint.
|
||||||
|
*/
|
||||||
|
boolean isSensitive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link MediaType}s that this endpoint produces or {@code null}.
|
||||||
|
*/
|
||||||
|
MediaType[] getProduces();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to invoke the endpoint.
|
||||||
|
* @return the results of the invocation
|
||||||
|
*/
|
||||||
|
T invoke();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConfigurationProperties;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Endpoint} to expose arbitrary application information.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(name = "endpoints.info", ignoreUnknownFields = false)
|
||||||
|
public class InfoEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||||
|
|
||||||
|
private Map<String, ? extends Object> info;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link InfoEndpoint} instance.
|
||||||
|
*
|
||||||
|
* @param info the info to expose
|
||||||
|
*/
|
||||||
|
public InfoEndpoint(Map<String, ? extends Object> info) {
|
||||||
|
super("/info", true);
|
||||||
|
Assert.notNull(info, "Info must not be null");
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> invoke() {
|
||||||
|
Map<String, Object> info = new LinkedHashMap<String, Object>(this.info);
|
||||||
|
info.putAll(getAdditionalInfo());
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Object> getAdditionalInfo() {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConfigurationProperties;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ActionEndpoint} to shutdown the {@link ApplicationContext}.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(name = "endpoints.shutdown", ignoreUnknownFields = false)
|
||||||
|
public class ShutdownEndpoint extends AbstractEndpoint<Map<String, Object>> implements
|
||||||
|
ApplicationContextAware, ActionEndpoint<Map<String, Object>> {
|
||||||
|
|
||||||
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private ManagementServerProperties configuration = new ManagementServerProperties();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link ShutdownEndpoint} instance.
|
||||||
|
*/
|
||||||
|
public ShutdownEndpoint() {
|
||||||
|
super("/shutdown");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> invoke() {
|
||||||
|
if (this.configuration == null || !this.configuration.isAllowShutdown()
|
||||||
|
|| this.context == null) {
|
||||||
|
return Collections.<String, Object> singletonMap("message",
|
||||||
|
"Shutdown not enabled, sorry.");
|
||||||
|
}
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(500L);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
ShutdownEndpoint.this.context.close();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
return Collections.<String, Object> singletonMap("message",
|
||||||
|
"Shutting down, bye...");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||||
|
if (context instanceof ConfigurableApplicationContext) {
|
||||||
|
this.context = (ConfigurableApplicationContext) context;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.bootstrap.actuate.trace.Trace;
|
||||||
|
import org.springframework.bootstrap.actuate.trace.TraceRepository;
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConfigurationProperties;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Endpoint} to expose {@link Trace} information.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(name = "endpoints.trace", ignoreUnknownFields = false)
|
||||||
|
public class TraceEndpoint extends AbstractEndpoint<List<Trace>> {
|
||||||
|
|
||||||
|
private TraceRepository repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link TraceEndpoint} instance.
|
||||||
|
*
|
||||||
|
* @param repository the trace repository
|
||||||
|
*/
|
||||||
|
public TraceEndpoint(TraceRepository repository) {
|
||||||
|
super("/trace");
|
||||||
|
Assert.notNull(repository, "Repository must not be null");
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Trace> invoke() {
|
||||||
|
return this.repository.findAll();
|
||||||
|
}
|
||||||
|
}
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.endpoint.info;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Controller
|
|
||||||
public class InfoEndpoint {
|
|
||||||
|
|
||||||
private Map<String, Object> info;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param info
|
|
||||||
*/
|
|
||||||
public InfoEndpoint(Map<String, Object> info) {
|
|
||||||
this.info = new LinkedHashMap<String, Object>(info);
|
|
||||||
this.info.putAll(getAdditionalInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("${endpoints.info.path:/info}")
|
|
||||||
@ResponseBody
|
|
||||||
public Map<String, Object> info() {
|
|
||||||
return this.info;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, Object> getAdditionalInfo() {
|
|
||||||
return Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,225 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint.mvc;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.Endpoint;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.http.server.ServletServerHttpResponse;
|
||||||
|
import org.springframework.web.HttpMediaTypeNotAcceptableException;
|
||||||
|
import org.springframework.web.accept.ContentNegotiationManager;
|
||||||
|
import org.springframework.web.context.request.ServletWebRequest;
|
||||||
|
import org.springframework.web.servlet.HandlerAdapter;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MVC {@link HandlerAdapter} for {@link Endpoint}s. Similar in may respects to
|
||||||
|
* {@link AbstractMessageConverterMethodProcessor} but not tied to annotated methods.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
* @see EndpointHandlerMapping
|
||||||
|
*/
|
||||||
|
public class EndpointHandlerAdapter implements HandlerAdapter {
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(EndpointHandlerAdapter.class);
|
||||||
|
|
||||||
|
private static final MediaType MEDIA_TYPE_APPLICATION = new MediaType("application");
|
||||||
|
|
||||||
|
private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager();
|
||||||
|
|
||||||
|
private List<HttpMessageConverter<?>> messageConverters;
|
||||||
|
|
||||||
|
private List<MediaType> allSupportedMediaTypes;
|
||||||
|
|
||||||
|
public EndpointHandlerAdapter() {
|
||||||
|
WebMvcConfigurationSupportConventions conventions = new WebMvcConfigurationSupportConventions();
|
||||||
|
setMessageConverters(conventions.getDefaultHttpMessageConverters());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Object handler) {
|
||||||
|
return handler instanceof Endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLastModified(HttpServletRequest request, Object handler) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
Object handler) throws Exception {
|
||||||
|
handle(request, response, (Endpoint<?>) handler);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private void handle(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
Endpoint<?> endpoint) throws Exception {
|
||||||
|
|
||||||
|
Object result = endpoint.invoke();
|
||||||
|
Class<?> resultClass = result.getClass();
|
||||||
|
|
||||||
|
List<MediaType> mediaTypes = getMediaTypes(request, endpoint, resultClass);
|
||||||
|
MediaType selectedMediaType = selectMediaType(mediaTypes);
|
||||||
|
|
||||||
|
ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response);
|
||||||
|
try {
|
||||||
|
if (selectedMediaType != null) {
|
||||||
|
selectedMediaType = selectedMediaType.removeQualityValue();
|
||||||
|
for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
|
||||||
|
if (messageConverter.canWrite(resultClass, selectedMediaType)) {
|
||||||
|
((HttpMessageConverter<Object>) messageConverter).write(result,
|
||||||
|
selectedMediaType, outputMessage);
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Written [" + result + "] as \""
|
||||||
|
+ selectedMediaType + "\" using [" + messageConverter
|
||||||
|
+ "]");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new HttpMediaTypeNotAcceptableException(this.allSupportedMediaTypes);
|
||||||
|
} finally {
|
||||||
|
outputMessage.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MediaType> getMediaTypes(HttpServletRequest request,
|
||||||
|
Endpoint<?> endpoint, Class<?> resultClass)
|
||||||
|
throws HttpMediaTypeNotAcceptableException {
|
||||||
|
List<MediaType> requested = getAcceptableMediaTypes(request);
|
||||||
|
List<MediaType> producible = getProducibleMediaTypes(endpoint, resultClass);
|
||||||
|
|
||||||
|
Set<MediaType> compatible = new LinkedHashSet<MediaType>();
|
||||||
|
for (MediaType r : requested) {
|
||||||
|
for (MediaType p : producible) {
|
||||||
|
if (r.isCompatibleWith(p)) {
|
||||||
|
compatible.add(getMostSpecificMediaType(r, p));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (compatible.isEmpty()) {
|
||||||
|
throw new HttpMediaTypeNotAcceptableException(producible);
|
||||||
|
}
|
||||||
|
List<MediaType> mediaTypes = new ArrayList<MediaType>(compatible);
|
||||||
|
MediaType.sortBySpecificityAndQuality(mediaTypes);
|
||||||
|
return mediaTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MediaType> getAcceptableMediaTypes(HttpServletRequest request)
|
||||||
|
throws HttpMediaTypeNotAcceptableException {
|
||||||
|
List<MediaType> mediaTypes = this.contentNegotiationManager
|
||||||
|
.resolveMediaTypes(new ServletWebRequest(request));
|
||||||
|
return mediaTypes.isEmpty() ? Collections.singletonList(MediaType.ALL)
|
||||||
|
: mediaTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MediaType> getProducibleMediaTypes(Endpoint<?> endpoint,
|
||||||
|
Class<?> returnValueClass) {
|
||||||
|
MediaType[] mediaTypes = endpoint.getProduces();
|
||||||
|
if (mediaTypes != null && mediaTypes.length != 0) {
|
||||||
|
return Arrays.asList(mediaTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.allSupportedMediaTypes.isEmpty()) {
|
||||||
|
return Collections.singletonList(MediaType.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MediaType> result = new ArrayList<MediaType>();
|
||||||
|
for (HttpMessageConverter<?> converter : this.messageConverters) {
|
||||||
|
if (converter.canWrite(returnValueClass, null)) {
|
||||||
|
result.addAll(converter.getSupportedMediaTypes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MediaType getMostSpecificMediaType(MediaType acceptType, MediaType produceType) {
|
||||||
|
produceType = produceType.copyQualityValue(acceptType);
|
||||||
|
return MediaType.SPECIFICITY_COMPARATOR.compare(acceptType, produceType) <= 0 ? acceptType
|
||||||
|
: produceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MediaType selectMediaType(List<MediaType> mediaTypes) {
|
||||||
|
MediaType selectedMediaType = null;
|
||||||
|
for (MediaType mediaType : mediaTypes) {
|
||||||
|
if (mediaType.isConcrete()) {
|
||||||
|
selectedMediaType = mediaType;
|
||||||
|
break;
|
||||||
|
} else if (mediaType.equals(MediaType.ALL)
|
||||||
|
|| mediaType.equals(MEDIA_TYPE_APPLICATION)) {
|
||||||
|
selectedMediaType = MediaType.APPLICATION_OCTET_STREAM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectedMediaType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentNegotiationManager(
|
||||||
|
ContentNegotiationManager contentNegotiationManager) {
|
||||||
|
this.contentNegotiationManager = contentNegotiationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
|
||||||
|
this.messageConverters = messageConverters;
|
||||||
|
Set<MediaType> allSupportedMediaTypes = new LinkedHashSet<MediaType>();
|
||||||
|
for (HttpMessageConverter<?> messageConverter : messageConverters) {
|
||||||
|
allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
|
||||||
|
}
|
||||||
|
this.allSupportedMediaTypes = new ArrayList<MediaType>(allSupportedMediaTypes);
|
||||||
|
MediaType.sortBySpecificity(this.allSupportedMediaTypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default conventions, taken from {@link WebMvcConfigurationSupport} with a few minor
|
||||||
|
* tweaks.
|
||||||
|
*/
|
||||||
|
private static class WebMvcConfigurationSupportConventions extends
|
||||||
|
WebMvcConfigurationSupport {
|
||||||
|
public List<HttpMessageConverter<?>> getDefaultHttpMessageConverters() {
|
||||||
|
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||||
|
addDefaultHttpMessageConverters(converters);
|
||||||
|
for (HttpMessageConverter<?> converter : converters) {
|
||||||
|
if (converter instanceof MappingJackson2HttpMessageConverter) {
|
||||||
|
MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
|
||||||
|
jacksonConverter.getObjectMapper().disable(
|
||||||
|
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return converters;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint.mvc;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.ActionEndpoint;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.Endpoint;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.servlet.HandlerExecutionChain;
|
||||||
|
import org.springframework.web.servlet.HandlerMapping;
|
||||||
|
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link HandlerMapping} to map {@link Endpoint}s to URLs via {@link Endpoint#getPath()}.
|
||||||
|
* Standard {@link Endpoint}s are mapped to GET requests, {@link ActionEndpoint}s are
|
||||||
|
* mapped to POST requests.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
* @see EndpointHandlerAdapter
|
||||||
|
*/
|
||||||
|
public class EndpointHandlerMapping extends AbstractUrlHandlerMapping implements
|
||||||
|
InitializingBean, ApplicationContextAware {
|
||||||
|
|
||||||
|
private List<Endpoint<?>> endpoints;
|
||||||
|
|
||||||
|
private String prefix = "";
|
||||||
|
|
||||||
|
private boolean disabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link EndpointHandlerMapping} instance. All {@link Endpoint}s will be
|
||||||
|
* detected from the {@link ApplicationContext}.
|
||||||
|
*/
|
||||||
|
public EndpointHandlerMapping() {
|
||||||
|
setOrder(HIGHEST_PRECEDENCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link EndpointHandlerMapping} with the specified endpoints.
|
||||||
|
* @param endpoints the endpoints
|
||||||
|
*/
|
||||||
|
public EndpointHandlerMapping(Collection<? extends Endpoint<?>> endpoints) {
|
||||||
|
Assert.notNull(endpoints, "Endpoints must not be null");
|
||||||
|
this.endpoints = new ArrayList<Endpoint<?>>(endpoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
if (this.endpoints == null) {
|
||||||
|
this.endpoints = findEndpointBeans();
|
||||||
|
}
|
||||||
|
if (!this.disabled) {
|
||||||
|
for (Endpoint<?> endpoint : this.endpoints) {
|
||||||
|
registerHandler(this.prefix + endpoint.getPath(), endpoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
private List<Endpoint<?>> findEndpointBeans() {
|
||||||
|
return new ArrayList(BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||||
|
getApplicationContext(), Endpoint.class).values());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object lookupHandler(String urlPath, HttpServletRequest request)
|
||||||
|
throws Exception {
|
||||||
|
Object handler = super.lookupHandler(urlPath, request);
|
||||||
|
if (handler != null) {
|
||||||
|
Object endpoint = (handler instanceof HandlerExecutionChain ? ((HandlerExecutionChain) handler)
|
||||||
|
.getHandler() : handler);
|
||||||
|
String method = (endpoint instanceof ActionEndpoint<?> ? "POST" : "GET");
|
||||||
|
if (request.getMethod().equals(method)) {
|
||||||
|
return endpoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix the prefix to set
|
||||||
|
*/
|
||||||
|
public void setPrefix(String prefix) {
|
||||||
|
Assert.isTrue("".equals(prefix) || StringUtils.startsWithIgnoreCase(prefix, "/"),
|
||||||
|
"prefix must start with '/'");
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if this mapping is disabled.
|
||||||
|
*/
|
||||||
|
public void setDisabled(boolean disabled) {
|
||||||
|
this.disabled = disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if this mapping is disabled.
|
||||||
|
*/
|
||||||
|
public boolean isDisabled() {
|
||||||
|
return this.disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the endpoints
|
||||||
|
*/
|
||||||
|
public List<Endpoint<?>> getEndpoints() {
|
||||||
|
return Collections.unmodifiableList(this.endpoints);
|
||||||
|
}
|
||||||
|
}
|
@ -1,98 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.endpoint.shutdown;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.context.ApplicationListener;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.context.support.ServletRequestHandledEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
@Controller
|
|
||||||
public class ShutdownEndpoint implements ApplicationContextAware,
|
|
||||||
ApplicationListener<ServletRequestHandledEvent> {
|
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(ShutdownEndpoint.class);
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ManagementServerProperties configuration = new ManagementServerProperties();
|
|
||||||
|
|
||||||
private boolean shuttingDown = false;
|
|
||||||
|
|
||||||
@RequestMapping(value = "${endpoints.shutdown.path:/shutdown}", method = RequestMethod.POST)
|
|
||||||
@ResponseBody
|
|
||||||
public Map<String, Object> shutdown() {
|
|
||||||
if (this.configuration.isAllowShutdown()) {
|
|
||||||
this.shuttingDown = true;
|
|
||||||
return Collections.<String, Object> singletonMap("message",
|
|
||||||
"Shutting down, bye...");
|
|
||||||
} else {
|
|
||||||
return Collections.<String, Object> singletonMap("message",
|
|
||||||
"Shutdown not enabled, sorry.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
|
||||||
if (context instanceof ConfigurableApplicationContext) {
|
|
||||||
this.context = (ConfigurableApplicationContext) context;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(ServletRequestHandledEvent event) {
|
|
||||||
|
|
||||||
if (this.context != null && this.configuration.isAllowShutdown()
|
|
||||||
&& this.shuttingDown) {
|
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
logger.info("Shutting down Spring in response to admin request");
|
|
||||||
ConfigurableApplicationContext context = ShutdownEndpoint.this.context;
|
|
||||||
ApplicationContext parent = context.getParent();
|
|
||||||
context.close();
|
|
||||||
if (parent != null
|
|
||||||
&& parent instanceof ConfigurableApplicationContext) {
|
|
||||||
context = (ConfigurableApplicationContext) parent;
|
|
||||||
context.close();
|
|
||||||
parent = context.getParent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.bootstrap.actuate.properties;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import javax.validation.constraints.Pattern;
|
|
||||||
|
|
||||||
import org.springframework.bootstrap.context.annotation.ConfigurationProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Externalized configuration for endpoints (e.g. paths)
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(name = "endpoints", ignoreUnknownFields = false)
|
|
||||||
public class EndpointsProperties {
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint info = new Endpoint("/info");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint metrics = new Endpoint("/metrics");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint health = new Endpoint("/health");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint error = new Endpoint("/error");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint shutdown = new Endpoint("/shutdown");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint trace = new Endpoint("/trace");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint dump = new Endpoint("/dump");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint beans = new Endpoint("/beans");
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
private Endpoint env = new Endpoint("/env");
|
|
||||||
|
|
||||||
public Endpoint getInfo() {
|
|
||||||
return this.info;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getMetrics() {
|
|
||||||
return this.metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getHealth() {
|
|
||||||
return this.health;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getError() {
|
|
||||||
return this.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getShutdown() {
|
|
||||||
return this.shutdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getTrace() {
|
|
||||||
return this.trace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getDump() {
|
|
||||||
return this.dump;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getBeans() {
|
|
||||||
return this.beans;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint getEnv() {
|
|
||||||
return this.env;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Endpoint {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Pattern(regexp = "/[^/]*", message = "Path must start with /")
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
public Endpoint() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Endpoint(String path) {
|
|
||||||
super();
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return this.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPath(String path) {
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getSecurePaths() {
|
|
||||||
return new String[] { getMetrics().getPath(), getBeans().getPath(),
|
|
||||||
getDump().getPath(), getShutdown().getPath(), getTrace().getPath(),
|
|
||||||
getEnv().getPath() };
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getOpenPaths() {
|
|
||||||
return new String[] { getHealth().getPath(), getInfo().getPath(),
|
|
||||||
getError().getPath() };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.web;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker interface used to indicate that a {@link Controller @Controller} is used to
|
||||||
|
* render errors.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public interface ErrorController {
|
||||||
|
|
||||||
|
public String getErrorPath();
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,11 @@
|
|||||||
org.springframework.bootstrap.context.annotation.EnableAutoConfiguration=\
|
org.springframework.bootstrap.context.annotation.EnableAutoConfiguration=\
|
||||||
org.springframework.bootstrap.actuate.autoconfigure.ActuatorAutoConfiguration,\
|
org.springframework.bootstrap.actuate.autoconfigure.AuditAutoConfiguration,\
|
||||||
|
org.springframework.bootstrap.actuate.autoconfigure.EndpointAutoConfiguration,\
|
||||||
|
org.springframework.bootstrap.actuate.autoconfigure.EndpointWebMvcAutoConfiguration,\
|
||||||
|
org.springframework.bootstrap.actuate.autoconfigure.ErrorMvcAutoConfiguration,\
|
||||||
|
org.springframework.bootstrap.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration,\
|
||||||
|
org.springframework.bootstrap.actuate.autoconfigure.MetricFilterAutoConfiguration,\
|
||||||
|
org.springframework.bootstrap.actuate.autoconfigure.MetricRepositoryAutoConfiguration,\
|
||||||
org.springframework.bootstrap.actuate.autoconfigure.SecurityAutoConfiguration,\
|
org.springframework.bootstrap.actuate.autoconfigure.SecurityAutoConfiguration,\
|
||||||
org.springframework.bootstrap.actuate.autoconfigure.ManagementAutoConfiguration
|
org.springframework.bootstrap.actuate.autoconfigure.TraceRepositoryAutoConfiguration,\
|
||||||
|
org.springframework.bootstrap.actuate.autoconfigure.TraceWebFilterAutoConfiguration
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class ActuatorWebConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWebConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigWebApplicationContext();
|
|
||||||
this.context.setServletContext(new MockServletContext());
|
|
||||||
this.context.register(ActuatorWebConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(WebMvcConfigurationSupport.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.audit.AuditEventRepository;
|
||||||
|
import org.springframework.bootstrap.actuate.audit.InMemoryAuditEventRepository;
|
||||||
|
import org.springframework.bootstrap.actuate.security.AuthenticationAuditListener;
|
||||||
|
import org.springframework.bootstrap.actuate.security.AuthorizationAuditListener;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link AuditAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
public class AuditAutoConfigurationTests {
|
||||||
|
|
||||||
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTraceConfiguration() throws Exception {
|
||||||
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
|
this.context.register(AuditAutoConfiguration.class);
|
||||||
|
this.context.refresh();
|
||||||
|
assertNotNull(this.context.getBean(AuditEventRepository.class));
|
||||||
|
assertNotNull(this.context.getBean(AuthenticationAuditListener.class));
|
||||||
|
assertNotNull(this.context.getBean(AuthorizationAuditListener.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ownAutoRepository() throws Exception {
|
||||||
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
|
this.context.register(Config.class, AuditAutoConfiguration.class);
|
||||||
|
this.context.refresh();
|
||||||
|
assertThat(this.context.getBean(AuditEventRepository.class),
|
||||||
|
instanceOf(TestAuditEventRepository.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TestAuditEventRepository testAuditEventRepository() {
|
||||||
|
return new TestAuditEventRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestAuditEventRepository extends InMemoryAuditEventRepository {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,236 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.TestUtils;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.AbstractEndpoint;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.Endpoint;
|
||||||
|
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
||||||
|
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.autoconfigure.web.ServerPropertiesAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.autoconfigure.web.WebMvcAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.client.ClientHttpRequest;
|
||||||
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.util.StreamUtils;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link EndpointWebMvcAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class EndpointWebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
|
private AnnotationConfigEmbeddedWebApplicationContext applicationContext = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void close() {
|
||||||
|
try {
|
||||||
|
this.applicationContext.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSamePort() throws Exception {
|
||||||
|
this.applicationContext.register(RootConfig.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
EmbeddedServletContainerAutoConfiguration.class,
|
||||||
|
WebMvcAutoConfiguration.class,
|
||||||
|
ManagementServerPropertiesAutoConfiguration.class,
|
||||||
|
EndpointWebMvcAutoConfiguration.class);
|
||||||
|
this.applicationContext.refresh();
|
||||||
|
assertContent("/controller", 8080, "controlleroutput");
|
||||||
|
assertContent("/endpoint", 8080, "endpointoutput");
|
||||||
|
assertContent("/controller", 8081, null);
|
||||||
|
assertContent("/endpoint", 8081, null);
|
||||||
|
this.applicationContext.close();
|
||||||
|
assertAllClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onDifferentPort() throws Exception {
|
||||||
|
this.applicationContext.register(RootConfig.class, DifferentPortConfig.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
EmbeddedServletContainerAutoConfiguration.class,
|
||||||
|
WebMvcAutoConfiguration.class,
|
||||||
|
ManagementServerPropertiesAutoConfiguration.class,
|
||||||
|
EndpointWebMvcAutoConfiguration.class);
|
||||||
|
this.applicationContext.refresh();
|
||||||
|
assertContent("/controller", 8080, "controlleroutput");
|
||||||
|
assertContent("/endpoint", 8080, null);
|
||||||
|
assertContent("/controller", 8081, null);
|
||||||
|
assertContent("/endpoint", 8081, "endpointoutput");
|
||||||
|
this.applicationContext.close();
|
||||||
|
assertAllClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void disabled() throws Exception {
|
||||||
|
this.applicationContext.register(RootConfig.class, DisableConfig.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
EmbeddedServletContainerAutoConfiguration.class,
|
||||||
|
WebMvcAutoConfiguration.class,
|
||||||
|
ManagementServerPropertiesAutoConfiguration.class,
|
||||||
|
EndpointWebMvcAutoConfiguration.class);
|
||||||
|
this.applicationContext.refresh();
|
||||||
|
assertContent("/controller", 8080, "controlleroutput");
|
||||||
|
assertContent("/endpoint", 8080, null);
|
||||||
|
assertContent("/controller", 8081, null);
|
||||||
|
assertContent("/endpoint", 8081, null);
|
||||||
|
this.applicationContext.close();
|
||||||
|
assertAllClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void specificPortsViaProperties() throws Exception {
|
||||||
|
TestUtils.addEnviroment(this.applicationContext, "server.port:7070",
|
||||||
|
"management.port:7071");
|
||||||
|
this.applicationContext.register(RootConfig.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
ManagementServerPropertiesAutoConfiguration.class,
|
||||||
|
ServerPropertiesAutoConfiguration.class,
|
||||||
|
EmbeddedServletContainerAutoConfiguration.class,
|
||||||
|
WebMvcAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class);
|
||||||
|
this.applicationContext.refresh();
|
||||||
|
assertContent("/controller", 7070, "controlleroutput");
|
||||||
|
assertContent("/endpoint", 7070, null);
|
||||||
|
assertContent("/controller", 7071, null);
|
||||||
|
assertContent("/endpoint", 7071, "endpointoutput");
|
||||||
|
this.applicationContext.close();
|
||||||
|
assertAllClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextPath() throws Exception {
|
||||||
|
TestUtils.addEnviroment(this.applicationContext, "management.contextPath:/test");
|
||||||
|
this.applicationContext.register(RootConfig.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
ManagementServerPropertiesAutoConfiguration.class,
|
||||||
|
ServerPropertiesAutoConfiguration.class,
|
||||||
|
EmbeddedServletContainerAutoConfiguration.class,
|
||||||
|
WebMvcAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class);
|
||||||
|
this.applicationContext.refresh();
|
||||||
|
assertContent("/controller", 8080, "controlleroutput");
|
||||||
|
assertContent("/test/endpoint", 8080, "endpointoutput");
|
||||||
|
this.applicationContext.close();
|
||||||
|
assertAllClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertAllClosed() throws Exception {
|
||||||
|
assertContent("/controller", 8080, null);
|
||||||
|
assertContent("/endpoint", 8080, null);
|
||||||
|
assertContent("/controller", 8081, null);
|
||||||
|
assertContent("/endpoint", 8081, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertContent(String url, int port, Object expected) throws Exception {
|
||||||
|
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
|
||||||
|
ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI(
|
||||||
|
"http://localhost:" + port + url), HttpMethod.GET);
|
||||||
|
try {
|
||||||
|
ClientHttpResponse response = request.execute();
|
||||||
|
try {
|
||||||
|
String actual = StreamUtils.copyToString(response.getBody(),
|
||||||
|
Charset.forName("UTF-8"));
|
||||||
|
assertThat(actual, equalTo(expected));
|
||||||
|
} finally {
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (expected == null) {
|
||||||
|
if (ConnectException.class.isInstance(ex)
|
||||||
|
|| FileNotFoundException.class.isInstance(ex)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class RootConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TestController testController() {
|
||||||
|
return new TestController();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Endpoint<String> testEndpoint() {
|
||||||
|
return new AbstractEndpoint<String>("/endpoint", false) {
|
||||||
|
@Override
|
||||||
|
public String invoke() {
|
||||||
|
return "endpointoutput";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public static class TestController {
|
||||||
|
|
||||||
|
@RequestMapping("/controller")
|
||||||
|
@ResponseBody
|
||||||
|
public String requestMappedMethod() {
|
||||||
|
return "controlleroutput";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class DifferentPortConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ManagementServerProperties managementServerProperties() {
|
||||||
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
|
properties.setPort(8081);
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class DisableConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ManagementServerProperties managementServerProperties() {
|
||||||
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
|
properties.setPort(0);
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.springframework.bootstrap.actuate.autoconfigure.ActuatorAutoConfiguration.ServerPropertiesConfiguration;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.error.ErrorEndpoint;
|
|
||||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
||||||
import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory;
|
|
||||||
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer;
|
|
||||||
import org.springframework.bootstrap.context.embedded.ErrorPage;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class ErrorConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testErrorEndpointConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(ErrorConfiguration.class,
|
|
||||||
ServerPropertiesConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(ErrorEndpoint.class));
|
|
||||||
ConfigurableEmbeddedServletContainerFactory factory = Mockito
|
|
||||||
.mock(ConfigurableEmbeddedServletContainerFactory.class);
|
|
||||||
this.context.getBean(EmbeddedServletContainerCustomizer.class).customize(factory);
|
|
||||||
Mockito.verify(factory).addErrorPages(Mockito.any(ErrorPage.class));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,169 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.Servlet;
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletRegistration.Dynamic;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.springframework.bootstrap.actuate.TestUtils;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.health.HealthEndpoint;
|
|
||||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
||||||
import org.springframework.bootstrap.autoconfigure.web.ServerPropertiesConfiguration;
|
|
||||||
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer;
|
|
||||||
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerException;
|
|
||||||
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory;
|
|
||||||
import org.springframework.bootstrap.context.embedded.ServletContextInitializer;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class ManagementConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void close() {
|
|
||||||
if (this.context != null) {
|
|
||||||
this.context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testManagementConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(MetricRepositoryConfiguration.class,
|
|
||||||
TraceFilterConfiguration.class, ServerPropertiesConfiguration.class,
|
|
||||||
ActuatorAutoConfiguration.ServerPropertiesConfiguration.class,
|
|
||||||
ManagementAutoConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(HealthEndpoint.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSuppressManagementConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
TestUtils.addEnviroment(this.context, "management.port:0");
|
|
||||||
this.context.register(MetricRepositoryConfiguration.class,
|
|
||||||
TraceFilterConfiguration.class, ServerPropertiesConfiguration.class,
|
|
||||||
ActuatorAutoConfiguration.ServerPropertiesConfiguration.class,
|
|
||||||
ManagementAutoConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertEquals(0, this.context.getBeanNamesForType(HealthEndpoint.class).length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testManagementConfigurationExtensions() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(MetricRepositoryConfiguration.class,
|
|
||||||
TraceFilterConfiguration.class, ServerPropertiesConfiguration.class,
|
|
||||||
ActuatorAutoConfiguration.ServerPropertiesConfiguration.class,
|
|
||||||
ManagementAutoConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class, NewEndpoint.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(NewEndpoint.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testManagementConfigurationExtensionsOrderDependence() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(NewEndpoint.class, MetricRepositoryConfiguration.class,
|
|
||||||
TraceFilterConfiguration.class, ServerPropertiesConfiguration.class,
|
|
||||||
ActuatorAutoConfiguration.ServerPropertiesConfiguration.class,
|
|
||||||
ManagementAutoConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(NewEndpoint.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testChildContextCreated() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
TestUtils.addEnviroment(this.context, "server.port:7000", "management.port:7001");
|
|
||||||
this.context.register(ParentContext.class, MetricRepositoryConfiguration.class,
|
|
||||||
TraceFilterConfiguration.class, ServerPropertiesConfiguration.class,
|
|
||||||
ActuatorAutoConfiguration.ServerPropertiesConfiguration.class,
|
|
||||||
ManagementAutoConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class, NewEndpoint.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertEquals(0, this.context.getBeanNamesForType(HealthEndpoint.class).length);
|
|
||||||
assertEquals(0, this.context.getBeanNamesForType(NewEndpoint.class).length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
protected static class ParentContext {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public EmbeddedServletContainerFactory factory() {
|
|
||||||
return new EmbeddedServletContainerFactory() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EmbeddedServletContainer getEmbdeddedServletContainer(
|
|
||||||
ServletContextInitializer... initializers) {
|
|
||||||
ServletContext servletContext = new MockServletContext() {
|
|
||||||
@Override
|
|
||||||
public Dynamic addServlet(String servletName, Servlet servlet) {
|
|
||||||
return Mockito.mock(Dynamic.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public javax.servlet.FilterRegistration.Dynamic addFilter(
|
|
||||||
String filterName, Filter filter) {
|
|
||||||
// TODO: remove this when @ConditionalOnBean works
|
|
||||||
return Mockito
|
|
||||||
.mock(javax.servlet.FilterRegistration.Dynamic.class);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
for (ServletContextInitializer initializer : initializers) {
|
|
||||||
try {
|
|
||||||
initializer.onStartup(servletContext);
|
|
||||||
} catch (ServletException ex) {
|
|
||||||
throw new IllegalStateException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new EmbeddedServletContainer() {
|
|
||||||
@Override
|
|
||||||
public void stop() throws EmbeddedServletContainerException {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@ConditionalOnManagementContext
|
|
||||||
protected static class NewEndpoint {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.springframework.bootstrap.actuate.autoconfigure.ActuatorAutoConfiguration.ServerPropertiesConfiguration;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.error.ErrorEndpoint;
|
|
||||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
||||||
import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory;
|
|
||||||
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer;
|
|
||||||
import org.springframework.bootstrap.context.embedded.ErrorPage;
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class ManagementServerConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWebConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigWebApplicationContext();
|
|
||||||
this.context.setServletContext(new MockServletContext());
|
|
||||||
this.context.register(ManagementServerConfiguration.class,
|
|
||||||
ServerPropertiesConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(WebMvcConfigurationSupport.class));
|
|
||||||
assertNotNull(this.context.getBean(ErrorEndpoint.class));
|
|
||||||
ConfigurableEmbeddedServletContainerFactory factory = Mockito
|
|
||||||
.mock(ConfigurableEmbeddedServletContainerFactory.class);
|
|
||||||
this.context.getBean(EmbeddedServletContainerCustomizer.class).customize(factory);
|
|
||||||
Mockito.verify(factory).addErrorPages(Mockito.any(ErrorPage.class));
|
|
||||||
Mockito.verify(factory).setPort(8080);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link ManagementServerPropertiesAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class ManagementServerPropertiesAutoConfigurationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void defaultManagementServerProperties() {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
ManagementServerPropertiesAutoConfiguration.class);
|
||||||
|
assertThat(context.getBean(ManagementServerProperties.class).getPort(),
|
||||||
|
nullValue());
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void definedManagementServerProperties() throws Exception {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
Config.class, ManagementServerPropertiesAutoConfiguration.class);
|
||||||
|
assertThat(context.getBean(ManagementServerProperties.class).getPort(),
|
||||||
|
equalTo(Integer.valueOf(123)));
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ManagementServerProperties managementServerProperties() {
|
||||||
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
|
properties.setPort(123);
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.CounterService;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.GaugeService;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.BDDMockito.willAnswer;
|
||||||
|
import static org.mockito.Matchers.anyDouble;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link MetricFilterAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class MetricFilterAutoConfigurationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void recordsHttpInteractions() throws Exception {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
Config.class, MetricFilterAutoConfiguration.class);
|
||||||
|
Filter filter = context.getBean(Filter.class);
|
||||||
|
final MockHttpServletRequest request = new MockHttpServletRequest("GET",
|
||||||
|
"/test/path");
|
||||||
|
final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
FilterChain chain = mock(FilterChain.class);
|
||||||
|
willAnswer(new Answer<Object>() {
|
||||||
|
@Override
|
||||||
|
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
response.setStatus(200);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).given(chain).doFilter(request, response);
|
||||||
|
filter.doFilter(request, response, chain);
|
||||||
|
verify(context.getBean(CounterService.class)).increment("status.200.test.path");
|
||||||
|
verify(context.getBean(GaugeService.class)).set(eq("response.test.path"),
|
||||||
|
anyDouble());
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void skipsFilterIfMissingServices() throws Exception {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
MetricFilterAutoConfiguration.class);
|
||||||
|
assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0));
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CounterService counterService() {
|
||||||
|
return mock(CounterService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GaugeService gaugeService() {
|
||||||
|
return mock(GaugeService.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.mock.web.MockFilterChain;
|
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class MetricFilterConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMetricFilterConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigWebApplicationContext();
|
|
||||||
this.context.setServletContext(new MockServletContext());
|
|
||||||
// Order is important
|
|
||||||
this.context.register(MetricRepositoryConfiguration.class,
|
|
||||||
MetricFilterConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
Filter filter = this.context.getBean(Filter.class);
|
|
||||||
assertNotNull(filter);
|
|
||||||
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(),
|
|
||||||
new MockFilterChain());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.CounterService;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.DefaultCounterService;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.DefaultGaugeService;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.GaugeService;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link MetricRepositoryAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class MetricRepositoryAutoConfigurationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createServices() {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
MetricRepositoryAutoConfiguration.class);
|
||||||
|
assertNotNull(context.getBean(DefaultGaugeService.class));
|
||||||
|
assertNotNull(context.getBean(DefaultCounterService.class));
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void skipsIfBeansExist() throws Exception {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
Config.class, MetricRepositoryAutoConfiguration.class);
|
||||||
|
assertThat(context.getBeansOfType(DefaultGaugeService.class).size(), equalTo(0));
|
||||||
|
assertThat(context.getBeansOfType(DefaultCounterService.class).size(), equalTo(0));
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public GaugeService gaugeService() {
|
||||||
|
return mock(GaugeService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CounterService counterService() {
|
||||||
|
return mock(CounterService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.bootstrap.actuate.metrics.MetricRepository;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class MetricRepositoryConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTraceConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(MetricRepositoryConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(MetricRepository.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.metrics.MetricsEndpoint;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class MetricsConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTraceConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(MetricRepositoryConfiguration.class,
|
|
||||||
MetricsConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(MetricsEndpoint.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.bootstrap.actuate.autoconfigure.ActuatorAutoConfiguration.ServerPropertiesConfiguration;
|
|
||||||
import org.springframework.bootstrap.actuate.endpoint.shutdown.ShutdownEndpoint;
|
|
||||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class ShutdownConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEndpointConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(ShutdownConfiguration.class,
|
|
||||||
ServerPropertiesConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(ShutdownEndpoint.class));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.bootstrap.actuate.trace.TraceRepository;
|
|
||||||
import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class TraceFilterConfigurationTests {
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTraceConfiguration() throws Exception {
|
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
|
||||||
this.context.register(PropertyPlaceholderAutoConfiguration.class,
|
|
||||||
TraceFilterConfiguration.class);
|
|
||||||
this.context.refresh();
|
|
||||||
assertNotNull(this.context.getBean(TraceRepository.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.trace.InMemoryTraceRepository;
|
||||||
|
import org.springframework.bootstrap.actuate.trace.TraceRepository;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link TraceRepositoryAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class TraceRepositoryAutoConfigurationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void configuresInMemoryTraceRepository() throws Exception {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
TraceRepositoryAutoConfiguration.class);
|
||||||
|
assertNotNull(context.getBean(InMemoryTraceRepository.class));
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void skipsIfRepositoryExists() throws Exception {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
Config.class, TraceRepositoryAutoConfiguration.class);
|
||||||
|
assertThat(context.getBeansOfType(InMemoryTraceRepository.class).size(),
|
||||||
|
equalTo(0));
|
||||||
|
assertThat(context.getBeansOfType(TraceRepository.class).size(), equalTo(1));
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TraceRepository traceRepository() {
|
||||||
|
return mock(TraceRepository.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.TestUtils;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.core.env.MapPropertySource;
|
||||||
|
import org.springframework.core.env.PropertySource;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract base class for endpoint tests.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
||||||
|
|
||||||
|
protected AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
|
private final Class<?> configClass;
|
||||||
|
|
||||||
|
private final Class<?> type;
|
||||||
|
|
||||||
|
private final String path;
|
||||||
|
|
||||||
|
private final boolean sensitive;
|
||||||
|
|
||||||
|
private final String property;
|
||||||
|
|
||||||
|
private MediaType[] produces;
|
||||||
|
|
||||||
|
public AbstractEndpointTests(Class<?> configClass, Class<?> type, String path,
|
||||||
|
boolean sensitive, String property, MediaType... produces) {
|
||||||
|
this.configClass = configClass;
|
||||||
|
this.type = type;
|
||||||
|
this.path = path;
|
||||||
|
this.sensitive = sensitive;
|
||||||
|
this.property = property;
|
||||||
|
this.produces = produces;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
|
this.context.register(this.configClass);
|
||||||
|
this.context.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void producesMediaType() {
|
||||||
|
assertThat(getEndpointBean().getProduces(), equalTo(this.produces));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPath() throws Exception {
|
||||||
|
assertThat(getEndpointBean().getPath(), equalTo(this.path));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSensitive() throws Exception {
|
||||||
|
assertThat(getEndpointBean().isSensitive(), equalTo(this.sensitive));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pathOverride() throws Exception {
|
||||||
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
|
TestUtils.addEnviroment(this.context, this.property + ".path:/mypath");
|
||||||
|
this.context.register(this.configClass);
|
||||||
|
this.context.refresh();
|
||||||
|
assertThat(getEndpointBean().getPath(), equalTo("/mypath"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSensitiveOverride() throws Exception {
|
||||||
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
|
PropertySource<?> propertySource = new MapPropertySource("test",
|
||||||
|
Collections.<String, Object> singletonMap(this.property + ".sensitive",
|
||||||
|
String.valueOf(!this.sensitive)));
|
||||||
|
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
|
||||||
|
this.context.register(this.configClass);
|
||||||
|
this.context.refresh();
|
||||||
|
assertThat(getEndpointBean().isSensitive(), equalTo(!this.sensitive));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected T getEndpointBean() {
|
||||||
|
return (T) this.context.getBean(this.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link BeansEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class BeansEndpointTests extends AbstractEndpointTests<BeansEndpoint> {
|
||||||
|
|
||||||
|
public BeansEndpointTests() {
|
||||||
|
super(Config.class, BeansEndpoint.class, "/beans", true, "endpoints.beans",
|
||||||
|
MediaType.APPLICATION_JSON);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
assertThat(getEndpointBean().invoke(), containsString("\"bean\": \"endpoint\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public BeansEndpoint endpoint() {
|
||||||
|
return new BeansEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.lang.management.ThreadInfo;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link DumpEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class DumpEndpointTests extends AbstractEndpointTests<DumpEndpoint> {
|
||||||
|
|
||||||
|
public DumpEndpointTests() {
|
||||||
|
super(Config.class, DumpEndpoint.class, "/dump", true, "endpoints.dump");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
List<ThreadInfo> threadInfo = getEndpointBean().invoke();
|
||||||
|
assertThat(threadInfo.size(), greaterThan(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DumpEndpoint endpoint() {
|
||||||
|
return new DumpEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link EnvironmentEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentEndpoint> {
|
||||||
|
|
||||||
|
public EnvironmentEndpointTests() {
|
||||||
|
super(Config.class, EnvironmentEndpoint.class, "/env", true, "endpoints.env");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
assertThat(getEndpointBean().invoke().size(), greaterThan(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public EnvironmentEndpoint endpoint() {
|
||||||
|
return new EnvironmentEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.health.HealthIndicator;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link HealthEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class HealthEndpointTests extends AbstractEndpointTests<HealthEndpoint<String>> {
|
||||||
|
|
||||||
|
public HealthEndpointTests() {
|
||||||
|
super(Config.class, HealthEndpoint.class, "/health", false, "endpoints.health");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
assertThat(getEndpointBean().invoke(), equalTo("fine"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HealthEndpoint<String> endpoint() {
|
||||||
|
return new HealthEndpoint<String>(new HealthIndicator<String>() {
|
||||||
|
@Override
|
||||||
|
public String health() {
|
||||||
|
return "fine";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link InfoEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class InfoEndpointTests extends AbstractEndpointTests<InfoEndpoint> {
|
||||||
|
|
||||||
|
public InfoEndpointTests() {
|
||||||
|
super(Config.class, InfoEndpoint.class, "/info", true, "endpoints.info");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
assertThat(getEndpointBean().invoke().get("a"), equalTo((Object) "b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public InfoEndpoint endpoint() {
|
||||||
|
return new InfoEndpoint(Collections.singletonMap("a", "b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.Metric;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link MetricsEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class MetricsEndpointTests extends AbstractEndpointTests<MetricsEndpoint> {
|
||||||
|
|
||||||
|
public MetricsEndpointTests() {
|
||||||
|
super(Config.class, MetricsEndpoint.class, "/metrics", true, "endpoints.metrics");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
assertThat(getEndpointBean().invoke().get("a"), equalTo((Object) 0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MetricsEndpoint endpoint() {
|
||||||
|
final Metric metric = new Metric("a", 0.5f);
|
||||||
|
PublicMetrics metrics = new PublicMetrics() {
|
||||||
|
@Override
|
||||||
|
public Collection<Metric> metrics() {
|
||||||
|
return Collections.singleton(metric);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new MetricsEndpoint(metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link ShutdownEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class ShutdownEndpointTests extends AbstractEndpointTests<ShutdownEndpoint> {
|
||||||
|
|
||||||
|
public ShutdownEndpointTests() {
|
||||||
|
super(Config.class, ShutdownEndpoint.class, "/shutdown", true,
|
||||||
|
"endpoints.shutdown");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
assertThat((String) getEndpointBean().invoke().get("message"),
|
||||||
|
startsWith("Shutting down"));
|
||||||
|
assertTrue(this.context.isActive());
|
||||||
|
Thread.sleep(600);
|
||||||
|
assertFalse(this.context.isActive());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ManagementServerProperties managementServerProperties() {
|
||||||
|
ManagementServerProperties properties = new ManagementServerProperties();
|
||||||
|
properties.setAllowShutdown(true);
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ShutdownEndpoint endpoint() {
|
||||||
|
return new ShutdownEndpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.trace.InMemoryTraceRepository;
|
||||||
|
import org.springframework.bootstrap.actuate.trace.Trace;
|
||||||
|
import org.springframework.bootstrap.actuate.trace.TraceRepository;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link TraceEndpoint}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class TraceEndpointTests extends AbstractEndpointTests<TraceEndpoint> {
|
||||||
|
|
||||||
|
public TraceEndpointTests() {
|
||||||
|
super(Config.class, TraceEndpoint.class, "/trace", true, "endpoints.trace");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invoke() throws Exception {
|
||||||
|
Trace trace = getEndpointBean().invoke().get(0);
|
||||||
|
assertThat(trace.getInfo().get("a"), equalTo((Object) "b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public static class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TraceEndpoint endpoint() {
|
||||||
|
TraceRepository repository = new InMemoryTraceRepository();
|
||||||
|
repository.add(Collections.<String, Object> singletonMap("a", "b"));
|
||||||
|
return new TraceEndpoint(repository);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.InMemoryMetricRepository;
|
||||||
|
import org.springframework.bootstrap.actuate.metrics.Metric;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link VanillaPublicMetrics}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class VanillaPublicMetricsTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetrics() throws Exception {
|
||||||
|
InMemoryMetricRepository repository = new InMemoryMetricRepository();
|
||||||
|
repository.set("a", 0.5, new Date());
|
||||||
|
VanillaPublicMetrics publicMetrics = new VanillaPublicMetrics(repository);
|
||||||
|
Map<String, Metric> results = new HashMap<String, Metric>();
|
||||||
|
for (Metric metric : publicMetrics.metrics()) {
|
||||||
|
results.put(metric.getName(), metric);
|
||||||
|
}
|
||||||
|
assertTrue(results.containsKey("mem"));
|
||||||
|
assertTrue(results.containsKey("mem.free"));
|
||||||
|
assertThat(results.get("a").getValue(), equalTo(0.5));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.endpoint.mvc;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.AbstractEndpoint;
|
||||||
|
import org.springframework.bootstrap.actuate.endpoint.ActionEndpoint;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link EndpointHandlerMapping}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class EndpointHandlerMappingTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withoutPrefix() throws Exception {
|
||||||
|
TestEndpoint endpointA = new TestEndpoint("/a");
|
||||||
|
TestEndpoint endpointB = new TestEndpoint("/b");
|
||||||
|
EndpointHandlerMapping mapping = new EndpointHandlerMapping(Arrays.asList(
|
||||||
|
endpointA, endpointB));
|
||||||
|
mapping.afterPropertiesSet();
|
||||||
|
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a"))
|
||||||
|
.getHandler(), equalTo((Object) endpointA));
|
||||||
|
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/b"))
|
||||||
|
.getHandler(), equalTo((Object) endpointB));
|
||||||
|
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/c")),
|
||||||
|
nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withPrefix() throws Exception {
|
||||||
|
TestEndpoint endpointA = new TestEndpoint("/a");
|
||||||
|
TestEndpoint endpointB = new TestEndpoint("/b");
|
||||||
|
EndpointHandlerMapping mapping = new EndpointHandlerMapping(Arrays.asList(
|
||||||
|
endpointA, endpointB));
|
||||||
|
mapping.setPrefix("/a");
|
||||||
|
mapping.afterPropertiesSet();
|
||||||
|
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a/a"))
|
||||||
|
.getHandler(), equalTo((Object) endpointA));
|
||||||
|
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a/b"))
|
||||||
|
.getHandler(), equalTo((Object) endpointB));
|
||||||
|
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")),
|
||||||
|
nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onlyGetHttpMethodForNonActionEndpoints() throws Exception {
|
||||||
|
TestEndpoint endpoint = new TestEndpoint("/a");
|
||||||
|
EndpointHandlerMapping mapping = new EndpointHandlerMapping(
|
||||||
|
Arrays.asList(endpoint));
|
||||||
|
mapping.afterPropertiesSet();
|
||||||
|
assertNotNull(mapping.getHandler(new MockHttpServletRequest("GET", "/a")));
|
||||||
|
assertNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onlyPostHttpMethodForActionEndpoints() throws Exception {
|
||||||
|
TestEndpoint endpoint = new TestActionEndpoint("/a");
|
||||||
|
EndpointHandlerMapping mapping = new EndpointHandlerMapping(
|
||||||
|
Arrays.asList(endpoint));
|
||||||
|
mapping.afterPropertiesSet();
|
||||||
|
assertNull(mapping.getHandler(new MockHttpServletRequest("GET", "/a")));
|
||||||
|
assertNotNull(mapping.getHandler(new MockHttpServletRequest("POST", "/a")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void disabled() throws Exception {
|
||||||
|
TestEndpoint endpointA = new TestEndpoint("/a");
|
||||||
|
EndpointHandlerMapping mapping = new EndpointHandlerMapping(
|
||||||
|
Arrays.asList(endpointA));
|
||||||
|
mapping.setDisabled(true);
|
||||||
|
mapping.afterPropertiesSet();
|
||||||
|
assertThat(mapping.getHandler(new MockHttpServletRequest("GET", "/a")),
|
||||||
|
nullValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestEndpoint extends AbstractEndpoint<Object> {
|
||||||
|
|
||||||
|
public TestEndpoint(String path) {
|
||||||
|
super(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestActionEndpoint extends TestEndpoint implements
|
||||||
|
ActionEndpoint<Object> {
|
||||||
|
|
||||||
|
public TestActionEndpoint(String path) {
|
||||||
|
super(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.fixme;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
public class ErrorConfigurationTests {
|
||||||
|
|
||||||
|
// private AnnotationConfigApplicationContext context;
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void testErrorEndpointConfiguration() throws Exception {
|
||||||
|
// this.context = new AnnotationConfigApplicationContext();
|
||||||
|
// this.context.register(ErrorConfiguration.class,
|
||||||
|
// ActuatorServerPropertiesConfiguration.class,
|
||||||
|
// PropertyPlaceholderAutoConfiguration.class);
|
||||||
|
// this.context.refresh();
|
||||||
|
// assertNotNull(this.context.getBean(ErrorEndpoint.class));
|
||||||
|
// ConfigurableEmbeddedServletContainerFactory factory = Mockito
|
||||||
|
// .mock(ConfigurableEmbeddedServletContainerFactory.class);
|
||||||
|
// this.context.getBean(EmbeddedServletContainerCustomizer.class).customize(factory);
|
||||||
|
// Mockito.verify(factory).addErrorPages(Mockito.any(ErrorPage.class));
|
||||||
|
// }
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.health;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link VanillaHealthIndicator}.
|
||||||
|
*
|
||||||
|
* @author Phillip Webb
|
||||||
|
*/
|
||||||
|
public class VanillaHealthIndicatorTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ok() throws Exception {
|
||||||
|
VanillaHealthIndicator healthIndicator = new VanillaHealthIndicator();
|
||||||
|
assertThat(healthIndicator.health(), equalTo("ok"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.bootstrap.actuate.metrics;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link DefaultCounterService}.
|
||||||
|
*/
|
||||||
|
@Ignore
|
||||||
|
public class DefaultCounterServiceTests {
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
fail("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue