Christoph Grothaus
Christoph Grothaus

Reputation: 175

spring-boot /health endpoint not supporting media type xml after upgrade to 1.3.0

I just tried to upgrade my spring-boot-web application (a REST webservice) to spring-boot version 1.3.0.RELEASE. I use spring-boot-actuator for the /health endpoint. With my previous spring-boot version (1.2.6.RELEASE), that endpoint was able to serve requests with media type application/xml, but that is now broken.

Please note that I am using XStream as XML serializer, which I have configured by providing a configuration to spring-boot that extends WebMvcConfigurerAdapter to configure marshallers for HTTP messages:

 @Configuration
 public class XStreamMarshallerConfiguration extends WebMvcConfigurerAdapter {

     @Autowired
     private Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder;

     @Override
     public void configureMessageConverters( final List<HttpMessageConverter<?>> converters ) {
         converters.add( createJsonConverter() ); // support JSON as default (because it is the first)
         converters.add( createXmlHttpMessageConverter() ); // support XStream XML
         super.configureMessageConverters( converters );
     }

     private MappingJackson2HttpMessageConverter createJsonConverter() {
         ObjectMapper jsonMapper = this.jackson2ObjectMapperBuilder.build();
         return new MappingJackson2HttpMessageConverter( jsonMapper );
     }

     private HttpMessageConverter<Object> createXmlHttpMessageConverter() {
         MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter();

         XStreamMarshaller xstreamMarshaller = new XStreamMarshaller();
         configureXStream( xstreamMarshaller.getXStream() ); // my XStream setup

         xmlConverter.setMarshaller( xstreamMarshaller );
         xmlConverter.setUnmarshaller( xstreamMarshaller );

         return xmlConverter;
     }

 }

Any ideas why the /health won't serialize its response to XML with the new spring-boot version?

Upvotes: 2

Views: 832

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116231

The endpoints were only ever designed to produce JSON responses. There was a bug in Spring Boot 1.2.x that meant it could return XML if an appropriate converter was available and the Accept header asked for it but there was a risk that the XML would be malformed.

Spring Boot 1.3 has addressed this by constraining the endpoints to only produce application/json irrespective of the HTTP message converters that are available.

If you would like the Actuator to officially support XML responses then please open an enhancement request.

Upvotes: 1

Related Questions