Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DAF39200D02 for ; Sat, 23 Sep 2017 10:25:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D960E1609B5; Sat, 23 Sep 2017 08:25:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8044A1609E8 for ; Sat, 23 Sep 2017 10:25:17 +0200 (CEST) Received: (qmail 20613 invoked by uid 500); 23 Sep 2017 08:25:16 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 20465 invoked by uid 99); 23 Sep 2017 08:25:16 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Sep 2017 08:25:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A684DF584F; Sat, 23 Sep 2017 08:25:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Sat, 23 Sep 2017 08:25:15 -0000 Message-Id: <0f7ccc035fb44bc4bcf843d45caa6b4d@git.apache.org> In-Reply-To: <23d7c6fa2d3b4cc4bce31840c761f000@git.apache.org> References: <23d7c6fa2d3b4cc4bce31840c761f000@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/7] camel git commit: CAMEL-11778: Polished archived-at: Sat, 23 Sep 2017 08:25:19 -0000 CAMEL-11778: Polished Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2e11ef53 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2e11ef53 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2e11ef53 Branch: refs/heads/master Commit: 2e11ef536e591b12f5bc3dd624b3bcdd05f0c149 Parents: c91fded Author: Claus Ibsen Authored: Sat Sep 23 09:16:03 2017 +0200 Committer: Claus Ibsen Committed: Sat Sep 23 09:16:03 2017 +0200 ---------------------------------------------------------------------- components/camel-ldif/pom.xml | 166 +++++++++---------- .../src/main/docs/ldif-component.adoc | 69 ++++---- .../camel/component/ldif/LdifComponent.java | 5 - .../camel/component/ldif/LdifEndpoint.java | 10 +- .../camel/component/ldif/LdifProducer.java | 63 ++----- .../src/test/resources/log4j2-test.xml | 46 ----- .../src/test/resources/log4j2.properties | 28 ++++ .../springboot/LdifComponentConfiguration.java | 4 +- 8 files changed, 154 insertions(+), 237 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/components/camel-ldif/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-ldif/pom.xml b/components/camel-ldif/pom.xml index 887d4c1..fdc36c8 100644 --- a/components/camel-ldif/pom.xml +++ b/components/camel-ldif/pom.xml @@ -17,97 +17,91 @@ limitations under the License. --> - - 4.0.0 + + 4.0.0 - - org.apache.camel - components - 2.20.0-SNAPSHOT - + + org.apache.camel + components + 2.20.0-SNAPSHOT + - camel-ldif - jar - Camel :: LDIF - Camel LDIF support + camel-ldif + jar + Camel :: LDIF + Camel LDIF support - - org.apache.camel.component.ldif.* - org.apache.camel.spi.ComponentResolver;component=ldif - + + org.apache.camel.component.ldif.* + org.apache.camel.spi.ComponentResolver;component=ldif + - + - - org.apache.camel - camel-core - - - org.apache.directory.server - apacheds-core-api - ${apacheds-version} - - - org.slf4j - slf4j-api - - - + + org.apache.camel + camel-core + - - - junit - junit - test - - - org.apache.camel - camel-test - test - - - org.apache.directory.server - apacheds-server-integ - ${apacheds-version} - test - - - log4j - log4j - - - - - org.apache.directory.server - apacheds-core-integ - ${apacheds-version} - test - - - org.apache.mina - mina-core - test - - - org.apache.logging.log4j - log4j-api - test - - - org.apache.logging.log4j - log4j-core - test - - - org.apache.logging.log4j - log4j-slf4j-impl - test - - - org.apache.logging.log4j - log4j-1.2-api - test - - + + org.apache.directory.server + apacheds-core-api + ${apacheds-version} + + + org.slf4j + slf4j-api + + + + + + + org.apache.camel + camel-test + test + + + org.apache.directory.server + apacheds-server-integ + ${apacheds-version} + + + log4j + log4j + + + test + + + org.apache.directory.server + apacheds-core-integ + ${apacheds-version} + test + + + org.apache.mina + mina-core + test + + + + + org.apache.logging.log4j + log4j-api + test + + + org.apache.logging.log4j + log4j-core + test + + + org.apache.logging.log4j + log4j-slf4j-impl + test + + http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/components/camel-ldif/src/main/docs/ldif-component.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ldif/src/main/docs/ldif-component.adoc b/components/camel-ldif/src/main/docs/ldif-component.adoc index 2b218ce..5152dbe 100644 --- a/components/camel-ldif/src/main/docs/ldif-component.adoc +++ b/components/camel-ldif/src/main/docs/ldif-component.adoc @@ -1,36 +1,38 @@ == LDIF Component -*Available as of Camel version 1.0* +*Available as of Camel version 2.20* The *ldif* component allows you to do updates on an LDAP server -from a LDIF body content. + - This component uses a basic URL syntax to access the server. It uses +from a LDIF body content. + +This component uses a basic URL syntax to access the server. It uses the Apache DS LDAP library to process the LDIF. After processing the LDIF, the response body will be a list of statuses for success/failure of each entry. -Note that the Apache LDAP API is very sensitive to LDIF syntax errors. If in doubt, +[NOTE] +The Apache LDAP API is very sensitive to LDIF syntax errors. If in doubt, refer to the unit tests to see an example of each change type. Maven users will need to add the following dependency to their `pom.xml` for this component: [source,xml] ------------------------------------------------------------- +---- org.apache.camel camel-ldif x.x.x ------------------------------------------------------------- +---- -### URI format +=== URI format -[source,java] ----------------------------------------- +[source] +---- ldap:ldapServerBean[?options] ----------------------------------------- +---- The _ldapServerBean_ portion of the URI refers to a https://directory.apache.org/api/gen-docs/latest/apidocs/org/apache/directory/ldap/client/api/LdapConnection.html[LdapConnection]. @@ -44,7 +46,7 @@ of setting up a custom SocketFactory instance. You can append query options to the URI in the following format, `?option=value&option=value&...` -### Options +=== Options // component options: START The LDIF component has no options. @@ -76,24 +78,24 @@ with the following path and query parameters: |=== // endpoint options: END -### Body types: +=== Body types: The body can be a URL to an LDIF file or an inline LDIF file. To signify the difference in body types, an inline LDIF must start with: -[source,ldif] ------------ +[source] +---- version: 1 ------------ +---- If not, the component will try to parse the body as a URL. -### Result +=== Result The result is returned in the Out body as a `ArrayList` object. This contains either "success" or an Exception message for each LDIF entry. -### LdapConnection +=== LdapConnection The URI, `ldif:ldapConnectionName`, references a bean with the ID, `ldapConnectionName`. The ldapConnection can be configured using a @@ -104,7 +106,7 @@ stale connection. The `LdapConnection` bean may be defined as follows in Spring XML: [source,xml] --------------------------------------------------------------------------------------------------- +---- @@ -119,10 +121,10 @@ The `LdapConnection` bean may be defined as follows in Spring XML: --------------------------------------------------------------------------------------------------- +---- -or in a blueprint.xml: --------------------------------------------------------------------------------------------------- +or in a OSGi blueprint.xml: +---- @@ -137,29 +139,25 @@ or in a blueprint.xml: --------------------------------------------------------------------------------------------------- +---- -### Samples +=== Samples Following on from the Spring configuration above, the code sample below sends an LDAP request to filter search a group for a member. The Common Name is then extracted from the response. [source,java] ----------------------------------------------------------- -ProducerTemplate template = exchange - .getContext().createProducerTemplate(); +---- +ProducerTemplate template = exchange.getContext().createProducerTemplate(); -List results = (Collection) (template - .sendBody( - "ldap:ldapConnection, - "FIXME - inline LDIF")); +List results = (Collection) template.sendBody("ldap:ldapConnection, "LDiff goes here"); if (results.size() > 0) { // Check for no errors - for (String result: results) { + for (String result : results) { if ("success".equalTo(result)) { // LDIF entry success } else { @@ -167,12 +165,5 @@ if (results.size() > 0) { } } } ----------------------------------------------------------- - -### See Also - -* link:configuring-camel.html[Configuring Camel] -* link:component.html[Component] -* link:endpoint.html[Endpoint] +---- -* link:getting-started.html[Getting Started] http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifComponent.java b/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifComponent.java index 6f5e073..8457353 100644 --- a/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifComponent.java +++ b/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifComponent.java @@ -21,11 +21,6 @@ import java.util.Map; import org.apache.camel.Endpoint; import org.apache.camel.impl.DefaultComponent; -/** - * Represents the component that manages {@link LdifEndpoint}(s). - * - * @version - */ public class LdifComponent extends DefaultComponent { @Override http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifEndpoint.java b/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifEndpoint.java index cde7712..2694932 100644 --- a/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifEndpoint.java +++ b/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifEndpoint.java @@ -21,17 +21,15 @@ import java.net.URISyntaxException; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; -import org.apache.camel.RuntimeCamelException; import org.apache.camel.impl.DefaultEndpoint; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriPath; /** - * The ldif component allows you to process an LDIF body content on an LDAP - * servers. + * The ldif component allows you to do updates on an LDAP server from a LDIF body content. */ -@UriEndpoint(firstVersion = "1.0.0", scheme = "ldif", title = "LDIF", syntax = "ldif:ldapConnectionName", producerOnly = true, label = "ldif") +@UriEndpoint(firstVersion = "2.20.0", scheme = "ldif", title = "LDIF", syntax = "ldif:ldapConnectionName", producerOnly = true, label = "ldap") public class LdifEndpoint extends DefaultEndpoint { @UriPath @Metadata(required = "true") @@ -44,7 +42,7 @@ public class LdifEndpoint extends DefaultEndpoint { @Override public Consumer createConsumer(Processor processor) throws Exception { - throw new RuntimeCamelException("An LDIF Consumer would be the LDAP server itself! No such support here"); + throw new UnsupportedOperationException("An LDIF Consumer would be the LDAP server itself! No such support here"); } @Override @@ -65,8 +63,6 @@ public class LdifEndpoint extends DefaultEndpoint { * The name of the LdapConnection bean to pull from the registry. Note that * this must be of scope "prototype" to avoid it being shared among threads * or using a connection that has timed out. - * - * @param ldapConnectionName */ public void setLdapConnectionName(String ldapConnectionName) { this.ldapConnectionName = ldapConnectionName; http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifProducer.java b/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifProducer.java index 5cef189..c718492 100644 --- a/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifProducer.java +++ b/components/camel-ldif/src/main/java/org/apache/camel/component/ldif/LdifProducer.java @@ -16,7 +16,6 @@ */ package org.apache.camel.component.ldif; -import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; @@ -29,6 +28,8 @@ import org.apache.camel.CamelException; import org.apache.camel.Exchange; import org.apache.camel.InvalidPayloadException; import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.util.IOHelper; +import org.apache.camel.util.ObjectHelper; import org.apache.directory.api.ldap.model.exception.LdapException; import org.apache.directory.api.ldap.model.ldif.LdifEntry; import org.apache.directory.api.ldap.model.ldif.LdifReader; @@ -36,12 +37,6 @@ import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Rdn; import org.apache.directory.ldap.client.api.LdapConnection; -/** - * LDIF Producer. This is the main processor that reads LDIF data/URLs and - * executes them against an LdapConnection. - * - * @version $ - */ public class LdifProducer extends DefaultProducer { // Constants private static final String LDIF_HEADER = "version: 1"; @@ -49,13 +44,8 @@ public class LdifProducer extends DefaultProducer { // properties private String ldapConnectionName; - /** - * @param endpoint - * @throws Exception - */ public LdifProducer(LdifEndpoint endpoint, String ldapConnectionName) throws Exception { super(endpoint); - this.ldapConnectionName = ldapConnectionName; } @@ -66,8 +56,6 @@ public class LdifProducer extends DefaultProducer { * "version: 1". *
  • A String body that is a URL to ready the LDIF content from
  • * - * - * @see org.apache.camel.impl.DefaultProducer#process(Exchange) */ public void process(Exchange exchange) throws Exception { String body = exchange.getIn().getBody(String.class); @@ -77,20 +65,16 @@ public class LdifProducer extends DefaultProducer { exchange.setOut(exchange.getIn()); // If nothing to do, then return an empty body - if (null == body || "".equals(body)) { + if (ObjectHelper.isEmpty(body)) { exchange.getOut().setBody(""); } else if (body.startsWith(LDIF_HEADER)) { - if (log.isDebugEnabled()) { - log.debug("reading from LDIF body"); - } + log.debug("Reading from LDIF body"); result = processLdif(new StringReader(body)); } else { - URL loc = null; + URL loc; try { loc = new URL(body); - if (log.isDebugEnabled()) { - log.debug("reading from URL: " + loc); - } + log.debug("Reading from URL: {}", loc); result = processLdif(new InputStreamReader(loc.openStream())); } catch (MalformedURLException e) { if (log.isDebugEnabled()) { @@ -117,13 +101,11 @@ public class LdifProducer extends DefaultProducer { /** * Process an LDIF file from a reader. - * - * @param ldifReader - * @return */ private List processLdif(Reader reader) throws CamelException { LdapConnection conn = getLdapConnection(); - LdifReader ldifReader = null; + LdifReader ldifReader; + List results = new ArrayList(); // Create the reader @@ -138,21 +120,7 @@ public class LdifProducer extends DefaultProducer { results.add(processLdifEntry(conn, e)); } - // Cleanup - try { - conn.close(); - } catch (IOException e) { - if (log.isDebugEnabled()) { - log.debug("failed to close the LDAP connection", e); - } - } - try { - ldifReader.close(); - } catch (IOException e) { - if (log.isDebugEnabled()) { - log.debug("failed to close LDIF reader", e); - } - } + IOHelper.close(conn, ldifReader, reader); return results; } @@ -160,8 +128,6 @@ public class LdifProducer extends DefaultProducer { /** * Figure out the change is and what to do about it. * - * @param conn - * @param ldifEntry * @return A success/failure message */ private String processLdifEntry(LdapConnection conn, LdifEntry ldifEntry) { @@ -193,23 +159,16 @@ public class LdifProducer extends DefaultProducer { conn.rename(ldifEntry.getDn(), new Rdn(ldifEntry.getNewRdn()), ldifEntry.isDeleteOldRdn()); } - if (log.isDebugEnabled()) { - log.debug("ldif success"); - } + log.debug("ldif success"); return "success"; } catch (LdapException e) { - if (log.isDebugEnabled()) { - log.debug("failed to apply ldif", e); - } + log.debug("failed to apply ldif", e); return getRootCause(e); } } /** * Get the root cause of an exception - * - * @param e - * @return */ private String getRootCause(LdapException e) { Throwable oldt; http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/components/camel-ldif/src/test/resources/log4j2-test.xml ---------------------------------------------------------------------- diff --git a/components/camel-ldif/src/test/resources/log4j2-test.xml b/components/camel-ldif/src/test/resources/log4j2-test.xml deleted file mode 100644 index 77e204a..0000000 --- a/components/camel-ldif/src/test/resources/log4j2-test.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/components/camel-ldif/src/test/resources/log4j2.properties ---------------------------------------------------------------------- diff --git a/components/camel-ldif/src/test/resources/log4j2.properties b/components/camel-ldif/src/test/resources/log4j2.properties new file mode 100644 index 0000000..8186827 --- /dev/null +++ b/components/camel-ldif/src/test/resources/log4j2.properties @@ -0,0 +1,28 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-ldif-test.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file http://git-wip-us.apache.org/repos/asf/camel/blob/2e11ef53/platforms/spring-boot/components-starter/camel-ldif-starter/src/main/java/org/apache/camel/component/ldif/springboot/LdifComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-ldif-starter/src/main/java/org/apache/camel/component/ldif/springboot/LdifComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-ldif-starter/src/main/java/org/apache/camel/component/ldif/springboot/LdifComponentConfiguration.java index def3fb8..17a9f25 100644 --- a/platforms/spring-boot/components-starter/camel-ldif-starter/src/main/java/org/apache/camel/component/ldif/springboot/LdifComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-ldif-starter/src/main/java/org/apache/camel/component/ldif/springboot/LdifComponentConfiguration.java @@ -21,8 +21,8 @@ import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** - * The ldif component allows you to process an LDIF body content on an LDAP - * servers. + * The ldif component allows you to do updates on an LDAP server from a LDIF + * body content. * * Generated by camel-package-maven-plugin - do not edit this file! */