0

I'm writing a Controller to replace a legacy system which serves an xml document - but the url has a .html extension

My controller looks like this

@RequestMapping(value="/{name}.html",
                method = RequestMethod.GET,
                consumes = MediaType.ALL_VALUE,
                produces = MediaType.APPLICATION_XML_VALUE)
public @ResponseBody XmlContent getContent(@PathVariable(value = "name") String name) {
    return service.getXmlContent();
}

When I try and hit the URL I get a 406 error:

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

If I change the request mapping to be .xml it all works fine. Is there a component that I need to disable - something that's intercepting the .html part of the request and refusing to map it to xml?

Harry Lime
  • 29,476
  • 4
  • 31
  • 37

1 Answers1

0

I found a similar a similar question/answer using spring xml configuration. For annotation based configuration you just need to add this configuration class

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(false);
    }
}
Harry Lime
  • 29,476
  • 4
  • 31
  • 37