From 13370f8e2f30b693a69464b4cf3a868e5f2d3eec Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 20 Dec 2018 17:16:49 +0100 Subject: [PATCH] DATAREST-1322 - Fix proxy detection for Hibernate 5+ compatibility. Switched to Spring Data Commons' ProxyUtils for a proxy detection mechanism that supports Hibernate 5 proxies. --- .../config/ProjectionDefinitionConfiguration.java | 4 ++-- .../core/event/AnnotatedEventHandlerInvoker.java | 15 +++------------ .../PersistentEntitiesResourceMappings.java | 6 +++--- .../rest/webmvc/BasePathAwareHandlerMapping.java | 5 ++--- .../rest/webmvc/RepositoryRestHandlerMapping.java | 4 ++-- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfiguration.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfiguration.java index 0b511d0c8..1b4c4f5e5 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfiguration.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/ProjectionDefinitionConfiguration.java @@ -27,8 +27,8 @@ import java.util.Set; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.rest.core.projection.ProjectionDefinitions; +import org.springframework.data.util.ProxyUtils; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; /** @@ -164,7 +164,7 @@ public class ProjectionDefinitionConfiguration implements ProjectionDefinitions Assert.notNull(sourceType, "Source type must not be null!"); - Class userType = ClassUtils.getUserClass(sourceType); + Class userType = ProxyUtils.getUserClass(sourceType); Map byName = new HashMap(); Map> result = new HashMap>(); diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvoker.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvoker.java index 2f0047e51..171e31cee 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvoker.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/event/AnnotatedEventHandlerInvoker.java @@ -34,17 +34,8 @@ import org.springframework.context.ApplicationListener; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.data.rest.core.annotation.HandleAfterCreate; -import org.springframework.data.rest.core.annotation.HandleAfterDelete; -import org.springframework.data.rest.core.annotation.HandleAfterLinkDelete; -import org.springframework.data.rest.core.annotation.HandleAfterLinkSave; -import org.springframework.data.rest.core.annotation.HandleAfterSave; -import org.springframework.data.rest.core.annotation.HandleBeforeCreate; -import org.springframework.data.rest.core.annotation.HandleBeforeDelete; -import org.springframework.data.rest.core.annotation.HandleBeforeLinkDelete; -import org.springframework.data.rest.core.annotation.HandleBeforeLinkSave; -import org.springframework.data.rest.core.annotation.HandleBeforeSave; -import org.springframework.data.rest.core.annotation.RepositoryEventHandler; +import org.springframework.data.rest.core.annotation.*; +import org.springframework.data.util.ProxyUtils; import org.springframework.util.ClassUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -115,7 +106,7 @@ public class AnnotatedEventHandlerInvoker implements ApplicationListener beanType = ClassUtils.getUserClass(bean); + Class beanType = ProxyUtils.getUserClass(bean); RepositoryEventHandler typeAnno = AnnotationUtils.findAnnotation(beanType, RepositoryEventHandler.class); if (typeAnno == null) { diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappings.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappings.java index ef2080a07..3d20052bb 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappings.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappings.java @@ -26,8 +26,8 @@ import java.util.Set; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.context.PersistentEntities; +import org.springframework.data.util.ProxyUtils; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; /** * {@link ResourceMappings} for {@link PersistentEntities}. @@ -63,7 +63,7 @@ public class PersistentEntitiesResourceMappings implements ResourceMappings { Assert.notNull(type, "Type must not be null!"); - type = ClassUtils.getUserClass(type); + type = ProxyUtils.getUserClass(type); if (cache.containsKey(type)) { return cache.get(type); @@ -85,7 +85,7 @@ public class PersistentEntitiesResourceMappings implements ResourceMappings { MappingResourceMetadata getMappingMetadataFor(Class type) { Assert.notNull(type, "Type must not be null!"); - Class userType = ClassUtils.getUserClass(type); + Class userType = ProxyUtils.getUserClass(type); MappingResourceMetadata mappingMetadata = mappingCache.get(userType); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMapping.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMapping.java index 3df7668e8..7874b08cc 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMapping.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMapping.java @@ -45,12 +45,11 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.http.Part; -import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; +import org.springframework.data.util.ProxyUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; @@ -171,7 +170,7 @@ public class BasePathAwareHandlerMapping extends RequestMappingHandlerMapping { @Override protected boolean isHandler(Class beanType) { - Class type = ClassUtils.getUserClass(beanType); + Class type = ProxyUtils.getUserClass(beanType); return type.isAnnotationPresent(BasePathAwareController.class); } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java index 13b8d3030..103c4113e 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestHandlerMapping.java @@ -35,11 +35,11 @@ import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.core.mapping.ResourceMetadata; import org.springframework.data.rest.webmvc.support.JpaHelper; +import org.springframework.data.util.ProxyUtils; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.StringValueResolver; @@ -184,7 +184,7 @@ public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping { @Override protected boolean isHandler(Class beanType) { - Class type = ClassUtils.getUserClass(beanType); + Class type = ProxyUtils.getUserClass(beanType); return AnnotationUtils.findAnnotation(type, RepositoryRestController.class) != null; }