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;
}
Aggregations