Skip to content

Commit

Permalink
#728 - API polishing.
Browse files Browse the repository at this point in the history
Renamed LinkBuilder implementations for the different web stacks Web(MVC|Flux)LinkBuilder for symmetry. Introduced dedicated builder types to be used from WebFluxLinkBuilder to more conveniently integrate with reactive flows (see the changes in WebFluxEmployeeController).

Deprecated ControllerLinkBuilder(Factory) in favor of WebMvcLinkBuilder(Factory).

Generally untangled the use of WebMvcLinkBuilder from the reactive examples.
  • Loading branch information
odrotbohm committed Feb 21, 2019
1 parent 576274c commit 1d9703a
Show file tree
Hide file tree
Showing 25 changed files with 1,798 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.lang.reflect.Method;

import org.springframework.hateoas.core.DummyInvocationUtils;
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
import org.springframework.hateoas.mvc.WebMvcLinkBuilder;

/**
* Extension of {@link LinkBuilderFactory} for implementations that also support creating {@link LinkBuilder}s by
Expand Down Expand Up @@ -52,9 +52,9 @@ public interface MethodLinkBuilderFactory<T extends LinkBuilder> extends LinkBui
/**
* Returns a {@link LinkBuilder} pointing to the URI mapped to the method the result is handed into this method. Use
* {@link DummyInvocationUtils#methodOn(Class, Object...)} to obtain a dummy instance of a controller to record a
* dummy method invocation on. See {@link ControllerLinkBuilder#linkTo(Object)} for an example.
*
* @see ControllerLinkBuilder#linkTo(Object)
* dummy method invocation on. See {@link WebMvcLinkBuilder#linkTo(Object)} for an example.
*
* @see WebMvcLinkBuilder#linkTo(Object)
* @param methodInvocationResult must not be {@literal null}.
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.core.ControllerEntityLinksFactoryBean;
import org.springframework.hateoas.core.DelegatingEntityLinks;
import org.springframework.hateoas.mvc.ControllerLinkBuilderFactory;
import org.springframework.hateoas.mvc.WebMvcLinkBuilderFactory;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.plugin.core.support.PluginRegistryFactoryBean;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -54,7 +54,7 @@ DelegatingEntityLinks delegatingEntityLinks(PluginRegistry<EntityLinks, Class<?>
}

@Bean
ControllerEntityLinksFactoryBean controllerEntityLinks(ControllerLinkBuilderFactory controllerLinkBuilderFactory) {
ControllerEntityLinksFactoryBean controllerEntityLinks(WebMvcLinkBuilderFactory controllerLinkBuilderFactory) {

ControllerEntityLinksFactoryBean factory = new ControllerEntityLinksFactoryBean();
factory.setAnnotation(Controller.class);
Expand All @@ -64,7 +64,7 @@ ControllerEntityLinksFactoryBean controllerEntityLinks(ControllerLinkBuilderFact
}

@Bean
ControllerLinkBuilderFactory controllerLinkBuilderFactoryBean() {
return new ControllerLinkBuilderFactory();
WebMvcLinkBuilderFactory webMvcLinkBuilderFactoryBean() {
return new WebMvcLinkBuilderFactory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.hateoas.mvc;
package org.springframework.hateoas.core;

import java.util.Map;

Expand All @@ -27,7 +27,7 @@
* @author Michal Stochmialek
* @author Oliver Drotbohm
*/
class UriTemplateFactory {
public class UriTemplateFactory {

private static final Map<String, UriTemplate> CACHE = new ConcurrentReferenceHashMap<String, UriTemplate>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.springframework.hateoas.LinkBuilder;
import org.springframework.hateoas.TemplateVariable;
import org.springframework.hateoas.TemplateVariables;
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.MultiValueMap;
Expand All @@ -57,13 +56,14 @@
import org.springframework.web.util.UriTemplate;

/**
* Utility for taking a method invocation and extracting a {@link ControllerLinkBuilder}.
* Utility for taking a method invocation and extracting a {@link LinkBuilder}.
*
* @author Greg Turnquist
*/
public class WebHandler {

private static final MappingDiscoverer DISCOVERER = new AnnotationMappingDiscoverer(RequestMapping.class);
private static final MappingDiscoverer DISCOVERER = CachingMappingDiscoverer
.of(new AnnotationMappingDiscoverer(RequestMapping.class));
private static final AnnotatedParametersParameterAccessor PATH_VARIABLE_ACCESSOR //
= new AnnotatedParametersParameterAccessor(new AnnotationAttribute(PathVariable.class));
private static final AnnotatedParametersParameterAccessor REQUEST_PARAM_ACCESSOR //
Expand All @@ -90,7 +90,7 @@ public static <T extends LinkBuilder> T linkTo(Object invocationValue,
String mapping = DISCOVERER.getMapping(invocation.getTargetType(), invocation.getMethod());

UriComponentsBuilder builder = mappingToUriComponentsBuilder.apply(mapping);
UriTemplate template = new UriTemplate(mapping == null ? "/" : mapping);
UriTemplate template = UriTemplateFactory.templateFor(mapping == null ? "/" : mapping);
Map<String, Object> values = new HashMap<>();

Iterator<String> names = template.getVariableNames().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.hateoas.core.DummyInvocationUtils;
import org.springframework.hateoas.core.MappingDiscoverer;
import org.springframework.hateoas.core.TemplateVariableAwareLinkBuilderSupport;
import org.springframework.hateoas.core.UriTemplateFactory;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.RequestContextHolder;
Expand All @@ -47,7 +48,9 @@
* @author Andrew Naydyonock
* @author Oliver Trosien
* @author Greg Turnquist
* @deprecated use {@link WebMvcLinkBuilder} instead.
*/
@Deprecated
public class ControllerLinkBuilder extends TemplateVariableAwareLinkBuilderSupport<ControllerLinkBuilder> {

private static final MappingDiscoverer DISCOVERER = CachingMappingDiscoverer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
* @author Kevin Conaway
* @author Andrew Naydyonock
* @author Greg Turnquist
* @deprecated use {@link WebMvcLinkBuilderFactory} instead.
*/
@Deprecated
public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<ControllerLinkBuilder> {

private List<UriComponentsContributor> uriComponentsContributors = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.hateoas.mvc;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import static org.springframework.hateoas.mvc.WebMvcLinkBuilder.*;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.hateoas.mvc;

import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
import static org.springframework.hateoas.mvc.WebMvcLinkBuilder.*;

import java.util.ArrayList;
import java.util.List;
Expand Down
Loading

0 comments on commit 1d9703a

Please sign in to comment.