Skip to content

Commit

Permalink
Rework mappings endpoint
Browse files Browse the repository at this point in the history
Improve the structure of the response and include mappings from
WebFlux and Servlet and Filter registrations in addition to the
mappings from Spring MVC.

Closes gh-9979
  • Loading branch information
wilkinsona committed Jan 16, 2018
1 parent 1f26a03 commit 67a2990
Show file tree
Hide file tree
Showing 46 changed files with 1,905 additions and 447 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-webtestclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[[mappings]]
= Mappings (`mappings`)

The `mappings` endpoint provides information about the application's request mappings.



[[mappings-retrieving]]
== Retrieving the Mappings

To retrieve the mappings, make a `GET` request to `/actuator/mappings`, as shown in the
following curl-based example:

include::{snippets}mappings/curl-request.adoc[]

The resulting response is similar to the following:

include::{snippets}mappings/http-response.adoc[]



[[mappings-retrieving-response-structure]]
=== Response Structure

The response contains details of the application's mappings. The items found in the
response depend on the type of web application (reactive or Servlet-based). The
following table describes the structure of the common elements of the response:

[cols="2,1,3"]
include::{snippets}mappings/response-fields.adoc[]

The entries that may be found in `contexts.*.mappings` are described in the
following sections.


[[mappings-retrieving-response-structure-dispatcher-servlets]]
=== Dispatcher Servlets Response Structure

When using Spring MVC, the response contains details of any `DispatcherServlet`
request mappings beneath `contexts.*.mappings.dispatcherServlets`. The following
table describes the structure of this section of the response:

[cols="2,1,3"]
include::{snippets}mappings/response-fields-dispatcher-servlets.adoc[]



[[mappings-retrieving-response-structure-servlets]]
=== Servlets Response Structure

When using the Servlet stack, the response contains details of any `Servlet` mappings
beneath `contexts.*.mappings.servlets`. The following table describes the structure of
this section of the response:

[cols="2,1,3"]
include::{snippets}mappings/response-fields-servlets.adoc[]



[[mappings-retrieving-response-structure-servlet-filters]]
=== Servlet Filters Response Structure

When using the Servlet stack, the response contains details of any `Filter` mappings
beneath `contexts.*.mappings.servletFilters`. The following table describes the
structure of this section of the response:

[cols="2,1,3"]
include::{snippets}mappings/response-fields-servlet-filters.adoc[]



[[mappings-retrieving-response-structure-dispatcher-servlets]]
=== Dispatcher Handlers Response Structure

When using Spring WebFlux, the response contains details of any `DispatcherHandler`
request mappings beneath `contexts.*.mappings.dispatcherHandlers`. The following
table describes the structure of this section of the response:

[cols="2,1,3"]
include::{snippets}mappings/response-fields-dispatcher-handlers.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ include::endpoints/info.adoc[leveloffset=+1]
include::endpoints/liquibase.adoc[leveloffset=+1]
include::endpoints/logfile.adoc[leveloffset=+1]
include::endpoints/loggers.adoc[leveloffset=+1]
include::endpoints/mappings.adoc[leveloffset=+1]
include::endpoints/metrics.adoc[leveloffset=+1]
include::endpoints/prometheus.adoc[leveloffset=+1]
include::endpoints/scheduledtasks.adoc[leveloffset=+1]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2012-2018 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.boot.actuate.autoconfigure.web;

import java.util.Collection;
import java.util.Collections;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.web.MappingDescriptionProvider;
import org.springframework.boot.actuate.web.MappingsEndpoint;
import org.springframework.boot.actuate.web.reactive.DispatcherHandlersMappingDescriptionProvider;
import org.springframework.boot.actuate.web.servlet.DispatcherServletsMappingDescriptionProvider;
import org.springframework.boot.actuate.web.servlet.FiltersMappingDescriptionProvider;
import org.springframework.boot.actuate.web.servlet.ServletsMappingDescriptionProvider;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.servlet.DispatcherServlet;

/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link MappingsEndpoint}.
*
* @author Andy Wilkinson
* @since 2.0.0
*/
@ManagementContextConfiguration
public class MappingsEndpointAutoConfiguration {

@Bean
@ConditionalOnEnabledEndpoint
public MappingsEndpoint mappingsEndpoint(ApplicationContext applicationContext,
ObjectProvider<Collection<MappingDescriptionProvider>> descriptionProviders) {
return new MappingsEndpoint(
descriptionProviders.getIfAvailable(Collections::emptyList),
applicationContext);
}

@Configuration
@ConditionalOnWebApplication(type = Type.SERVLET)
static class ServletWebConfiguration {

@Bean
ServletsMappingDescriptionProvider servletMappingDescriptionProvider() {
return new ServletsMappingDescriptionProvider();
}

@Bean
FiltersMappingDescriptionProvider filterMappingDescriptionProvider() {
return new FiltersMappingDescriptionProvider();
}

@Configuration
@ConditionalOnClass(DispatcherServlet.class)
@ConditionalOnBean(DispatcherServlet.class)
static class SpringMvcConfiguration {

@Bean
DispatcherServletsMappingDescriptionProvider dispatcherServletMappingDescriptionProvider(
ApplicationContext applicationContext) {
return new DispatcherServletsMappingDescriptionProvider();
}

}

}

@Configuration
@ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnClass(DispatcherHandler.class)
@ConditionalOnBean(DispatcherHandler.class)
static class ReactiveWebConfiguration {

@Bean
public DispatcherHandlersMappingDescriptionProvider dispatcherHandlerMappingDescriptionProvider(
ApplicationContext applicationContext) {
return new DispatcherHandlersMappingDescriptionProvider();
}

}

}

This file was deleted.

Loading

0 comments on commit 67a2990

Please sign in to comment.