diff --git a/pom.xml b/pom.xml index 3711d60a..3bad57ed 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,6 @@ ${project.build.directory}/jacoco.exec 2.9.1 spring.hateoas - 2.0.1 2.2.1 2.2.0 1.7.25 @@ -454,13 +453,6 @@ true - - javax.ws.rs - javax.ws.rs-api - ${jaxrs.version} - true - - com.jayway.jsonpath json-path diff --git a/src/main/java/org/springframework/hateoas/config/LinkBuilderBeanDefinitionRegistrar.java b/src/main/java/org/springframework/hateoas/config/LinkBuilderBeanDefinitionRegistrar.java index 48fc4e71..5a9c02fa 100644 --- a/src/main/java/org/springframework/hateoas/config/LinkBuilderBeanDefinitionRegistrar.java +++ b/src/main/java/org/springframework/hateoas/config/LinkBuilderBeanDefinitionRegistrar.java @@ -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(); - } - } } diff --git a/src/main/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilder.java b/src/main/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilder.java deleted file mode 100644 index 5cb94757..00000000 --- a/src/main/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilder.java +++ /dev/null @@ -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 { - - 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 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 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); - } - } -} diff --git a/src/main/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilderFactory.java b/src/main/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilderFactory.java deleted file mode 100644 index c80ae0d2..00000000 --- a/src/main/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilderFactory.java +++ /dev/null @@ -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 { - - /* - * (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 parameters) { - return JaxRsLinkBuilder.linkTo(service, parameters); - } -} diff --git a/src/main/java/org/springframework/hateoas/jaxrs/package-info.java b/src/main/java/org/springframework/hateoas/jaxrs/package-info.java deleted file mode 100644 index 9ad19760..00000000 --- a/src/main/java/org/springframework/hateoas/jaxrs/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * {@link org.springframework.hateoas.LinkBuilder} implementations to consider JAX-RS annotations. - */ -package org.springframework.hateoas.jaxrs; - diff --git a/src/test/java/org/springframework/hateoas/config/EnableEntityLinksIntegrationTest.java b/src/test/java/org/springframework/hateoas/config/EnableEntityLinksIntegrationTest.java index bcc13f53..8e6b1e60 100755 --- a/src/test/java/org/springframework/hateoas/config/EnableEntityLinksIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/config/EnableEntityLinksIntegrationTest.java @@ -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 { } diff --git a/src/test/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilderFactoryUnitTest.java b/src/test/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilderFactoryUnitTest.java deleted file mode 100755 index 5c64b3f8..00000000 --- a/src/test/java/org/springframework/hateoas/jaxrs/JaxRsLinkBuilderFactoryUnitTest.java +++ /dev/null @@ -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 { - - } -}