Repository: camel Updated Branches: refs/heads/master 633b659cc -> 33abe0f95
CAMEL-11345: Remove dependency on spring-core from gRPC component Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/33abe0f9 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/33abe0f9 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/33abe0f9 Branch: refs/heads/master Commit: 33abe0f95acd23a5fe11e89910702052afd44d92 Parents: 633b659 Author: Dmitry Volodin <[email protected]> Authored: Mon May 29 13:22:38 2017 +0300 Committer: Claus Ibsen <[email protected]> Committed: Mon May 29 13:49:52 2017 +0200 ---------------------------------------------------------------------- .../apache/camel/util/IntrospectionSupport.java | 0 .../org/apache/camel/util/ReflectionHelper.java | 29 ++++++++++++++++++++ components/camel-grpc/pom.xml | 5 ---- .../camel/component/grpc/GrpcComponent.java | 4 +-- .../apache/camel/component/grpc/GrpcUtils.java | 19 +++++++------ .../camel-grpc-starter/pom.xml | 8 ------ 6 files changed, 41 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/33abe0f9/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java b/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java old mode 100755 new mode 100644 http://git-wip-us.apache.org/repos/asf/camel/blob/33abe0f9/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java b/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java index c794a72..fb84766 100644 --- a/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java @@ -17,8 +17,11 @@ package org.apache.camel.util; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.lang.reflect.UndeclaredThrowableException; +import java.util.Arrays; /** * Helper for working with reflection on classes. @@ -113,6 +116,32 @@ public final class ReflectionHelper { } } } + + /** + * Attempt to find a {@link Method} on the supplied class with the supplied name + * and parameter types. Searches all superclasses up to {@code Object}. + * <p>Returns {@code null} if no {@link Method} can be found. + * @param clazz the class to introspect + * @param name the name of the method + * @param paramTypes the parameter types of the method + * (may be {@code null} to indicate any signature) + * @return the Method object, or {@code null} if none found + */ + public static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) { + ObjectHelper.notNull(clazz, "Class must not be null"); + ObjectHelper.notNull(name, "Method name must not be null"); + Class<?> searchType = clazz; + while (searchType != null) { + Method[] methods = searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods(); + for (Method method : methods) { + if (name.equals(method.getName()) && (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) { + return method; + } + } + searchType = searchType.getSuperclass(); + } + return null; + } public static void setField(Field f, Object instance, Object value) { try { http://git-wip-us.apache.org/repos/asf/camel/blob/33abe0f9/components/camel-grpc/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-grpc/pom.xml b/components/camel-grpc/pom.xml index 2f142d5..e1a2740 100644 --- a/components/camel-grpc/pom.xml +++ b/components/camel-grpc/pom.xml @@ -58,11 +58,6 @@ <artifactId>grpc-stub</artifactId> <version>${grpc-version}</version> </dependency> - - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - </dependency> <dependency> <groupId>org.javassist</groupId> http://git-wip-us.apache.org/repos/asf/camel/blob/33abe0f9/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcComponent.java b/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcComponent.java index 5a64aec..b5a6a6a 100644 --- a/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcComponent.java +++ b/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcComponent.java @@ -20,7 +20,7 @@ import java.util.Map; import org.apache.camel.Endpoint; import org.apache.camel.impl.DefaultComponent; -import org.springframework.util.ObjectUtils; +import org.apache.camel.util.ObjectHelper; /** * Represents the component that manages {@link GrpcEndpoint}. @@ -36,7 +36,7 @@ public class GrpcComponent extends DefaultComponent { config.setServicePackage(extractServicePackage(remaining)); // Convert method name to the camel case style // This requires if method name as described inside .proto file directly - if (!ObjectUtils.isEmpty(config.getMethod())) { + if (!ObjectHelper.isEmpty(config.getMethod())) { config.setMethod(GrpcUtils.convertMethod2CamelCase(config.getMethod())); } http://git-wip-us.apache.org/repos/asf/camel/blob/33abe0f9/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcUtils.java ---------------------------------------------------------------------- diff --git a/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcUtils.java b/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcUtils.java index 8f1a92e..39861cd 100644 --- a/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcUtils.java +++ b/components/camel-grpc/src/main/java/org/apache/camel/component/grpc/GrpcUtils.java @@ -24,7 +24,8 @@ import java.util.List; import io.grpc.Channel; import io.grpc.stub.StreamObserver; import org.apache.camel.CamelContext; -import org.springframework.util.ReflectionUtils; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.ReflectionHelper; /** * GrpcUtils helpers are working with dynamic methods via Spring reflection @@ -58,11 +59,11 @@ public final class GrpcUtils { String serviceClassName = packageName + "." + serviceName + GrpcConstants.GRPC_SERVICE_CLASS_POSTFIX; try { Class grpcServiceClass = context.getClassResolver().resolveMandatoryClass(serviceClassName); - Method grpcBlockingMethod = ReflectionUtils.findMethod(grpcServiceClass, stubMethod, paramChannel); + Method grpcBlockingMethod = ReflectionHelper.findMethod(grpcServiceClass, stubMethod, paramChannel); if (grpcBlockingMethod == null) { throw new IllegalArgumentException("gRPC service method not found: " + serviceClassName + "." + GrpcConstants.GRPC_SERVICE_SYNC_STUB_METHOD); } - grpcBlockingStub = ReflectionUtils.invokeMethod(grpcBlockingMethod, grpcServiceClass, channel); + grpcBlockingStub = ObjectHelper.invokeMethod(grpcBlockingMethod, grpcServiceClass, channel); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("gRPC service class not found: " + serviceClassName); @@ -88,12 +89,12 @@ public final class GrpcUtils { public static void invokeAsyncMethod(Object asyncStubClass, String invokeMethod, Object request, StreamObserver responseObserver) { Class[] paramMethod = null; - Method method = ReflectionUtils.findMethod(asyncStubClass.getClass(), invokeMethod, paramMethod); + Method method = ReflectionHelper.findMethod(asyncStubClass.getClass(), invokeMethod, paramMethod); if (method == null) { throw new IllegalArgumentException("gRPC service method not found: " + asyncStubClass.getClass().getName() + "." + invokeMethod); } if (method.getReturnType().equals(StreamObserver.class)) { - StreamObserver<Object> requestObserver = (StreamObserver<Object>)ReflectionUtils.invokeMethod(method, asyncStubClass, responseObserver); + StreamObserver<Object> requestObserver = (StreamObserver<Object>)ObjectHelper.invokeMethod(method, asyncStubClass, responseObserver); if (request instanceof List) { List<Object> requestList = (List<Object>)request; requestList.forEach((requestItem) -> { @@ -104,7 +105,7 @@ public final class GrpcUtils { } requestObserver.onCompleted(); } else { - ReflectionUtils.invokeMethod(method, asyncStubClass, request, responseObserver); + ObjectHelper.invokeMethod(method, asyncStubClass, request, responseObserver); } } @@ -112,19 +113,19 @@ public final class GrpcUtils { public static Object invokeSyncMethod(Object blockingStubClass, String invokeMethod, Object request) { Class[] paramMethod = null; - Method method = ReflectionUtils.findMethod(blockingStubClass.getClass(), invokeMethod, paramMethod); + Method method = ReflectionHelper.findMethod(blockingStubClass.getClass(), invokeMethod, paramMethod); if (method == null) { throw new IllegalArgumentException("gRPC service method not found: " + blockingStubClass.getClass().getName() + "." + invokeMethod); } if (method.getReturnType().equals(Iterator.class)) { - Iterator<Object> responseObjects = (Iterator<Object>)ReflectionUtils.invokeMethod(method, blockingStubClass, request); + Iterator<Object> responseObjects = (Iterator<Object>)ObjectHelper.invokeMethod(method, blockingStubClass, request); List<Object> objectList = new ArrayList<Object>(); while (responseObjects.hasNext()) { objectList.add(responseObjects.next()); } return objectList; } else { - return ReflectionUtils.invokeMethod(method, blockingStubClass, request); + return ObjectHelper.invokeMethod(method, blockingStubClass, request); } } http://git-wip-us.apache.org/repos/asf/camel/blob/33abe0f9/platforms/spring-boot/components-starter/camel-grpc-starter/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-grpc-starter/pom.xml b/platforms/spring-boot/components-starter/camel-grpc-starter/pom.xml index adf3d24..baeeace 100644 --- a/platforms/spring-boot/components-starter/camel-grpc-starter/pom.xml +++ b/platforms/spring-boot/components-starter/camel-grpc-starter/pom.xml @@ -38,14 +38,6 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-grpc</artifactId> <version>${project.version}</version> - <!--START OF GENERATED CODE--> - <exclusions> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> - <!--END OF GENERATED CODE--> </dependency> <!--START OF GENERATED CODE--> <dependency>
