Description
Spring Boot version: 2.0.3.RELEASE
The Spring Boot example for using @WriteOperation
can be found at "Endpoint infrastructure" section
This example is working OK because JSON body is passed as a parameter with string value: { "configuredLevel": "WARN" }
and LogLevel is an enum.
Unfortunately, if you will try to pass a bean class included in body for a HTTP POST request then it will fail with 400 - bad request. You can take a look at this example which is not working:
http://www.baeldung.com/spring-boot-actuators, 4.7. "Creating a Custom Endpoint" section
Using curl command:
$ curl -X POST http://localhost:8080/actuator/features/payment -H "Content-Type: application/json" -d '{"enabled": true}'
response:
{"timestamp":"2018-07-23T09:57:57.922+0000","status":400,"error":"Bad Request","message":"Missing parameters: feature","path":"/actuator/features/payment"}
It indicates a missing feature parameter. Even though this feature parameter is added:
$ curl -X POST http://localhost:8080/actuator/features/payment -H "Content-Type: application/json" -d '{"feature": {"enabled":true}}'
response:
"Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException"
Feature bean class is not interpreted because Jackson is expecting a string instead of a bean class.
After debugging Jackson and Spring sources I found that the problem appears at startup, because RequestMappingHandlerMapping.isHandler()
knows to create handler for identifying bean classes from endpoint methods only for Controller
and RequestMapping
. According to 50.8 "Implementing Custom Endpoints" section Endpoint and WebEndpoint are exposed over HTTP.
Therefore, both classes should be added in isHandler()
method to create a handler for parsing bean classes.