Skip to content

actuate endpoint "actuator/serviceregistry" return object type error #1051

@guerlab

Description

@guerlab

Describe the bug
env: Spring cloud commons 3.1.0

when use webflux, this actuate endpoint return body like this

{
"body": "UP",
"headers": {},
"statusCode": "OK",
"statusCodeValue": 200
}

but use webmvc, this actuate endpoint return body like this

UP

because org.springframework.boot.actuate.endpoint.web.reactive.AbstractWebFluxEndpointHandlerMapping#toResponseEntity() method judge response is WebEndpointResponse instance

private ResponseEntity<Object> toResponseEntity(Object response) 
	if (!(response instanceof WebEndpointResponse)) {
		return new ResponseEntity<>(response, HttpStatus.OK);
	}
	WebEndpointResponse<?> webEndpointResponse = (WebEndpointResponse<?>) response;
	MediaType contentType = (webEndpointResponse.getContentType() != null)
			? new MediaType(webEndpointResponse.getContentType()) : null;
	return ResponseEntity.status(webEndpointResponse.getStatus()).contentType(contentType)
			.body(webEndpointResponse.getBody());
}

and in webmvc environment, org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping#handleResult method judge response is WebEndpointResponse instance too.

private Object handleResult(Object result, HttpMethod httpMethod) {
	if (result == null) {
		return new ResponseEntity<>(
				(httpMethod != HttpMethod.GET) ? HttpStatus.NO_CONTENT : HttpStatus.NOT_FOUND);
	}
	if (!(result instanceof WebEndpointResponse)) {
		return result;
	}
	WebEndpointResponse<?> response = (WebEndpointResponse<?>) result;
	MediaType contentType = (response.getContentType() != null) ? new MediaType(response.getContentType())
			: null;
	return ResponseEntity.status(response.getStatus()).contentType(contentType).body(response.getBody());
}

So, to fix this bug, need change org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint.
change setStatus(String status) and getStatus() method return type to WebEndpointResponse

Sample
If possible, please provide a test case or sample application that reproduces
the problem. This makes it much easier for us to diagnose the problem and to verify that
we have fixed it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions