Added first version of the documentation which should be complete.

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

Branch: refs/heads/master
Commit: 0624507966ea9a6c53c0e0c14c19b77ec548e217
Parents: c2f3e4d
Author: gilfernandes <gil.fernan...@gmail.com>
Authored: Tue Nov 22 17:54:22 2016 +0000
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Fri Nov 25 10:05:37 2016 +0100

----------------------------------------------------------------------
 .../src/main/docs/firebase-component.adoc       | 220 ++++++++-----------
 1 file changed, 89 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/06245079/components/camel-firebase/src/main/docs/firebase-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-firebase/src/main/docs/firebase-component.adoc 
b/components/camel-firebase/src/main/docs/firebase-component.adoc
index e3ca1bb..c0701cf 100644
--- a/components/camel-firebase/src/main/docs/firebase-component.adoc
+++ b/components/camel-firebase/src/main/docs/firebase-component.adoc
@@ -2,7 +2,7 @@
 Firebase Component
 ~~~~~~~~~~~~~~~~~
 
-*Available as of Camel 2.18.x*
+*Available as of Camel 2.19.x*
 
 The *firebase* component enables you to save, modify data in Google Firebase 
database
 and consume to all child of a specific reference.
@@ -25,41 +25,32 @@ their `pom.xml` for this component:
 </dependency>
 ------------------------------------------------------------
 
-[[Ehcache-URIformat]]
+[[Firebase-URIformat]]
 URI format
 ^^^^^^^^^^
 
 [source,java]
 -----------------------------
-firebase://databaseUrl[?options]
+firebase://[endpoint]?[options]
 -----------------------------
 
 You can append query options to the URI in the following
-format, `?option=value&option=#beanRef&...`
+format, `?option=value&option=value1&...`
 
-Do not forget to URL encode the parameters
+Do not forget to URL encode the option values.
 
 [[Firebase-Options]]
 Options
 ^^^^^^^
 
-
-// component options: START
-The Firebase component has no options.
-// component options: END
-
-
-
 // endpoint options: START
 The Firebase component supports 9 endpoint options which are listed below:
 
-{% raw %}
 [width="100%",cols="2,1,1m,1m,5",options="header"]
 |=======================================================================
 | Name | Group | Default | Java Type | Description
-| databaseUrl | common |  | String | *Required* The Firebase database URL. 
Always uses https
-| async | common | async | boolean | If true the save or update request (set 
value in Firebase terms) is fired and the reply will be ignored else the 
routing thread will wait and the reply will be saved in the exchange message
 | keyName | common | firebaseKey | String | The Camel exchange header name in 
which the Firebase key is specified. Only needed in case you are saving or 
updating data
+| reply | common | false | boolean | If *false* the save or update request 
(*setValue* in Firebase terms) is fired and the reply will be ignored, 
otherwise the routing thread will wait and the reply will be saved in the body 
of the exchange message
 | rootReference | common |  | String | *Required* The path in the database 
tree where the key value pairs are to be stored
 | serviceAccountFile | common |  | String | *Required* The path to the JSON 
file which provided the keys used to connect to Firebase. This file is 
typically generated when you create the database
 | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the 
consumer to the Camel routing Error Handler which mean any exceptions occurred 
while the consumer is trying to pickup incoming messages or the likes will now 
be processed as a message and handled by the routing Error Handler. By default 
the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with 
exceptions that will be logged at WARN/ERROR level and ignored.
@@ -67,138 +58,105 @@ The Firebase component supports 9 endpoint options which 
are listed below:
 | exchangePattern | consumer (advanced) |  | ExchangePattern | Sets the 
exchange pattern when the consumer creates an exchange.
 | synchronous | advanced | false | boolean | Sets whether synchronous 
processing should be strictly used or Camel is allowed to use asynchronous 
processing (if supported).
 |=======================================================================
-{% endraw %}
 // endpoint options: END
 
 
-[[Ehcache-MessageHeadersCamel]]
+[[Firebase-MessageHeadersCamel]]
 Message Headers Camel 
 ++++++++++++++++++++++
 
- 
-[width="100%",cols="10%,10%,80%",options="header",]
-|=======================================================================
-|Header |Type |Description
-
-|CamelEhcacheAction |`String` |The operation to be perfomed on the cache, 
valid options are:
-
-* CLEAR
-* PUT
-* PUT_ALL
-* PUT_IF_ABSENT
-* GET
-* GET_ALL
-* REMOVE
-* REMOVE_ALL
-* REPLACE
-
-|CamelEhcacheActionHasResult |Boolean |Set to true if the action has a result
 
-|CamelEhcacheActionSucceeded |`Boolean` |Set to true if the actionsuccedded
-
-|CamelEhcacheKey |Object |The cache key used for an action
-
-|CamelEhcacheKeys |Set<Object> |A list of keys, used in
-
-* PUT_ALL
-* GET_ALL
-* REMOVE_ALL
-
-|CamelEhcacheValue |Object |The value to put in the cache or the result of an 
operation
-
-|CamelEhcacheOldValue |Object |The old value associated to a key for actions 
like PUT_IF_ABSENT or the
-Object used for comparison for actions like REPLACE
-
-|CamelEhcacheEventType |EventType |The type of event received
+[width="100%",cols="20%,10%,70%",options="header"]
+|=======================================================================
+| Header | Type | Description
+| firebaseKey | `String` | The Firebase key to which a child listener is 
attached. This name of this parameter can be overriden using the *firebaseKey* 
option
 |=======================================================================
 
-[[Ehcache-Ehcachebasedidempotentrepositoryexample:]]
-Ehcache based idempotent repository example:
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+[[Firebase-Usageexamples]]
 
-[source,java]
-------------------------------------------------------------------------------------------------
-CacheManager manager = CacheManagerBuilder.newCacheManager(new 
XmlConfiguration("ehcache.xml"));
-EhcacheIdempotentRepository repo = new EhcacheIdempotentRepository(manager, 
"idempotent-cache");
- 
-from("direct:in")
-    .idempotentConsumer(header("messageId"), idempotentRepo)
-    .to("mock:out");
-------------------------------------------------------------------------------------------------
+Usage examples
+^^^^^^^^^^^^^^
 
- 
+[[Firebase-Consumer]]
+Firebase Consumer
++++++++++++++++++
 
-[[Ehcache-Ehcachebasedaggregationrepositoryexample:]]
-Ehcache based aggregation repository example:
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The code below demonstrates how you can create a route which consumes the 
messages coming from a Firebase listener.
 
 [source,java]
----------------------------------------------------------------------------------------------------------------------------------
-public class EhcacheAggregationRepositoryRoutesTest extends CamelTestSupport {
-    private static final String ENDPOINT_MOCK = "mock:result";
-    private static final String ENDPOINT_DIRECT = "direct:one";
-    private static final int[] VALUES = generateRandomArrayOfInt(10, 0, 30);
-    private static final int SUM = IntStream.of(VALUES).reduce(0, (a, b) -> a 
+ b);
-    private static final String CORRELATOR = "CORRELATOR";
-
-    @EndpointInject(uri = ENDPOINT_MOCK)
-    private MockEndpoint mock;
-
-    @Produce(uri = ENDPOINT_DIRECT)
-    private ProducerTemplate producer;
-
-    @Test
-    public void checkAggregationFromOneRoute() throws Exception {
-        mock.expectedMessageCount(VALUES.length);
-        mock.expectedBodiesReceived(SUM);
-
-        IntStream.of(VALUES).forEach(
-            i -> producer.sendBodyAndHeader(i, CORRELATOR, CORRELATOR)
-        );
-
-        mock.assertIsSatisfied();
-    }
-
-    private Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
-        if (oldExchange == null) {
-            return newExchange;
-        } else {
-            Integer n = newExchange.getIn().getBody(Integer.class);
-            Integer o = oldExchange.getIn().getBody(Integer.class);
-            Integer v = (o == null ? 0 : o) + (n == null ? 0 : n);
-
-            oldExchange.getIn().setBody(v, Integer.class);
-
-            return oldExchange;
-        }
-    }
-
-    @Override
-    protected RoutesBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from(ENDPOINT_DIRECT)
-                    .routeId("AggregatingRouteOne")
-                    .aggregate(header(CORRELATOR))
-                    .aggregationRepository(createAggregateRepository())
-                    
.aggregationStrategy(EhcacheAggregationRepositoryRoutesTest.this::aggregate)
-                    .completionSize(VALUES.length)
-                        
.to("log:org.apache.camel.component.ehcache.processor.aggregate.level=INFO&showAll=true&mulltiline=true")
-                        .to(ENDPOINT_MOCK);
+--------------------------------------------------------------------------------------
+@Override
+protected RouteBuilder createRouteBuilder() throws Exception {
+    final String databaseUrl = "gil-sample-app.firebaseio.com";
+    final String originalRootReference = "server/saving-data";
+    String serviceAccountFile = 
ConfigurationProvider.createFirebaseConfigLink();
+    String rootReference = URLEncoder.encode(originalRootReference, "UTF-8");
+    insertDummyData(String.format("https://%s";, databaseUrl), 
originalRootReference, serviceAccountFile);
+
+    return new RouteBuilder() {
+        public void configure() {
+            try {
+                from(String.format("firebase://" + databaseUrl + 
"?rootReference=%s&serviceAccountFile=%s",
+                        rootReference, serviceAccountFile))
+                        .to("log:firebasetest?level=WARN")
+                        .to("mock:result");
+            } catch (Exception e) {
+                fail(e.toString());
             }
-        };
-    }
+        }
+    };
+}
+--------------------------------------------------------------------------------------
 
-    protected EhcacheAggregationRepository createAggregateRepository() throws 
Exception {
-        CacheManager cacheManager = CacheManagerBuilder.newCacheManager(new 
XmlConfiguration("ehcache.xml"));
-        cacheManager.init();
+[[Firebase-Producer]]
+Firebase Producer
++++++++++++++++++
 
-        EhcacheAggregationRepository repository = new 
EhcacheAggregationRepository();
-        repository.setCacheManager(cacheManager);
-        repository.setCacheName("aggregate");
+The example below shows how you can send data to Firebase.
 
-        return repository;
+[source,java]
+--------------------------------------
+CamelContext context = new DefaultCamelContext();
+context.addRoutes(new RouteBuilder() {
+    @Override
+    public void configure() throws Exception {
+        String rootReference = URLEncoder.encode("server/saving-data", 
"UTF-8");
+        String serviceAccountFile = "firebase-admin-connection.json";
+        from(sampleInputProvider.getTargetFolder().toUri().toString())
+            .process(exchange -> {
+                GenericFile file = (GenericFile) exchange.getIn().getBody();
+                String content = new 
String(Files.readAllBytes(Paths.get(file.getAbsoluteFilePath())), "UTF-8");
+                String[] keyValue = content.split("=");
+                final Message out = exchange.getOut();
+                out.setHeader("firebaseKey", keyValue[0]);
+                out.setBody(keyValue[1].trim());
+            })
+            
.to(String.format("firebase://%s?rootReference=%s&serviceAccountFile=%s&reply=%b",
+                    "gil-sample-app.firebaseio.com", rootReference, 
serviceAccountFile, reply))
+            .to("log:whenFirebaseSet?level=WARN")
+            .process(exchange1 -> {
+                
assertThat(exchange1.getIn().getBody().getClass()).isEqualTo(expectedBodyClass);
+                if (reply) {
+                    
assertThat(exchange1.getIn().getHeader("firebaseKey")).isNotNull();
+                }
+                try {
+                    reentrantLock.lock();
+                    wake.signal();
+                } finally {
+                    reentrantLock.unlock();
+                }
+            });
     }
-}
----------------------------------------------------------------------------------------------------------------------------------
+});
+--------------------------------------
+
+[[Exec-SeeAlso]]
+See Also
+^^^^^^^^
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]
+* link:https://firebase.google.com/[Firebase]
+* link:https://console.firebase.google.com/[Firebase console]
\ No newline at end of file

Reply via email to