Updated Branches:
  refs/heads/master 58d72abdb -> f67b2b925

CAMEL-6638: Polished and fixed CS


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

Branch: refs/heads/master
Commit: dfc5753fc846d90c815a8ab4ed42c0a27b1bd607
Parents: 58d72ab
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Aug 15 10:06:30 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Aug 15 10:06:30 2013 +0200

----------------------------------------------------------------------
 components/camel-vertx/pom.xml                  | 15 ++------
 .../camel/component/vertx/VertxComponent.java   | 39 ++++++++++++--------
 .../camel/component/vertx/VertxConsumer.java    |  9 ++---
 .../camel/component/vertx/VertxEndpoint.java    | 14 ++++---
 .../camel/component/vertx/VertxProducer.java    | 30 +++++++--------
 .../camel/component/vertx/VertxRouteTest.java   |  2 +-
 .../src/test/resources/log4j.properties         |  2 +-
 parent/pom.xml                                  |  1 +
 8 files changed, 57 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/components/camel-vertx/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-vertx/pom.xml b/components/camel-vertx/pom.xml
index 0dcd804..bb09f6c 100644
--- a/components/camel-vertx/pom.xml
+++ b/components/camel-vertx/pom.xml
@@ -31,6 +31,7 @@
 
   <properties>
     
<camel.osgi.export.pkg>org.apache.camel.component.vertx.*</camel.osgi.export.pkg>
+    
<camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=vertx</camel.osgi.export.service>
   </properties>
 
   <dependencies>
@@ -42,7 +43,7 @@
     <dependency>
       <groupId>io.vertx</groupId>
       <artifactId>vertx-core</artifactId>
-      <version>2.0.1-final</version>
+      <version>${vertx-version}</version>
     </dependency>
 
     <!-- testing -->
@@ -56,16 +57,6 @@
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
-      <version>${mockito-version}</version>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
+
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxComponent.java
 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxComponent.java
index f7b55c8..b79b652 100644
--- 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxComponent.java
+++ 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxComponent.java
@@ -1,5 +1,4 @@
 /**
- *
  * 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.
@@ -7,7 +6,7 @@
  * (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
+ *      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,
@@ -61,14 +60,6 @@ public class VertxComponent extends UriEndpointComponent 
implements EndpointComp
     }
 
     public Vertx getVertx() {
-        if (vertx == null) {
-            // lets using a host / port if a host name is specified
-            if (host != null && host.length() > 0) {
-                vertx = VertxFactory.newVertx(port, host);
-            } else {
-                vertx = VertxFactory.newVertx();
-            }
-        }
         return vertx;
     }
 
@@ -76,15 +67,33 @@ public class VertxComponent extends UriEndpointComponent 
implements EndpointComp
         this.vertx = vertx;
     }
 
-    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters)
-            throws Exception {
-        // lazily create vertx
-        getVertx();
-        return new VertxEndpoint(uri, this, remaining);
+    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+        VertxEndpoint endpoint = new VertxEndpoint(uri, this, remaining);
+        setProperties(endpoint, parameters);
+        return endpoint;
     }
 
     public List<String> completeEndpointPath(ComponentConfiguration 
componentConfiguration, String text) {
         // TODO is there any way to find out the list of endpoint names in 
vertx?
         return null;
     }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        if (vertx == null) {
+            // lets using a host / port if a host name is specified
+            if (host != null && host.length() > 0) {
+                vertx = VertxFactory.newVertx(port, host);
+            } else {
+                vertx = VertxFactory.newVertx();
+            }
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
index 4eed5c5..ba1927e 100644
--- 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
+++ 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
@@ -1,5 +1,4 @@
 /**
- *
  * 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.
@@ -7,7 +6,7 @@
  * (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
+ *      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,
@@ -43,22 +42,22 @@ public class VertxConsumer extends DefaultConsumer {
     protected void doStart() throws Exception {
         endpoint.getEventBus().registerHandler(endpoint.getAddress(), handler);
         super.doStart();
-
     }
 
     protected void doStop() throws Exception {
         endpoint.getEventBus().unregisterHandler(endpoint.getAddress(), 
handler);
         super.doStop();
-
     }
 
     protected void onEventBusEvent(Message event) {
+        LOG.debug("onEvent {}", event);
+
         Exchange exchange = endpoint.createExchange();
         exchange.getIn().setBody(event.body());
         try {
             getProcessor().process(exchange);
         } catch (Exception e) {
-            LOG.error("Failed to prcess message " + exchange);
+            getExceptionHandler().handleException("Error processing vertx 
message " + event, exchange, e);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxEndpoint.java
 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxEndpoint.java
index b76d5b3..733d337 100644
--- 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxEndpoint.java
+++ 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxEndpoint.java
@@ -1,5 +1,4 @@
 /**
- *
  * 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.
@@ -7,7 +6,7 @@
  * (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
+ *      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,
@@ -31,22 +30,27 @@ import org.vertx.java.core.eventbus.EventBus;
  */
 @UriEndpoint(scheme = "vertx", consumerClass = VertxConsumer.class)
 public class VertxEndpoint extends DefaultEndpoint {
-    private final VertxComponent component;
+
     @UriParam
     private String address;
 
     public VertxEndpoint(String uri, VertxComponent component, String address) 
{
         super(uri, component);
-        this.component = component;
         this.address = address;
     }
 
+    @Override
+    public VertxComponent getComponent() {
+        return (VertxComponent) super.getComponent();
+    }
+
     public Producer createProducer() throws Exception {
         return new VertxProducer(this);
     }
 
     public Consumer createConsumer(Processor processor) throws Exception {
         VertxConsumer consumer = new VertxConsumer(this, processor);
+        configureConsumer(consumer);
         return consumer;
     }
 
@@ -59,7 +63,7 @@ public class VertxEndpoint extends DefaultEndpoint {
     }
 
     public Vertx getVertx() {
-        return component.getVertx();
+        return getComponent().getVertx();
     }
 
     public String getAddress() {

http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxProducer.java
 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxProducer.java
index 284231b..917eed2 100644
--- 
a/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxProducer.java
+++ 
b/components/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxProducer.java
@@ -1,5 +1,4 @@
 /**
- *
  * 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.
@@ -7,7 +6,7 @@
  * (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
+ *      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,
@@ -21,26 +20,24 @@ import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadRuntimeException;
 import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultProducer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.vertx.java.core.eventbus.EventBus;
 import org.vertx.java.core.json.JsonArray;
 import org.vertx.java.core.json.JsonObject;
 
-/**
- */
 public class VertxProducer extends DefaultProducer {
-    private static final Logger LOG = 
LoggerFactory.getLogger(VertxProducer.class);
-    private final VertxEndpoint endpoint;
 
     public VertxProducer(VertxEndpoint endpoint) {
         super(endpoint);
-        this.endpoint = endpoint;
+    }
+
+    @Override
+    public VertxEndpoint getEndpoint() {
+        return (VertxEndpoint) super.getEndpoint();
     }
 
     public void process(Exchange exchange) throws Exception {
-        EventBus eventBus = endpoint.getEventBus();
-        String address = endpoint.getAddress();
+        EventBus eventBus = getEndpoint().getEventBus();
+        String address = getEndpoint().getAddress();
 
         Message in = exchange.getIn();
 
@@ -49,17 +46,18 @@ public class VertxProducer extends DefaultProducer {
             eventBus.publish(address, jsonObject);
             return;
         }
+        JsonArray jsonArray = in.getBody(JsonArray.class);
+        if (jsonArray != null) {
+            eventBus.publish(address, jsonArray);
+            return;
+        }
 
+        // and fallback and use string which almost all can be converted
         String text = in.getBody(String.class);
         if (text != null) {
             eventBus.publish(address, new JsonObject(text));
             return;
         }
-        JsonArray jsonArray = in.getBody(JsonArray.class);
-        if (jsonArray != null) {
-            eventBus.publish(address, jsonArray);
-            return;
-        }
         throw new InvalidPayloadRuntimeException(exchange, String.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRouteTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRouteTest.java
 
b/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRouteTest.java
index c23f8e7..4fed89f 100644
--- 
a/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRouteTest.java
+++ 
b/components/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRouteTest.java
@@ -43,7 +43,7 @@ public class VertxRouteTest extends CamelTestSupport {
     @Test
     public void testVertxMessages() throws Exception {
         resultEndpoint = context.getEndpoint(resultUri, MockEndpoint.class);
-        resultEndpoint.expectedBodiesReceived(body1, body2);
+        resultEndpoint.expectedBodiesReceivedInAnyOrder(body1, body2);
 
         template.sendBody(startUri, body1);
         template.sendBody(startUri, body2);

http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/components/camel-vertx/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-vertx/src/test/resources/log4j.properties 
b/components/camel-vertx/src/test/resources/log4j.properties
index 5db23c6..e169468 100644
--- a/components/camel-vertx/src/test/resources/log4j.properties
+++ b/components/camel-vertx/src/test/resources/log4j.properties
@@ -16,7 +16,7 @@
 ## ------------------------------------------------------------------------
 
 #
-# The logging properties used for eclipse testing, We want to see debug output 
on the console.
+# The logging properties used for testing
 #
 log4j.rootLogger=INFO, file
 

http://git-wip-us.apache.org/repos/asf/camel/blob/dfc5753f/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 6d129b1..9b111a9 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -390,6 +390,7 @@
     <velocity-bundle-version>1.7_6</velocity-bundle-version>
     <velocity-tools-version>2.0</velocity-tools-version>
     <velocity-version>1.7</velocity-version>
+    <vertx-version>2.0.1-final</vertx-version>
     <vysper-version>0.7</vysper-version>
     <!-- should be in-sync with deltaspike -->
     <weld-version>1.1.5.Final</weld-version>

Reply via email to