You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/05/05 12:07:25 UTC

[1/4] camel git commit: Added camel-kura docs to Gitbook

Repository: camel
Updated Branches:
  refs/heads/master 050c76cdc -> 0ff884956


Added camel-kura docs to Gitbook


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

Branch: refs/heads/master
Commit: bccfc2b59293159bd5ad5f3903dcfecf8819f757
Parents: 050c76c
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu May 5 13:25:07 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu May 5 13:25:07 2016 +0200

----------------------------------------------------------------------
 components/camel-kura/src/main/docs/kura.adoc | 320 +++++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                |   1 +
 2 files changed, 321 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bccfc2b5/components/camel-kura/src/main/docs/kura.adoc
----------------------------------------------------------------------
diff --git a/components/camel-kura/src/main/docs/kura.adoc b/components/camel-kura/src/main/docs/kura.adoc
new file mode 100644
index 0000000..f8cf9ad
--- /dev/null
+++ b/components/camel-kura/src/main/docs/kura.adoc
@@ -0,0 +1,320 @@
+[[Kura-EclipseKuracomponent]]
+Eclipse Kura component
+~~~~~~~~~~~~~~~~~~~~~~
+
+INFO: Kura component is available starting from Camel *2.15*.
+
+This documentation page covers the integration options of Camel with the
+https://eclipse.org/kura/[Eclipse Kura] M2M gateway. The common reason
+to deploy Camel routes into the Eclipse Kura is to provide enterprise
+integration patterns and Camel components to the messaging M2M gateway.
+For example you might want to install Kura on Raspberry PI, then�read
+temperature from the sensor attached to that Raspberry PI using Kura
+services and finally forward the current temperature value to your data
+center service using Camel EIP and components.
+
+[[Kura-KuraRouteractivator]]
+KuraRouter activator
+^^^^^^^^^^^^^^^^^^^^
+
+Bundles deployed to the Eclipse�Kura�are usually
+http://eclipse.github.io/kura/doc/hello-example.html#create-java-class[developed
+as bundle activators]. So the easiest way to deploy Apache Camel routes
+into the Kura is to create an OSGi bundle containing the class extending
+`org.apache.camel.kura.KuraRouter` class:
+
+[source,java]
+-------------------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+  @Override
+  public void configure() throws Exception {
+    from("timer:trigger").
+      to("netty-http:http://app.mydatacenter.com/api");
+  }
+
+}
+-------------------------------------------------------
+
+Keep in mind that `KuraRouter` implements
+the�`org.osgi.framework.BundleActivator`�interface, so you need to
+register its�`start`�and�`stop`�lifecycle methods
+while�http://eclipse.github.io/kura/doc/hello-example.html#create-component-class[creating
+Kura bundle component class].
+
+Kura router starts its own OSGi-aware `CamelContext`. It means that for
+every class extending `KuraRouter`, there will be a dedicated
+`CamelContext` instance. Ideally we recommend to deploy one `KuraRouter`
+per OSGi bundle.
+
+[[Kura-DeployingKuraRouter]]
+Deploying KuraRouter
+^^^^^^^^^^^^^^^^^^^^
+
+Bundle containing your Kura router class should import the following
+packages in the OSGi manifest:
+
+[source,xml]
+--------------------------------------------------------------------------------------------------------------------
+Import-Package: org.osgi.framework;version="1.3.0",
+  org.slf4j;version="1.6.4",
+  org.apache.camel,org.apache.camel.impl,org.apache.camel.core.osgi,org.apache.camel.builder,org.apache.camel.model,
+  org.apache.camel.component.kura
+--------------------------------------------------------------------------------------------------------------------
+
+Keep in mind that you don't have to import every Camel component bundle
+you plan to use in your routes, as Camel components are resolved as the
+services on the runtime level.
+
+Before you deploy your router bundle, be sure that you have deployed
+(and started) the following Camel core bundles (using Kura GoGo
+shell)...
+
+[source,xml]
+-----------------------------------------------------------------------------------------------------------
+install file:///home/user/.m2/repository/org/apache/camel/camel-core/2.15.0/camel-core-2.15.0.jar
+start <camel-core-bundle-id>
+install file:///home/user/.m2/repository/org/apache/camel/camel-core-osgi/2.15.0/camel-core-osgi-2.15.0.jar
+start <camel-core-osgi-bundle-id>
+install file:///home/user/.m2/repository/org/apache/camel/camel-kura/2.15.0/camel-kura-2.15.0.jar 
+start <camel-kura-bundle-id>
+-----------------------------------------------------------------------------------------------------------
+
+...and all the components you plan to use in your routes:
+
+[source,xml]
+-----------------------------------------------------------------------------------------------------
+install file:///home/user/.m2/repository/org/apache/camel/camel-stream/2.15.0/camel-stream-2.15.0.jar
+start <camel-stream-bundle-id>
+-----------------------------------------------------------------------------------------------------
+
+Then finally deploy your router bundle:
+
+[source,xml]
+----------------------------------------------------------------------------------
+install file:///home/user/.m2/repository/com/example/myrouter/1.0/myrouter-1.0.jar
+start <your-bundle-id>
+----------------------------------------------------------------------------------
+
+[[Kura-KuraRouterutilities]]
+KuraRouter utilities�
+^^^^^^^^^^^^^^^^^^^^^
+
+�Kura router base class provides many useful utilities. This section
+explores each of them.
+
+[[Kura-SLF4Jlogger]]
+SLF4J logger
+++++++++++++
+
+Kura uses SLF4J facade for logging purposes. Protected member `log`
+returns SLF4J logger instance associated with the given Kura router.
+
+[source,java]
+----------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+    @Override
+    public void configure() throws Exception {
+        log.info("Configuring Camel routes!");
+        ...
+    }
+
+}
+----------------------------------------------
+
+[[Kura-BundleContext]]
+BundleContext
++++++++++++++
+
+Protected member `bundleContext` returns bundle context associated with
+the given Kura router.
+
+[source,java]
+---------------------------------------------------------------------------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+    @Override
+    public void configure() throws Exception {
+        ServiceReference<MyService> serviceRef = bundleContext.getServiceReference(LogService.class.getName());
+        MyService myService = bundleContext.getService(serviceRef);
+        ...
+    }
+
+}
+---------------------------------------------------------------------------------------------------------------
+
+[[Kura-CamelContext]]
+CamelContext
+++++++++++++
+
+Protected member `camelContext` is the `CamelContext` associated with
+the given Kura router.
+
+[source,java]
+----------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+    @Override
+    public void configure() throws Exception {
+        camelContext.getStatus();
+        ...
+    }
+
+}
+----------------------------------------------
+
+[[Kura-ProducerTemplate]]
+ProducerTemplate
+++++++++++++++++
+
+Protected member�`producerTemplate`�is the�`ProducerTemplate`�instance
+associated with the given Camel context.
+
+[source,java]
+-----------------------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+    @Override
+    public void configure() throws Exception {
+        producerTemplate.sendBody("jms:temperature", 22.0);
+        ...
+    }
+
+}
+-----------------------------------------------------------
+
+[[Kura-ConsumerTemplate]]
+ConsumerTemplate
+++++++++++++++++
+
+Protected member�`consumerTemplate`�is the�`ConsumerTemplate`�instance
+associated with the given Camel context.
+
+[source,java]
+--------------------------------------------------------------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+    @Override
+    public void configure() throws Exception {
+        double currentTemperature = producerTemplate.receiveBody("jms:temperature", Double.class);
+        ...
+    }
+
+}
+--------------------------------------------------------------------------------------------------
+
+[[Kura-OSGiserviceresolver]]
+OSGi service resolver
++++++++++++++++++++++
+
+OSGi service resolver (`service(Class<T> serviceType)`) can be used to
+easily retrieve service by type from the OSGi bundle context.
+
+[source,java]
+-------------------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+    @Override
+    public void configure() throws Exception {
+        MyService myService = service(MyService.class);
+        ...
+    }
+
+}
+-------------------------------------------------------
+
+If service is not found, a `null` value is returned. If you want your
+application to fail if the service is not available, use
+`requiredService(Class)` method instead. The `requiredService`�throws
+`IllegalStateException` if a service cannot be found.
+
+[source,java]
+---------------------------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+
+    @Override
+    public void configure() throws Exception {
+        MyService myService = requiredService(MyService.class);
+        ...
+    }
+
+}
+---------------------------------------------------------------
+
+[[Kura-KuraRouteractivatorcallbacks]]
+KuraRouter activator callbacks
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Kura router comes with the lifecycle callbacks that can be used to
+customize the way the Camel router works. For example to configure the
+`CamelContext` instance associated with the router just before the
+former is started, override `beforeStart` method of the `KuraRouter`
+class:
+
+[source,java]
+--------------------------------------------------------------------------
+public class MyKuraRouter extends KuraRouter {
+�
+  ...
+
+  protected void beforeStart(CamelContext camelContext) {
+    OsgiDefaultCamelContext osgiContext = (OsgiCamelContext) camelContext;
+    osgiContext.setName("NameOfTheRouter");
+  }
+
+}
+--------------------------------------------------------------------------
+
+[[Kura-LoadingXMLroutesfromConfigurationAdmin]]
+Loading XML routes from ConfigurationAdmin
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Sometimes it is desired to read the XML definition of the routes from
+the server configuration. This a common scenario for IoT gateways where
+over-the-air redeployment cost may be significant. To address this
+requirement each `KuraRouter` looks for the
+`kura.camel.BUNDLE-SYMBOLIC-NAME.route` property from the `kura.camel`
+PID using the OSGi ConfigurationAdmin. This approach allows you to
+define Camel XML routes file per deployed `KuraRouter`. In order to
+update a route, just edit an appropriate configuration property and
+restart a bundle associated with it. The content of
+the�`kura.camel.BUNDLE-SYMBOLIC-NAME.route`�property is expected to be
+Camel XML route file, for example:
+
+[source,java]
+------------------------------------------------------
+<routes xmlns="http://camel.apache.org/schema/spring">
+    <route id="loaded">
+        <from uri="direct:bar"/>
+        <to uri="mock:bar"/>
+    </route>
+</routes>
+------------------------------------------------------
+
+�
+
+[[Kura-DeployingKurarouterasadeclarativeOSGiservice]]
+Deploying Kura router as a declarative OSGi service
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If you would like to deploy your Kura router as a declarative OSGi
+service, you can use `activate` and `deactivate` methods provided by
+`KuraRouter`.
+
+[source,java]
+----------------------------------------------------------------------------------------------------------------------------------------------
+<scr:component name="org.eclipse.kura.example.camel.MyKuraRouter" activate="activate" deactivate="deactivate" enabled="true" immediate="true">
+  <implementation class="org.eclipse.kura.example.camel.MyKuraRouter"/>
+</scr:component>
+----------------------------------------------------------------------------------------------------------------------------------------------
+
+[[Kura-SeeAlso]]
+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/bccfc2b5/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 5ec547e..b8a7719 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -180,6 +180,7 @@
     * [Kestrel](kestrel.adoc)
     * [Krati](krati.adoc)
     * [Kubernetes](kubernetes.adoc)
+    * [Kura](kura.adoc)
     * [Metrics](metrics.adoc)
     * [Mock](mock.adoc)
     * [NATS](nats.adoc)


[4/4] camel git commit: Added camel-lucene docs to Gitbook

Posted by ac...@apache.org.
Added camel-lucene docs to Gitbook


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

Branch: refs/heads/master
Commit: 0ff884956a559e459bdee5d44a99f4ab15ec581f
Parents: 9aa27a3
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu May 5 14:05:11 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu May 5 14:05:11 2016 +0200

----------------------------------------------------------------------
 .../camel-lucene/src/main/docs/lucene.adoc      | 238 +++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                  |   1 +
 2 files changed, 239 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0ff88495/components/camel-lucene/src/main/docs/lucene.adoc
----------------------------------------------------------------------
diff --git a/components/camel-lucene/src/main/docs/lucene.adoc b/components/camel-lucene/src/main/docs/lucene.adoc
new file mode 100644
index 0000000..f27e07e
--- /dev/null
+++ b/components/camel-lucene/src/main/docs/lucene.adoc
@@ -0,0 +1,238 @@
+[[Lucene-LuceneIndexerandSearchComponent]]
+Lucene (Indexer and Search) Component
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+*Available as of Camel 2.2*
+
+The *lucene* component is based on the Apache Lucene project. Apache
+Lucene is a powerful high-performance, full-featured text search engine
+library written entirely in Java. For more details about Lucene, please
+see the following links
+
+* http://lucene.apache.org/java/docs/[http://lucene.apache.org/java/docs/]
+* http://lucene.apache.org/java/docs/features.html[http://lucene.apache.org/java/docs/features.html]
+
+The lucene component in camel facilitates integration and utilization of
+Lucene endpoints in enterprise integration patterns and scenarios. The
+lucene component does the following
+
+* builds a searchable index of documents when payloads are sent to the
+Lucene Endpoint
+* facilitates performing of indexed searches in Camel
+
+This component only supports producer endpoints.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-lucene</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+[[Lucene-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+------------------------------------
+lucene:searcherName:insert[?options]
+lucene:searcherName:query[?options]
+------------------------------------
+
+You can append query options to the URI in the following format,
+`?option=value&option=value&...`
+
+[[Lucene-InsertOptions]]
+Insert Options
+^^^^^^^^^^^^^^
+
+
+// component options: START
+The Lucene component supports 1 options which are listed below.
+
+
+
+[width="100%",cols="2s,1m,8",options="header"]
+|=======================================================================
+| Name | Java Type | Description
+| config | LuceneConfiguration | To use a shared lucene configuration
+|=======================================================================
+// component options: END
+
+
+
+// endpoint options: START
+The Lucene component supports 8 endpoint options which are listed below:
+
+[width="100%",cols="2s,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| host | producer |  | String | *Required* The URL to the lucene server
+| operation | producer |  | LuceneOperation | *Required* Operation to do such as insert or query.
+| analyzer | producer |  | Analyzer | An Analyzer builds TokenStreams which analyze text. It thus represents a policy for extracting index terms from text. The value for analyzer can be any class that extends the abstract class org.apache.lucene.analysis.Analyzer. Lucene also offers a rich set of analyzers out of the box
+| indexDir | producer |  | File | A file system directory in which index files are created upon analysis of the document by the specified analyzer
+| maxHits | producer |  | int | An integer value that limits the result set of the search operation
+| srcDir | producer |  | File | An optional directory containing files to be used to be analyzed and added to the index at producer startup.
+| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange
+| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
+|=======================================================================
+// endpoint options: END
+
+
+[[Lucene-Sending/ReceivingMessagestoFromthecache]]
+Sending/Receiving Messages to/from the cache
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+[[Lucene-MessageHeaders]]
+Message Headers
++++++++++++++++
+
+[width="100%",cols="10%,90%",options="header",]
+|=======================================================================
+|Header |Description
+
+|`QUERY` |The Lucene Query to performed on the index. The query may include
+wildcards and phrases
+
+|`RETURN_LUCENE_DOCS` | *Camel 2.15:* Set this header to true to include the actual Lucene
+documentation when returning hit information.
+|=======================================================================
+
+[[Lucene-LuceneProducers]]
+Lucene Producers
+++++++++++++++++
+
+This component supports 2 producer endpoints.
+
+*insert* - The insert producer builds a searchable index by analyzing
+the body in incoming exchanges and associating it with a token
+("content").
+*query* - The query producer performs searches on a pre-created index.
+The query uses the searchable index to perform score & relevance based
+searches. Queries are sent via the incoming exchange contains a header
+property name called 'QUERY'. The value of the header property 'QUERY'
+is a Lucene Query. For more details on how to create Lucene Queries
+check out http://lucene.apache.org/java/3_0_0/queryparsersyntax.html[http://lucene.apache.org/java/3_0_0/queryparsersyntax.html]
+
+[[Lucene-LuceneProcessor]]
+Lucene Processor
+++++++++++++++++
+
+There is a processor called LuceneQueryProcessor available to perform
+queries against lucene without the need to create a producer.
+
+[[Lucene-LuceneUsageSamples]]
+Lucene Usage Samples
+^^^^^^^^^^^^^^^^^^^^
+
+[[Lucene-Example1:CreatingaLuceneindex]]
+Example 1: Creating a Lucene index
+++++++++++++++++++++++++++++++++++
+
+[source,java]
+------------------------------------------------------------------------------------
+RouteBuilder builder = new RouteBuilder() {
+    public void configure() {
+       from("direct:start").
+           to("lucene:whitespaceQuotesIndex:insert?
+               analyzer=#whitespaceAnalyzer&indexDir=#whitespace&srcDir=#load_dir").
+           to("mock:result");
+    }
+};
+------------------------------------------------------------------------------------
+
+[[Lucene-Example2:LoadingpropertiesintotheJNDIregistryintheCamelContext]]
+Example 2: Loading properties into the JNDI registry in the Camel Context
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+[source,java]
+-----------------------------------------------------------------
+@Override
+protected JndiRegistry createRegistry() throws Exception {
+  JndiRegistry registry =
+         new JndiRegistry(createJndiContext());
+  registry.bind("whitespace", new File("./whitespaceIndexDir"));
+  registry.bind("load_dir",
+        new File("src/test/resources/sources"));
+  registry.bind("whitespaceAnalyzer",
+        new WhitespaceAnalyzer());
+  return registry;
+}
+...
+CamelContext context = new DefaultCamelContext(createRegistry());
+-----------------------------------------------------------------
+
+[[Lucene-Example2:PerformingsearchesusingaQueryProducer]]
+Example 2: Performing searches using a Query Producer
++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+[source,java]
+----------------------------------------------------------------------------------------------------
+RouteBuilder builder = new RouteBuilder() {
+    public void configure() {
+       from("direct:start").
+          setHeader("QUERY", constant("Seinfeld")).
+          to("lucene:searchIndex:query?
+             analyzer=#whitespaceAnalyzer&indexDir=#whitespace&maxHits=20").
+          to("direct:next");
+                
+       from("direct:next").process(new Processor() {
+          public void process(Exchange exchange) throws Exception {
+             Hits hits = exchange.getIn().getBody(Hits.class);
+             printResults(hits);
+          }
+
+          private void printResults(Hits hits) {
+              LOG.debug("Number of hits: " + hits.getNumberOfHits());
+              for (int i = 0; i < hits.getNumberOfHits(); i++) {
+                 LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
+                 LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
+                 LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
+              }
+           }
+       }).to("mock:searchResult");
+   }
+};
+----------------------------------------------------------------------------------------------------
+
+[[Lucene-Example3:PerformingsearchesusingaQueryProcessor]]
+Example 3: Performing searches using a Query Processor
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+[source,java]
+-------------------------------------------------------------------------------------------------------
+RouteBuilder builder = new RouteBuilder() {
+    public void configure() {            
+        try {
+            from("direct:start").
+                setHeader("QUERY", constant("Rodney Dangerfield")).
+                process(new LuceneQueryProcessor("target/stdindexDir", analyzer, null, 20)).
+                to("direct:next");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+                
+        from("direct:next").process(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                Hits hits = exchange.getIn().getBody(Hits.class);
+                printResults(hits);
+            }
+                    
+            private void printResults(Hits hits) {
+                LOG.debug("Number of hits: " + hits.getNumberOfHits());
+                for (int i = 0; i < hits.getNumberOfHits(); i++) {
+                    LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
+                    LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
+                    LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
+                }
+            }
+       }).to("mock:searchResult");
+   }
+};
+-------------------------------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/camel/blob/0ff88495/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 5cad8b7..370cac5 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -183,6 +183,7 @@
     * [Kura](kura.adoc)
     * [LDAP](ldap.adoc)
     * [LevelDB](leveldb.adoc)
+    * [Lucene](lucene.adoc)
     * [Metrics](metrics.adoc)
     * [Mock](mock.adoc)
     * [NATS](nats.adoc)


[2/4] camel git commit: Added camel-ldap docs to Gitbook

Posted by ac...@apache.org.
Added camel-ldap docs to Gitbook


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

Branch: refs/heads/master
Commit: d83af66135bb46961f13685792f0bdda77133c5c
Parents: bccfc2b
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu May 5 13:28:51 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu May 5 13:28:51 2016 +0200

----------------------------------------------------------------------
 components/camel-ldap/src/main/docs/ldap.adoc | 345 +++++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                |   1 +
 2 files changed, 346 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d83af661/components/camel-ldap/src/main/docs/ldap.adoc
----------------------------------------------------------------------
diff --git a/components/camel-ldap/src/main/docs/ldap.adoc b/components/camel-ldap/src/main/docs/ldap.adoc
new file mode 100644
index 0000000..09a21c5
--- /dev/null
+++ b/components/camel-ldap/src/main/docs/ldap.adoc
@@ -0,0 +1,345 @@
+[[LDAP-LDAPComponent]]
+LDAP Component
+~~~~~~~~~~~~~~
+
+The *ldap* component allows you to perform searches in LDAP servers
+using filters as the message payload. +
+ This component uses standard JNDI (`javax.naming` package) to access
+the server.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-ldap</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+[[LDAP-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+-----------------------------
+ldap:ldapServerBean[?options]
+-----------------------------
+
+The _ldapServerBean_ portion of the URI refers to a
+http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html[DirContext]
+bean in the registry. The LDAP component only supports producer
+endpoints, which means that an `ldap` URI cannot appear in the `from` at
+the start of a route.
+
+You can append query options to the URI in the following format,
+`?option=value&option=value&...`
+
+[[LDAP-Options]]
+Options
+^^^^^^^
+
+
+// component options: START
+The LDAP component has no options.
+// component options: END
+
+
+
+// endpoint options: START
+The LDAP component supports 7 endpoint options which are listed below:
+
+[width="100%",cols="2s,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| dirContextName | producer |  | String | *Required* Name of javax.naming.directory.DirContext bean to lookup in the registry.
+| base | producer | ou=system | String | The base DN for searches.
+| pageSize | producer |  | Integer | When specified the ldap module uses paging to retrieve all results (most LDAP Servers throw an exception when trying to retrieve more than 1000 entries in one query). To be able to use this a LdapContext (subclass of DirContext) has to be passed in as ldapServerBean (otherwise an exception is thrown)
+| returnedAttributes | producer |  | String | Comma-separated list of attributes that should be set in each entry of the result
+| scope | producer | subtree | String | Specifies how deeply to search the tree of entries starting at the base DN.
+| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange
+| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
+|=======================================================================
+// endpoint options: END
+
+
+[[LDAP-Result]]
+Result
+^^^^^^
+
+The result is returned in the Out body as a
+`ArrayList<javax.naming.directory.SearchResult>` object.
+
+[[LDAP-DirContext]]
+DirContext
+^^^^^^^^^^
+
+The URI, `ldap:ldapserver`, references a Spring bean with the ID,
+`ldapserver`. The `ldapserver` bean may be defined as follows:
+
+[source,java]
+-----------------------------------------------------------------------------------------
+<bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
+  <constructor-arg>
+    <props>
+      <prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
+      <prop key="java.naming.provider.url">ldap://localhost:10389</prop>
+      <prop key="java.naming.security.authentication">none</prop>
+    </props>
+  </constructor-arg>
+</bean>
+-----------------------------------------------------------------------------------------
+
+The preceding example declares a regular Sun based LDAP `DirContext`
+that connects anonymously to a locally hosted LDAP server.
+
+NOTE: `DirContext` objects are *not* required to support concurrency by
+contract. It is therefore important that the directory context is
+declared with the setting, `scope="prototype"`, in the `bean` definition
+or that the context supports concurrency. In the Spring framework,
+`prototype` scoped objects are instantiated each time they are looked
+up.
+
+[[LDAP-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<Exchange> template = exchange
+  .getContext().createProducerTemplate();
+
+Collection<?> results = (Collection<?>) (template
+  .sendBody(
+    "ldap:ldapserver?base=ou=mygroup,ou=groups,ou=system",
+    "(member=uid=huntc,ou=users,ou=system)"));
+
+if (results.size() > 0) {
+  // Extract what we need from the device's profile
+
+  Iterator<?> resultIter = results.iterator();
+  SearchResult searchResult = (SearchResult) resultIter
+      .next();
+  Attributes attributes = searchResult
+      .getAttributes();
+  Attribute deviceCNAttr = attributes.get("cn");
+  String deviceCN = (String) deviceCNAttr.get();
+
+  ...
+----------------------------------------------------------
+
+If no specific filter is required - for example, you just need to look
+up a single entry - specify a wildcard filter expression. For example,
+if the LDAP entry has a Common Name, use a filter expression like:
+
+[source,java]
+------
+(cn=*)
+------
+
+[[LDAP-Bindingusingcredentials]]
+Binding using credentials
++++++++++++++++++++++++++
+
+A Camel end user donated this sample code he used to bind to the ldap
+server using credentials.
+
+[source,java]
+---------------------------------------------------------------------------------------
+Properties props = new Properties();
+props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
+props.setProperty(Context.PROVIDER_URL, "ldap://localhost:389");
+props.setProperty(Context.URL_PKG_PREFIXES, "com.sun.jndi.url");
+props.setProperty(Context.REFERRAL, "ignore");
+props.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
+props.setProperty(Context.SECURITY_PRINCIPAL, "cn=Manager");
+props.setProperty(Context.SECURITY_CREDENTIALS, "secret");
+
+SimpleRegistry reg = new SimpleRegistry();
+reg.put("myldap", new InitialLdapContext(props, null));
+
+CamelContext context = new DefaultCamelContext(reg);
+context.addRoutes(
+    new RouteBuilder() {
+        public void configure() throws Exception { 
+            from("direct:start").to("ldap:myldap?base=ou=test");
+        }
+    }
+);
+context.start();
+
+ProducerTemplate template = context.createProducerTemplate();
+
+Endpoint endpoint = context.getEndpoint("direct:start");
+Exchange exchange = endpoint.createExchange();
+exchange.getIn().setBody("(uid=test)");
+Exchange out = template.send(endpoint, exchange);
+
+Collection<SearchResult> data = out.getOut().getBody(Collection.class);
+assert data != null;
+assert !data.isEmpty();
+
+System.out.println(out.getOut().getBody());
+
+context.stop();
+---------------------------------------------------------------------------------------
+
+[[LDAP-ConfiguringSSL]]
+Configuring SSL
+^^^^^^^^^^^^^^^
+
+All required is to create a custom socket factory and reference it in
+the InitialDirContext bean - see below sample.
+
+*SSL Configuration*
+
+[source,xml]
+----------------------------------------------------------------------------------------------------------------------------------
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+                 http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
+
+
+    <sslContextParameters xmlns="http://camel.apache.org/schema/blueprint"
+                          id="sslContextParameters">
+        <keyManagers
+                keyPassword="{{keystore.pwd}}">
+            <keyStore
+                    resource="{{keystore.url}}"
+                    password="{{keystore.pwd}}"/>
+        </keyManagers>
+    </sslContextParameters>
+
+    <bean id="customSocketFactory" class="zotix.co.util.CustomSocketFactory">
+        <argument ref="sslContextParameters" />
+    </bean>
+    <bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
+        <argument>
+            <props>
+                <prop key="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory"/>
+                <prop key="java.naming.provider.url" value="ldaps://lab.zotix.co:636"/>
+                <prop key="java.naming.security.protocol" value="ssl"/>
+                <prop key="java.naming.security.authentication" value="simple" />
+                <prop key="java.naming.security.principal" value="cn=Manager,dc=example,dc=com"/>
+                <prop key="java.naming.security.credentials" value="passw0rd"/>
+                <prop key="java.naming.ldap.factory.socket"
+                      value="zotix.co.util.CustomSocketFactory"/>
+            </props>
+        </argument>
+    </bean>
+</blueprint>
+----------------------------------------------------------------------------------------------------------------------------------
+
+*Custom Socket Factory*
+
+[source,java]
+-----------------------------------------------------------------------------------------------------
+import org.apache.camel.util.jsse.SSLContextParameters;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManagerFactory;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.security.KeyStore;
+
+/**
+ * The CustomSocketFactory. Loads the KeyStore and creates an instance of SSLSocketFactory
+ */
+public class CustomSocketFactory extends SSLSocketFactory {
+
+    private static SSLSocketFactory socketFactory;
+
+    /**
+     * Called by the getDefault() method.
+     */
+    public CustomSocketFactory() {
+
+    }
+
+    /**
+     * Called by Blueprint DI to initialise an instance of SocketFactory
+     *
+     * @param sslContextParameters
+     */
+    public CustomSocketFactory(SSLContextParameters sslContextParameters) {
+        try {
+            KeyStore keyStore = sslContextParameters.getKeyManagers().getKeyStore().createKeyStore();
+            TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
+            tmf.init(keyStore);
+            SSLContext ctx = SSLContext.getInstance("TLS");
+            ctx.init(null, tmf.getTrustManagers(), null);
+            socketFactory = ctx.getSocketFactory();
+        } catch (Exception ex) {
+            ex.printStackTrace(System.err);  /* handle exception */
+        }
+    }
+
+    /**
+     * Getter for the SocketFactory
+     *
+     * @return
+     */
+    public static SocketFactory getDefault() {
+        return new CustomSocketFactory();
+    }
+
+    @Override
+    public String[] getDefaultCipherSuites() {
+        return socketFactory.getDefaultCipherSuites();
+    }
+
+    @Override
+    public String[] getSupportedCipherSuites() {
+        return socketFactory.getSupportedCipherSuites();
+    }
+
+    @Override
+    public Socket createSocket(Socket socket, String string, int i, boolean bln) throws IOException {
+        return socketFactory.createSocket(socket, string, i, bln);
+    }
+
+    @Override
+    public Socket createSocket(String string, int i) throws IOException {
+        return socketFactory.createSocket(string, i);
+    }
+
+    @Override
+    public Socket createSocket(String string, int i, InetAddress ia, int i1) throws IOException {
+        return socketFactory.createSocket(string, i, ia, i1);
+    }
+
+    @Override
+    public Socket createSocket(InetAddress ia, int i) throws IOException {
+        return socketFactory.createSocket(ia, i);
+    }
+
+    @Override
+    public Socket createSocket(InetAddress ia, int i, InetAddress ia1, int i1) throws IOException {
+        return socketFactory.createSocket(ia, i, ia1, i1);
+    }
+}
+-----------------------------------------------------------------------------------------------------
+
+�
+
+[[LDAP-SeeAlso]]
+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/d83af661/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index b8a7719..86f524d 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -181,6 +181,7 @@
     * [Krati](krati.adoc)
     * [Kubernetes](kubernetes.adoc)
     * [Kura](kura.adoc)
+    * [LDAP](ldap.adoc)
     * [Metrics](metrics.adoc)
     * [Mock](mock.adoc)
     * [NATS](nats.adoc)


[3/4] camel git commit: Added Camel-LevelDB docs to Gitbook

Posted by ac...@apache.org.
Added Camel-LevelDB docs to Gitbook


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

Branch: refs/heads/master
Commit: 9aa27a3b7a22b382442a98639fb8a7ffd13c8d89
Parents: d83af66
Author: Andrea Cosentino <an...@gmail.com>
Authored: Thu May 5 13:37:40 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Thu May 5 13:37:40 2016 +0200

----------------------------------------------------------------------
 .../camel-leveldb/src/main/docs/leveldb.adoc    | 171 +++++++++++++++++++
 docs/user-manual/en/SUMMARY.md                  |   1 +
 2 files changed, 172 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9aa27a3b/components/camel-leveldb/src/main/docs/leveldb.adoc
----------------------------------------------------------------------
diff --git a/components/camel-leveldb/src/main/docs/leveldb.adoc b/components/camel-leveldb/src/main/docs/leveldb.adoc
new file mode 100644
index 0000000..17351d6
--- /dev/null
+++ b/components/camel-leveldb/src/main/docs/leveldb.adoc
@@ -0,0 +1,171 @@
+[[LevelDB-LevelDB]]
+LevelDB
+~~~~~~~
+
+*Available as of Camel 2.10*
+
+https://code.google.com/p/leveldb/[Leveldb] is a very lightweight and
+embedable key value database. It allows together with Camel to provide
+persistent support for various Camel features such as
+link:aggregator2.html[Aggregator].
+
+Current features it provides:
+
+* LevelDBAggregationRepository
+
+[[LevelDB-UsingLevelDBAggregationRepository]]
+Using LevelDBAggregationRepository
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+`LevelDBAggregationRepository` is an `AggregationRepository` which on
+the fly persists the aggregated messages. This ensures that you will not
+loose messages, as the default aggregator will use an in memory only
+`AggregationRepository`.
+
+It has the following options:
+
+[width="100%",cols="10%,10%,80%",options="header",]
+|=======================================================================
+
+|Option |Type |Description
+
+|`repositoryName` |String |A mandatory repository name. Allows you to use a shared `LevelDBFile`
+for multiple repositories.
+
+|`persistentFileName` |String |Filename for the persistent storage. If no file exists on startup a new
+file is created.
+
+|`levelDBFile` |LevelDBFile |Use an existing configured
+`org.apache.camel.component.leveldb.LevelDBFile` instance.
+
+|`sync` |boolean |*Camel 2.12:* Whether or not the LevelDBFile should sync on write or
+not. Default is false. By sync on write ensures that its always waiting
+for all writes to be spooled to disk and thus will not loose updates.
+See http://leveldb.googlecode.com/svn/trunk/doc/index.html[LevelDB docs]
+for more details about async vs sync writes.
+
+|`returnOldExchange` |boolean |Whether the get operation should return the old existing Exchange if any
+existed. By default this option is `false` to optimize as we do not need
+the old exchange when aggregating.
+
+|`useRecovery` |boolean |Whether or not recovery is enabled. This option is by default `true`.
+When enabled the Camel link:aggregator2.html[Aggregator] automatic
+recover failed aggregated exchange and have them resubmitted.
+
+|`recoveryInterval` |long |If recovery is enabled then a background task is run every x'th time to
+scan for failed exchanges to recover and resubmit. By default this
+interval is 5000 millis.
+
+|`maximumRedeliveries` |int |Allows you to limit the maximum number of redelivery attempts for a
+recovered exchange. If enabled then the Exchange will be moved to the
+dead letter channel if all redelivery attempts failed. By default this
+option is disabled. If this option is used then the `deadLetterUri`
+option must also be provided.
+
+|`deadLetterUri` |String |An endpoint uri for a link:dead-letter-channel.html[Dead Letter Channel]
+where exhausted recovered Exchanges will be moved. If this option is
+used then the `maximumRedeliveries` option must also be provided.
+|=======================================================================
+
+The `repositoryName` option must be provided. Then either the
+`persistentFileName` or the `levelDBFile` must be provided.
+
+[[LevelDB-Whatispreservedwhenpersisting]]
+What is preserved when persisting
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+`LevelDBAggregationRepository` will only preserve any `Serializable`
+compatible message body data types. Message headers must be primitive /
+string / numbers / etc. If a data type is not such a type its dropped
+and a `WARN` is logged. And it only persists the `Message` body and the
+`Message` headers. The `Exchange` properties are *not* persisted.
+
+[[LevelDB-Recovery]]
+Recovery
+^^^^^^^^
+
+The `LevelDBAggregationRepository` will by default recover any failed
+link:exchange.html[Exchange]. It does this by having a background tasks
+that scans for failed link:exchange.html[Exchange]s in the persistent
+store. You can use the `checkInterval` option to set how often this task
+runs. The recovery works as transactional which ensures that Camel will
+try to recover and redeliver the failed link:exchange.html[Exchange].
+Any link:exchange.html[Exchange] which was found to be recovered will be
+restored from the persistent store and resubmitted and send out again.
+
+The following headers is set when an link:exchange.html[Exchange] is
+being recovered/redelivered:
+
+[width="100%",cols="10%,10%,80%",options="header",]
+|=======================================================================
+|Header |Type |Description
+
+|`Exchange.REDELIVERED` |Boolean |Is set to true to indicate the link:exchange.html[Exchange] is being
+redelivered.
+
+|`Exchange.REDELIVERY_COUNTER` |Integer |The redelivery attempt, starting from 1.
+|=======================================================================
+
+Only when an link:exchange.html[Exchange] has been successfully
+processed it will be marked as complete which happens when the `confirm`
+method is invoked on the `AggregationRepository`. This means if the same
+link:exchange.html[Exchange] fails again it will be kept retried until
+it success.
+
+You can use option `maximumRedeliveries` to limit the maximum number of
+redelivery attempts for a given recovered link:exchange.html[Exchange].
+You must also set the `deadLetterUri` option so Camel knows where to
+send the link:exchange.html[Exchange] when the `maximumRedeliveries` was
+hit.
+
+You can see some examples in the unit tests of camel-leveldb, for
+example
+https://svn.apache.org/repos/asf/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverTest.java[this
+test].
+
+[[LevelDB-UsingLevelDBAggregationRepositoryinJavaDSL]]
+Using LevelDBAggregationRepository in Java DSL
+++++++++++++++++++++++++++++++++++++++++++++++
+
+In this example we want to persist aggregated messages in the
+`target/data/leveldb.dat` file.
+
+[[LevelDB-UsingLevelDBAggregationRepositoryinSpringXML]]
+Using LevelDBAggregationRepository in Spring XML
+++++++++++++++++++++++++++++++++++++++++++++++++
+
+The same example but using Spring XML instead:
+
+[[LevelDB-Dependencies]]
+Dependencies
+^^^^^^^^^^^^
+
+To use link:leveldb.html[LevelDB] in your camel routes you need to add
+the a dependency on *camel-leveldb*.
+
+If you use maven you could just add the following to your pom.xml,
+substituting the version number for the latest & greatest release (see
+link:download.html[the download page for the latest versions]).
+
+[source,xml]
+----------------------------------------
+<dependency>
+  <groupId>org.apache.camel</groupId>
+  <artifactId>camel-leveldb</artifactId>
+  <version>2.10.0</version>
+</dependency>
+----------------------------------------
+
+[[LevelDB-SeeAlso]]
+See Also
+^^^^^^^^
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]
+
+* link:aggregator2.html[Aggregator]
+* link:hawtdb.html[HawtDB]
+* link:components.html[Components]
+

http://git-wip-us.apache.org/repos/asf/camel/blob/9aa27a3b/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 86f524d..5cad8b7 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -182,6 +182,7 @@
     * [Kubernetes](kubernetes.adoc)
     * [Kura](kura.adoc)
     * [LDAP](ldap.adoc)
+    * [LevelDB](leveldb.adoc)
     * [Metrics](metrics.adoc)
     * [Mock](mock.adoc)
     * [NATS](nats.adoc)