Commit Graph

60 Commits

Author SHA1 Message Date
Oliver Gierke
1db0068013 #85 - Added HeaderLinksResponseEntity.
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.
2013-06-12 13:05:30 +02:00
Oliver Gierke
4d4a43b88f #84 - Made constructor in Resource package private.
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.
2013-06-12 11:01:51 +02:00
Dietrich Schulten
693faae0fe #81, #83 - Fixed potential NullPointerExceptions in HalEmbeddedBuilder. 2013-06-12 10:00:11 +02:00
Dietrich Schulten
3f995ee8f0 #70 - Fixed link build for controllers with type-level mapping parameters. 2013-05-27 14:15:27 +02:00
Oliver Gierke
85e3a2462f #73 - ControllerLinkBuilder does not reject unmapped types anymore.
ControllerLinkBuilder now simply assumes an empty mapping if no type-level mapping can be found.
2013-05-27 13:57:15 +02:00
Oliver Gierke
a46e662632 #72 - Improved mapping discovery in AnnotationMappingDiscoverer.
AnnotationMappingDiscoverer now returns a polished mapping in case the type mapping consists of a plain slash only.
2013-05-27 13:51:44 +02:00
Oliver Gierke
45c05a3203 Polishing in annotations of PagedResources. 2013-05-27 13:40:26 +02:00
Oliver Gierke
a9ccfc6782 #64 - Extended support for PagedResources.
Changed Relation type to identify previous links to standardized value of prev. Added integration tests for HAL rendering of PagedResources.
2013-05-16 00:07:57 +02:00
Oliver Gierke
0df0f2aab8 #63 - Use collection relation types for embedded collections.
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.
2013-05-07 19:08:03 +02:00
Oliver Gierke
4af8c917c2 #62 - Added support for application/vnd.error+(json|xml).
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
2013-05-01 22:03:44 +02:00
Oliver Gierke
64663a5648 #57 - Method reference link building now considers formatting annotations.
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.
2013-04-30 16:12:00 +02:00
Oliver Gierke
6acf17e730 #47, #60 - Added RelProvider implementation pluralizing using the Evo Inflector algorithm.
See http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html for details of the algorithm.
2013-04-29 12:18:54 +02:00
Oliver Gierke
254339c3b2 #47, #60 - Implemented RelProvider registration into HAL serializers.
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
2013-04-29 12:18:32 +02:00
Alexander Bätz
47b50266b8 #47, #60 - First draft on extended HAL integration.
Collections are now rendered as _embedded in combination with a topic relation (https://groups.google.com/forum/?fromgroups=#!topic/hal-discuss/bCzydTlHB3M
). Adapted deserializers accordingly.
2013-04-29 12:17:41 +02:00
Oliver Gierke
1d1d959143 #47, #60 - Added provider interface for relation types by entity type. 2013-04-29 12:17:16 +02:00
Oliver Gierke
2c49f397da #56 - LinkBuilderSupport.slash(…) now handles fragments correctly. 2013-03-08 17:49:45 +01:00
Oliver Gierke
db4f96a4e0 #29 - Fixed obsolete inline rendering of rel in HAL links. 2013-03-06 18:39:47 +01:00
Oliver Gierke
6bc906971a #26, #39 - Fixed potential transitive assertion error in UrComponentsBuilder.
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.
2013-03-04 16:04:19 +01:00
Oliver Gierke
f568845146 #52 - ControllerLinkBuilder builds absolute URIs again.
Commit 8039c306e9 introduced a glitch in ControllerLinkBuilderFactory that caused URIs created not being absolute ones anymore. This commit fixes that glitch.
2013-03-01 12:20:11 +01:00
Oliver Gierke
0db1916dde #50 - Add HAL JSON Module to handler adapters.
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.
2013-02-28 22:50:07 +01:00
Oliver Gierke
8aad5cf83b #50 - Only register LinkDiscoverer if JsonPath is on the classpath. 2013-02-28 22:47:18 +01:00
Oliver Gierke
84efebc7a6 #26, #39 - Added support for request parameters to ControllerLinkBuilder.
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
2013-02-23 22:34:21 +01:00
Oliver Gierke
d152bcb7d1 #54 - Added support for RFC5988 link headers.
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.
2013-02-20 14:44:08 +01:00
Oliver Gierke
3976ae168b #50 - Added @EnableHypermediaSupport annotation.
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).
2013-02-18 19:30:51 +01:00
Oliver Gierke
8039c306e9 #52 - Introduced UriComponentsContributor SPI.
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.
2013-02-18 19:14:35 +01:00
Oliver Gierke
72837210ee #51 - Added HalLinkDiscoverer.
Added LinkDiscoverer implementation that discovers Links from HAL style representations. Extracted AbstractLinkDiscovererUnitTest to define expected behavior for LinkDiscoverers in general.
2013-02-15 11:25:45 +01:00
Alexander Chilingaryan
29b433445c #46 - AnnotationMappingDiscoverer now deals with missing method mapping.
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.
2013-02-14 18:10:42 +01:00
Oliver Gierke
0bd6657dd5 #43 - Improved contract in ControllerEntityLinks.
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.
2013-01-23 16:27:29 +01:00
Alex Coyle
6b7256edad #41, #42 - Allow ResourceAssemberSupport to be used without Identifiable.
Extracted Identifiable related code into an IdentifiableResourceAssemblerSupport to be able to use ResourceAssemblerSupport without the need of the domain object to implement Identifiable.
2013-01-22 14:09:26 +01:00
Oliver Gierke
3f8b90e2b5 #33 - ControllerLinkBuilder now regards X-Forwarded-Host header.
When setting up the builder we now set the host to the value held in the X-Forwarded-Host [0] header if present. This allows to render appropriate URIs in reverse proxy scenarios. This is essentially an extension of ServletUriComponentsBuilder that will be fixed in there eventually. See SPR-10110 [1] for details.

[0] http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10
[1] https://jira.springsource.org/browse/SPR-10110
2012-12-19 17:34:47 +01:00
Oliver Gierke
87537a4def #32 - @EnableEntityLinks is now inherited and documented. 2012-12-19 14:32:06 +01:00
Oliver Gierke
531dd8f5ed #18 - Added support for creating links from method mappings.
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.
2012-12-19 13:10:31 +01:00
Oliver Gierke
220366b240 Method links. 2012-12-19 10:40:15 +01:00
Oliver Gierke
0e0bf16957 #31 - Introduced LinkDiscoverer to extract Link instances from representations.
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.
2012-12-15 19:07:03 +01:00
Alexander Bätz
7af38348a9 #29 - Added support for HAL-style representation of Links.
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.
2012-11-20 12:39:48 +01:00
Oliver Gierke
c7396c24a9 Cleaned up hashCode() method in PagedResources. 2012-11-18 18:58:07 +01:00
Oliver Gierke
a1b706c21c Added assertions based on EntityLinks interface. 2012-11-18 18:57:43 +01:00
Oliver Gierke
40b486cb43 #27 - Added support for Jackson 2.
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.
2012-11-16 21:32:47 +01:00
Oliver Gierke
04be1871c3 Introduced EntityLinks abstraction.
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.
2012-10-29 15:21:28 +01:00
Oliver Gierke
b8add74fc1 Improvements to LinkBuilder API.
Renamed UriComponentsLinkBuilder to LinkBuilderSupport and moved it from mvc into core package. slash(Object object) now transparently unwraps Identifiables<?>.
2012-10-29 15:02:21 +01:00
Ricardo Gladwell
9e728b4660 #13 - Introduced LinkBuilder implementation inspecting JAX-RS @Path annotation.
Refactored LinkBuilder(Factory) classes to extract reusable code into common superclass for ControllerLinkBuilder and JaxRsLinkBuilder.
2012-09-13 17:42:54 +02:00
Oliver Gierke
acdb0c8a5b #11 - Revert to List for links in ResourceSupport.
The order of the links needs to be stable across different requests. Thus we have to revert to List instead of a Set.
2012-09-12 12:51:28 +02:00
Ricardo Gladwell
fc4eebd128 #12 - Introduced interfaces for LinkBuilder(Factory) to improve testability.
LinkBuilder and LinkBuilderFactory interface extracted from ControllerLinkBuilder for easier mocking and so that alternative implementations (such as for CXF) can be created.
2012-09-12 12:43:02 +02:00
Oliver Gierke
c5ee47cce4 Resources - Make returned content Collection immutable. 2012-08-30 14:19:16 +02:00
Oliver Gierke
dab25f25fc Resources - Switched from Collection to Iterable for source content. 2012-08-30 14:19:16 +02:00
Oliver Gierke
b33231ffaa Polished Javadoc of ControllerLinkBuilder. 2012-08-30 14:19:09 +02:00
Oliver Gierke
91a6e99e3f Renamed ResourceProcessor.{enrich(…) -> process(…)}. 2012-08-27 19:08:11 +02:00
Oliver Gierke
15a2092cf7 Moved back to Resource{Enricher -> Processor} to allow exchanging the Resource. 2012-08-24 21:46:17 +02:00
Oliver Gierke
5bc711ee9b #11 - Moved from List to Set for Links in ResourceSupport. 2012-08-24 21:29:02 +02:00
Oliver Gierke
ee515f6f04 #10 - Renamed fromEntities(…) to wrap(…). 2012-08-23 23:59:29 +02:00