Commit Graph

39 Commits

Author SHA1 Message Date
Greg Turnquist
b592ddda92 #342 - Augment error message when building link without a web request.
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.
2015-05-21 14:47:39 +02:00
Oemer Yildiz
312fa3ead9 #331 - Fixed handling of @RequestParam with default value set.
ControllerLinkBuilderFactory now checks the default value of an @RequestParam annotated handler method parameter before triggering strict validation.

Original pull request: #332.
2015-04-13 16:41:34 +02:00
Oliver Gierke
c3dcdf1b9e #306 - Renamed type references types to allow more concise usage.
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.
2015-03-02 12:48:21 +01:00
Matteo Castellini
1ae44c1896 #237 - Added missing variable in call to ControllerLinkBuilder.linkTo(…).
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.
2015-02-27 13:03:41 +01:00
Oliver Gierke
b00bbe7504 #209 - Polishing.
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.
2015-02-27 12:57:56 +01:00
rossturner
65f0c451d5 #209 - Added support for Map<String, String> and MultiValueMap<String, String> RequestParams in ControllerLinkBuilderFactory.
Original pull request: #210.
2015-02-27 12:56:42 +01:00
Oliver Gierke
9c45341564 #306 - Introduced TypeReferences helper to create ParameterizedTypeReferences easily.
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.
2015-02-26 19:52:19 +01:00
Oliver Gierke
994347c005 #257 - Added support for Forwarded and X-Forwarded-Proto headers.
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.
2014-12-02 08:17:17 +01:00
Oliver Gierke
5882fcf0d6 #219 - HAL setup now registers a more strict HttpMessageConverter.
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.
2014-07-25 10:24:30 +02:00
Oliver Gierke
673f82d388 #192 - Added linkTo(Class<?>, Method, Object...) to MethodLinkBuilderFactory.
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).
2014-06-05 16:19:10 +02:00
Kamill Sokol
6473c10113 #96 - Fixed double-encoding issues in LinkBuilderSupport.
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.
2014-05-20 10:49:05 +02:00
Oliver Gierke
c9675640f2 #114 - Support for type mappings on sub-types in ControllerLinkBuilder.
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.
2014-05-01 18:38:52 +02:00
Vladimir Lyubitelev
2c6fa4d1b3 #170 - LinkBuilder takes X-Forwarded-Port header into account if present.
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.
2014-05-01 18:17:15 +02:00
Oliver Gierke
bb0a578701 #135 - HAL embedded resources are now rendered as collection by default.
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(…).
2014-01-24 14:52:57 +01:00
Oliver Gierke
653f28727c #122 - Fixed parameter binding for optional request parameters.
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.
2014-01-02 12:15:47 +01:00
Oliver Gierke
137e7c390f #128 - Severe refactoring regarding LinkDiscoverers.
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.
2013-12-19 13:01:35 +01:00
Ito Zapata
27069b82d6 #112 - Added support for X-Forwarded-Ssl header during link construction. 2013-12-10 14:42:44 +01:00
Frank Bille
c5caea5efd #90 - Fixed port handling in X-Forwarded-Host treatment.
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.
2013-07-03 15:25:57 +02:00
Oliver Gierke
4142140a37 #91 - Improved proxying for method link references with Objenesis.
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.
2013-06-28 23:25:20 +02:00
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
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
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
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
Oliver Gierke
1d1d959143 #47, #60 - Added provider interface for relation types by entity type. 2013-04-29 12:17:16 +02: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
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
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
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
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
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
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
b33231ffaa Polished Javadoc of ControllerLinkBuilder. 2012-08-30 14:19:09 +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
21b1a4ec8c Initial commit. 2012-05-10 20:25:31 +02:00