#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.
This commit is contained in:
committed by
Oliver Gierke
parent
9790d94872
commit
6473c10113
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.hateoas.core;
|
||||
|
||||
import static org.springframework.web.util.UriComponentsBuilder.*;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.hateoas.Identifiable;
|
||||
@@ -30,6 +32,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*
|
||||
* @author Ricardo Gladwell
|
||||
* @author Oliver Gierke
|
||||
* @author Kamill Sokol
|
||||
*/
|
||||
public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkBuilder {
|
||||
|
||||
@@ -70,8 +73,11 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
|
||||
return getThis();
|
||||
}
|
||||
|
||||
String uriString = uriComponents.toUriString();
|
||||
UriComponentsBuilder builder = uriString.isEmpty() ? fromUri(uriComponents.toUri())
|
||||
: fromUriString(uriString);
|
||||
|
||||
UriComponents components = UriComponentsBuilder.fromUriString(path).build();
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(uriComponents.toUri());
|
||||
|
||||
for (String pathSegment : components.getPathSegments()) {
|
||||
builder.pathSegment(pathSegment);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,13 +22,14 @@ import org.springframework.hateoas.core.AnnotationMappingDiscoverer;
|
||||
import org.springframework.hateoas.core.LinkBuilderSupport;
|
||||
import org.springframework.hateoas.core.MappingDiscoverer;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
|
||||
/**
|
||||
* {@link LinkBuilder} to derive URI mappings from a JAX-RS {@link Path} annotation.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Kamill Sokol
|
||||
*/
|
||||
public class JaxRsLinkBuilder extends LinkBuilderSupport<JaxRsLinkBuilder> {
|
||||
|
||||
@@ -66,8 +67,9 @@ public class JaxRsLinkBuilder extends LinkBuilderSupport<JaxRsLinkBuilder> {
|
||||
|
||||
JaxRsLinkBuilder builder = new JaxRsLinkBuilder(ServletUriComponentsBuilder.fromCurrentServletMapping());
|
||||
|
||||
UriTemplate template = new UriTemplate(DISCOVERER.getMapping(service));
|
||||
return builder.slash(template.expand(parameters));
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(DISCOVERER.getMapping(service)).build();
|
||||
UriComponents expandedComponents = uriComponents.expand(parameters);
|
||||
return builder.slash(expandedComponents);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
|
||||
@@ -39,6 +40,7 @@ import org.springframework.web.util.UriTemplate;
|
||||
* Builder to ease building {@link Link} instances pointing to Spring MVC controllers.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Kamill Sokol
|
||||
*/
|
||||
public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuilder> {
|
||||
|
||||
@@ -79,9 +81,11 @@ public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuil
|
||||
|
||||
ControllerLinkBuilder builder = new ControllerLinkBuilder(getBuilder());
|
||||
String mapping = DISCOVERER.getMapping(controller);
|
||||
UriTemplate template = new UriTemplate(mapping == null ? "/" : mapping);
|
||||
|
||||
return builder.slash(template.expand(parameters));
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(mapping == null ? "/" : mapping).build();
|
||||
UriComponents expandedComponents = uriComponents.expand(parameters);
|
||||
|
||||
return builder.slash(expandedComponents);
|
||||
}
|
||||
|
||||
public static ControllerLinkBuilder linkTo(Method method, Object... parameters) {
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.springframework.web.util.UriTemplate;
|
||||
* @author Ricardo Gladwell
|
||||
* @author Oliver Gierke
|
||||
* @author Dietrich Schulten
|
||||
* @author Kamill Sokol
|
||||
*/
|
||||
public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<ControllerLinkBuilder> {
|
||||
|
||||
@@ -133,7 +134,7 @@ public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<Co
|
||||
}
|
||||
|
||||
UriComponents components = applyUriComponentsContributer(builder, invocation).buildAndExpand(values);
|
||||
return new ControllerLinkBuilder(UriComponentsBuilder.fromUri(components.toUri()));
|
||||
return new ControllerLinkBuilder(UriComponentsBuilder.fromUriString(components.toUriString()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user