#700 - Remove JAX-RS support.

This commit is contained in:
Greg Turnquist
2018-02-19 12:05:27 -06:00
committed by Oliver Gierke
parent 22bd76db49
commit 3af698d928
7 changed files with 1 additions and 344 deletions

View File

@@ -74,7 +74,6 @@
<jacoco.destfile>${project.build.directory}/jacoco.exec</jacoco.destfile>
<jackson.version>2.9.1</jackson.version>
<java-module-name>spring.hateoas</java-module-name>
<jaxrs.version>2.0.1</jaxrs.version>
<minidevjson.version>2.2.1</minidevjson.version>
<jsonpath.version>2.2.0</jsonpath.version>
<slf4j.version>1.7.25</slf4j.version>
@@ -454,13 +453,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${jaxrs.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>

View File

@@ -17,9 +17,6 @@ package org.springframework.hateoas.config;
import java.lang.annotation.Annotation;
import javax.ws.rs.Path;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -30,7 +27,6 @@ import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.LinkBuilderFactory;
import org.springframework.hateoas.core.ControllerEntityLinksFactoryBean;
import org.springframework.hateoas.core.DelegatingEntityLinks;
import org.springframework.hateoas.jaxrs.JaxRsLinkBuilderFactory;
import org.springframework.hateoas.mvc.ControllerLinkBuilderFactory;
import org.springframework.plugin.core.support.PluginRegistryFactoryBean;
import org.springframework.stereotype.Controller;
@@ -69,12 +65,6 @@ class LinkBuilderBeanDefinitionRegistrar implements ImportBeanDefinitionRegistra
registry.registerBeanDefinition("controllerEntityLinks", builder.getBeanDefinition());
delegateBuilder.addDependsOn("controllerEntityLinks");
if (IS_JAX_RS_PRESENT) {
JaxRsEntityControllerBuilderDefinitionBuilder definitionBuilder = new JaxRsEntityControllerBuilderDefinitionBuilder();
registry.registerBeanDefinition("jaxRsEntityLinks", definitionBuilder.getBeanDefinition());
delegateBuilder.addDependsOn("jaxRsEntityLinks");
}
AbstractBeanDefinition beanDefinition = delegateBuilder.getBeanDefinition();
beanDefinition.setPrimary(true);
registry.registerBeanDefinition("delegatingEntityLinks", beanDefinition);
@@ -92,12 +82,4 @@ class LinkBuilderBeanDefinitionRegistrar implements ImportBeanDefinitionRegistra
return builder;
}
static class JaxRsEntityControllerBuilderDefinitionBuilder {
public BeanDefinition getBeanDefinition() {
BeanDefinitionBuilder builder = getEntityControllerLinksFor(Path.class, JaxRsLinkBuilderFactory.class);
return builder.getBeanDefinition();
}
}
}

View File

@@ -1,147 +0,0 @@
/*
* Copyright 2012-2016 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.hateoas.jaxrs;
import java.util.Map;
import javax.ws.rs.Path;
import org.springframework.hateoas.LinkBuilder;
import org.springframework.hateoas.core.AnnotationMappingDiscoverer;
import org.springframework.hateoas.core.LinkBuilderSupport;
import org.springframework.hateoas.core.MappingDiscoverer;
import org.springframework.util.Assert;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.util.DefaultUriTemplateHandler;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
/**
* {@link LinkBuilder} to derive URI mappings from a JAX-RS {@link Path} annotation.
*
* @author Oliver Gierke
* @author Kamill Sokol
* @author Andrew Naydyonock
*/
public class JaxRsLinkBuilder extends LinkBuilderSupport<JaxRsLinkBuilder> {
private static final MappingDiscoverer DISCOVERER = new AnnotationMappingDiscoverer(Path.class);
private static final CustomUriTemplateHandler HANDLER = new CustomUriTemplateHandler();
/**
* Creates a new {@link JaxRsLinkBuilder} from the given {@link UriComponentsBuilder}.
*
* @param builder must not be {@literal null}.
*/
private JaxRsLinkBuilder(UriComponentsBuilder builder) {
super(builder);
}
/**
* Creates a {@link JaxRsLinkBuilder} instance to link to the {@link Path} mapping tied to the given class.
*
* @param service the class to discover the annotation on, must not be {@literal null}.
* @return
*/
public static JaxRsLinkBuilder linkTo(Class<?> service) {
return linkTo(service, new Object[0]);
}
/**
* Creates a new {@link JaxRsLinkBuilder} instance to link to the {@link Path} mapping tied to the given class binding
* the given parameters to the URI template.
*
* @param resourceType the class to discover the annotation on, must not be {@literal null}.
* @param parameters additional parameters to bind to the URI template declared in the annotation, must not be
* {@literal null}.
* @return
*/
public static JaxRsLinkBuilder linkTo(Class<?> resourceType, Object... parameters) {
Assert.notNull(resourceType, "Controller type must not be null!");
Assert.notNull(parameters, "Parameters must not be null!");
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(DISCOVERER.getMapping(resourceType));
UriComponents expandedComponents = HANDLER.expandAndEncode(builder, parameters);
return new JaxRsLinkBuilder(ServletUriComponentsBuilder.fromCurrentServletMapping())//
.slash(expandedComponents, true);
}
/**
* Creates a new {@link JaxRsLinkBuilder} instance to link to the {@link Path} mapping tied to the given class binding
* the given parameters to the URI template.
*
* @param resourceType the class to discover the annotation on, must not be {@literal null}.
* @param parameters map of additional parameters to bind to the URI template declared in the annotation, must not be
* {@literal null}.
* @return
*/
public static JaxRsLinkBuilder linkTo(Class<?> resourceType, Map<String, ?> parameters) {
Assert.notNull(resourceType, "Controller type must not be null!");
Assert.notNull(parameters, "Parameters must not be null!");
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(DISCOVERER.getMapping(resourceType));
UriComponents expandedComponents = HANDLER.expandAndEncode(builder, parameters);
return new JaxRsLinkBuilder(ServletUriComponentsBuilder.fromCurrentServletMapping())//
.slash(expandedComponents, true);
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.UriComponentsLinkBuilder#getThis()
*/
@Override
protected JaxRsLinkBuilder getThis() {
return this;
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.UriComponentsLinkBuilder#createNewInstance(org.springframework.web.util.UriComponentsBuilder)
*/
@Override
protected JaxRsLinkBuilder createNewInstance(UriComponentsBuilder builder) {
return new JaxRsLinkBuilder(builder);
}
private static class CustomUriTemplateHandler extends DefaultUriTemplateHandler {
public CustomUriTemplateHandler() {
setStrictEncoding(true);
}
/*
* (non-Javadoc)
* @see org.springframework.web.util.DefaultUriTemplateHandler#expandAndEncode(org.springframework.web.util.UriComponentsBuilder, java.util.Map)
*/
@Override
public UriComponents expandAndEncode(UriComponentsBuilder builder, Map<String, ?> uriVariables) {
return super.expandAndEncode(builder, uriVariables);
}
/*
* (non-Javadoc)
* @see org.springframework.web.util.DefaultUriTemplateHandler#expandAndEncode(org.springframework.web.util.UriComponentsBuilder, java.lang.Object[])
*/
@Override
public UriComponents expandAndEncode(UriComponentsBuilder builder, Object[] uriVariables) {
return super.expandAndEncode(builder, uriVariables);
}
}
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright 2012-2016 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.hateoas.jaxrs;
import java.util.Map;
import org.springframework.hateoas.LinkBuilder;
import org.springframework.hateoas.LinkBuilderFactory;
/**
* Factory for {@link LinkBuilder} instances based on the path mapping annotated on the given JAX-RS service.
*
* @author Ricardo Gladwell
* @author Oliver Gierke
* @author Andrew Naydyonock
*/
public class JaxRsLinkBuilderFactory implements LinkBuilderFactory<JaxRsLinkBuilder> {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.LinkBuilderFactory#linkTo(java.lang.Class)
*/
public JaxRsLinkBuilder linkTo(Class<?> service) {
return JaxRsLinkBuilder.linkTo(service);
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.LinkBuilderFactory#linkTo(java.lang.Class, java.lang.Object[])
*/
@Override
public JaxRsLinkBuilder linkTo(Class<?> service, Object... parameters) {
return JaxRsLinkBuilder.linkTo(service, parameters);
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.LinkBuilderFactory#linkTo(java.lang.Class, java.util.Map)
*/
@Override
public JaxRsLinkBuilder linkTo(Class<?> service, Map<String, ?> parameters) {
return JaxRsLinkBuilder.linkTo(service, parameters);
}
}

View File

@@ -1,5 +0,0 @@
/**
* {@link org.springframework.hateoas.LinkBuilder} implementations to consider JAX-RS annotations.
*/
package org.springframework.hateoas.jaxrs;

View File

@@ -17,8 +17,6 @@ package org.springframework.hateoas.config;
import static org.assertj.core.api.Assertions.*;
import javax.ws.rs.Path;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -48,11 +46,6 @@ public class EnableEntityLinksIntegrationTest {
public SampleController controller() {
return new SampleController();
}
@Bean
public SampleResource resource() {
return new SampleResource();
}
}
@Autowired DelegatingEntityLinks builder;
@@ -62,7 +55,7 @@ public class EnableEntityLinksIntegrationTest {
assertThat(builder).isNotNull();
assertThat(builder.supports(Person.class)).isTrue();
assertThat(builder.supports(Address.class)).isTrue();
assertThat(builder.supports(Address.class)).isFalse();
assertThat(builder.supports(Object.class)).isFalse();
}
@@ -73,12 +66,6 @@ public class EnableEntityLinksIntegrationTest {
}
@Path("/address")
@ExposesResourceFor(Address.class)
static class SampleResource {
}
static class Person {
}

View File

@@ -1,95 +0,0 @@
/*
* Copyright 2011-2016 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.hateoas.jaxrs;
import static org.assertj.core.api.Assertions.*;
import java.util.Collections;
import javax.ws.rs.Path;
import org.junit.Test;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.TestUtils;
/**
* Unit test for {@link JaxRsLinkBuilderFactory}.
*
* @author Ricardo Gladwell
* @author Oliver Gierke
* @author Kamill Sokol
* @author Andrew Naydyonock
*/
public class JaxRsLinkBuilderFactoryUnitTest extends TestUtils {
JaxRsLinkBuilderFactory factory = new JaxRsLinkBuilderFactory();
@Test
public void createsLinkToServiceRoot() {
Link link = factory.linkTo(PersonServiceImpl.class).withSelfRel();
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people");
}
@Test
public void createsLinkToParameterizedServiceRoot() {
Link link = factory.linkTo(PersonsAddressesService.class, 15).withSelfRel();
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/15/addresses");
}
/**
* @see #96
*/
@Test
public void createsLinkToParameterizedServiceRootWithUrlEncoding() {
Link link = factory.linkTo(PersonsAddressesService.class, "with blank").withSelfRel();
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/with%20blank/addresses");
}
/**
* @see #372
*/
@Test
public void createsLinkToParameterizedServiceRootWithParameterMap() {
Link link = factory.linkTo(PersonsAddressesService.class, Collections.singletonMap("id", "17")).withSelfRel();
assertThat(link.getRel()).isEqualTo(Link.REL_SELF);
assertThat(link.getHref()).endsWith("/people/17/addresses");
}
@Path("/people")
interface PersonService {
}
class PersonServiceImpl implements PersonService {
}
@Path("/people/{id}/addresses")
class PersonsAddressesService {
}
}