Commit Graph

44 Commits

Author SHA1 Message Date
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
Oliver Gierke
a4bf7fb4bf #9 - Added constructors taking Iterable<Link> to resource abstractions. 2012-08-23 23:57:13 +02:00
Oliver Gierke
7646e11a26 #7 - Added @JsonIgnore to ResourceSupport.getId().
Added integration tests for the JSON marshaling.
2012-08-23 23:56:25 +02:00
Oliver Gierke
1bb4669828 Polished Resources abstraction.
Added correct equals(…)/hashCode() methods to PagedResource, PageMetadata. Polished toString() methods of ResourceSupport, Resource, Resources and PagedResources. Added factory method to PagedResources to easily create a plain instance from a set of entities.
2012-08-23 18:34:21 +02:00
Oliver Gierke
2c5dfc12f6 Replaced Resource(s)Processor with ResourceEnricher. 2012-08-23 00:08:51 +02:00
Oliver Gierke
6c368faa0e #5 - Added equals(…) / hashCode() to Resource/Resources. 2012-08-22 18:37:52 +02:00
Oliver Gierke
bc09140769 #3 - Added PageableResources value object 2012-08-17 18:39:41 +02:00
Oliver Gierke
ca57ed440d Enhancements of Resource abstraction.
Introduced Resource and Resources value objects. The former captures single entity instances but adds links to it. The latter does the same for a collection of entities. Added SPI interfaces ResourcePostProcessor and ResourcesPostProcessor to allow manipulating Resource and Resources instances.
2012-08-07 19:17:51 +02:00
Oliver Gierke
cd3e433d98 Incorporate feedback from @rstoyanchev.
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.
2012-07-19 13:32:02 +02:00
Oliver Gierke
0b15928dd6 Javadoc polishing. 2012-07-19 13:17:12 +02:00
Oliver Gierke
21b1a4ec8c Initial commit. 2012-05-10 20:25:31 +02:00