Repository: camel
Updated Branches:
  refs/heads/master 2310011d1 -> 0da97136b


CAMEL-10491 - Spring-LDAP - Utilizing java.util.function.BiFunction (Java 8) 
for FUNCTION_DRIVEN operation.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0da97136
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0da97136
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0da97136

Branch: refs/heads/master
Commit: 0da97136b05ca4d004a14984e919c388e14b1c12
Parents: 2310011
Author: Thakker <thak...@ad.vzwcorp.com>
Authored: Tue Nov 29 14:13:13 2016 -0500
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Thu Dec 1 10:53:31 2016 +0100

----------------------------------------------------------------------
 .../src/main/docs/spring-ldap-component.adoc    |  2 +-
 .../component/springldap/LdapOperation.java     |  4 +-
 .../springldap/LdapOperationsFunction.java      | 39 --------------------
 .../springldap/SpringLdapProducer.java          |  3 +-
 .../springldap/SpringLdapProducerTest.java      | 15 +++-----
 5 files changed, 12 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0da97136/components/camel-spring-ldap/src/main/docs/spring-ldap-component.adoc
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-ldap/src/main/docs/spring-ldap-component.adoc 
b/components/camel-spring-ldap/src/main/docs/spring-ldap-component.adoc
index 8c7c200..5d0e813 100644
--- a/components/camel-spring-ldap/src/main/docs/spring-ldap-component.adoc
+++ b/components/camel-spring-ldap/src/main/docs/spring-ldap-component.adoc
@@ -120,7 +120,7 @@ 
http://docs.oracle.com/javase/6/docs/api/javax/naming/directory/ModificationItem
 Function-Driven
 ++++++++++++++++
 
-The message body must have entries with the keys *`function`* and *`request`*. 
The *`function`* value must be of type 
`org.apache.camel.component.springldap.LdapOperationsFunction<Q, S>`. The 
*`request`* value must be the same type as the `Q` type parameter in the 
*`function`* and it must encapsulate the parameters expected by the 
LdapTemplate method being invoked within the *`function`*. The `S` type 
parameter represents the response type as returned by the LdapTemplate method 
being invoked.
+The message body must have entries with the keys *`function`* and *`request`*. 
The *`function`* value must be of type `java.util.function.BiFunction<L, Q, 
S>`. The `L` type parameter must be of type 
`org.springframework.ldap.core.LdapOperations`. The *`request`* value must be 
the same type as the `Q` type parameter in the *`function`* and it must 
encapsulate the parameters expected by the LdapTemplate method being invoked 
within the *`function`*. The `S` type parameter represents the response type as 
returned by the LdapTemplate method being invoked.
 This operation allows dynamic invocation of LdapTemplate methods that are not 
covered by the operations mentioned above.
 
 *Key definitions*

http://git-wip-us.apache.org/repos/asf/camel/blob/0da97136/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperation.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperation.java
 
b/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperation.java
index c88e00f..c0fefed 100644
--- 
a/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperation.java
+++ 
b/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperation.java
@@ -16,13 +16,15 @@
  */
 package org.apache.camel.component.springldap;
 
+import java.util.function.BiFunction;
+
 import org.springframework.ldap.core.LdapOperations;
 
 /**
  * The list of supported LDAP operations. Currently supported operations are
  * search, bind, and unbind, authenticate and modify_attributes. The
  * function_driven operation expects a request {@link Object} along with an
- * instance of {@link LdapOperationsFunction} that can be used to invoke any
+ * instance of {@link BiFunction} that can be used to invoke any
  * method on the {@link LdapOperations} instance
  */
 public enum LdapOperation {

http://git-wip-us.apache.org/repos/asf/camel/blob/0da97136/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperationsFunction.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperationsFunction.java
 
b/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperationsFunction.java
deleted file mode 100644
index ae3cf21..0000000
--- 
a/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/LdapOperationsFunction.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.camel.component.springldap;
-
-import org.springframework.ldap.core.LdapOperations;
-
-/**
- * Provides a way to invoke any method on {@link LdapOperations} when an
- * operation is not provided out of the box by this component.
- * 
- * @param <Q> - The set of request parameters as expected by the method being
- *            invoked
- * @param <S> - The response to be returned by the method being invoked
- */
-public interface LdapOperationsFunction<Q, S> {
-
-    /**
-     * @param ldapOperations - An instance of {@link LdapOperations}
-     * @param request - Any object needed by the {@link LdapOperations} method
-     *            being invoked
-     * @return - result of the {@link LdapOperations} method being invoked
-     */
-    S apply(LdapOperations ldapOperations, Q request);
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/0da97136/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/SpringLdapProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/SpringLdapProducer.java
 
b/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/SpringLdapProducer.java
index 2c84bb3..23e2779 100644
--- 
a/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/SpringLdapProducer.java
+++ 
b/components/camel-spring-ldap/src/main/java/org/apache/camel/component/springldap/SpringLdapProducer.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.springldap;
 
 import java.util.Map;
+import java.util.function.BiFunction;
 
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
@@ -114,7 +115,7 @@ public class SpringLdapProducer extends DefaultProducer {
             ldapTemplate.modifyAttributes(dn, modificationItems);
             break;
         case FUNCTION_DRIVEN:
-            LdapOperationsFunction<Object, ?> ldapOperationFunction = 
(LdapOperationsFunction<Object, ?>)body.get(FUNCTION);
+            BiFunction<LdapOperations, Object, ?> ldapOperationFunction = 
(BiFunction<LdapOperations, Object, ?>)body.get(FUNCTION);
             Object ldapOperationRequest = body.get(REQUEST);
             exchange.getIn().setBody(ldapOperationFunction.apply(ldapTemplate, 
ldapOperationRequest));
             break;

http://git-wip-us.apache.org/repos/asf/camel/blob/0da97136/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
 
b/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
index d811c99..7bda60e 100644
--- 
a/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
+++ 
b/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.springldap;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.function.BiFunction;
 
 import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
@@ -89,7 +90,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
         Message in = new DefaultMessage();
 
         Map<String, Object> body = new HashMap<String, Object>();
-        body.put(SpringLdapProducer.FUNCTION, 
Mockito.mock(LdapOperationsFunction.class));
+        body.put(SpringLdapProducer.FUNCTION, Mockito.mock(BiFunction.class));
 
         
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.FUNCTION_DRIVEN);
 
@@ -230,13 +231,6 @@ public class SpringLdapProducerTest extends 
CamelTestSupport {
     @Test
     public void testFunctionDriven() throws Exception {
         String dn = "cn=dn";
-        LdapOperationsFunction<String, Void> function = new 
LdapOperationsFunction<String, Void>() {
-            @Override
-            public Void apply(LdapOperations ldapOperations, String request) {
-                ldapOperations.lookup(request);
-                return null;
-            }
-        };
 
         Exchange exchange = new DefaultExchange(context);
         Message in = new DefaultMessage();
@@ -244,7 +238,10 @@ public class SpringLdapProducerTest extends 
CamelTestSupport {
         Map<String, Object> body = new HashMap<String, Object>();
         body.put(SpringLdapProducer.DN, dn);
         body.put(SpringLdapProducer.REQUEST, dn);
-        body.put(SpringLdapProducer.FUNCTION, function);
+        body.put(SpringLdapProducer.FUNCTION, (BiFunction<LdapOperations, 
String, Void>)(l, q) -> {
+            l.lookup(q);
+            return null;
+        });
 
         
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.FUNCTION_DRIVEN);
 

Reply via email to