Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
17c7f027
Commit
17c7f027
authored
Feb 16, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add details of the request mapping conditions to mappings endpoint
Closes gh-12080
parent
2c19257d
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
516 additions
and
76 deletions
+516
-76
mappings.adoc
...r-autoconfigure/src/main/asciidoc/endpoints/mappings.adoc
+2
-2
MappingsEndpointReactiveDocumentationTests.java
...mentation/MappingsEndpointReactiveDocumentationTests.java
+99
-37
MappingsEndpointServletDocumentationTests.java
...umentation/MappingsEndpointServletDocumentationTests.java
+94
-31
DispatcherHandlersMappingDescriptionProvider.java
...eactive/DispatcherHandlersMappingDescriptionProvider.java
+2
-0
RequestMappingConditionsDescription.java
...appings/reactive/RequestMappingConditionsDescription.java
+142
-0
DispatcherServletMappingDetails.java
...web/mappings/servlet/DispatcherServletMappingDetails.java
+15
-4
DispatcherServletsMappingDescriptionProvider.java
...servlet/DispatcherServletsMappingDescriptionProvider.java
+6
-2
RequestMappingConditionsDescription.java
...mappings/servlet/RequestMappingConditionsDescription.java
+140
-0
ExampleController.java
...bflux/src/main/java/sample/webflux/ExampleController.java
+16
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/endpoints/mappings.adoc
View file @
17c7f027
...
...
@@ -40,7 +40,7 @@ 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="
3,1,3
"]
[cols="
4,1,2
"]
include::{snippets}mappings/response-fields-dispatcher-servlets.adoc[]
...
...
@@ -76,5 +76,5 @@ When using Spring WebFlux, the response contains details of any `DispatcherHandl
request mappings beneath `contexts.*.mappings.dispatcherHandlers`. The following
table describes the structure of this section of the response:
[cols="
3,1,3
"]
[cols="
4,1,2
"]
include::{snippets}mappings/response-fields-dispatcher-handlers.adoc[]
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointReactiveDocumentationTests.java
View file @
17c7f027
...
...
@@ -16,7 +16,10 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
endpoint
.
web
.
documentation
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Rule
;
...
...
@@ -34,10 +37,14 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.http.MediaType
;
import
org.springframework.restdocs.JUnitRestDocumentation
;
import
org.springframework.restdocs.payload.FieldDescriptor
;
import
org.springframework.restdocs.payload.JsonFieldType
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.reactive.function.server.RequestPredicates
;
import
org.springframework.web.reactive.function.server.RouterFunction
;
import
org.springframework.web.reactive.function.server.RouterFunctions
;
...
...
@@ -77,49 +84,88 @@ public class MappingsEndpointReactiveDocumentationTests
@Test
public
void
mappings
()
throws
Exception
{
this
.
client
.
get
().
uri
(
"/actuator/mappings"
).
exchange
().
expectStatus
().
isOk
()
.
expectBody
()
.
consumeWith
(
document
(
"mappings"
,
responseFields
(
beneathPath
(
"contexts.*.mappings.dispatcherHandlers"
)
.
withSubsectionId
(
"dispatcher-handlers"
),
fieldWithPath
(
"*"
).
description
(
"Dispatcher handler mappings, if any, keyed by "
+
"dispatcher handler bean name."
),
fieldWithPath
(
"*.[].handler"
)
.
description
(
"Handler for the mapping."
),
fieldWithPath
(
"*.[].predicate"
)
.
description
(
"Predicate for the mapping."
),
fieldWithPath
(
"*.[].details"
).
optional
()
.
type
(
JsonFieldType
.
OBJECT
)
.
description
(
"Additional implementation-specific "
+
"details about the mapping. Optional."
),
List
<
FieldDescriptor
>
requestMappingConditions
=
Arrays
.
asList
(
requestMappingConditionField
(
""
)
.
description
(
"Details of the request mapping conditions."
)
.
optional
(),
requestMappingConditionField
(
".consumes"
)
.
description
(
"Details of the consumes condition"
),
requestMappingConditionField
(
".consumes.[].mediaType"
)
.
description
(
"Consumed media type."
),
requestMappingConditionField
(
".consumes.[].negated"
)
.
description
(
"Whether the media type is negated."
),
requestMappingConditionField
(
".headers"
)
.
description
(
"Details of the headers condition."
),
requestMappingConditionField
(
".headers.[].name"
)
.
description
(
"Name of the header."
),
requestMappingConditionField
(
".headers.[].value"
)
.
description
(
"Required value of the header, if any."
),
requestMappingConditionField
(
".headers.[].negated"
)
.
description
(
"Whether the value is negated."
),
requestMappingConditionField
(
".methods"
)
.
description
(
"HTTP methods that are handled."
),
requestMappingConditionField
(
".params"
)
.
description
(
"Details of the params condition."
),
requestMappingConditionField
(
".params.[].name"
)
.
description
(
"Name of the parameter."
),
requestMappingConditionField
(
".params.[].value"
)
.
description
(
"Required value of the parameter, if any."
),
requestMappingConditionField
(
".params.[].negated"
)
.
description
(
"Whether the value is negated."
),
requestMappingConditionField
(
".patterns"
).
description
(
"Patterns identifying the paths handled by the mapping."
),
requestMappingConditionField
(
".produces"
)
.
description
(
"Details of the produces condition."
),
requestMappingConditionField
(
".produces.[].mediaType"
)
.
description
(
"Produced media type."
),
requestMappingConditionField
(
".produces.[].negated"
)
.
description
(
"Whether the media type is negated."
));
List
<
FieldDescriptor
>
handlerMethod
=
Arrays
.
asList
(
fieldWithPath
(
"*.[].details.handlerMethod"
).
optional
()
.
type
(
JsonFieldType
.
OBJECT
)
.
description
(
"Details of the method, if any, "
+
"that will handle requests to "
+
"this mapping."
),
+
"that will handle requests to this mapping."
),
fieldWithPath
(
"*.[].details.handlerMethod.className"
)
.
type
(
JsonFieldType
.
STRING
)
.
description
(
"Fully qualified name of the class"
+
" of the method."
),
.
description
(
"Fully qualified name of the class of the method."
),
fieldWithPath
(
"*.[].details.handlerMethod.name"
)
.
type
(
JsonFieldType
.
STRING
)
.
description
(
"Name of the method."
),
.
type
(
JsonFieldType
.
STRING
).
description
(
"Name of the method."
),
fieldWithPath
(
"*.[].details.handlerMethod.descriptor"
)
.
type
(
JsonFieldType
.
STRING
)
.
description
(
"Descriptor of the method as "
+
"specified in the Java Language "
+
"Specification."
),
fieldWithPath
(
"*.[].details.handlerFunction"
)
.
optional
().
type
(
JsonFieldType
.
OBJECT
)
.
description
(
"Details of the function, if any, "
+
"that will handle requests to this "
+
"mapping."
),
.
description
(
"Descriptor of the method as specified in the Java "
+
"Language Specification."
));
List
<
FieldDescriptor
>
handlerFunction
=
Arrays
.
asList
(
fieldWithPath
(
"*.[].details.handlerFunction"
).
optional
()
.
type
(
JsonFieldType
.
OBJECT
)
.
description
(
"Details of the function, if any, that will handle "
+
"requests to this mapping."
),
fieldWithPath
(
"*.[].details.handlerFunction.className"
)
.
type
(
JsonFieldType
.
STRING
).
description
(
"Fully qualified name of the class of "
+
"the function."
))));
"Fully qualified name of the class of the function."
));
List
<
FieldDescriptor
>
dispatcherHandlerFields
=
new
ArrayList
<>(
Arrays
.
asList
(
fieldWithPath
(
"*"
)
.
description
(
"Dispatcher handler mappings, if any, keyed by "
+
"dispatcher handler bean name."
),
fieldWithPath
(
"*.[].details"
).
optional
().
type
(
JsonFieldType
.
OBJECT
)
.
description
(
"Additional implementation-specific "
+
"details about the mapping. Optional."
),
fieldWithPath
(
"*.[].handler"
).
description
(
"Handler for the mapping."
),
fieldWithPath
(
"*.[].predicate"
)
.
description
(
"Predicate for the mapping."
)));
dispatcherHandlerFields
.
addAll
(
requestMappingConditions
);
dispatcherHandlerFields
.
addAll
(
handlerMethod
);
dispatcherHandlerFields
.
addAll
(
handlerFunction
);
this
.
client
.
get
().
uri
(
"/actuator/mappings"
).
exchange
().
expectStatus
().
isOk
()
.
expectBody
()
.
consumeWith
(
document
(
"mappings"
,
responseFields
(
beneathPath
(
"contexts.*.mappings.dispatcherHandlers"
)
.
withSubsectionId
(
"dispatcher-handlers"
),
dispatcherHandlerFields
)));
}
private
FieldDescriptor
requestMappingConditionField
(
String
path
)
{
return
fieldWithPath
(
"*.[].details.requestMappingConditions"
+
path
);
}
@Configuration
...
...
@@ -149,6 +195,22 @@ public class MappingsEndpointReactiveDocumentationTests
(
request
)
->
ServerResponse
.
ok
().
build
());
}
@Bean
public
ExampleController
exampleController
()
{
return
new
ExampleController
();
}
}
@RestController
private
static
class
ExampleController
{
@PostMapping
(
path
=
"/"
,
consumes
=
{
MediaType
.
APPLICATION_JSON_VALUE
,
"!application/xml"
},
produces
=
MediaType
.
TEXT_PLAIN_VALUE
,
headers
=
"X-Custom=Foo"
,
params
=
"a!=alpha"
)
public
String
example
()
{
return
"Hello World"
;
}
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java
View file @
17c7f027
...
...
@@ -16,7 +16,10 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
endpoint
.
web
.
documentation
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Rule
;
...
...
@@ -36,11 +39,15 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.http.MediaType
;
import
org.springframework.restdocs.JUnitRestDocumentation
;
import
org.springframework.restdocs.payload.FieldDescriptor
;
import
org.springframework.restdocs.payload.JsonFieldType
;
import
org.springframework.restdocs.payload.ResponseFieldsSnippet
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.reactive.server.WebTestClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.
beneathPath
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.
fieldWithPath
;
...
...
@@ -91,39 +98,75 @@ public class MappingsEndpointServletDocumentationTests
.
description
(
"Dispatcher handler mappings, if any."
).
optional
()
.
type
(
JsonFieldType
.
OBJECT
),
parentIdField
());
this
.
client
.
get
().
uri
(
"/actuator/mappings"
).
exchange
().
expectBody
()
.
consumeWith
(
document
(
"mappings"
,
commonResponseFields
,
responseFields
(
beneathPath
(
"contexts.*.mappings.dispatcherServlets"
)
.
withSubsectionId
(
"dispatcher-servlets"
),
fieldWithPath
(
"*"
).
description
(
"Dispatcher servlet mappings, if any, keyed by "
List
<
FieldDescriptor
>
dispatcherServletFields
=
new
ArrayList
<>(
Arrays
.
asList
(
fieldWithPath
(
"*"
)
.
description
(
"Dispatcher servlet mappings, if any, keyed by "
+
"dispatcher servlet bean name."
),
fieldWithPath
(
"*.[].handler"
)
.
description
(
"Handler for the mapping."
),
fieldWithPath
(
"*.[].predicate"
)
.
description
(
"Predicate for the mapping."
),
fieldWithPath
(
"*.[].details"
).
optional
()
.
type
(
JsonFieldType
.
OBJECT
)
fieldWithPath
(
"*.[].details"
).
optional
().
type
(
JsonFieldType
.
OBJECT
)
.
description
(
"Additional implementation-specific "
+
"details about the mapping. Optional."
),
fieldWithPath
(
"*.[].handler"
).
description
(
"Handler for the mapping."
),
fieldWithPath
(
"*.[].predicate"
)
.
description
(
"Predicate for the mapping."
)));
List
<
FieldDescriptor
>
requestMappingConditions
=
Arrays
.
asList
(
requestMappingConditionField
(
""
)
.
description
(
"Details of the request mapping conditions."
)
.
optional
(),
requestMappingConditionField
(
".consumes"
)
.
description
(
"Details of the consumes condition"
),
requestMappingConditionField
(
".consumes.[].mediaType"
)
.
description
(
"Consumed media type."
),
requestMappingConditionField
(
".consumes.[].negated"
)
.
description
(
"Whether the media type is negated."
),
requestMappingConditionField
(
".headers"
)
.
description
(
"Details of the headers condition."
),
requestMappingConditionField
(
".headers.[].name"
)
.
description
(
"Name of the header."
),
requestMappingConditionField
(
".headers.[].value"
)
.
description
(
"Required value of the header, if any."
),
requestMappingConditionField
(
".headers.[].negated"
)
.
description
(
"Whether the value is negated."
),
requestMappingConditionField
(
".methods"
)
.
description
(
"HTTP methods that are handled."
),
requestMappingConditionField
(
".params"
)
.
description
(
"Details of the params condition."
),
requestMappingConditionField
(
".params.[].name"
)
.
description
(
"Name of the parameter."
),
requestMappingConditionField
(
".params.[].value"
)
.
description
(
"Required value of the parameter, if any."
),
requestMappingConditionField
(
".params.[].negated"
)
.
description
(
"Whether the value is negated."
),
requestMappingConditionField
(
".patterns"
).
description
(
"Patterns identifying the paths handled by the mapping."
),
requestMappingConditionField
(
".produces"
)
.
description
(
"Details of the produces condition."
),
requestMappingConditionField
(
".produces.[].mediaType"
)
.
description
(
"Produced media type."
),
requestMappingConditionField
(
".produces.[].negated"
)
.
description
(
"Whether the media type is negated."
));
List
<
FieldDescriptor
>
handlerMethod
=
Arrays
.
asList
(
fieldWithPath
(
"*.[].details.handlerMethod"
).
optional
()
.
type
(
JsonFieldType
.
OBJECT
)
.
description
(
"Details of the method, if any, "
+
"that will handle requests to "
+
"this mapping."
),
+
"that will handle requests to this mapping."
),
fieldWithPath
(
"*.[].details.handlerMethod.className"
)
.
type
(
JsonFieldType
.
STRING
)
.
description
(
"Fully qualified name of the class"
+
" of the method."
),
.
description
(
"Fully qualified name of the class of the method."
),
fieldWithPath
(
"*.[].details.handlerMethod.name"
)
.
type
(
JsonFieldType
.
STRING
)
.
description
(
"Name of the method."
),
.
type
(
JsonFieldType
.
STRING
).
description
(
"Name of the method."
),
fieldWithPath
(
"*.[].details.handlerMethod.descriptor"
)
.
type
(
JsonFieldType
.
STRING
)
.
description
(
"Descriptor of the method as "
+
"specified in the Java Language "
+
"Specification."
)),
.
description
(
"Descriptor of the method as specified in the Java "
+
"Language Specification."
));
dispatcherServletFields
.
addAll
(
handlerMethod
);
dispatcherServletFields
.
addAll
(
requestMappingConditions
);
this
.
client
.
get
().
uri
(
"/actuator/mappings"
).
exchange
().
expectBody
()
.
consumeWith
(
document
(
"mappings"
,
commonResponseFields
,
responseFields
(
beneathPath
(
"contexts.*.mappings.dispatcherServlets"
)
.
withSubsectionId
(
"dispatcher-servlets"
),
dispatcherServletFields
),
responseFields
(
beneathPath
(
"contexts.*.mappings.servletFilters"
)
.
withSubsectionId
(
"servlet-filters"
),
...
...
@@ -146,6 +189,10 @@ public class MappingsEndpointServletDocumentationTests
.
description
(
"Class name of the servlet"
))));
}
private
FieldDescriptor
requestMappingConditionField
(
String
path
)
{
return
fieldWithPath
(
"*.[].details.requestMappingConditions"
+
path
);
}
@Configuration
@Import
(
BaseDocumentationConfiguration
.
class
)
static
class
TestConfiguration
{
...
...
@@ -177,6 +224,22 @@ public class MappingsEndpointServletDocumentationTests
return
new
MappingsEndpoint
(
descriptionProviders
,
context
);
}
@Bean
public
ExampleController
exampleController
()
{
return
new
ExampleController
();
}
}
@RestController
private
static
class
ExampleController
{
@PostMapping
(
path
=
"/"
,
consumes
=
{
MediaType
.
APPLICATION_JSON_VALUE
,
"!application/xml"
},
produces
=
MediaType
.
TEXT_PLAIN_VALUE
,
headers
=
"X-Custom=Foo"
,
params
=
"a!=alpha"
)
public
String
example
()
{
return
"Hello World"
;
}
}
}
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/reactive/DispatcherHandlersMappingDescriptionProvider.java
View file @
17c7f027
...
...
@@ -125,6 +125,8 @@ public class DispatcherHandlersMappingDescriptionProvider
DispatcherHandlerMappingDetails
handlerMapping
=
new
DispatcherHandlerMappingDetails
();
handlerMapping
.
setHandlerMethod
(
new
HandlerMethodDescription
(
mapping
.
getValue
()));
handlerMapping
.
setRequestMappingConditions
(
new
RequestMappingConditionsDescription
(
mapping
.
getKey
()));
return
new
DispatcherHandlerMappingDescription
(
mapping
.
getKey
().
toString
(),
mapping
.
getValue
().
toString
(),
handlerMapping
);
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/reactive/RequestMappingConditionsDescription.java
0 → 100644
View file @
17c7f027
/*
* 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
.
web
.
mappings
.
reactive
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.reactive.result.condition.MediaTypeExpression
;
import
org.springframework.web.reactive.result.condition.NameValueExpression
;
import
org.springframework.web.reactive.result.method.RequestMappingInfo
;
import
org.springframework.web.util.pattern.PathPattern
;
/**
* Description of the conditions of a {@link RequestMappingInfo}.
*
* @author Andy Wilkinson
* @since 2.0.0
*/
public
class
RequestMappingConditionsDescription
{
private
final
List
<
MediaTypeExpressionDescription
>
consumes
;
private
final
List
<
NameValueExpressionDescription
>
headers
;
private
final
Set
<
RequestMethod
>
methods
;
private
final
List
<
NameValueExpressionDescription
>
params
;
private
final
Set
<
String
>
patterns
;
private
final
List
<
MediaTypeExpressionDescription
>
produces
;
RequestMappingConditionsDescription
(
RequestMappingInfo
requestMapping
)
{
this
.
consumes
=
requestMapping
.
getConsumesCondition
().
getExpressions
().
stream
()
.
map
(
MediaTypeExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
this
.
headers
=
requestMapping
.
getHeadersCondition
().
getExpressions
().
stream
()
.
map
(
NameValueExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
this
.
methods
=
requestMapping
.
getMethodsCondition
().
getMethods
();
this
.
params
=
requestMapping
.
getParamsCondition
().
getExpressions
().
stream
()
.
map
(
NameValueExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
this
.
patterns
=
requestMapping
.
getPatternsCondition
().
getPatterns
().
stream
()
.
map
(
PathPattern:
:
getPatternString
).
collect
(
Collectors
.
toSet
());
this
.
produces
=
requestMapping
.
getProducesCondition
().
getExpressions
().
stream
()
.
map
(
MediaTypeExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
}
public
List
<
MediaTypeExpressionDescription
>
getConsumes
()
{
return
this
.
consumes
;
}
public
List
<
NameValueExpressionDescription
>
getHeaders
()
{
return
this
.
headers
;
}
public
Set
<
RequestMethod
>
getMethods
()
{
return
this
.
methods
;
}
public
List
<
NameValueExpressionDescription
>
getParams
()
{
return
this
.
params
;
}
public
Set
<
String
>
getPatterns
()
{
return
this
.
patterns
;
}
public
List
<
MediaTypeExpressionDescription
>
getProduces
()
{
return
this
.
produces
;
}
/**
* A description of a {@link MediaTypeExpression} in a request mapping condition.
*/
public
static
class
MediaTypeExpressionDescription
{
private
final
String
mediaType
;
private
final
boolean
negated
;
MediaTypeExpressionDescription
(
MediaTypeExpression
expression
)
{
this
.
mediaType
=
expression
.
getMediaType
().
toString
();
this
.
negated
=
expression
.
isNegated
();
}
public
String
getMediaType
()
{
return
this
.
mediaType
;
}
public
boolean
isNegated
()
{
return
this
.
negated
;
}
}
/**
* A description of a {@link NameValueExpression} in a request mapping condition.
*/
public
static
class
NameValueExpressionDescription
{
private
final
String
name
;
private
final
Object
value
;
private
final
boolean
negated
;
NameValueExpressionDescription
(
NameValueExpression
<?>
expression
)
{
this
.
name
=
expression
.
getName
();
this
.
value
=
expression
.
getValue
();
this
.
negated
=
expression
.
isNegated
();
}
public
String
getName
()
{
return
this
.
name
;
}
public
Object
getValue
()
{
return
this
.
value
;
}
public
boolean
isNegated
()
{
return
this
.
negated
;
}
}
}
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletMappingDetails.java
View file @
17c7f027
...
...
@@ -27,14 +27,25 @@ import org.springframework.web.servlet.DispatcherServlet;
*/
public
class
DispatcherServletMappingDetails
{
private
final
HandlerMethodDescription
handlerMethod
;
private
HandlerMethodDescription
handlerMethod
;
DispatcherServletMappingDetails
(
HandlerMethodDescription
handlerMethod
)
{
this
.
handlerMethod
=
handlerMethod
;
}
private
RequestMappingConditionsDescription
requestMappingConditions
;
public
HandlerMethodDescription
getHandlerMethod
()
{
return
this
.
handlerMethod
;
}
void
setHandlerMethod
(
HandlerMethodDescription
handlerMethod
)
{
this
.
handlerMethod
=
handlerMethod
;
}
public
RequestMappingConditionsDescription
getRequestMappingConditions
()
{
return
this
.
requestMappingConditions
;
}
void
setRequestMappingConditions
(
RequestMappingConditionsDescription
requestMappingConditions
)
{
this
.
requestMappingConditions
=
requestMappingConditions
;
}
}
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletsMappingDescriptionProvider.java
View file @
17c7f027
...
...
@@ -140,9 +140,13 @@ public class DispatcherServletsMappingDescriptionProvider
private
DispatcherServletMappingDescription
describe
(
Entry
<
RequestMappingInfo
,
HandlerMethod
>
mapping
)
{
DispatcherServletMappingDetails
mappingDetails
=
new
DispatcherServletMappingDetails
();
mappingDetails
.
setHandlerMethod
(
new
HandlerMethodDescription
(
mapping
.
getValue
()));
mappingDetails
.
setRequestMappingConditions
(
new
RequestMappingConditionsDescription
(
mapping
.
getKey
()));
return
new
DispatcherServletMappingDescription
(
mapping
.
getKey
().
toString
(),
mapping
.
getValue
().
toString
(),
new
DispatcherServletMappingDetails
(
new
HandlerMethodDescription
(
mapping
.
getValue
())));
mapping
.
getValue
().
toString
(),
mappingDetails
);
}
}
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/RequestMappingConditionsDescription.java
0 → 100644
View file @
17c7f027
/*
* 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
.
web
.
mappings
.
servlet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.servlet.mvc.condition.MediaTypeExpression
;
import
org.springframework.web.servlet.mvc.condition.NameValueExpression
;
import
org.springframework.web.servlet.mvc.method.RequestMappingInfo
;
/**
* Description of the conditions of a {@link RequestMappingInfo}.
*
* @author Andy Wilkinson
* @since 2.0.0
*/
public
class
RequestMappingConditionsDescription
{
private
final
List
<
MediaTypeExpressionDescription
>
consumes
;
private
final
List
<
NameValueExpressionDescription
>
headers
;
private
final
Set
<
RequestMethod
>
methods
;
private
final
List
<
NameValueExpressionDescription
>
params
;
private
final
Set
<
String
>
patterns
;
private
final
List
<
MediaTypeExpressionDescription
>
produces
;
RequestMappingConditionsDescription
(
RequestMappingInfo
requestMapping
)
{
this
.
consumes
=
requestMapping
.
getConsumesCondition
().
getExpressions
().
stream
()
.
map
(
MediaTypeExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
this
.
headers
=
requestMapping
.
getHeadersCondition
().
getExpressions
().
stream
()
.
map
(
NameValueExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
this
.
methods
=
requestMapping
.
getMethodsCondition
().
getMethods
();
this
.
params
=
requestMapping
.
getParamsCondition
().
getExpressions
().
stream
()
.
map
(
NameValueExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
this
.
patterns
=
requestMapping
.
getPatternsCondition
().
getPatterns
();
this
.
produces
=
requestMapping
.
getProducesCondition
().
getExpressions
().
stream
()
.
map
(
MediaTypeExpressionDescription:
:
new
).
collect
(
Collectors
.
toList
());
}
public
List
<
MediaTypeExpressionDescription
>
getConsumes
()
{
return
this
.
consumes
;
}
public
List
<
NameValueExpressionDescription
>
getHeaders
()
{
return
this
.
headers
;
}
public
Set
<
RequestMethod
>
getMethods
()
{
return
this
.
methods
;
}
public
List
<
NameValueExpressionDescription
>
getParams
()
{
return
this
.
params
;
}
public
Set
<
String
>
getPatterns
()
{
return
this
.
patterns
;
}
public
List
<
MediaTypeExpressionDescription
>
getProduces
()
{
return
this
.
produces
;
}
/**
* A description of a {@link MediaTypeExpression} in a request mapping condition.
*/
public
static
class
MediaTypeExpressionDescription
{
private
final
String
mediaType
;
private
final
boolean
negated
;
MediaTypeExpressionDescription
(
MediaTypeExpression
expression
)
{
this
.
mediaType
=
expression
.
getMediaType
().
toString
();
this
.
negated
=
expression
.
isNegated
();
}
public
String
getMediaType
()
{
return
this
.
mediaType
;
}
public
boolean
isNegated
()
{
return
this
.
negated
;
}
}
/**
* A description of a {@link NameValueExpression} in a request mapping condition.
*/
public
static
class
NameValueExpressionDescription
{
private
final
String
name
;
private
final
Object
value
;
private
final
boolean
negated
;
NameValueExpressionDescription
(
NameValueExpression
<?>
expression
)
{
this
.
name
=
expression
.
getName
();
this
.
value
=
expression
.
getValue
();
this
.
negated
=
expression
.
isNegated
();
}
public
String
getName
()
{
return
this
.
name
;
}
public
Object
getValue
()
{
return
this
.
value
;
}
public
boolean
isNegated
()
{
return
this
.
negated
;
}
}
}
spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/ExampleController.java
0 → 100644
View file @
17c7f027
package
sample
.
webflux
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
public
class
ExampleController
{
@PostMapping
(
path
=
"/"
,
consumes
=
{
MediaType
.
APPLICATION_JSON_VALUE
,
"!application/xml"
},
produces
=
MediaType
.
TEXT_PLAIN_VALUE
,
headers
=
"X-Custom=Foo"
,
params
=
"a!=alpha"
)
public
String
example
()
{
return
"Hello World"
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment