use of com.cloudant.client.internal.URIBase in project java-cloudant by cloudant.
the class URIBaseTest method buildAccountUri_noTrailingPathSeparator.
@Test
public void buildAccountUri_noTrailingPathSeparator() throws Exception {
CloudantClient client = ClientBuilder.url(clientResource.get().getBaseUri().toURL()).build();
Assertions.assertFalse(client.getBaseUri().toString().endsWith("/"));
URI clientUri = new URIBase(client.getBaseUri()).build();
Assertions.assertFalse(clientUri.toString().endsWith("/"));
// Check that path is not missing / separators
clientUri = new URIBase(client.getBaseUri()).path("").path("api").path("couch").build();
URI expectedAccountUri = new URI(clientResource.get().getBaseUri().toString() + "/api/couch");
Assertions.assertEquals(expectedAccountUri, clientUri);
}
use of com.cloudant.client.internal.URIBase in project java-cloudant by cloudant.
the class CouchDbClient method getAllDbs.
/**
* @return All Server databases.
*/
public List<String> getAllDbs() {
InputStream instream = null;
try {
instream = get(new URIBase(clientUri).path("_all_dbs").build());
Reader reader = new InputStreamReader(instream, "UTF-8");
return getGson().fromJson(reader, DeserializationTypes.STRINGS);
} catch (UnsupportedEncodingException e) {
// to support UTF-8.
throw new RuntimeException(e);
} finally {
close(instream);
}
}
use of com.cloudant.client.internal.URIBase in project java-cloudant by cloudant.
the class CouchDbClient method shutdown.
/**
* Shuts down and releases resources used by this couchDbClient instance.
* Note: Apache's httpclient was replaced by HttpUrlConnection.
* Connection manager is no longer used.
*/
public void shutdown() {
// Delete the cookie _session if there is one
Response response = executeToResponse(Http.DELETE(new URIBase(clientUri).path("_session").build()));
if (!response.isOk()) {
log.warning("Error deleting session on client shutdown.");
}
// The execute method handles non-2xx response codes by throwing a CouchDbException.
factory.shutdown();
}
use of com.cloudant.client.internal.URIBase in project java-cloudant by cloudant.
the class Replicator method replicatorDB.
public Replicator replicatorDB(String replicatorDB) {
this.replicatorDB = replicatorDB;
dbURI = new URIBase(client.getBaseUri()).path(replicatorDB).build();
return this;
}
use of com.cloudant.client.internal.URIBase in project java-cloudant by cloudant.
the class Utils method removeReplicatorTestDoc.
public static void removeReplicatorTestDoc(CloudantClient account, String replicatorDocId) throws Exception {
// Grab replicator doc revision using HTTP HEAD command
String replicatorDb = "_replicator";
URI uri = new URIBase(account.getBaseUri()).path(replicatorDb).path(replicatorDocId).build();
HttpConnection head = Http.HEAD(uri);
// add a response interceptor to allow us to retrieve the ETag revision header
final AtomicReference<String> revisionRef = new AtomicReference<String>();
head.responseInterceptors.add(new HttpConnectionResponseInterceptor() {
@Override
public HttpConnectionInterceptorContext interceptResponse(HttpConnectionInterceptorContext context) {
revisionRef.set(context.connection.getConnection().getHeaderField("ETag"));
return context;
}
});
account.executeRequest(head);
String revision = revisionRef.get();
assertNotNull("The revision should not be null", revision);
Database replicator = account.database(replicatorDb, false);
Response removeResponse = replicator.remove(replicatorDocId, revision.replaceAll("\"", ""));
assertThat(removeResponse.getError(), is(nullValue()));
}
Aggregations