Author: hadrian
Date: Wed Sep 21 20:18:14 2011
New Revision: 1173830

URL: http://svn.apache.org/viewvc?rev=1173830&view=rev
Log:
CAMEL-4034. Add experimental camel-jclouds component as contributed (missing 
directory)

Added:
    camel/trunk/components/camel-jclouds/
    camel/trunk/components/camel-jclouds/pom.xml
    camel/trunk/components/camel-jclouds/src/
    camel/trunk/components/camel-jclouds/src/main/
    camel/trunk/components/camel-jclouds/src/main/java/
    camel/trunk/components/camel-jclouds/src/main/java/org/
    camel/trunk/components/camel-jclouds/src/main/java/org/apache/
    camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreConsumer.java
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreEndpoint.java
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreProducer.java
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsComponent.java
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConsumer.java
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsEndpoint.java
    
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsProducer.java
    camel/trunk/components/camel-jclouds/src/main/resources/
    camel/trunk/components/camel-jclouds/src/test/
    camel/trunk/components/camel-jclouds/src/test/java/
    camel/trunk/components/camel-jclouds/src/test/java/org/
    camel/trunk/components/camel-jclouds/src/test/java/org/apache/
    camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/
    
camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/component/
    
camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/
    
camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsComponentTest.java
    camel/trunk/components/camel-jclouds/src/test/resources/
    camel/trunk/components/camel-jclouds/src/test/resources/blobstore-test.xml
    camel/trunk/components/camel-jclouds/src/test/resources/log4j.properties

Added: camel/trunk/components/camel-jclouds/pom.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/pom.xml?rev=1173830&view=auto
==============================================================================
--- camel/trunk/components/camel-jclouds/pom.xml (added)
+++ camel/trunk/components/camel-jclouds/pom.xml Wed Sep 21 20:18:14 2011
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>2.9-SNAPSHOT</version>
+        <relativePath>../../parent</relativePath>
+    </parent>
+
+    <artifactId>camel-jclouds</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: JClouds</name>
+    <description>Camel JClouds support</description>
+
+
+    <properties>
+        
<camel.osgi.export.pkg>org.apache.camel.component.jclouds.*</camel.osgi.export.pkg>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+        </dependency>
+
+        <!-- jclouds -->
+        <dependency>
+            <groupId>org.jclouds</groupId>
+            <artifactId>jclouds-blobstore</artifactId>
+            <version>${jclouds-version}</version>
+        </dependency>
+
+        <!-- logging -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+</project>

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreConsumer.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreConsumer.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreConsumer.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jclouds;
+
+import org.apache.camel.BatchConsumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ShutdownRunningTask;
+import org.apache.camel.spi.ShutdownAware;
+import org.apache.camel.spi.Synchronization;
+import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.ObjectHelper;
+import org.jclouds.blobstore.BlobStore;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.domain.StorageMetadata;
+import org.jclouds.blobstore.options.ListContainerOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.util.LinkedList;
+import java.util.Queue;
+
+
+public class JcloudsBlobStoreConsumer extends JcloudsConsumer implements 
BatchConsumer, ShutdownAware {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(JcloudsBlobStoreConsumer.class);
+
+    private final JcloudsBlobStoreEndpoint endpoint;
+
+    private BlobStoreContext blobStoreContext;
+    private String container;
+    private BlobStore blobStore;
+
+    private int maxMessagesPerPoll = 10;
+
+    private volatile ShutdownRunningTask shutdownRunningTask;
+    private volatile int pendingExchanges;
+
+
+    public JcloudsBlobStoreConsumer(JcloudsBlobStoreEndpoint endpoint, 
Processor processor, BlobStoreContext blobStoreContext, String container) {
+        super(endpoint, processor);
+        this.endpoint = endpoint;
+        this.blobStoreContext = blobStoreContext;
+        this.container = container;
+        blobStore = blobStoreContext.getBlobStore();
+    }
+
+    @Override
+    protected int poll() throws Exception {
+        int messages = 0;
+        shutdownRunningTask = null;
+        pendingExchanges = 0;
+
+        Queue<Exchange> queue = new LinkedList<Exchange>();
+
+        ListContainerOptions opt = new ListContainerOptions();
+
+        for (StorageMetadata md : blobStore.list(container, 
opt.maxResults(maxMessagesPerPoll))) {
+            messages++;
+            String blobName = md.getName();
+            Object body = readBlob(container, blobName);
+            Exchange exchange = endpoint.createExchange();
+            exchange.getIn().setBody(body);
+            exchange.setProperty(JcloudsConstants.BLOB_NAME, blobName);
+            queue.add(exchange);
+        }
+        if (!queue.isEmpty())
+            return processBatch(CastUtils.cast(queue));
+        else return 0;
+    }
+
+    @Override
+    public void setMaxMessagesPerPoll(int maxMessagesPerPoll) {
+        this.maxMessagesPerPoll = maxMessagesPerPoll;
+    }
+
+    public int processBatch(Queue<Object> exchanges) throws Exception {
+        int total = exchanges.size();
+
+        for (int index = 0; index < total && isBatchAllowed(); index++) {
+            // only loop if we are started (allowed to run)
+            Exchange exchange = ObjectHelper.cast(Exchange.class, 
exchanges.poll());
+            // add current index and total as properties
+            exchange.setProperty(Exchange.BATCH_INDEX, index);
+            exchange.setProperty(Exchange.BATCH_SIZE, total);
+            exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1);
+
+            // update pending number of exchanges
+            pendingExchanges = total - index - 1;
+
+            // add on completion to handle after work when the exchange is done
+            exchange.addOnCompletion(new Synchronization() {
+                public void onComplete(Exchange exchange) {
+                    String blobName = (String) 
exchange.getProperty(JcloudsConstants.BLOB_NAME);
+                    blobStore.removeBlob(container, blobName);
+                }
+
+                public void onFailure(Exchange exchange) {
+
+                }
+            });
+
+            logger.trace("Processing exchange [{}]...", exchange);
+            getProcessor().process(exchange);
+        }
+
+        return total;
+    }
+
+    public boolean isBatchAllowed() {
+        // stop if we are not running
+        boolean answer = isRunAllowed();
+        if (!answer) {
+            return false;
+        }
+
+        if (shutdownRunningTask == null) {
+            // we are not shutting down so continue to run
+            return true;
+        }
+
+        // we are shutting down so only continue if we are configured to 
complete all tasks
+        return ShutdownRunningTask.CompleteAllTasks == shutdownRunningTask;
+    }
+
+    public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask) {
+        // store a reference what to do in case when shutting down and we have 
pending messages
+        this.shutdownRunningTask = shutdownRunningTask;
+        // do not defer shutdown
+        return false;
+    }
+
+    public int getPendingExchangesSize() {
+        // only return the real pending size in case we are configured to 
complete all tasks
+        if (ShutdownRunningTask.CompleteAllTasks == shutdownRunningTask) {
+            return pendingExchanges;
+        } else {
+            return 0;
+        }
+    }
+
+    @Override
+    public void prepareShutdown() {
+
+    }
+
+    /**
+     * Reads from a {@link BlobStore}. It returns an Object.
+     *
+     * @param container
+     * @param blobName
+     * @return
+     */
+    protected Object readBlob(String container, String blobName) {
+        Object result = null;
+        ObjectInputStream ois = null;
+        BlobStore blobStore = blobStoreContext.getBlobStore();
+        blobStore.createContainerInLocation(null, container);
+
+        InputStream is = blobStore.getBlob(container, 
blobName).getPayload().getInput();
+
+        try {
+            ois = new ObjectInputStream(is) {
+                @Override
+                public Class resolveClass(ObjectStreamClass desc) throws 
IOException,
+                        ClassNotFoundException {
+                    try {
+                        return 
getEndpoint().getCamelContext().getClassResolver().resolveClass(desc.getName());
+                    } catch (Exception e) {
+                    }
+                    return super.resolveClass(desc);
+                }
+            };
+            result = ois.readObject();
+        } catch (IOException
+                e) {
+            e.printStackTrace();
+        } catch (ClassNotFoundException
+                e) {
+            e.printStackTrace();
+        } finally {
+            if (ois != null) {
+                try {
+                    ois.close();
+                } catch (IOException e) {
+                }
+            }
+
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+
+        return result;
+    }
+}

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreEndpoint.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreEndpoint.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreEndpoint.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jclouds;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.jclouds.blobstore.BlobStoreContext;
+
+
+public class JcloudsBlobStoreEndpoint extends JcloudsEndpoint {
+
+    private String container;
+
+    private BlobStoreContext blobStoreContext;
+
+    /**
+     * Constructor
+     *
+     * @param uri
+     * @param component
+     * @param blobStoreContext
+     */
+    public JcloudsBlobStoreEndpoint(String uri, JcloudsComponent component, 
BlobStoreContext blobStoreContext,String container) {
+        super(uri, component);
+        this.blobStoreContext=blobStoreContext;
+        this.container=container;
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        return new JcloudsBlobStoreProducer(this,blobStoreContext,container);
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) {
+        return new 
JcloudsBlobStoreConsumer(this,processor,blobStoreContext,container);
+    }
+}

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreProducer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreProducer.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreProducer.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsBlobStoreProducer.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jclouds;
+
+import org.apache.camel.Exchange;
+import org.jclouds.blobstore.BlobStore;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.domain.Blob;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+
+public class JcloudsBlobStoreProducer extends JcloudsProducer {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(JcloudsBlobStoreProducer.class);
+
+    private BlobStoreContext blobStoreContext;
+    private String container;
+
+    public JcloudsBlobStoreProducer(JcloudsEndpoint endpoint, BlobStoreContext 
blobStoreContext, String container) {
+        super(endpoint);
+        this.blobStoreContext = blobStoreContext;
+        this.container = container;
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        String blobName = extractBlobName(exchange);
+        if (blobName != null && exchange.getIn() != null && 
exchange.getIn().getBody() != null) {
+            Object body = exchange.getIn().getBody();
+            BlobStore blobStore = blobStoreContext.getBlobStore();
+            Blob blob = blobStore.newBlob(blobName);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = null;
+            try {
+                oos = new ObjectOutputStream(baos);
+                oos.writeObject(body);
+                blob.setPayload(baos.toByteArray());
+                blobStore.putBlob(container, blob);
+            } catch (IOException e) {
+                logger.error("Error while writing blob", e);
+            } finally {
+                if (oos != null) {
+                    try {
+                        oos.close();
+                    } catch (IOException e) {
+                    }
+                }
+
+                if (baos != null) {
+                    try {
+                        baos.close();
+                    } catch (IOException e) {
+                    }
+                }
+            }
+        }
+
+    }
+
+    /**
+     * Extracts the BLOB_NAME from Exchange headers / properties.
+     *
+     * @param exchange
+     * @return
+     */
+    public String extractBlobName(Exchange exchange) {
+        String blobName = null;
+        if (exchange != null) {
+            if (exchange.getProperty(JcloudsConstants.BLOB_NAME) != null) {
+                blobName = (String) 
exchange.getProperty(JcloudsConstants.BLOB_NAME);
+            } else if (exchange.getIn() != null && 
exchange.getIn().getHeader(JcloudsConstants.BLOB_NAME) != null) {
+                blobName = (String) 
exchange.getIn().getHeader(JcloudsConstants.BLOB_NAME);
+            }
+        }
+        return blobName;
+    }
+}

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsComponent.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsComponent.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsComponent.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jclouds;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.BlobStoreContextFactory;
+
+/**
+ * Represents the component that manages {@link JcloudsEndpoint}.
+ */
+public class JcloudsComponent extends DefaultComponent {
+
+    private String provider;
+    private String identity;
+    private String creadential;
+
+
+    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+        Endpoint endpoint = null;
+
+        String[] uriParts = null;
+        String endpointType = null;
+
+        if (remaining != null) {
+            uriParts = remaining.split(JcloudsConstants.DELIMETER);
+            if (uriParts != null && uriParts.length > 0) {
+                endpointType = uriParts[0];
+            }
+        }
+
+        if (JcloudsConstants.BLOBSTORE.endsWith(endpointType)) {
+
+            if (uriParts.length >= 2) {
+                String container = uriParts[1];
+                BlobStoreContext blobStoreContext = new 
BlobStoreContextFactory().createContext(provider, identity, creadential);
+                endpoint = new JcloudsBlobStoreEndpoint(uri, this, 
blobStoreContext, container);
+            } else throw new Exception("Invalid Endpoint URI. It should 
contains a valid container name");
+        }
+
+        setProperties(endpoint, parameters);
+        return endpoint;
+    }
+
+    public String getProvider() {
+        return provider;
+    }
+
+    public void setProvider(String provider) {
+        this.provider = provider;
+    }
+
+    public String getIdentity() {
+        return identity;
+    }
+
+    public void setIdentity(String identity) {
+        this.identity = identity;
+    }
+
+    public String getCreadential() {
+        return creadential;
+    }
+
+    public void setCreadential(String creadential) {
+        this.creadential = creadential;
+    }
+}

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConstants.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jclouds;
+
+public class JcloudsConstants {
+    public static final String DELIMETER = ":";
+    public static final String BLOBSTORE = "blobstore";
+    public static final String BLOB_NAME = "BLOB_NAME";
+
+}

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConsumer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConsumer.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConsumer.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsConsumer.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jclouds;
+
+import java.util.Date;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.ScheduledPollConsumer;
+
+
+public class JcloudsConsumer extends ScheduledPollConsumer {
+    private final JcloudsEndpoint endpoint;
+
+    public JcloudsConsumer(JcloudsEndpoint endpoint, Processor processor) {
+        super(endpoint, processor);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    protected int poll() throws Exception {
+        Exchange exchange = endpoint.createExchange();
+
+        // create a message body
+        Date now = new Date();
+        exchange.getIn().setBody("Hello World! The time is " + now);
+
+        try {
+            // send message to next processor in the route
+            getProcessor().process(exchange);
+            return 1; // number of messages polled
+        } finally {
+            // log exception if an exception occurred and was not handled
+            if (exchange.getException() != null) {
+                getExceptionHandler().handleException("Error processing 
exchange", exchange, exchange.getException());
+            }
+        }
+    }
+}

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsEndpoint.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsEndpoint.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsEndpoint.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jclouds;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+
+
+public abstract class JcloudsEndpoint extends DefaultEndpoint {
+
+    /**
+     * Constructor
+     * @param uri
+     * @param component
+     */
+    public JcloudsEndpoint(String uri, JcloudsComponent component) {
+        super(uri, component);
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public abstract Producer createProducer() throws Exception;
+    public abstract Consumer createConsumer(Processor processor);
+}

Added: 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsProducer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsProducer.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsProducer.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsProducer.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jclouds;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JcloudsProducer extends DefaultProducer {
+    private static final transient Logger LOG = 
LoggerFactory.getLogger(JcloudsProducer.class);
+
+    private JcloudsEndpoint endpoint;
+
+    public JcloudsProducer(JcloudsEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        System.out.println(exchange.getIn().getBody());    
+    }
+}

Added: 
camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsComponentTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsComponentTest.java?rev=1173830&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsComponentTest.java
 (added)
+++ 
camel/trunk/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsComponentTest.java
 Wed Sep 21 20:18:14 2011
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jclouds;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.BlobStoreContextFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class JcloudsComponentTest extends CamelSpringTestSupport {
+
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint result;
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+       BlobStoreContext context = new 
BlobStoreContextFactory().createContext("transient","id","credential");
+       context.getBlobStore().createContainerInLocation(null, "foo");
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("classpath:blobstore-test.xml");
+    }
+
+    @Test
+    public void testProduce() throws InterruptedException {
+         result.expectedMessageCount(1);
+         result.assertIsSatisfied();
+    }
+}

Added: 
camel/trunk/components/camel-jclouds/src/test/resources/blobstore-test.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/test/resources/blobstore-test.xml?rev=1173830&view=auto
==============================================================================
--- camel/trunk/components/camel-jclouds/src/test/resources/blobstore-test.xml 
(added)
+++ camel/trunk/components/camel-jclouds/src/test/resources/blobstore-test.xml 
Wed Sep 21 20:18:14 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns:camel="http://activemq.apache.org/camel/schema/spring";
+       xmlns:util="http://www.springframework.org/schema/util";
+       xmlns:tx="http://www.springframework.org/schema/tx";
+       xmlns:ctx="http://www.springframework.org/schema/context";
+
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://www.springframework.org/schema/osgi 
http://www.springframework.org/schema/osgi/spring-osgi.xsd
+       http://www.springframework.org/schema/osgi-compendium 
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
+       http://www.springframework.org/schema/util 
http://www.springframework.org/schema/util/spring-util.xsd
+       http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx.xsd
+       http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd";>
+
+    <camelContext xmlns="http://camel.apache.org/schema/spring";>
+        <route>
+            <from uri="dataset:testset"/>
+            <setProperty propertyName="BLOB_NAME">
+                <constant>testName</constant>
+            </setProperty>
+            <to uri="jclouds:blobstore:foo"/>
+        </route>
+
+        <route>
+            <from uri="jclouds:blobstore:foo"/>
+            <to uri="mock:result"/>
+        </route>
+
+    </camelContext>
+
+    <bean id="testset" 
class="org.apache.camel.component.dataset.SimpleDataSet">
+        <property name="size" value="1"/>
+    </bean>
+
+    <bean id="jclouds" 
class="org.apache.camel.component.jclouds.JcloudsComponent">
+        <property name="provider" value="transient"/>
+        <property name="identity"  value="identity"/>
+        <property name="creadential" value="creadential"/>
+    </bean>
+
+</beans>
\ No newline at end of file

Added: camel/trunk/components/camel-jclouds/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jclouds/src/test/resources/log4j.properties?rev=1173830&view=auto
==============================================================================
--- camel/trunk/components/camel-jclouds/src/test/resources/log4j.properties 
(added)
+++ camel/trunk/components/camel-jclouds/src/test/resources/log4j.properties 
Wed Sep 21 20:18:14 2011
@@ -0,0 +1,22 @@
+
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# uncomment the following line to turn on ActiveMQ debugging
+#log4j.logger.org.apache.activemq=DEBUG
+
+log4j.logger.org.springframework=WARN
+
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - 
%m%n
+
+log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
\ No newline at end of file


Reply via email to