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.
This change is to essentially prevent people from subclassing Resource and call the default constructor which wrecks the assumption of content never being null. For custom resources extend ResourceSupport.
Added missing license header in ResourcesMixin.
When embedding values into HAL representations we now correctly expose the collection relation type as exposed by RelProvider.getCollectionResourceRelFor(…). Added EmbeddedHalBuilder to ease building these kinds of nested maps easily and use the commonly shared code between Jackson 1 and 2 implementations.
Introduced representation models for the application/vnd.error media type as specified in [0]. Added default mapping annotations to get it rendered in XML (via JAXB), and JSON (via Jackson 1 and 2).
[0] https://github.com/blongden/vnd.error
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
If a String piped into LinkBuilderSupport.slash(…) is empty, the call to UriComponentsBuilder.fromUriString(…) fails with an assertion exception. We now guard against this specific case by returning the current builder instance in case an empty String (potentially returned from the toString() method of the object handed in) would be handed to the UriComponentsBuilder.
The issue was introduced by commit 84efebc7a6.
Commit 8039c306e9 introduced a glitch in ControllerLinkBuilderFactory that caused URIs created not being absolute ones anymore. This commit fixes that glitch.
In case no ObjectMapper bean has been configured explicitly, the Spring MVC infrastructure registers HttpMessageConverters directly and does not declare them as Spring beans. Thus we now also inspect RequestMappingHandlerAdapter and AnnotationMethodHandlerAdapter instances for their HttpMessageConverters and transparently augment the ObjectMappers backing potentially registered Jackson converters.
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 new Links container element to group a list of links and allow parsing an RFC5988 compatible String representation of links into it. The parsing mechanism is currently regarding the rel attribute only.
Added valueOf(…) factory methods to allow Spring MVC to pick the types up out of the box.
The annotation registers supporting application components as Spring beans based on the configured hypermedia type. Currently supported are the default rendering as well as HAL. We register a matching LinkDiscoverer implementation as well as the appropriate Jackson modules (if present on the classpath) to support HAL.
Upgraded to Spring 3.1.4 to benefit from fix to prevent multiple invocations of ImportBeanDefinitionRegistrars (see SPR-9939 / SPR-9925).
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.
Added LinkDiscoverer implementation that discovers Links from HAL style representations. Extracted AbstractLinkDiscovererUnitTest to define expected behavior for LinkDiscoverers in general.
If a method level @RequestMapping is not carrying a value we now fall back to the type level mapping as Spring MVC does. Before the fix, providing no mapping lead to an ArrayIndexOutOfBoundsException.
Fixed StackOverflowError in ControllerEntityLinks by delegating to the proper methods now. Clarified contract in EntityLinks interface. Added further unit tests to make sure the implementation behaves like the interface specifies.
Fixes#43.
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.
LinkDiscoverer exposes an API to find Links by their relation types in representations. Added JSONPath based base class and a DefaultLinkDiscoverer that finds Links based on the default rendering of our Jackson mappings.
Added Jackson 1 and 2 modules to render Link objects in a HAL-compliant way. Introduced custom Jackson mixins to avoid introducing new value objects for the representation model.
The rendering can be activated by simply registering Jackson1HalModule or Jackson2HalModule with the Jackson ObjectMapper.
Added Jackson 2 dependencies. Doubly annotated representation model classes with both Jackson 1 and Jackson 2 annotations. Added Integration tests for Jackson 2 marshaling provided by Jon. Polished template.mf.
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.