Search in sources :

Example 1 with StdHttpClient

use of org.ektorp.http.StdHttpClient in project pac4j by pac4j.

the class CouchServer method start.

public CouchDbConnector start() {
    InMemoryCouchDb couchDbClient = new InMemoryCouchDb();
    couchDbClient.createDatabase("users");
    StdHttpClient stdHttpClient = new StdHttpClient(couchDbClient);
    StdCouchDbInstance stdCouchDbInstance = new StdCouchDbInstance(stdHttpClient);
    StdCouchDbConnector couchDbConnector = new StdCouchDbConnector("users", stdCouchDbInstance);
    couchDbConnector.createDatabaseIfNotExists();
    // uploading design doc:
    String designDocString = "{\"_id\":\"_design/pac4j\",\"language\":\"javascript\",\"views\":{\"by_username\":{\"map\":\"" + "function(doc){if (doc.username) emit(doc.username, doc);}\"},\"by_linkedid\":{\"map\":\"function(doc) {" + "if (doc.linkedid) emit(doc.linkedid, doc);}\"}}}";
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        couchDbConnector.create(objectMapper.readTree(designDocString));
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return couchDbConnector;
}
Also used : InMemoryCouchDb(mcouch.core.InMemoryCouchDb) StdHttpClient(org.ektorp.http.StdHttpClient) StdCouchDbInstance(org.ektorp.impl.StdCouchDbInstance) StdCouchDbConnector(org.ektorp.impl.StdCouchDbConnector) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 InMemoryCouchDb (mcouch.core.InMemoryCouchDb)1 StdHttpClient (org.ektorp.http.StdHttpClient)1 StdCouchDbConnector (org.ektorp.impl.StdCouchDbConnector)1 StdCouchDbInstance (org.ektorp.impl.StdCouchDbInstance)1