Example usage for com.mongodb MongoClientURI MongoClientURI

List of usage examples for com.mongodb MongoClientURI MongoClientURI

Introduction

In this page you can find the example usage for com.mongodb MongoClientURI MongoClientURI.

Prototype

public MongoClientURI(final String uri) 

Source Link

Document

Creates a MongoURI from the given string.

Usage

From source file:org.netbeans.modules.mongodb.ui.components.MongoURIEditorPanel.java

License:Open Source License

public boolean valid() {
    try {//from  w w w.ja  va 2  s . c  o m
        return new MongoClientURI(computeMongoURIString()) != null;
    } catch (IllegalArgumentException ex) {
        return false;
    }
}

From source file:org.netbeans.modules.mongodb.ui.components.MongoURIEditorPanel.java

License:Open Source License

public MongoClientURI getMongoURI() {
    return new MongoClientURI(uriField.getText().trim());
}

From source file:org.netbeans.modules.mongodb.ui.components.NewConnectionPanel.java

License:Open Source License

@Override
protected String computeValidationProblem() {
    final String name = getConnectionName();
    if (name.isEmpty()) {
        return Bundle.ConnectionNameNotSet();
    }/*from   www  . j  av a  2 s  .  co m*/
    try {
        lastValidURI = new MongoClientURI(uriField.getText().trim());
    } catch (IllegalArgumentException ex) {
        return ex.getLocalizedMessage();
    }
    return null;
}

From source file:org.nuxeo.ecm.core.storage.mongodb.GridFSBinaryManager.java

License:Apache License

@Override
public void initialize(String blobProviderId, Map<String, String> properties) throws IOException {
    super.initialize(blobProviderId, properties);
    this.properties = properties;
    String server = properties.get(SERVER_PROPERTY);
    if (StringUtils.isBlank(server)) {
        throw new NuxeoException(
                "Missing server property in GridFS Binary Manager descriptor: " + blobProviderId);
    }/*  w w  w  . j av a 2  s . c  o m*/
    String dbname = properties.get(DBNAME_PROPERTY);
    if (StringUtils.isBlank(dbname)) {
        throw new NuxeoException(
                "Missing dbname property in GridFS Binary Manager descriptor: " + blobProviderId);
    }
    String bucket = properties.get(BUCKET_PROPERTY);
    if (StringUtils.isBlank(bucket)) {
        bucket = blobProviderId + ".fs";
    }
    if (server.startsWith("mongodb://")) {
        client = new MongoClient(new MongoClientURI(server));
    } else {
        client = new MongoClient(new ServerAddress(server));
    }
    gridFS = new GridFS(client.getDB(dbname), bucket);
    garbageCollector = new GridFSBinaryGarbageCollector();
}

From source file:org.nuxeo.tools.esync.db.DbMongo.java

License:Open Source License

private MongoCollection<org.bson.Document> getMongoCollection() {
    if (mongoCollection == null) {
        log.debug("Connect to mongoClient: " + uri + " on org.nuxeo.tools.esync.db: " + dbName
                + " mongoCollection: " + collectionName + " from " + getHostName());
        try {/*from w  ww .  j a  va 2 s  .co m*/
            if (mongoClient == null) {
                mongoClient = new MongoClient(new MongoClientURI(uri));
            }
            MongoDatabase db = mongoClient.getDatabase(dbName);
            mongoCollection = db.getCollection(collectionName);
        } catch (MongoException e) {
            log.error("Failed to connect to " + uri, e);
            throw new RuntimeException(e.getMessage());
        }
    }
    assert (mongoCollection != null);
    return mongoCollection;
}

From source file:org.onebusaway.gtfs_realtime.producer_demo.GtfsRealtimeProviderImpl.java

License:Apache License

/**
 * @param url is a string pointing to our MongoDB (w/ authentication)
 *//*from   w  ww.ja  v  a  2  s. co m*/
public void setMongo(String url) throws IOException {
    MongoClientURI uri = new MongoClientURI(url);
    System.out.println(uri);
    _client = new MongoClient(uri);
}

From source file:org.openhab.persistence.mongodb.internal.MongoDBPersistenceService.java

License:Open Source License

/**
 * Connects to the database/*from   www.  jav  a 2 s .c om*/
 */
private void connectToDatabase() {
    try {
        logger.debug("Connect MongoDB");
        this.cl = new MongoClient(new MongoClientURI(this.url));
        mongoCollection = cl.getDB(this.db).getCollection(this.collection);

        BasicDBObject idx = new BasicDBObject();
        idx.append(FIELD_TIMESTAMP, 1).append(FIELD_ITEM, 1);
        this.mongoCollection.createIndex(idx);
        logger.debug("Connect MongoDB ... done");
    } catch (Exception e) {
        logger.error("Failed to connect to database {}", this.url);
        throw new RuntimeException("Cannot connect to database", e);
    }
}

From source file:org.opentestsystem.delivery.AccValidator.handlers.ValidationHandler.java

License:Open Source License

/**
 * @return/*  ww  w .ja va 2  s . com*/
 */
private DB getMongoDBConnection() throws StoringException {
    MongoClient mongoClient = null;
    DB database = null;
    try {

        MongoClientURI uri = null;

        if (!_userName.equalsIgnoreCase(EMPTY) && !_password.equalsIgnoreCase(EMPTY)) {
            uri = new MongoClientURI("mongodb://" + _userName + ":" + _password + "@" + _hostName + ":" + _port
                    + "/?authSource=" + _databaseName);
        } else {
            uri = new MongoClientURI("mongodb://" + _hostName + ":" + _port);
        }
        mongoClient = new MongoClient(uri);
        database = mongoClient.getDB(_databaseName);
    } catch (UnknownHostException e) {
        throw new StoringException(e.getMessage());
    } catch (CommandFailureException e) {

        if (e.getCode() == 18) {
            throw new StoringException("Authentication Exception:Invalid Credentials");
        } else {
            throw new StoringException(e.getMessage());
        }
    } catch (Exception e) {
        throw new StoringException(e.getMessage());
    }

    return database;
}

From source file:org.pentaho.mongo.wrapper.MongoAtlasClientWrapper.java

License:Open Source License

MongoAtlasClientWrapper(MongoProperties props, MongoUtilLogger log) throws MongoDbException {
    this.log = log;
    this.props = props;

    String uri = new StringBuilder("mongodb://").append(props.get(MongoProp.USERNAME)).append(":")
            .append(props.get(MongoProp.PASSWORD)).append("@").append(props.get(MongoProp.HOST)).toString();
    this.mongoClientURI = new MongoClientURI(uri);
    this.mongo = new MongoClient(mongoClientURI);
}

From source file:org.restheart.Configuration.java

License:Open Source License

/**
 * Creates a new instance of Configuration with defaults values.
 *//*w ww  .ja v  a2 s . c  o m*/
public Configuration() {
    httpsListener = true;
    httpsPort = DEFAULT_HTTPS_PORT;
    httpsHost = DEFAULT_HTTPS_HOST;

    httpListener = true;
    httpPort = DEFAULT_HTTP_PORT;
    httpHost = DEFAULT_HTTP_HOST;

    ajpListener = false;
    ajpPort = DEFAULT_AJP_PORT;
    ajpHost = DEFAULT_AJP_HOST;

    instanceName = DEFAULT_INSTANCE_NAME;

    defaultRepresentationFromat = DEFAULT_REPRESENTATION_FORMAT;

    useEmbeddedKeystore = true;
    keystoreFile = null;
    keystorePassword = null;
    certPassword = null;

    mongoUri = new MongoClientURI(DEFAULT_MONGO_URI);

    mongoMounts = new ArrayList<>();
    Map<String, Object> defaultMongoMounts = new HashMap<>();
    defaultMongoMounts.put(MONGO_MOUNT_WHAT_KEY, "*");
    defaultMongoMounts.put(MONGO_MOUNT_WHERE_KEY, "/");
    mongoMounts.add(defaultMongoMounts);

    applicationLogicMounts = new ArrayList<>();

    staticResourcesMounts = new ArrayList<>();

    metadataNamedSingletons = new ArrayList<>();

    HashMap<String, Object> browserStaticResourcesMountArgs = new HashMap<>();

    browserStaticResourcesMountArgs.put(STATIC_RESOURCES_MOUNT_WHAT_KEY, "browser");
    browserStaticResourcesMountArgs.put(STATIC_RESOURCES_MOUNT_WHERE_KEY, "/browser");
    browserStaticResourcesMountArgs.put(STATIC_RESOURCES_MOUNT_WELCOME_FILE_KEY, "browser.html");
    browserStaticResourcesMountArgs.put(STATIC_RESOURCES_MOUNT_SECURED_KEY, false);
    browserStaticResourcesMountArgs.put(STATIC_RESOURCES_MOUNT_EMBEDDED_KEY, true);

    staticResourcesMounts.add(browserStaticResourcesMountArgs);

    idmImpl = null;
    idmArgs = null;

    amImpl = null;
    amArgs = null;

    logFilePath = URLUtils.removeTrailingSlashes(System.getProperty("java.io.tmpdir"))
            .concat(File.separator + "restheart.log");
    logToConsole = true;
    logToFile = true;
    logLevel = Level.INFO;

    localCacheEnabled = true;
    localCacheTtl = 1000;

    schemaCacheEnabled = false;
    schemaCacheTtl = 1000;

    requestsLimit = 100;
    ioThreads = 2;
    workerThreads = 32;
    bufferSize = 16384;
    buffersPerRegion = 20;
    directBuffers = true;

    forceGzipEncoding = false;

    eagerPoolSize = 100;
    eagerLinearSliceWidht = 1000;
    eagerLinearSliceDelta = 100;
    eagerLinearSliceHeights = new int[] { 4, 2, 1 };
    eagerRndSliceMinWidht = 1000;
    eagerRndMaxCursors = 50;

    authTokenEnabled = true;
    authTokenTtl = 15; // minutes

    dbEtagCheckPolicy = DEFAULT_DB_ETAG_CHECK_POLICY;
    collEtagCheckPolicy = DEFAULT_COLL_ETAG_CHECK_POLICY;
    docEtagCheckPolicy = DEFAULT_DOC_ETAG_CHECK_POLICY;

    logExchangeDump = 0;

    connectionOptions = Maps.newHashMap();
}