Rename camel-gridfs to camel-mongodb-gridfs
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b4845575 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b4845575 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b4845575 Branch: refs/heads/master Commit: b4845575fcf22e64aa35da0a971b55c35a4ebf14 Parents: 2d5000e Author: Daniel Kulp <dk...@apache.org> Authored: Fri Mar 4 11:55:35 2016 -0500 Committer: Daniel Kulp <dk...@apache.org> Committed: Fri Mar 4 11:55:35 2016 -0500 ---------------------------------------------------------------------- components/camel-gridfs/.gitignore | 3 - components/camel-gridfs/pom.xml | 69 ---- .../camel/component/gridfs/GridFsComponent.java | 64 ---- .../camel/component/gridfs/GridFsConsumer.java | 178 --------- .../camel/component/gridfs/GridFsEndpoint.java | 360 ------------------- .../camel/component/gridfs/GridFsProducer.java | 145 -------- .../src/main/resources/META-INF/LICENSE.txt | 203 ----------- .../src/main/resources/META-INF/NOTICE.txt | 11 - .../services/org/apache/camel/component/gridfs | 18 - .../component/gridfs/AbstractMongoDbTest.java | 62 ---- .../gridfs/EmbedMongoConfiguration.java | 58 --- .../component/gridfs/GridFsConsumerTest.java | 99 ----- .../gridfs/GridFsProducerOperationsTest.java | 74 ---- .../src/test/resources/log4j.properties | 37 -- .../src/test/resources/mongodb.test.properties | 21 -- components/camel-mongodb-gridfs/.gitignore | 3 + components/camel-mongodb-gridfs/pom.xml | 69 ++++ .../camel/component/gridfs/GridFsComponent.java | 64 ++++ .../camel/component/gridfs/GridFsConsumer.java | 178 +++++++++ .../camel/component/gridfs/GridFsEndpoint.java | 360 +++++++++++++++++++ .../camel/component/gridfs/GridFsProducer.java | 145 ++++++++ .../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++ .../src/main/resources/META-INF/NOTICE.txt | 11 + .../services/org/apache/camel/component/gridfs | 18 + .../component/gridfs/AbstractMongoDbTest.java | 62 ++++ .../gridfs/EmbedMongoConfiguration.java | 58 +++ .../component/gridfs/GridFsConsumerTest.java | 99 +++++ .../gridfs/GridFsProducerOperationsTest.java | 74 ++++ .../src/test/resources/log4j.properties | 37 ++ .../src/test/resources/mongodb.test.properties | 21 ++ components/pom.xml | 2 +- .../features/src/main/resources/features.xml | 4 +- 32 files changed, 1405 insertions(+), 1405 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/.gitignore ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/.gitignore b/components/camel-gridfs/.gitignore deleted file mode 100644 index fe30fe5..0000000 --- a/components/camel-gridfs/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -target -*.i?? -.idea http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/pom.xml b/components/camel-gridfs/pom.xml deleted file mode 100644 index ec8e6bd..0000000 --- a/components/camel-gridfs/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ -<?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/xsd/maven-4.0.0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.camel</groupId> - <artifactId>components</artifactId> - <version>2.17-SNAPSHOT</version> - </parent> - - <artifactId>camel-gridfs</artifactId> - <packaging>bundle</packaging> - <name>Camel :: MongoDB GridFS</name> - <description>Camel MongoDB GridFS component</description> - - <properties> - <camel.osgi.export.pkg>org.apache.camel.component.gridfs.*</camel.osgi.export.pkg> - <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=gridfs</camel.osgi.export.service> - </properties> - - <dependencies> - - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - </dependency> - - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-jackson</artifactId> - </dependency> - - <dependency> - <groupId>org.mongodb</groupId> - <artifactId>mongo-java-driver</artifactId> - <version>3.2.2</version> - </dependency> - <dependency> - <groupId>de.flapdoodle.embed</groupId> - <artifactId>de.flapdoodle.embed.mongo</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test-spring</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java b/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java deleted file mode 100644 index 62701a0..0000000 --- a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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.gridfs; - -import java.util.Map; - -import com.mongodb.Mongo; -import org.apache.camel.Endpoint; -import org.apache.camel.impl.UriEndpointComponent; -import org.apache.camel.util.CamelContextHelper; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class GridFsComponent extends UriEndpointComponent { - - private static final Logger LOG = LoggerFactory.getLogger(GridFsComponent.class); - - private volatile Mongo db; - - public GridFsComponent() { - super(GridFsEndpoint.class); - } - - protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - if (db == null) { - db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Mongo.class); - LOG.debug("Resolved the connection with the name {} as {}", remaining, db); - } - - GridFsEndpoint endpoint = new GridFsEndpoint(uri, this); - parameters.put("mongoConnection", db); - endpoint.setConnectionBean(remaining); - endpoint.setMongoConnection(db); - setProperties(endpoint, parameters); - - return endpoint; - } - - @Override - protected void doShutdown() throws Exception { - if (db != null) { - LOG.debug("Closing the connection {} on {}", db, this); - db.close(); - } - super.doShutdown(); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java b/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java deleted file mode 100644 index bfce711..0000000 --- a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * 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.gridfs; - -import java.io.InputStream; -import java.util.concurrent.ExecutorService; - -import com.mongodb.BasicDBObject; -import com.mongodb.BasicDBObjectBuilder; -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; -import com.mongodb.MongoException; -import com.mongodb.gridfs.GridFSDBFile; -import com.mongodb.util.JSON; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.component.gridfs.GridFsEndpoint.QueryStrategy; -import org.apache.camel.impl.DefaultConsumer; - -/** - * - */ -public class GridFsConsumer extends DefaultConsumer implements Runnable { - final GridFsEndpoint endpoint; - private ExecutorService executor; - - /** - * @param endpoint - * @param processor - */ - public GridFsConsumer(GridFsEndpoint endpoint, Processor processor) { - super(endpoint, processor); - this.endpoint = endpoint; - } - - @Override - protected void doStop() throws Exception { - super.doStop(); - if (executor != null) { - executor.shutdown(); - executor = null; - } - } - - @Override - protected void doStart() throws Exception { - super.doStart(); - executor = endpoint.getCamelContext().getExecutorServiceManager().newFixedThreadPool(this, endpoint.getEndpointUri(), 1); - executor.execute(this); - } - - @Override - public void run() { - DBCursor c = null; - java.util.Date fromDate = null; - - QueryStrategy s = endpoint.getQueryStrategy(); - boolean usesTimestamp = s != QueryStrategy.FileAttribute; - boolean persistsTimestamp = s == QueryStrategy.PersistentTimestamp || s == QueryStrategy.PersistentTimestampAndFileAttribute; - boolean usesAttribute = s == QueryStrategy.FileAttribute - || s == QueryStrategy.TimeStampAndFileAttribute - || s == QueryStrategy.PersistentTimestampAndFileAttribute; - - DBCollection ptsCollection = null; - DBObject persistentTimestamp = null; - if (persistsTimestamp) { - ptsCollection = endpoint.getDB().getCollection(endpoint.getPersistentTSCollection()); - // ensure standard indexes as long as collections are small - try { - if (ptsCollection.count() < 1000) { - ptsCollection.createIndex(new BasicDBObject("id", 1)); - } - } catch (MongoException e) { - //TODO: Logging - } - persistentTimestamp = ptsCollection.findOne(new BasicDBObject("id", endpoint.getPersistentTSObject())); - if (persistentTimestamp == null) { - persistentTimestamp = new BasicDBObject("id", endpoint.getPersistentTSObject()); - fromDate = new java.util.Date(); - persistentTimestamp.put("timestamp", fromDate); - ptsCollection.save(persistentTimestamp); - } - fromDate = (java.util.Date)persistentTimestamp.get("timestamp"); - } else if (usesTimestamp) { - fromDate = new java.util.Date(); - } - try { - Thread.sleep(endpoint.getInitialDelay()); - while (isStarted()) { - if (c == null || c.getCursorId() == 0) { - if (c != null) { - c.close(); - } - String queryString = endpoint.getQuery(); - DBObject query; - if (queryString == null) { - query = new BasicDBObject(); - } else { - query = (DBObject) JSON.parse(queryString); - } - if (usesTimestamp) { - query.put("uploadDate", new BasicDBObject("$gt", fromDate)); - } - if (usesAttribute) { - query.put(endpoint.getFileAttributeName(), null); - } - c = endpoint.getFilesCollection().find(query); - } - boolean dateModified = false; - while (c.hasNext() && isStarted()) { - GridFSDBFile file = (GridFSDBFile)c.next(); - GridFSDBFile forig = file; - if (usesAttribute) { - file.put(endpoint.getFileAttributeName(), "processing"); - DBObject q = BasicDBObjectBuilder.start("_id", file.getId()).append("camel-processed", null).get(); - forig = (GridFSDBFile)endpoint.getFilesCollection().findAndModify(q, null, null, false, file, true, false); - } - if (forig != null) { - file = endpoint.getGridFs().findOne(new BasicDBObject("_id", file.getId())); - - Exchange exchange = endpoint.createExchange(); - exchange.getIn().setHeader(GridFsEndpoint.GRIDFS_METADATA, JSON.serialize(file.getMetaData())); - exchange.getIn().setHeader(Exchange.FILE_CONTENT_TYPE, file.getContentType()); - exchange.getIn().setHeader(Exchange.FILE_LENGTH, file.getLength()); - exchange.getIn().setHeader(Exchange.FILE_LAST_MODIFIED, file.getUploadDate()); - exchange.getIn().setBody(file.getInputStream(), InputStream.class); - try { - getProcessor().process(exchange); - //System.out.println("Processing " + file.getFilename()); - if (usesAttribute) { - forig.put(endpoint.getFileAttributeName(), "done"); - endpoint.getFilesCollection().save(forig); - } - if (usesTimestamp) { - if (file.getUploadDate().compareTo(fromDate) > 0) { - fromDate = file.getUploadDate(); - dateModified = true; - } - } - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - if (persistsTimestamp && dateModified) { - persistentTimestamp.put("timestamp", fromDate); - ptsCollection.save(persistentTimestamp); - } - Thread.sleep(endpoint.getDelay()); - } - } catch (Throwable e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - if (c != null) { - c.close(); - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java b/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java deleted file mode 100644 index 4856a7f..0000000 --- a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java +++ /dev/null @@ -1,360 +0,0 @@ -/** - * 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.gridfs; - -import com.mongodb.DB; -import com.mongodb.DBCollection; -import com.mongodb.Mongo; -import com.mongodb.ReadPreference; -import com.mongodb.WriteConcern; -import com.mongodb.gridfs.GridFS; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.impl.DefaultEndpoint; -import org.apache.camel.spi.Metadata; -import org.apache.camel.spi.UriEndpoint; -import org.apache.camel.spi.UriParam; -import org.apache.camel.spi.UriPath; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@UriEndpoint(scheme = "gridfs", title = "MongoDBGridFS", syntax = "gridfs:connectionBean", - label = "database,nosql") -public class GridFsEndpoint extends DefaultEndpoint { - - public enum QueryStrategy { - TimeStamp, - PersistentTimestamp, - FileAttribute, - TimeStampAndFileAttribute, - PersistentTimestampAndFileAttribute - }; - public static final String GRIDFS_OPERATION = "gridfs.operation"; - public static final String GRIDFS_METADATA = "gridfs.metadata"; - public static final String GRIDFS_CHUNKSIZE = "gridfs.chunksize"; - - private static final Logger LOG = LoggerFactory.getLogger(GridFsEndpoint.class); - - @UriPath @Metadata(required = "true") - private String connectionBean; - @UriParam @Metadata(required = "true") - private String database; - @UriParam(defaultValue = GridFS.DEFAULT_BUCKET) - private String bucket; - @UriParam(enums = "ACKNOWLEDGED,W1,W2,W3,UNACKNOWLEDGED,JOURNALED,MAJORITY,SAFE") - private WriteConcern writeConcern; - @UriParam - private WriteConcern writeConcernRef; - @UriParam - private ReadPreference readPreference; - - @UriParam(label = "producer") - private String operation; - - @UriParam(label = "consumer") - private String query; - @UriParam(label = "consumer", defaultValue = "1000") - private long initialDelay = 1000; - @UriParam(label = "consumer", defaultValue = "500") - private long delay = 500; - - @UriParam(label = "consumer", defaultValue = "TimeStamp") - private QueryStrategy queryStrategy = QueryStrategy.TimeStamp; - @UriParam(label = "consumer", defaultValue = "camel-timestamps") - private String persistentTSCollection = "camel-timestamps"; - @UriParam(label = "consumer", defaultValue = "camel-timestamp") - private String persistentTSObject = "camel-timestamp"; - @UriParam(label = "consumer", defaultValue = "camel-processed") - private String fileAttributeName = "camel-processed"; - - - private Mongo mongoConnection; - private DB db; - private GridFS gridFs; - private DBCollection filesCollection; - - public GridFsEndpoint(String uri, GridFsComponent component) { - super(uri, component); - } - - @Override - public Producer createProducer() throws Exception { - initializeConnection(); - return new GridFsProducer(this); - } - - @Override - public Consumer createConsumer(Processor processor) throws Exception { - initializeConnection(); - return new GridFsConsumer(this, processor); - } - - public boolean isSingleton() { - return true; - } - - @SuppressWarnings("deprecation") - public void initializeConnection() throws Exception { - LOG.info("Initialize GridFS endpoint: {}", this.toString()); - if (database == null) { - throw new IllegalStateException("Missing required endpoint configuration: database"); - } - db = mongoConnection.getDB(database); - if (db == null) { - throw new IllegalStateException("Could not initialize GridFsComponent. Database " + database + " does not exist."); - } - gridFs = new GridFS(db, bucket == null ? GridFS.DEFAULT_BUCKET : bucket) { - { - filesCollection = getFilesCollection(); - } - }; - } - - - @Override - protected void doStart() throws Exception { - if (writeConcern != null && writeConcernRef != null) { - String msg = "Cannot set both writeConcern and writeConcernRef at the same time. Respective values: " + writeConcern - + ", " + writeConcernRef + ". Aborting initialization."; - throw new IllegalArgumentException(msg); - } - - setWriteReadOptionsOnConnection(); - super.doStart(); - } - private void setWriteReadOptionsOnConnection() { - // Set the WriteConcern - if (writeConcern != null) { - mongoConnection.setWriteConcern(writeConcern); - } else if (writeConcernRef != null) { - mongoConnection.setWriteConcern(writeConcernRef); - } - - // Set the ReadPreference - if (readPreference != null) { - mongoConnection.setReadPreference(readPreference); - } - } - - - - - // ======= Getters and setters =============================================== - public String getConnectionBean() { - return connectionBean; - } - /** - * Name of {@link com.mongodb.Mongo} to use. - */ - public void setConnectionBean(String connectionBean) { - this.connectionBean = connectionBean; - } - - public Mongo getMongoConnection() { - return mongoConnection; - } - /** - * Sets the Mongo instance that represents the backing connection - * - * @param mongoConnection the connection to the database - */ - public void setMongoConnection(Mongo mongoConnection) { - this.mongoConnection = mongoConnection; - } - - public DB getDB() { - return db; - } - - public String getDatabase() { - return database; - } - /** - * Sets the name of the MongoDB database to target - * - * @param database name of the MongoDB database - */ - public void setDatabase(String database) { - this.database = database; - } - /** - * Sets the name of the GridFS bucket within the database. Default is "fs". - * - * @param database name of the MongoDB database - */ - public String getBucket() { - return bucket; - } - public void setBucket(String bucket) { - this.bucket = bucket; - } - - public String getQuery() { - return query; - } - /** - * Additional query parameters (in JSON) that are used to configure the query used for finding - * files in the GridFsConsumer - * @param query - */ - public void setQuery(String query) { - this.query = query; - } - public long getDelay() { - return delay; - } - /** - * Sets the delay between polls within the Consumer. Default is 500ms - * @param delay - */ - public void setDelay(long delay) { - this.delay = delay; - } - public long getInitialDelay() { - return initialDelay; - } - /** - * Sets the initialDelay before the consumer will start polling. Default is 1000ms - * @param initialDelay - */ - public void setInitialDelay(long initialDelay) { - this.initialDelay = delay; - } - - /** - * Sets the QueryStrategy that is used for polling for new files. Default is Timestamp - * @see QueryStrategy - * @param s - */ - public void setQueryStrategy(String s) { - queryStrategy = QueryStrategy.valueOf(s); - } - public QueryStrategy getQueryStrategy() { - return queryStrategy; - } - /** - * If the QueryType uses a persistent timestamp, this sets the name of the collection within - * the DB to store the timestamp. - * @param s - */ - public void setPersistentTSCollection(String s) { - persistentTSCollection = s; - } - public String getPersistentTSCollection() { - return persistentTSCollection; - } - /** - * If the QueryType uses a persistent timestamp, this is the ID of the object in the collection - * to store the timestamp. - * @param s - */ - public void setPersistentTSObject(String id) { - persistentTSObject = id; - } - public String getPersistentTSObject() { - return persistentTSObject; - } - - /** - * If the QueryType uses a FileAttribute, this sets the name of the attribute that is used. Default is "camel-processed". - * @param f - */ - public void setFileAttributeName(String f) { - fileAttributeName = f; - } - public String getFileAttributeName() { - return fileAttributeName; - } - - /** - * Set the {@link WriteConcern} for write operations on MongoDB using the standard ones. - * Resolved from the fields of the WriteConcern class by calling the {@link WriteConcern#valueOf(String)} method. - * - * @param writeConcern the standard name of the WriteConcern - * @see <a href="http://api.mongodb.org/java/current/com/mongodb/WriteConcern.html#valueOf(java.lang.String)">possible options</a> - */ - public void setWriteConcern(String writeConcern) { - this.writeConcern = WriteConcern.valueOf(writeConcern); - } - - public WriteConcern getWriteConcern() { - return writeConcern; - } - - /** - * Set the {@link WriteConcern} for write operations on MongoDB, passing in the bean ref to a custom WriteConcern which exists in the Registry. - * You can also use standard WriteConcerns by passing in their key. See the {@link #setWriteConcern(String) setWriteConcern} method. - * - * @param writeConcernRef the name of the bean in the registry that represents the WriteConcern to use - */ - public void setWriteConcernRef(String writeConcernRef) { - WriteConcern wc = this.getCamelContext().getRegistry().lookupByNameAndType(writeConcernRef, WriteConcern.class); - if (wc == null) { - String msg = "Camel MongoDB component could not find the WriteConcern in the Registry. Verify that the " - + "provided bean name (" + writeConcernRef + ") is correct. Aborting initialization."; - throw new IllegalArgumentException(msg); - } - - this.writeConcernRef = wc; - } - - public WriteConcern getWriteConcernRef() { - return writeConcernRef; - } - - /** - * Sets a MongoDB {@link ReadPreference} on the Mongo connection. Read preferences set directly on the connection will be - * overridden by this setting. - * <p/> - * The {@link com.mongodb.ReadPreference#valueOf(String)} utility method is used to resolve the passed {@code readPreference} - * value. Some examples for the possible values are {@code nearest}, {@code primary} or {@code secondary} etc. - * - * @param readPreference the name of the read preference to set - */ - public void setReadPreference(String readPreference) { - this.readPreference = ReadPreference.valueOf(readPreference); - } - - public ReadPreference getReadPreference() { - return readPreference; - } - - - /** - * Sets the operation this endpoint will execute against GridRS. - */ - public void setOperation(String operation) { - this.operation = operation; - } - - public String getOperation() { - return operation; - } - - public GridFS getGridFs() { - return gridFs; - } - - public void setGridFs(GridFS gridFs) { - this.gridFs = gridFs; - } - public DBCollection getFilesCollection() { - return filesCollection; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java b/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java deleted file mode 100644 index dccb499..0000000 --- a/components/camel-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * 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.gridfs; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; - -import com.mongodb.BasicDBObject; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; -import com.mongodb.gridfs.GridFSDBFile; -import com.mongodb.gridfs.GridFSInputFile; -import com.mongodb.util.JSON; -import org.apache.camel.Exchange; -import org.apache.camel.impl.DefaultProducer; - - -public class GridFsProducer extends DefaultProducer { - private GridFsEndpoint endpoint; - - public GridFsProducer(GridFsEndpoint endpoint) { - super(endpoint); - this.endpoint = endpoint; - } - - public void process(Exchange exchange) throws Exception { - String operation = endpoint.getOperation(); - if (operation == null) { - operation = exchange.getIn().getHeader(GridFsEndpoint.GRIDFS_OPERATION, String.class); - } - if (operation == null || "create".equals(operation)) { - final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); - Long chunkSize = exchange.getIn().getHeader(GridFsEndpoint.GRIDFS_CHUNKSIZE, Long.class); - - InputStream ins = exchange.getIn().getMandatoryBody(InputStream.class); - GridFSInputFile gfsFile = endpoint.getGridFs().createFile(ins, filename, true); - if (chunkSize != null && chunkSize > 0) { - gfsFile.setChunkSize(chunkSize); - } - final String ct = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class); - if (ct != null) { - gfsFile.setContentType(ct); - } - String metaData = exchange.getIn().getHeader(GridFsEndpoint.GRIDFS_METADATA, String.class); - DBObject dbObject = (DBObject) JSON.parse(metaData); - gfsFile.setMetaData(dbObject); - gfsFile.save(); - exchange.getIn().setHeader(Exchange.FILE_NAME_PRODUCED, gfsFile.getFilename()); - } else if ("remove".equals(operation)) { - final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); - endpoint.getGridFs().remove(filename); - } else if ("findOne".equals(operation)) { - final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); - GridFSDBFile file = endpoint.getGridFs().findOne(filename); - if (file != null) { - exchange.getIn().setHeader(GridFsEndpoint.GRIDFS_METADATA, JSON.serialize(file.getMetaData())); - exchange.getIn().setHeader(Exchange.FILE_CONTENT_TYPE, file.getContentType()); - exchange.getIn().setHeader(Exchange.FILE_LENGTH, file.getLength()); - exchange.getIn().setHeader(Exchange.FILE_LAST_MODIFIED, file.getUploadDate()); - exchange.getIn().setBody(file.getInputStream(), InputStream.class); - } else { - throw new FileNotFoundException("No GridFS file for " + filename); - } - } else if ("listAll".equals(operation)) { - final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); - DBCursor cursor; - if (filename == null) { - cursor = endpoint.getGridFs().getFileList(); - } else { - cursor = endpoint.getGridFs().getFileList(new BasicDBObject("filename", filename)); - } - exchange.getIn().setBody(new DBCursorFilenameReader(cursor), Reader.class); - } else if ("count".equals(operation)) { - final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); - DBCursor cursor; - if (filename == null) { - cursor = endpoint.getGridFs().getFileList(); - } else { - cursor = endpoint.getGridFs().getFileList(new BasicDBObject("filename", filename)); - } - exchange.getIn().setBody(cursor.count(), Integer.class); - } - - } - - - private class DBCursorFilenameReader extends Reader { - DBCursor cursor; - StringBuilder current; - int pos; - - DBCursorFilenameReader(DBCursor c) { - cursor = c; - current = new StringBuilder(4096); - pos = 0; - fill(); - } - void fill() { - if (pos > 0) { - current.delete(0, pos); - pos = 0; - } - while (cursor.hasNext() && current.length() < 4000) { - DBObject o = cursor.next(); - current.append(o.get("filename")).append("\t").append(o.get("_id")).append("\n"); - } - } - @Override - public int read(char[] cbuf, int off, int len) throws IOException { - if (pos == current.length()) { - fill(); - } - if (pos == current.length()) { - return -1; - } - if (len > (current.length() - pos)) { - len = current.length() - pos; - } - current.getChars(pos, pos + len, cbuf, off); - pos += len; - return len; - } - - @Override - public void close() throws IOException { - cursor.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/main/resources/META-INF/LICENSE.txt ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/main/resources/META-INF/LICENSE.txt b/components/camel-gridfs/src/main/resources/META-INF/LICENSE.txt deleted file mode 100644 index 6b0b127..0000000 --- a/components/camel-gridfs/src/main/resources/META-INF/LICENSE.txt +++ /dev/null @@ -1,203 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed 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. - http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/main/resources/META-INF/NOTICE.txt ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/main/resources/META-INF/NOTICE.txt b/components/camel-gridfs/src/main/resources/META-INF/NOTICE.txt deleted file mode 100644 index 2e215bf..0000000 --- a/components/camel-gridfs/src/main/resources/META-INF/NOTICE.txt +++ /dev/null @@ -1,11 +0,0 @@ - ========================================================================= - == NOTICE file corresponding to the section 4 d of == - == the Apache License, Version 2.0, == - == in this case for the Apache Camel distribution. == - ========================================================================= - - This product includes software developed by - The Apache Software Foundation (http://www.apache.org/). - - Please read the different LICENSE files present in the licenses directory of - this distribution. http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/main/resources/META-INF/services/org/apache/camel/component/gridfs ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/main/resources/META-INF/services/org/apache/camel/component/gridfs b/components/camel-gridfs/src/main/resources/META-INF/services/org/apache/camel/component/gridfs deleted file mode 100644 index 50df682..0000000 --- a/components/camel-gridfs/src/main/resources/META-INF/services/org/apache/camel/component/gridfs +++ /dev/null @@ -1,18 +0,0 @@ -# -# 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. -# - -class=org.apache.camel.component.gridfs.GridFsComponent http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/AbstractMongoDbTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/AbstractMongoDbTest.java b/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/AbstractMongoDbTest.java deleted file mode 100644 index f4c2bff..0000000 --- a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/AbstractMongoDbTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.gridfs; - - -import com.mongodb.MongoClient; -import com.mongodb.gridfs.GridFS; - -import org.apache.camel.CamelContext; -import org.apache.camel.component.properties.PropertiesComponent; -import org.apache.camel.spring.SpringCamelContext; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; - -public abstract class AbstractMongoDbTest extends CamelTestSupport { - - protected MongoClient mongo; - protected GridFS gridfs; - - protected ApplicationContext applicationContext; - - @SuppressWarnings("deprecation") - @Override - public void doPostSetup() { - mongo = applicationContext.getBean(MongoClient.class); - gridfs = new GridFS(mongo.getDB("test"), getBucket()); - } - - public String getBucket() { - return this.getClass().getSimpleName(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - mongo.close(); - } - - @Override - protected CamelContext createCamelContext() throws Exception { - applicationContext = new AnnotationConfigApplicationContext(EmbedMongoConfiguration.class); - CamelContext ctx = new SpringCamelContext(applicationContext); - PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties"); - ctx.addComponent("properties", pc); - return ctx; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/EmbedMongoConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/EmbedMongoConfiguration.java b/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/EmbedMongoConfiguration.java deleted file mode 100644 index d755a45..0000000 --- a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/EmbedMongoConfiguration.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.gridfs; - -import java.io.IOException; -import java.net.UnknownHostException; - -import com.mongodb.MongoClient; -import de.flapdoodle.embed.mongo.MongodExecutable; -import de.flapdoodle.embed.mongo.MongodStarter; -import de.flapdoodle.embed.mongo.config.IMongodConfig; -import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; -import de.flapdoodle.embed.mongo.config.Net; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import static de.flapdoodle.embed.mongo.distribution.Version.Main.PRODUCTION; -import static de.flapdoodle.embed.process.runtime.Network.localhostIsIPv6; -import static org.springframework.util.SocketUtils.findAvailableTcpPort; - -@Configuration -public class EmbedMongoConfiguration { - - private static final int PORT = findAvailableTcpPort(); - - static { - try { - IMongodConfig mongodConfig = new MongodConfigBuilder() - .version(PRODUCTION) - .net(new Net(PORT, localhostIsIPv6())) - .build(); - MongodExecutable mongodExecutable = MongodStarter.getDefaultInstance().prepare(mongodConfig); - mongodExecutable.start(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Bean - public MongoClient myDb() throws UnknownHostException { - return new MongoClient("0.0.0.0", PORT); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsConsumerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsConsumerTest.java b/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsConsumerTest.java deleted file mode 100644 index 64aa1d9..0000000 --- a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsConsumerTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.gridfs; - -import java.util.HashMap; -import java.util.Map; - -import com.mongodb.gridfs.GridFS; - -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; - -import org.junit.Test; - -/** - * - */ -public class GridFsConsumerTest extends AbstractMongoDbTest { - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - from("direct:create").to("gridfs:myDb?database={{mongodb.testDb}}&operation=create&bucket=" + getBucket()); - from("direct:create-a").to("gridfs:myDb?database={{mongodb.testDb}}&operation=create&bucket=" + getBucket() + "-a"); - from("direct:create-pts").to("gridfs:myDb?database={{mongodb.testDb}}&operation=create&bucket=" + getBucket() + "-pts"); - - from("gridfs:myDb?database={{mongodb.testDb}}&bucket=" + getBucket()).convertBodyTo(String.class).to("mock:test"); - from("gridfs:myDb?database={{mongodb.testDb}}&bucket=" + getBucket() + "-a&queryStrategy=FileAttribute") - .convertBodyTo(String.class).to("mock:test"); - from("gridfs:myDb?database={{mongodb.testDb}}&bucket=" + getBucket() + "-pts&queryStrategy=PersistentTimestamp") - .convertBodyTo(String.class).to("mock:test"); - } - }; - } - - - @Test - public void testTimestamp() throws Exception { - runTest("direct:create", gridfs); - } - @Test - @SuppressWarnings("deprecation") - public void testAttribute() throws Exception { - runTest("direct:create-a", new GridFS(mongo.getDB("test"), getBucket() + "-a")); - } - - @Test - @SuppressWarnings("deprecation") - public void testPersistentTS() throws Exception { - runTest("direct:create-pts", new GridFS(mongo.getDB("test"), getBucket() + "-pts")); - } - - public void runTest(String target, GridFS gridfs) throws Exception { - MockEndpoint mock = getMockEndpoint("mock:test"); - String data = "This is some stuff to go into the db"; - mock.expectedMessageCount(1); - mock.expectedBodiesReceived(data); - - Map<String, Object> headers = new HashMap<String, Object>(); - String fn = "filename.for.db.txt"; - assertEquals(0, gridfs.find(fn).size()); - - headers.put(Exchange.FILE_NAME, fn); - template.requestBodyAndHeaders(target, data, headers); - - mock.assertIsSatisfied(); - mock.reset(); - - mock.expectedMessageCount(3); - mock.expectedBodiesReceived(data, data, data); - - headers.put(Exchange.FILE_NAME, fn + "_1"); - template.requestBodyAndHeaders(target, data, headers); - headers.put(Exchange.FILE_NAME, fn + "_2"); - template.requestBodyAndHeaders(target, data, headers); - headers.put(Exchange.FILE_NAME, fn + "_3"); - template.requestBodyAndHeaders(target, data, headers); - mock.assertIsSatisfied(); - Thread.sleep(1000); - mock.assertIsSatisfied(); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsProducerOperationsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsProducerOperationsTest.java b/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsProducerOperationsTest.java deleted file mode 100644 index df7882d..0000000 --- a/components/camel-gridfs/src/test/java/org/apache/camel/component/gridfs/GridFsProducerOperationsTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * 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.gridfs; - -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class GridFsProducerOperationsTest extends AbstractMongoDbTest { - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - from("direct:create").to("gridfs:myDb?database={{mongodb.testDb}}&operation=create&bucket=" + getBucket()); - from("direct:remove").to("gridfs:myDb?database={{mongodb.testDb}}&operation=remove&bucket=" + getBucket()); - from("direct:findOne").to("gridfs:myDb?database={{mongodb.testDb}}&operation=findOne&bucket=" + getBucket()); - from("direct:listAll").to("gridfs:myDb?database={{mongodb.testDb}}&operation=listAll&bucket=" + getBucket()); - from("direct:count").to("gridfs:myDb?database={{mongodb.testDb}}&operation=count&bucket=" + getBucket()); - from("direct:headerOp").to("gridfs:myDb?database={{mongodb.testDb}}&bucket=" + getBucket()); - } - }; - } - - @Test - public void testOperations() throws Exception { - Map<String, Object> headers = new HashMap<String, Object>(); - String fn = "filename.for.db.txt"; - assertEquals(0, gridfs.find(fn).size()); - - headers.put(Exchange.FILE_NAME, fn); - String data = "This is some stuff to go into the db"; - template.requestBodyAndHeaders("direct:create", data, headers); - assertEquals(1, gridfs.find(fn).size()); - assertEquals(1, template.requestBodyAndHeaders("direct:count", null, headers)); - InputStream ins = template.requestBodyAndHeaders("direct:findOne", null, headers, InputStream.class); - assertNotNull(ins); - byte b[] = new byte[2048]; - int i = ins.read(b); - assertEquals(data, new String(b, 0, i, "utf-8")); - - headers.put(Exchange.FILE_NAME, "2-" + fn); - - template.requestBodyAndHeaders("direct:create", data + "data2", headers); - assertEquals(1, template.requestBodyAndHeaders("direct:count", null, headers)); - assertEquals(2, template.requestBody("direct:count", null, Integer.class).intValue()); - - String s = template.requestBody("direct:listAll", null, String.class); - assertTrue(s.contains("2-" + fn)); - template.requestBodyAndHeaders("direct:remove", null, headers); - assertEquals(1, template.requestBody("direct:count", null, Integer.class).intValue()); - s = template.requestBody("direct:listAll", null, String.class); - assertFalse(s.contains("2-" + fn)); - } -} - http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/test/resources/log4j.properties b/components/camel-gridfs/src/test/resources/log4j.properties deleted file mode 100644 index cb64298..0000000 --- a/components/camel-gridfs/src/test/resources/log4j.properties +++ /dev/null @@ -1,37 +0,0 @@ -# -# 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. -# - -log4j.rootLogger=INFO, file -# change the logging level of this category to increase verbosity of the MongoDB component -log4j.category.org.apache.camel.component.mongodb=INFO, file -log4j.additivity.org.apache.camel.component.mongodb=false - -# uncomment the following line to turn on Camel debugging -#log4j.logger.org.apache.camel=DEBUG - -# 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 - - -# File appender -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n -log4j.appender.file.file=target/camel-mongodb-test.log http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-gridfs/src/test/resources/mongodb.test.properties ---------------------------------------------------------------------- diff --git a/components/camel-gridfs/src/test/resources/mongodb.test.properties b/components/camel-gridfs/src/test/resources/mongodb.test.properties deleted file mode 100644 index 20c529d..0000000 --- a/components/camel-gridfs/src/test/resources/mongodb.test.properties +++ /dev/null @@ -1,21 +0,0 @@ -# -# 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. -# - -mongodb.connectionURI=mongodb://localhost:27017 -mongodb.testDb=test -mongodb.testCollection=camelTest -mongodb.cappedTestCollection=camelTestCapped \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-mongodb-gridfs/.gitignore ---------------------------------------------------------------------- diff --git a/components/camel-mongodb-gridfs/.gitignore b/components/camel-mongodb-gridfs/.gitignore new file mode 100644 index 0000000..fe30fe5 --- /dev/null +++ b/components/camel-mongodb-gridfs/.gitignore @@ -0,0 +1,3 @@ +target +*.i?? +.idea http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-mongodb-gridfs/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-mongodb-gridfs/pom.xml b/components/camel-mongodb-gridfs/pom.xml new file mode 100644 index 0000000..d52762d --- /dev/null +++ b/components/camel-mongodb-gridfs/pom.xml @@ -0,0 +1,69 @@ +<?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/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components</artifactId> + <version>2.17-SNAPSHOT</version> + </parent> + + <artifactId>camel-mongodb-gridfs</artifactId> + <packaging>bundle</packaging> + <name>Camel :: MongoDB GridFS</name> + <description>Camel MongoDB GridFS component</description> + + <properties> + <camel.osgi.export.pkg>org.apache.camel.component.gridfs.*</camel.osgi.export.pkg> + <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=gridfs</camel.osgi.export.service> + </properties> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jackson</artifactId> + </dependency> + + <dependency> + <groupId>org.mongodb</groupId> + <artifactId>mongo-java-driver</artifactId> + <version>3.2.2</version> + </dependency> + <dependency> + <groupId>de.flapdoodle.embed</groupId> + <artifactId>de.flapdoodle.embed.mongo</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java new file mode 100644 index 0000000..62701a0 --- /dev/null +++ b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java @@ -0,0 +1,64 @@ +/** + * 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.gridfs; + +import java.util.Map; + +import com.mongodb.Mongo; +import org.apache.camel.Endpoint; +import org.apache.camel.impl.UriEndpointComponent; +import org.apache.camel.util.CamelContextHelper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class GridFsComponent extends UriEndpointComponent { + + private static final Logger LOG = LoggerFactory.getLogger(GridFsComponent.class); + + private volatile Mongo db; + + public GridFsComponent() { + super(GridFsEndpoint.class); + } + + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + if (db == null) { + db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Mongo.class); + LOG.debug("Resolved the connection with the name {} as {}", remaining, db); + } + + GridFsEndpoint endpoint = new GridFsEndpoint(uri, this); + parameters.put("mongoConnection", db); + endpoint.setConnectionBean(remaining); + endpoint.setMongoConnection(db); + setProperties(endpoint, parameters); + + return endpoint; + } + + @Override + protected void doShutdown() throws Exception { + if (db != null) { + LOG.debug("Closing the connection {} on {}", db, this); + db.close(); + } + super.doShutdown(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/b4845575/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java new file mode 100644 index 0000000..bfce711 --- /dev/null +++ b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java @@ -0,0 +1,178 @@ +/** + * 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.gridfs; + +import java.io.InputStream; +import java.util.concurrent.ExecutorService; + +import com.mongodb.BasicDBObject; +import com.mongodb.BasicDBObjectBuilder; +import com.mongodb.DBCollection; +import com.mongodb.DBCursor; +import com.mongodb.DBObject; +import com.mongodb.MongoException; +import com.mongodb.gridfs.GridFSDBFile; +import com.mongodb.util.JSON; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.component.gridfs.GridFsEndpoint.QueryStrategy; +import org.apache.camel.impl.DefaultConsumer; + +/** + * + */ +public class GridFsConsumer extends DefaultConsumer implements Runnable { + final GridFsEndpoint endpoint; + private ExecutorService executor; + + /** + * @param endpoint + * @param processor + */ + public GridFsConsumer(GridFsEndpoint endpoint, Processor processor) { + super(endpoint, processor); + this.endpoint = endpoint; + } + + @Override + protected void doStop() throws Exception { + super.doStop(); + if (executor != null) { + executor.shutdown(); + executor = null; + } + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + executor = endpoint.getCamelContext().getExecutorServiceManager().newFixedThreadPool(this, endpoint.getEndpointUri(), 1); + executor.execute(this); + } + + @Override + public void run() { + DBCursor c = null; + java.util.Date fromDate = null; + + QueryStrategy s = endpoint.getQueryStrategy(); + boolean usesTimestamp = s != QueryStrategy.FileAttribute; + boolean persistsTimestamp = s == QueryStrategy.PersistentTimestamp || s == QueryStrategy.PersistentTimestampAndFileAttribute; + boolean usesAttribute = s == QueryStrategy.FileAttribute + || s == QueryStrategy.TimeStampAndFileAttribute + || s == QueryStrategy.PersistentTimestampAndFileAttribute; + + DBCollection ptsCollection = null; + DBObject persistentTimestamp = null; + if (persistsTimestamp) { + ptsCollection = endpoint.getDB().getCollection(endpoint.getPersistentTSCollection()); + // ensure standard indexes as long as collections are small + try { + if (ptsCollection.count() < 1000) { + ptsCollection.createIndex(new BasicDBObject("id", 1)); + } + } catch (MongoException e) { + //TODO: Logging + } + persistentTimestamp = ptsCollection.findOne(new BasicDBObject("id", endpoint.getPersistentTSObject())); + if (persistentTimestamp == null) { + persistentTimestamp = new BasicDBObject("id", endpoint.getPersistentTSObject()); + fromDate = new java.util.Date(); + persistentTimestamp.put("timestamp", fromDate); + ptsCollection.save(persistentTimestamp); + } + fromDate = (java.util.Date)persistentTimestamp.get("timestamp"); + } else if (usesTimestamp) { + fromDate = new java.util.Date(); + } + try { + Thread.sleep(endpoint.getInitialDelay()); + while (isStarted()) { + if (c == null || c.getCursorId() == 0) { + if (c != null) { + c.close(); + } + String queryString = endpoint.getQuery(); + DBObject query; + if (queryString == null) { + query = new BasicDBObject(); + } else { + query = (DBObject) JSON.parse(queryString); + } + if (usesTimestamp) { + query.put("uploadDate", new BasicDBObject("$gt", fromDate)); + } + if (usesAttribute) { + query.put(endpoint.getFileAttributeName(), null); + } + c = endpoint.getFilesCollection().find(query); + } + boolean dateModified = false; + while (c.hasNext() && isStarted()) { + GridFSDBFile file = (GridFSDBFile)c.next(); + GridFSDBFile forig = file; + if (usesAttribute) { + file.put(endpoint.getFileAttributeName(), "processing"); + DBObject q = BasicDBObjectBuilder.start("_id", file.getId()).append("camel-processed", null).get(); + forig = (GridFSDBFile)endpoint.getFilesCollection().findAndModify(q, null, null, false, file, true, false); + } + if (forig != null) { + file = endpoint.getGridFs().findOne(new BasicDBObject("_id", file.getId())); + + Exchange exchange = endpoint.createExchange(); + exchange.getIn().setHeader(GridFsEndpoint.GRIDFS_METADATA, JSON.serialize(file.getMetaData())); + exchange.getIn().setHeader(Exchange.FILE_CONTENT_TYPE, file.getContentType()); + exchange.getIn().setHeader(Exchange.FILE_LENGTH, file.getLength()); + exchange.getIn().setHeader(Exchange.FILE_LAST_MODIFIED, file.getUploadDate()); + exchange.getIn().setBody(file.getInputStream(), InputStream.class); + try { + getProcessor().process(exchange); + //System.out.println("Processing " + file.getFilename()); + if (usesAttribute) { + forig.put(endpoint.getFileAttributeName(), "done"); + endpoint.getFilesCollection().save(forig); + } + if (usesTimestamp) { + if (file.getUploadDate().compareTo(fromDate) > 0) { + fromDate = file.getUploadDate(); + dateModified = true; + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + if (persistsTimestamp && dateModified) { + persistentTimestamp.put("timestamp", fromDate); + ptsCollection.save(persistentTimestamp); + } + Thread.sleep(endpoint.getDelay()); + } + } catch (Throwable e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + if (c != null) { + c.close(); + } + } + +}