camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-11345: Remove dependency on spring-core from gRPC component
Date Mon, 29 May 2017 12:03:14 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.19.x 1d6bde9de -> bcac1fb15


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/bcac1fb1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bcac1fb1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bcac1fb1

Branch: refs/heads/camel-2.19.x
Commit: bcac1fb15d8f66586f7c707d61b295fbc443691a
Parents: 1d6bde9
Author: Dmitry Volodin <dmvolod@gmail.com>
Authored: Mon May 29 14:13:22 2017 +0300
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon May 29 13:52:37 2017 +0200

----------------------------------------------------------------------
 .../apache/camel/util/IntrospectionSupport.java |  0
 .../org/apache/camel/util/ReflectionHelper.java | 27 ++++++++++++++++++++
 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, 39 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bcac1fb1/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/bcac1fb1/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..0a4b8cf 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
@@ -19,6 +19,7 @@ package org.apache.camel.util;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Arrays;
 
 /**
  * Helper for working with reflection on classes.
@@ -113,6 +114,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/bcac1fb1/components/camel-grpc/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-grpc/pom.xml b/components/camel-grpc/pom.xml
index c131130..010f582 100644
--- a/components/camel-grpc/pom.xml
+++ b/components/camel-grpc/pom.xml
@@ -56,11 +56,6 @@
       <version>${grpc-version}</version>
     </dependency>
 
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-core</artifactId>
-    </dependency>
-
     <!-- for testing -->
     <dependency>
       <groupId>org.apache.camel</groupId>

http://git-wip-us.apache.org/repos/asf/camel/blob/bcac1fb1/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/bcac1fb1/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 dc915eb..1270ab6 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);
@@ -74,12 +75,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) -> {
@@ -90,7 +91,7 @@ public final class GrpcUtils {
             }
             requestObserver.onCompleted();
         } else {
-            ReflectionUtils.invokeMethod(method, asyncStubClass, request, responseObserver);
+            ObjectHelper.invokeMethod(method, asyncStubClass, request, responseObserver);
         }
     }
 
@@ -98,19 +99,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/bcac1fb1/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 c82c16a..534185e 100644
--- a/platforms/spring-boot/components-starter/camel-grpc-starter/pom.xml
+++ b/platforms/spring-boot/components-starter/camel-grpc-starter/pom.xml
@@ -36,14 +36,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>


Mime
View raw message