You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2008/08/27 02:06:43 UTC
svn commit: r689291 - in /activemq/camel/trunk: ./ components/
components/camel-juel/src/test/resources/ components/camel-ldap/
components/camel-ldap/src/ components/camel-ldap/src/main/
components/camel-ldap/src/main/java/ components/camel-ldap/src/ma...
Author: hadrian
Date: Tue Aug 26 17:06:42 2008
New Revision: 689291
URL: http://svn.apache.org/viewvc?rev=689291&view=rev
Log:
CAMEL-853. New camel-ldap component
Added:
activemq/camel/trunk/components/camel-ldap/
activemq/camel/trunk/components/camel-ldap/ReadMe.txt
activemq/camel/trunk/components/camel-ldap/pom.xml
activemq/camel/trunk/components/camel-ldap/src/
activemq/camel/trunk/components/camel-ldap/src/main/
activemq/camel/trunk/components/camel-ldap/src/main/java/
activemq/camel/trunk/components/camel-ldap/src/main/java/org/
activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/
activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/
activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapComponent.java
activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapEndpoint.java
activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapProducer.java
activemq/camel/trunk/components/camel-ldap/src/main/resources/
activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/
activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/
activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/
activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/camel/
activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/camel/component/
activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/camel/component/ldap
activemq/camel/trunk/components/camel-ldap/src/test/
activemq/camel/trunk/components/camel-ldap/src/test/java/
activemq/camel/trunk/components/camel-ldap/src/test/java/org/
activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/
activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/
activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapRouteTest.java
activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapTestSupport.java
activemq/camel/trunk/components/camel-ldap/src/test/resources/
activemq/camel/trunk/components/camel-ldap/src/test/resources/log4j.properties
activemq/camel/trunk/components/camel-ldap/src/test/resources/org/
activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/
activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/camel/
activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/camel/ldap/
activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/camel/ldap/LdapRouteTest.ldif
Modified:
activemq/camel/trunk/components/camel-juel/src/test/resources/log4j.properties
activemq/camel/trunk/components/pom.xml
activemq/camel/trunk/pom.xml
Modified: activemq/camel/trunk/components/camel-juel/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-juel/src/test/resources/log4j.properties?rev=689291&r1=689290&r2=689291&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-juel/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/components/camel-juel/src/test/resources/log4j.properties Tue Aug 26 17:06:42 2008
@@ -1,20 +1,3 @@
-## ------------------------------------------------------------------------
-## 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.
-## ------------------------------------------------------------------------
-
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
Added: activemq/camel/trunk/components/camel-ldap/ReadMe.txt
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/ReadMe.txt?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/ReadMe.txt (added)
+++ activemq/camel/trunk/components/camel-ldap/ReadMe.txt Tue Aug 26 17:06:42 2008
@@ -0,0 +1,9 @@
+Camel Component Project
+====================
+This Project is a template of the Camel component.
+When you create the component project , you need to move the META-INF/services/direct file to META-INF/services/PACKAGE_NAME/FOO where FOO is the URI scheme for your component and any related endpoints created on the fly and PACKAGE_NAME is your component's package name which is replaced the '.' with '/'.
+
+For more help see the Apache Camel documentation
+
+ http://cwiki.apache.org/CAMEL/writing-components.html
+
\ No newline at end of file
Added: activemq/camel/trunk/components/camel-ldap/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/pom.xml?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/pom.xml (added)
+++ activemq/camel/trunk/components/camel-ldap/pom.xml Tue Aug 26 17:06:42 2008
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-ldap</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: LDAP</name>
+ <description>Camel LDAP support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.ldap.*</camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-server-unit</artifactId>
+ <version>${apacheds-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-server-jndi</artifactId>
+ <version>${apacheds-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.directory.server</groupId>
+ <artifactId>apacheds-bootstrap-partition</artifactId>
+ <version>${apacheds-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapComponent.java?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapComponent.java (added)
+++ activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapComponent.java Tue Aug 26 17:06:42 2008
@@ -0,0 +1,45 @@
+/**
+ * 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.ldap;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultComponent;
+
+import java.util.Map;
+
+/**
+ * Represents the component that manages {@link LdapEndpoint}(s).
+ *
+ * @version
+ */
+public class LdapComponent<E extends Exchange> extends DefaultComponent<E> {
+
+ public LdapComponent() {
+ }
+
+ public LdapComponent(CamelContext context) {
+ super(context);
+ }
+
+ protected Endpoint<E> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+ Endpoint<E> endpoint = new LdapEndpoint<E>(uri, remaining, this);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+}
Added: activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapEndpoint.java?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapEndpoint.java (added)
+++ activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapEndpoint.java Tue Aug 26 17:06:42 2008
@@ -0,0 +1,95 @@
+/**
+ * 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.ldap;
+
+import java.net.URISyntaxException;
+
+import javax.naming.directory.SearchControls;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Represents an endpoint that synchronously invokes an LDAP server when a producer sends a message to it.
+ *
+ * @version
+ */
+public class LdapEndpoint<E extends Exchange> extends DefaultEndpoint<E> {
+ public static final String OBJECT_SCOPE = "object";
+ public static final String ONELEVEL_SCOPE = "onelevel";
+ public static final String SUBTREE_SCOPE = "subtree";
+
+ private String remaining;
+ private String base;
+ private String scope = SUBTREE_SCOPE;
+
+ protected LdapEndpoint(String endpointUri, String remaining, LdapComponent component) throws URISyntaxException {
+ super(endpointUri, component);
+ this.remaining = remaining;
+ }
+
+ public LdapEndpoint(String endpointUri, String remaining) throws URISyntaxException {
+ super(endpointUri);
+ this.remaining = remaining;
+ }
+
+ public Consumer<E> createConsumer(Processor processor) throws Exception {
+ throw new RuntimeCamelException("An LDAP Consumer would be the LDAP server itself! No such support here");
+ }
+
+ public Producer<E> createProducer() throws Exception {
+ return new LdapProducer(this, remaining, base, toSearchControlScope(scope));
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public String getBase() {
+ return base;
+ }
+
+ public void setBase(String base) {
+ this.base = base;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public void setScope(String scope) {
+ this.scope = scope;
+ }
+
+ private int toSearchControlScope(String scope) throws CamelException {
+ if (scope.equalsIgnoreCase(OBJECT_SCOPE)) {
+ return SearchControls.OBJECT_SCOPE;
+ } else if (scope.equalsIgnoreCase(ONELEVEL_SCOPE)) {
+ return SearchControls.ONELEVEL_SCOPE;
+ } else if (scope.equalsIgnoreCase(SUBTREE_SCOPE)) {
+ return SearchControls.SUBTREE_SCOPE;
+ } else {
+ throw new CamelException("Invalid search scope \"" + scope
+ + "\" for LdapEndpoint: " + getEndpointUri());
+ }
+ }
+}
Added: activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapProducer.java?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapProducer.java (added)
+++ activemq/camel/trunk/components/camel-ldap/src/main/java/org/apache/camel/ldap/LdapProducer.java Tue Aug 26 17:06:42 2008
@@ -0,0 +1,73 @@
+/**
+ *
+ * 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.ldap;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $
+ */
+public class LdapProducer<E extends Exchange> extends DefaultProducer<DefaultExchange> {
+ private static final transient Log LOG = LogFactory.getLog(LdapProducer.class);
+ private DirContext ldapContext;
+ private SearchControls controls;
+ private String searchBase;
+
+ public LdapProducer(LdapEndpoint endpoint, String remaining, String base, int scope) throws Exception {
+ super(endpoint);
+
+ ldapContext = (DirContext)getEndpoint().getCamelContext().getRegistry().lookup(remaining);
+ searchBase = base;
+ controls = new SearchControls();
+ controls.setSearchScope(scope);
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ String filter = exchange.getIn().getBody(String.class);
+
+ // could throw NamingException
+ List<SearchResult> data = new ArrayList<SearchResult>();
+ NamingEnumeration<SearchResult> namingEnumeration =
+ ldapContext.search(searchBase, filter, getControls());
+
+ while(namingEnumeration.hasMore()) {
+ data.add(namingEnumeration.next());
+ }
+ exchange.getOut().setBody(data);
+ }
+
+ public DirContext getDirContext() {
+ return ldapContext;
+ }
+
+ protected SearchControls getControls() {
+ return controls;
+ }
+}
Added: activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/camel/component/ldap
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/camel/component/ldap?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/camel/component/ldap (added)
+++ activemq/camel/trunk/components/camel-ldap/src/main/resources/META-INF/services/org/apache/camel/component/ldap Tue Aug 26 17:06:42 2008
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.ldap.LdapComponent
Added: activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapRouteTest.java?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapRouteTest.java (added)
+++ activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapRouteTest.java Tue Aug 26 17:06:42 2008
@@ -0,0 +1,72 @@
+/**
+ *
+ * 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.ldap;
+
+import java.util.Collection;
+
+import javax.naming.directory.SearchResult;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+
+public class LdapRouteTest extends LdapTestSupport {
+
+ public void testLdapRoute() throws Exception {
+ Endpoint endpoint = context.getEndpoint("direct:start");
+ Exchange exchange = endpoint.createExchange();
+ // then we set the SQL on the in body
+ exchange.getIn().setBody("(!(ou=test1))");
+
+ // now we send the exchange to the endpoint, and receives the response from Camel
+ Exchange out = template.send(endpoint, exchange);
+
+ // assertions of the response
+ assertNotNull(out);
+ assertNotNull(out.getOut());
+ Collection<SearchResult> data = out.getOut().getBody(Collection.class);
+ assertNotNull("out body could not be converted to a Collection - was: " + out.getOut().getBody(), data);
+
+ assertFalse(contains("uid=test1,ou=test,ou=system", data));
+ assertTrue(contains("uid=test2,ou=test,ou=system", data));
+ assertTrue(contains("uid=testNoOU,ou=test,ou=system", data));
+ assertTrue(contains("uid=tcruise,ou=actors,ou=system", data));
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ // START SNIPPET: register
+ JndiRegistry reg = super.createRegistry();
+ reg.bind("localhost:" + port, this.getWiredContext());
+ return reg;
+ // END SNIPPET: register
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ // START SNIPPET: route
+ public void configure() throws Exception {
+ from("direct:start").to("ldap:localhost:" + port + "?base=ou=system");
+ }
+ // END SNIPPET: route
+ };
+ }
+}
Added: activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapTestSupport.java?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapTestSupport.java (added)
+++ activemq/camel/trunk/components/camel-ldap/src/test/java/org/apache/camel/ldap/LdapTestSupport.java Tue Aug 26 17:06:42 2008
@@ -0,0 +1,167 @@
+/**
+ *
+ * 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.ldap;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.Service;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.management.JmxSystemPropertyKeys;
+import org.apache.camel.util.jndi.JndiTest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.ldap.handlers.DefaultUnbindHandler;
+import org.apache.directory.server.unit.AbstractServerTest;
+
+
+/**
+ * @version $
+ */
+public abstract class LdapTestSupport extends AbstractServerTest {
+ protected transient Log log = LogFactory.getLog(getClass());
+ protected CamelContext context;
+ protected ProducerTemplate<Exchange> template;
+ private boolean useRouteBuilder = true;
+ private Service camelContextService;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ loadTestLdif(true);
+
+ // disable JMX
+ System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
+
+ // create Camel context
+ context = createCamelContext();
+ assertValidContext(context);
+
+ template = context.createProducerTemplate();
+ if (useRouteBuilder) {
+ RouteBuilder[] builders = createRouteBuilders();
+ for (RouteBuilder builder : builders) {
+ log.debug("Using created route builder: " + builder);
+ context.addRoutes(builder);
+ }
+ } else {
+ log.debug("Using route builder from the created context: " + context);
+ }
+
+ startCamelContext();
+
+ log.debug("Routing Rules are: " + context.getRoutes());
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ log.debug("tearDown test: " + getName());
+ template.stop();
+ stopCamelContext();
+
+ super.tearDown();
+ }
+
+ protected Set<SearchResult> getResults(DirContext ctx, String filter) throws Exception {
+ Set<SearchResult> results = new HashSet<SearchResult>();
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+
+ NamingEnumeration<SearchResult> namingEnumeration = ctx.search(
+ ServerDNConstants.SYSTEM_DN, filter, controls);
+ while(namingEnumeration.hasMore()) {
+ results.add(namingEnumeration.next());
+ }
+ return results;
+ }
+
+ protected boolean contains(String dn, Collection<SearchResult> results) {
+ for (SearchResult result : results) {
+ if (result.getNameInNamespace().equals(dn)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ return new DefaultCamelContext(createRegistry());
+ }
+
+ protected JndiRegistry createRegistry() throws Exception {
+ return new JndiRegistry(createJndiContext());
+ }
+
+ protected Context createJndiContext() throws Exception {
+ return JndiTest.createInitialContext();
+ }
+
+ protected void stopCamelContext() throws Exception {
+ if (camelContextService != null) {
+ camelContextService.stop();
+ } else {
+ context.stop();
+ }
+ }
+
+ protected void startCamelContext() throws Exception {
+ if (camelContextService != null) {
+ camelContextService.start();
+ } else {
+ if (context instanceof DefaultCamelContext) {
+ DefaultCamelContext defaultCamelContext = (DefaultCamelContext)context;
+ if (!defaultCamelContext.isStarted()) {
+ defaultCamelContext.start();
+ }
+ } else {
+ context.start();
+ }
+ }
+ }
+
+ protected void assertValidContext(CamelContext context) {
+ assertNotNull("No context found!", context);
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // no routes added by default
+ }
+ };
+ }
+
+ protected RouteBuilder[] createRouteBuilders() throws Exception {
+ return new RouteBuilder[] {createRouteBuilder()};
+ }
+}
Added: activemq/camel/trunk/components/camel-ldap/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/test/resources/log4j.properties?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/test/resources/log4j.properties (added)
+++ activemq/camel/trunk/components/camel-ldap/src/test/resources/log4j.properties Tue Aug 26 17:06:42 2008
@@ -0,0 +1,36 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# uncomment the following line to turn on ActiveMQ debugging
+#log4j.logger.org.apache.activemq=DEBUG
+
+log4j.logger.org.springframework=WARN
+
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
Added: activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/camel/ldap/LdapRouteTest.ldif
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/camel/ldap/LdapRouteTest.ldif?rev=689291&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/camel/ldap/LdapRouteTest.ldif (added)
+++ activemq/camel/trunk/components/camel-ldap/src/test/resources/org/apache/camel/ldap/LdapRouteTest.ldif Tue Aug 26 17:06:42 2008
@@ -0,0 +1,62 @@
+#
+# 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.
+#
+# EXAMPLE.COM is reserved for testing according to this RFC:
+#
+# http://www.rfc-editor.org/rfc/rfc2606.txt
+#
+
+dn: ou=test,ou=system
+objectClass: top
+objectClass: organizationalUnit
+ou: test
+
+dn: uid=test1,ou=test,ou=system
+objectClass: top
+objectClass: account
+uid: test1
+ou: test1
+
+dn: uid=test2,ou=test,ou=system
+objectClass: top
+objectClass: account
+uid: test2
+ou: test2
+
+dn: uid=testNoOU,ou=test,ou=system
+objectClass: top
+objectClass: account
+uid: testNoOU
+
+dn: ou=actors,ou=system
+objectClass: top
+objectClass: organizationalUnit
+ou: actors
+
+dn: uid=tcruise,ou=actors,ou=system
+objectClass: top
+objectClass: person
+objectClass: organizationalPerson
+objectClass: uidObject
+uid: tcruise
+ou: drama
+ou: adventure
+cn: Tom Cruise
+sn: Cruise
+
+
Modified: activemq/camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?rev=689291&r1=689290&r2=689291&view=diff
==============================================================================
--- activemq/camel/trunk/components/pom.xml (original)
+++ activemq/camel/trunk/components/pom.xml Tue Aug 26 17:06:42 2008
@@ -55,6 +55,7 @@
<module>camel-jhc</module>
<module>camel-jing</module>
<module>camel-jms</module>
+ <module>camel-ldap</module>
<module>camel-josql</module>
<module>camel-jcr</module>
<!--<module>camel-jmxconnect</module>-->
Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?rev=689291&r1=689290&r2=689291&view=diff
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Tue Aug 26 17:06:42 2008
@@ -74,6 +74,8 @@
<testng-version>5.7</testng-version>
<hamcrest-version>1.1</hamcrest-version>
<saxon-version>9.1.0.1</saxon-version>
+ <apacheds-version>1.5.3</apacheds-version>
+ <slf4j-version>1.4.3</slf4j-version>
<!-- Repositories -->
<m1-repo-url>scpexe://minotaur.apache.org/www/people.apache.org/repo/m1-snapshot-repository</m1-repo-url>