|
36 | 36 | import org.springframework.boot.endpoint.CachingConfiguration;
|
37 | 37 | import org.springframework.boot.endpoint.CachingOperationInvoker;
|
38 | 38 | import org.springframework.boot.endpoint.ConversionServiceOperationParameterMapper;
|
| 39 | +import org.springframework.boot.endpoint.DeleteOperation; |
39 | 40 | import org.springframework.boot.endpoint.Endpoint;
|
40 | 41 | import org.springframework.boot.endpoint.EndpointExposure;
|
41 | 42 | import org.springframework.boot.endpoint.EndpointInfo;
|
@@ -216,6 +217,24 @@ public void operationsThatReturnResourceProduceApplicationOctetStream() {
|
216 | 217 | });
|
217 | 218 | }
|
218 | 219 |
|
| 220 | + @Test |
| 221 | + public void operationCanProduceCustomMediaTypes() { |
| 222 | + load(CustomMediaTypesEndpointConfiguration.class, (discoverer) -> { |
| 223 | + Map<String, EndpointInfo<WebEndpointOperation>> endpoints = mapEndpoints( |
| 224 | + discoverer.discoverEndpoints()); |
| 225 | + assertThat(endpoints).containsOnlyKeys("custommediatypes"); |
| 226 | + EndpointInfo<WebEndpointOperation> endpoint = endpoints |
| 227 | + .get("custommediatypes"); |
| 228 | + assertThat(requestPredicates(endpoint)).has(requestPredicates( |
| 229 | + path("custommediatypes").httpMethod(WebEndpointHttpMethod.GET) |
| 230 | + .consumes().produces("text/plain"), |
| 231 | + path("custommediatypes").httpMethod(WebEndpointHttpMethod.POST) |
| 232 | + .consumes().produces("a/b", "c/d"), |
| 233 | + path("custommediatypes").httpMethod(WebEndpointHttpMethod.DELETE) |
| 234 | + .consumes().produces("text/plain"))); |
| 235 | + }); |
| 236 | + } |
| 237 | + |
219 | 238 | private void load(Class<?> configuration,
|
220 | 239 | Consumer<WebAnnotationEndpointDiscoverer> consumer) {
|
221 | 240 | this.load((id) -> null, configuration, consumer);
|
@@ -415,6 +434,27 @@ public Resource read() {
|
415 | 434 |
|
416 | 435 | }
|
417 | 436 |
|
| 437 | + @Endpoint(id = "custommediatypes") |
| 438 | + static class CustomMediaTypesEndpoint { |
| 439 | + |
| 440 | + @ReadOperation(produces = "text/plain") |
| 441 | + public String read() { |
| 442 | + return "read"; |
| 443 | + } |
| 444 | + |
| 445 | + @WriteOperation(produces = { "a/b", "c/d" }) |
| 446 | + public String write() { |
| 447 | + return "write"; |
| 448 | + |
| 449 | + } |
| 450 | + |
| 451 | + @DeleteOperation(produces = "text/plain") |
| 452 | + public String delete() { |
| 453 | + return "delete"; |
| 454 | + } |
| 455 | + |
| 456 | + } |
| 457 | + |
418 | 458 | @Configuration
|
419 | 459 | static class MultipleEndpointsConfiguration {
|
420 | 460 |
|
@@ -578,6 +618,17 @@ public ResourceEndpoint resourceEndpoint() {
|
578 | 618 |
|
579 | 619 | }
|
580 | 620 |
|
| 621 | + @Configuration |
| 622 | + @Import(BaseConfiguration.class) |
| 623 | + static class CustomMediaTypesEndpointConfiguration { |
| 624 | + |
| 625 | + @Bean |
| 626 | + public CustomMediaTypesEndpoint customMediaTypesEndpoint() { |
| 627 | + return new CustomMediaTypesEndpoint(); |
| 628 | + } |
| 629 | + |
| 630 | + } |
| 631 | + |
581 | 632 | private static final class RequestPredicateMatcher {
|
582 | 633 |
|
583 | 634 | private final String path;
|
|
0 commit comments