We now explicitly check whether we could look up request attributes and throw an exception with a message indicating the cause of the failure.
Original pull request: #344.
ControllerLinkBuilderFactory now checks the default value of an @RequestParam annotated handler method parameter before triggering strict validation.
Original pull request: #332.
Renamed the Resource, Resources and PagedResources types in TypeReferences to *Type so that new TypeReferences.Resources<User>() {} now becomes new ResourcesType<User>() {}.
Prior to this change a static import of TypeReferences would've cause the actual Resource types to be fully qualified.
673f82d introduced a glitch in a delegation within ControllerLinkBuilder.linkTo(Class<?> controller, Method method, Object... parameters) which is fixed by this commit.
Original pull request: #300.
Fixed imports in production code and test cases. Extended copyright range. Extracted request parameter handling into dedicated method. Added missing ticket reference.
Original pull request: #210.
TypeReferences contains a set of predefined types that allows to shortcut the creation of ParameterizedTypeReference instances a bit, which is very useful for the usage on the client side (e.g., via RestTemplate).
new ParameterizedTypeReference<Resources<Resource<User>>>() {};
becomes
new TypeReferences.Resources<Resource<User>>() {};
The latter can even be abbreviated by using a static import for TypeReferences.
ControllerLinkBuilder now favors the value of the Forwarded and X-Forwarded-Proto header to build the scheme for the link created.
For more information on the Forwarded header, see http://tools.ietf.org/html/rfc7239.
Related issue: #107.
Previously we registered a special HttpMessageConverter with a custom ObjectMapper to deploy the HAL customizations. That converter was added to Spring MVC registered HandlerAdapters and registered as the first converter.
In case Spring MVC handled a request with Accept header */* or no Accept header at all, this meant that this converter kicked in and served HAL even for objects that don't need the customizations.
We now restrict the applicability of that special HttpMessageConverter to subtypes of ResourceSupport so that it will only be chosen if the object to render is of such type.
The newly introduced method is needed to make sure the correct mappings are looked up if the method given is actually not declared on the class the method shall eventually be invoked on.
This is basically allowing to try to build links, similar to the dummy invocation mechanism but effectively avoiding the overhead of creating such invocation manually (as it would usually require reflection to be used).
LinkBuilderSupport now prefers the URI string over the URI to avoid double encoding issues.
VndErrorsMarshallingTest.jackson2marshalling(…) shouldn't take line breaks into account due to platform differences (Win, OSX, Linux)
Original pull request: #179.
When building links for method invocations we previously only inspected the type that declared the method for type level mappings. We now use the type the method was invoked on explicitly.
ControllerLinkBuilder now inspects the X-Forwarded-Port and uses that if present. If an X-Forwarded-Host header doesn't contain a :, we now also reset the port to prevent the local one from leaking into links generated.
To get consistent representations rendered for single-item collections and multi-item collections, we now use an enforceEmbeddedCollections flag in the Jackson 2 HAL module. Adapted HalEmbeddedBuilder to respect that setting and exposed it via the HandlerInstantiator for user level customization.
Changed RelProvider.getSingleResourceRel(…) to getItemResourceRel(…).
If the method arguments handed into a dummy controller method invocation are required but null we now throw an exception as we cannot build a URI that hits the very same method in the very same way. Based on that, we now inspect @RequestParam annotated parameters for null values, allow them but don't bind a parameter for them anymore.
The LinkDiscoverer interface is now a Plugin<MediaType> to allow selecting a discoverer per media type. We also provide a LinkDiscoverers wrapper around a PluginRegistry for easier injection.
Dropped DefaultLinkDiscoverer as the above mentioned changed prohibits the usage of a discoverer without a media type. Clients that previously used DefaultLinkDiscoverer should switch to JsonPathLinkDiscoverer with a custom JsonPath expression and media type.
@EnableHypermediaSupport now supports multiple HypermediaType values set to be able to set up support for multiple hypermedia formats. Admittedly, the only currently supported type is HAL but we prepare for the addition of other (e.g. Collection/JSON or the like). We changed the infrastructure setup taken care of by @EnableHypermediaSupport to not enrich all ObjectMapper instances with our HAL modules but explicitly register an ObjectMapper with the application context and then registering a custom MappingJackson(2)HttpMessageConverter with the HandlerAdapter instances present in the ApplicationContext. We skip the registration if an already registered MJ2HMC has an ObjectMapper already supporting the Spring HATEOAS mixins.
Removed some compiler warnings.
ControllerLinkBuilder now correctly uses the X-Fowarded-Host header by inspecting it for a port being set and configuring the discovered one on the ServletUriComponentsBuilder created.
Also added that the first host listed in the header is used.
Upgraded to Spring 3.2.3 to be able to use inlined CGLib directly. We now use Objenesis to create the proxy instances which avoids the need for a default constructor.
The HeaderLinksResponseEntity wraps any HttpEntity containing a ResourceSupport and will transform it to contain the Links the ResourceSupport instance held in the first place in the entities headers now.
The String value handed into the UriTemplate created through mock method invocations now uses a DefaultFormattingConversionService to consider formatting annotations on the controller method parameters.
Added @Relation annotation to be able to define the relations that shall be exposed. The annotation can be used on domain classes or ResourceSupport subtypes to define the relations that shall be used to build links pointing to them.
Introduced RelProvider implementations that use the plain domain class name plus an appended List by default (DefaultRelProvider, fallback) as well as an AnnotationRelProvider that will inspect @Relation on the domain type. Added a DelegatingRelProvider that is based on a Spring Plugin PluginRegistry to allow adding RelProvider implementations transparently. Polished AnnotationRelProvider (added annotation caching) and corrected ControllerRelProvider to lookup relation types from Controller classes. Added BeanDefinition setup to HypermediaSupportBeanDefinitionRegistrar to setup a PluginRegistry of RelProviders and the wrapping DelegatingRelProvider to become the primary auto wiring candidate.
Moved RelProvider registration into Jackson HandlerInstantiator implementations. Made the BeanPostProcessors for Jackson ObjectMapper customization aware of the BeanFactory to lookup the DelegatingRelProvider instance to hand them into the Jackson HandlerInstantiators.
TODOs:
- More tests
- Correctly register ControllerRelProviders
Commit 8039c306e9 introduced a glitch in ControllerLinkBuilderFactory that caused URIs created not being absolute ones anymore. This commit fixes that glitch.
We now transparently handle "?foo=bar" expressions passed into ….slash(…). Added method to return UriComponentsBuilder to allow more fine grained control over the URI to be built if needed. The dummy method invocations handled to ….linkTo(…) now transparently adds the values handed in for parameters annotated with @RequestParam.
Most of the commit is highly inspired by Dietrich Schultens work at [0]. I just reworked and polished it slightly as we had too many merge conflicts due to related changes in the meantime.
[0] 1ebdc9025a
Introduced UriComponentsContributor interface to allow components to enhance the UriComponentsBuilder used while building links point in to controller methods.
Moved logic from ControllerLinkBuilder into ControllerLinkBuilderFactory as we now potentially need access to Spring injected components. Might be necessary to get rid of the static LinkBuilder implementations entirely.
Extracted Identifiable related code into an IdentifiableResourceAssemblerSupport to be able to use ResourceAssemblerSupport without the need of the domain object to implement Identifiable.
ControllerLinkBuilder(Factory) now has a linkTo(Method method, Object… parameters) and linkTo(Object dummyMethodInvocationResult) method to either inspect the given method or the result of the dummy method invocation that can be created through DummyInvocationUtils.methodOn(…). So for the following controller:
@Controller
@RequestMapping("/people")
class PersonController {
@RequestMapping(value = "/{person}", method = RequestMethod.GET)
public HttpEntity<PersonResource> show(@PathVariable Long person) { … }
}
you could now do:
Link link = linkTo(methodOn(PersonController.class).show(2L)).withSelfRel();
assertThat(link.getHref(), is("/people/2")));
The code is highly inspired by the code Dietrich Schulten (@dschulten) provided in his pull requests but radically reduced to the core functionality. I also didn't add support for JAX-RS in the first place, but this is definitely a topic going forward.
EntityLinks allow accessing LinkBuilders or even Link instance based on components exposing REST resources for a particular domain type. The core implementation is ControllerEntityLinks that assumes a particular URI structure so that it can derive the URIs to be asked for per domain type. The domain type managed will be inspected from the @ExposesResourceFor annotation on a controller class. We provide a factory bean to allow configuring instances of ControllerEntityLinks based on a mapping annotation and LinkBuilderFactory.
Added infrastructure to activate automatic discovery of EntityLinks implementations through @EnableEntityLinks. This will automatically register ControllerEntityLinks instances for Spring MVC controllers annotated with @ExposesResourceFor as well as JAX-RS resources if JAX-RS is on the classpath. The mechanism essentially registers a DelegatingEntityLinks instance leveraging the Spring Plugin PluginRegistry mechanism to delegate to the actual EntityLinks instance actually registered for the entity type. It will become the primary EntityLinks bean in the ApplicationContext so that they can be autowired into client components safely.
Renamed UriComponentsLinkBuilder to LinkBuilderSupport and moved it from mvc into core package. slash(Object object) now transparently unwraps Identifiables<?>.
LinkBuilder and LinkBuilderFactory interface extracted from ControllerLinkBuilder for easier mocking and so that alternative implementations (such as for CXF) can be created.
Improve ResourceAssemblerSupport by introducing a dedicated method instead of an overload. Got rid of EntityId in the course. ControllerLinkBuilder now inspects type hierarchy for @RequestMapping annotations instead of the class only. Made links list in ResourceSupport final. Polished variable names and JavaDoc.