#700 - Remove JAX-RS support.
This commit is contained in:
committed by
Oliver Gierke
parent
22bd76db49
commit
3af698d928
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
/**
|
||||
* {@link org.springframework.hateoas.LinkBuilder} implementations to consider JAX-RS annotations.
|
||||
*/
|
||||
package org.springframework.hateoas.jaxrs;
|
||||
|
||||
Reference in New Issue
Block a user