@Override public Operation call() throws Exception { try { String ritePropertiesFilename = Rite.getInstance().getProperty(Rite.PropertyKeys.HOST); Properties hostProps = new Properties(); hostProps.load(new FileInputStream(ritePropertiesFilename)); String hostname = hostProps.getProperty("hostname"); int port = Integer.parseInt(hostProps.getProperty("port")); String dbname = hostProps.getProperty("dbname"); boolean auth = Boolean.parseBoolean(hostProps.getProperty("auth")); Mongo mongo = new Mongo(hostname, port); DB db = mongo.getDB(dbname); if (auth) { String user = hostProps.getProperty("user"); String pass = hostProps.getProperty("pass"); db.authenticate(user, pass.toCharArray()); } GridFS gfs = new GridFS(db); String filename = getFileName(); File f = new File(filename); if (!f.exists()) { throw new Exception("The file " + filename + " does not exist locally!"); } int filesInDb = gfs.find(filename).size(); if (filesInDb > 0) { throw new Exception("The file " + filename + " already exists in the database!"); } GridFSInputFile gsampleFile = gfs.createFile(f); gsampleFile.setFilename(f.getName()); gsampleFile.save(); mongo.close(); } catch (Exception e) { this.setProperty( GenericOperation.PropertyKeys.ERROR, OperationUtilities.getStackTraceAsString(e)); this.fail(); this.complete(); return this; } this.complete(); return this; }