DATAREST-155 - Introduce API to alter exposed backend ids.

Introduced BackendIdConverter SPI to be able to register custom components that will be used during URI construction and URI parsing to determine the actual backend identifier.

To register a custom BackendIdConverter simply declare a bean definition for it in the ApplicationContext. The Spring Data REST URI creation infrastructure (RepositoryEntityLinks in particular) will pick it up transparently.
This commit is contained in:
Oliver Gierke
2014-03-11 17:41:17 +01:00
parent 0a3738782d
commit 572690b888
19 changed files with 529 additions and 163 deletions

View File

@@ -1,25 +0,0 @@
package org.springframework.data.rest.core.util;
import java.net.URI;
import org.springframework.web.util.UriComponentsBuilder;
/**
* Helper methods for dealing with URIs.
*
* @author Jon Brisbin
*/
public abstract class UriUtils {
/**
* Create a new {@link URI} out of the components.
*
* @param baseUri The base URI these path segments are relative to.
* @param pathSegments The path segments to add to the given base URI.
* @return A new URI built from the given base URI and additional path segments.
*/
public static URI buildUri(URI baseUri, String... pathSegments) {
return UriComponentsBuilder.fromUri(baseUri).pathSegment(pathSegments).build().toUri();
}
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2012-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.core.util;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import java.net.URI;
import org.junit.Test;
/**
* Tests to verify that {@link UriUtils} can manipulate {@link URI}s.
*
* @author Jon Brisbin
*/
public class UriUtilsUnitTests {
private static final String BASE_URI_STR = "http://localhost:8080/data";
private static final URI BASE_URI = URI.create(BASE_URI_STR);
private static final String PERSON_2LVL_STR = BASE_URI_STR + "/person/1";
private static final URI PERSON_2LVL_URI = URI.create(PERSON_2LVL_STR);
@Test
public void shouldBuildURIFromPathSegments() throws Exception {
URI uri = UriUtils.buildUri(BASE_URI, "person", "1");
assertThat(uri, is(PERSON_2LVL_URI));
}
}