Skip to content

Instantly share code, notes, and snippets.

@dvntucker
Created January 8, 2018 19:10
Show Gist options
  • Select an option

  • Save dvntucker/fac1c4964f31e4ff0d4d1f3fe298ca7f to your computer and use it in GitHub Desktop.

Select an option

Save dvntucker/fac1c4964f31e4ff0d4d1f3fe298ca7f to your computer and use it in GitHub Desktop.
Rest Debugging Notes

Controller not hit/Response Code 415

The most common issue I've run into during the conversion was the handler method not being hit at all. This usually results in a response code 415 from Spring (media type not accepted). Debugging this ranges from simple to aggravating. Here are a few tips, from most obvious to least:

  • Is the request path correct?
  • Does your request Content-Type match the "consumes" parameter of the handler
  • Are all your path elements matched correctly?
  • Is the HttpMessageConverter you expect to be hit -- based on the requested content type -- actually being invoked? Be sure to check the canWrite/canRead method to see that it's returning true as expected.
  • Are you requesting something via extension (say .zip) that can't actually be produced (ie. POSTING to .zip when the controller only produces XML)
  • Do you have a second Spring MVC context existing in the same runtime? This can happen if the mvc:annotation-driven directive is used multiple times. In this case you may find during debugging that the path for the request is matched, but a handler isn't found.
  • org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#addMatchingMappings: This method goes through all the handlers to find the one that matches. Useful for debugging why a controller isn't being hit (415 response code). Digging around here is your last resort to find out WHY a specific handler is being rejected.
  • org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver#readWithMessageConverters is where the converters are invoked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment