View RSS Feed

Spring Framework

Factors Influencing Media Type Selection in Spring

Rate this Entry
by , 11-28-2011 at 01:17 AM (1853 Views)
In my previous tips, we looked at the components Spring uses to determine the appropriate media type for the results returned. We know that the ContentNegotiatingViewResolver is used to determine what the appropriate media type is for the results. I will discuss the second part of the strategy used for making this determination. This involves factors that influence the requested media type(s).

After the ContentNegotiatingViewResolver has determined the requested media type, there are a number of factors that can modify this decision as well as influence itís behavior. They are:

  • Setting the favorPathExtension property to false will cause Content- NegotiatingViewResolver to ignore the URLís path extension.
  • Adding the Java Activation Framework (JAF) to the classpath will cause ContentNegotiatingViewResolver to request help from the JAF in determining the media type for the path extension in addition to entries in the mediaTypes property.
  • By setting favorParameter property to true and if the request has a format parameter, then the value of the format parameter will be matched against the mediaTypes property. (Additionally, the name of the parameter can be chosen by setting the parameterName property.)
  • By setting the ignoreAcceptHeader to true, the Accept header will be removed from consideration.


So if the favorParameter is set to true, the ContentNegotiatingViewResolver could match up a URL with the application/json media type as long as the request format parameter is set to json. The ContentNegotiatingViewResolver now knows what media type the client wants. Itís time to find a view to render the content. That will be our next post in this series.

Submit "Factors Influencing Media Type Selection in Spring" to Facebook Submit "Factors Influencing Media Type Selection in Spring" to Digg Submit "Factors Influencing Media Type Selection in Spring" to del.icio.us Submit "Factors Influencing Media Type Selection in Spring" to StumbleUpon Submit "Factors Influencing Media Type Selection in Spring" to Google

Updated 11-30-2011 at 01:51 PM by Spring Framework

Categories
MVC , REST , Spring 3 , Resource

Comments