You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/12/27 18:28:39 UTC

[09/20] camel git commit: CAMEL-9454: camel-gora - Should preserve headers

CAMEL-9454: camel-gora - Should preserve headers


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

Branch: refs/heads/master
Commit: ea488090ba0673809d35a73ed7fd5724fbcac30a
Parents: cfc1f1f
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Dec 27 13:50:55 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Dec 27 18:25:26 2015 +0100

----------------------------------------------------------------------
 .../camel/component/gora/GoraAttribute.java     |  5 +-
 .../camel/component/gora/GoraComponent.java     | 30 +------
 .../camel/component/gora/GoraConfiguration.java | 93 --------------------
 .../camel/component/gora/GoraConstants.java     |  1 -
 .../camel/component/gora/GoraConsumer.java      | 12 +--
 .../camel/component/gora/GoraOperation.java     |  5 +-
 .../camel/component/gora/GoraProducer.java      | 19 +---
 7 files changed, 8 insertions(+), 157 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ea488090/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraAttribute.java
----------------------------------------------------------------------
diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraAttribute.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraAttribute.java
index 069a42d..31d8337 100644
--- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraAttribute.java
+++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraAttribute.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.gora;
 
 /**
@@ -86,6 +85,7 @@ public enum GoraAttribute {
      * Gora Query Fields attribute
      */
     GORA_QUERY_FIELDS("fields");
+
     /**
      * Enum value
      */
@@ -96,8 +96,7 @@ public enum GoraAttribute {
      *
      * @param str Operation Value
      */
-    private GoraAttribute(final String str) {
-
+    GoraAttribute(final String str) {
         value = str;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/ea488090/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraComponent.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraComponent.java
index c2f899d..a3825b0 100644
--- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraComponent.java
+++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraComponent.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.gora;
 
 import java.io.IOException;
@@ -30,10 +29,6 @@ import org.apache.hadoop.conf.Configuration;
 
 import static org.apache.camel.component.gora.GoraConstants.GORA_DEFAULT_DATASTORE_KEY;
 
-/**
- * Camel-Gora {@link Endpoint}.
- *
- */
 public class GoraComponent extends UriEndpointComponent {
 
     /**
@@ -63,9 +58,7 @@ public class GoraComponent extends UriEndpointComponent {
      * @throws IOException
      */
     private void init(final GoraConfiguration config) throws IOException {
-        
         this.goraProperties = DataStoreFactory.createProps();
-
         this.dataStore = DataStoreFactory.getDataStore(goraProperties.getProperty(GORA_DEFAULT_DATASTORE_KEY,
                                                                                   config.getDataStoreClass()),
                                                         config.getKeyClass(),
@@ -73,9 +66,6 @@ public class GoraComponent extends UriEndpointComponent {
                                                         this.configuration);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected Endpoint createEndpoint(final String uri,
                                       final String remaining,
@@ -84,31 +74,17 @@ public class GoraComponent extends UriEndpointComponent {
         final GoraConfiguration config = new GoraConfiguration();
         setProperties(config, parameters);
         config.setName(remaining);
-
-        try {
-
-            init(config);
-        } catch (IOException ex) {
-
-            throw new RuntimeException(ex);
-        }
-
+        init(config);
         return new GoraEndpoint(uri, this, config, dataStore);
     }
 
     /**
      * Get DataStore
-     *
-     * @return DataStore
      */
     public DataStore<Object, Persistent> getDataStore() {
-
         return dataStore;
     }
     
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected void doStart() throws Exception {
         if (configuration == null) {
@@ -116,12 +92,8 @@ public class GoraComponent extends UriEndpointComponent {
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected void doStop() throws Exception {
-
         if (dataStore != null) {
             dataStore.close();
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/ea488090/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConfiguration.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConfiguration.java
index a8e8a91..4be4836 100644
--- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConfiguration.java
+++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConfiguration.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.gora;
 
 import com.google.common.base.Strings;
@@ -27,10 +26,8 @@ import org.apache.hadoop.conf.Configuration;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Strings.isNullOrEmpty;
 
-
 /**
  * Gora Configuration.
- *
  */
 @UriParams
 public class GoraConfiguration {
@@ -150,7 +147,6 @@ public class GoraConfiguration {
      * Default Constructor
      */
     public GoraConfiguration() {
-
         this.hadoopConfiguration = new Configuration();
     }
 
@@ -160,17 +156,13 @@ public class GoraConfiguration {
      * @return key class
      */
     public String getKeyClass() {
-
         return keyClass;
     }
 
     /**
      * Set type class of the key
-     *
-     * @param keyClass
      */
     public void setKeyClass(final String keyClass) {
-
         if (isNullOrEmpty(keyClass)) {
             throw new IllegalArgumentException("Key class could not be null or empty!");
         }
@@ -180,157 +172,110 @@ public class GoraConfiguration {
 
     /**
      * Get type of the value
-     *
-     * @return
      */
     public String getValueClass() {
-
         return valueClass;
     }
 
     /**
      * Set type of the value
-     *
-     * @param valueClass
      */
     public void setValueClass(final String valueClass) {
-
         if (isNullOrEmpty(valueClass)) {
             throw new IllegalArgumentException("Value class  could not be null or empty!");
         }
-
         this.valueClass = valueClass;
     }
 
     /**
      * Get type of the dataStore
-     *
-     * @return  DataStore class
      */
     public String getDataStoreClass() {
-
         return dataStoreClass;
     }
 
     /**
      * Set type of the dataStore
-     *
-     * @param dataStoreClass
      */
     public void setDataStoreClass(String dataStoreClass) {
-
-
         if (isNullOrEmpty(dataStoreClass)) {
             throw new IllegalArgumentException("DataStore class could not be null or empty!");
         }
-
         this.dataStoreClass = dataStoreClass;
     }
 
     /**
      * Get Hadoop Configuration
-     *
-     * @return
      */
     public Configuration getHadoopConfiguration() {
-
         return hadoopConfiguration;
     }
 
     /**
      * Get Start Time
-     *
-     * @return
      */
     public long getStartTime() {
-
         return startTime;
     }
 
     /**
      * Set Start Time
-     *
-     * @return
      */
     public void setStartTime(long startTime) {
-
         this.startTime = startTime;
     }
 
     /**
      * Get End Time
-     *
-     * @return
      */
     public long getEndTime() {
-
         return endTime;
     }
 
     /**
      * Set End Time
-     *
-     * @return
      */
     public void setEndTime(long endTime) {
-
         this.endTime = endTime;
     }
 
     /**
      * Get Time Range From
-     *
-     * @return
      */
     public long getTimeRangeFrom() {
-
         return timeRangeFrom;
     }
 
     /**
      * Set Time Range From
-     *
-     * @return
      */
     public void setTimeRangeFrom(long timeRangeFrom) {
-
         this.timeRangeFrom = timeRangeFrom;
     }
 
     /**
      * Get Time Range To
-     *
-     * @return
      */
     public long getTimeRangeTo() {
-
         return timeRangeTo;
     }
 
     /**
      * Set Time Range To
-     *
-     * @return
      */
     public void setTimeRangeTo(long timeRangeTo) {
-
         this.timeRangeTo = timeRangeTo;
     }
 
     /**
      * Get Limit
-     *
-     * @return
      */
     public long getLimit() {
-
         return limit;
     }
 
     /**
      * Set Limit
-     *
-     * @param limit
      */
     public void setLimit(long limit) {
         this.limit = limit;
@@ -338,28 +283,20 @@ public class GoraConfiguration {
 
     /**
      * Get Timestamp
-     *
-     * @return
      */
     public long getTimestamp() {
-
         return timestamp;
     }
 
     /**
      * Set Timestamp
-     *
-     * @param timestamp
      */
     public void setTimestamp(long timestamp) {
-
         this.timestamp = timestamp;
     }
 
     /**
      * Get Start Key
-     *
-     * @return
      */
     public Object getStartKey() {
         return startKey;
@@ -367,8 +304,6 @@ public class GoraConfiguration {
 
     /**
      * Set Start Key
-     *
-     * @param startKey
      */
     public void setStartKey(Object startKey) {
         this.startKey = startKey;
@@ -376,8 +311,6 @@ public class GoraConfiguration {
 
     /**
      * Get End Key
-     *
-     * @return
      */
     public Object getEndKey() {
         return endKey;
@@ -385,8 +318,6 @@ public class GoraConfiguration {
 
     /**
      * Set End Key
-     *
-     * @param endKey
      */
     public void setEndKey(Object endKey) {
         this.endKey = endKey;
@@ -394,7 +325,6 @@ public class GoraConfiguration {
 
     /**
      * Get Key Range From
-     * @return
      */
     public Object getKeyRangeFrom() {
         return keyRangeFrom;
@@ -402,8 +332,6 @@ public class GoraConfiguration {
 
     /**
      * Set Key Range From
-     *
-     * @param keyRangeFrom
      */
     public void setKeyRangeFrom(Object keyRangeFrom) {
         this.keyRangeFrom = keyRangeFrom;
@@ -411,7 +339,6 @@ public class GoraConfiguration {
 
     /**
      * Get Key Range To
-     * @return
      */
     public Object getKeyRangeTo() {
         return keyRangeTo;
@@ -419,8 +346,6 @@ public class GoraConfiguration {
 
     /**
      * Set Key Range To
-     *
-     * @param keyRangeTo
      */
     public void setKeyRangeTo(Object keyRangeTo) {
         this.keyRangeTo = keyRangeTo;
@@ -428,47 +353,34 @@ public class GoraConfiguration {
 
     /**
      * Get Fields
-     *
-     * @return
      */
     public Strings getFields() {
-
         return fields;
     }
 
     /**
      * Set Fields
-     *
-     * @param fields
      */
     public void setFields(Strings fields) {
-
         this.fields = fields;
     }
 
     /**
      * Get Concurrent Consumers
-     * @return
      */
     public int getConcurrentConsumers() {
-
         return concurrentConsumers;
     }
 
     /**
      * Set Concurrent Consumers
-     *
-     * @param concurrentConsumers
      */
     public void setConcurrentConsumers(int concurrentConsumers) {
-
         this.concurrentConsumers = concurrentConsumers;
     }
 
     /**
      * Get flush on every operation
-     *
-     * @return
      */
     public boolean isFlushOnEveryOperation() {
         return flushOnEveryOperation;
@@ -476,8 +388,6 @@ public class GoraConfiguration {
 
     /**
      * Set flush on every operation
-     *
-     * @param flushOnEveryOperation
      */
     public void setFlushOnEveryOperation(boolean flushOnEveryOperation) {
         this.flushOnEveryOperation = flushOnEveryOperation;
@@ -485,11 +395,8 @@ public class GoraConfiguration {
 
     /**
      * Set Hadoop Configuration
-     *
-     * @param hadoopConfiguration
      */
     public void setHadoopConfiguration(Configuration hadoopConfiguration) {
-
         checkNotNull(hadoopConfiguration, "Hadoop Configuration could not be null!");
         this.hadoopConfiguration = hadoopConfiguration;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/ea488090/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConstants.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConstants.java
index 999056e..04ab7ea 100644
--- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConstants.java
+++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConstants.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.gora;
 
 /**

http://git-wip-us.apache.org/repos/asf/camel/blob/ea488090/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConsumer.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConsumer.java
index 24c2e22..2ec9176 100644
--- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConsumer.java
+++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraConsumer.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.gora;
 
 import java.lang.reflect.InvocationTargetException;
@@ -84,22 +83,16 @@ public class GoraConsumer extends ScheduledPollConsumer {
                         final DataStore<Object, Persistent> dataStore) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
 
         super(endpoint, processor);
-
         this.configuration = configuration;
         this.dataStore = dataStore;
-
         this.query = GoraUtils.constractQueryFromConfiguration(this.dataStore, this.configuration);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
     protected int poll() throws Exception {
-
         final Exchange exchange = this.getEndpoint().createExchange();
 
-        // compute time (aprox) since last update
+        // compute time (approx) since last update
         if (firstRun) {
             this.query.setStartTime(System.currentTimeMillis());
         } else {
@@ -112,12 +105,9 @@ public class GoraConsumer extends ScheduledPollConsumer {
         LOG.trace("Processing exchange [{}]...", exchange);
 
         try {
-
             getProcessor().process(exchange);
         } finally {
-
             if (exchange.getException() != null) {
-
                 getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/ea488090/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraOperation.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraOperation.java
index 29dbe6c..400c186 100644
--- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraOperation.java
+++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraOperation.java
@@ -73,11 +73,8 @@ public enum GoraOperation {
 
     /**
      * Enum constructor
-     *
-     * @param str Operation Value
      */
-    private GoraOperation(final String str) {
-
+     GoraOperation(final String str) {
         value = str;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/ea488090/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraProducer.java b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraProducer.java
index 7e25fd5..8ed67fd 100644
--- a/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraProducer.java
+++ b/components/camel-gora/src/main/java/org/apache/camel/component/gora/GoraProducer.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.gora;
 
 import java.util.Map;
@@ -32,10 +31,8 @@ import static org.apache.camel.component.gora.utils.GoraUtils.constractQueryFrom
 import static org.apache.camel.component.gora.utils.GoraUtils.getKeyFromExchange;
 import static org.apache.camel.component.gora.utils.GoraUtils.getValueFromExchange;
 
-
 /**
  * Camel-Gora {@link DefaultProducer}.
- *
  */
 public class GoraProducer extends DefaultProducer implements ServicePoolAware {
 
@@ -75,48 +72,36 @@ public class GoraProducer extends DefaultProducer implements ServicePoolAware {
      */
     @Override
     public void process(final Exchange exchange) throws Exception {
-
         final String operation = (String) exchange.getIn().getHeader(GoraAttribute.GORA_OPERATION.value);
 
         if (operation == null || operation.isEmpty()) {
-
             throw new RuntimeException("Gora operation is null or empty!");
         }
 
         Object result = 0; // 0 used as default response in order to avoid null body exception
 
         if (GoraOperation.PUT.value.equalsIgnoreCase(operation)) {
-
             dataStore.put(getKeyFromExchange(exchange), getValueFromExchange(exchange));
         } else if (GoraOperation.GET.value.equalsIgnoreCase(operation)) {
-
             result = dataStore.get(getKeyFromExchange(exchange));
         } else if (GoraOperation.DELETE.value.equalsIgnoreCase(operation)) {
-
             result = dataStore.delete(getKeyFromExchange(exchange));
         } else if (GoraOperation.QUERY.value.equalsIgnoreCase(operation)) {
-
             final Map<String, Object> props = exchange.getIn().getHeaders();
             result = constractQueryFromPropertiesMap(props, dataStore, this.configuration).execute();
         } else if (GoraOperation.DELETE_BY_QUERY.value.equalsIgnoreCase(operation)) {
-
             final Map<String, Object> props = exchange.getIn().getHeaders();
             result = dataStore.deleteByQuery(constractQueryFromPropertiesMap(props, dataStore, this.configuration));
         } else if (GoraOperation.GET_SCHEMA_NAME.value.equalsIgnoreCase(operation)) {
-
             result = dataStore.getSchemaName();
         } else if (GoraOperation.DELETE_SCHEMA.value.equalsIgnoreCase(operation)) {
-
             dataStore.deleteSchema();
         } else if (GoraOperation.CREATE_SCHEMA.value.equalsIgnoreCase(operation)) {
-
             dataStore.createSchema();
         } else if (GoraOperation.SCHEMA_EXIST.value.equalsIgnoreCase(operation)) {
-
             result = dataStore.schemaExists();
         } else {
-
-            throw new RuntimeException("Unknown operation!");
+            throw new RuntimeException("Unknown operation: " + operation);
         }
 
         /*
@@ -129,6 +114,8 @@ public class GoraProducer extends DefaultProducer implements ServicePoolAware {
         }
 
         exchange.getOut().setBody(result);
+        // preserve headers
+        exchange.getOut().setHeaders(exchange.getIn().getHeaders());
     }
 
 }