Search in sources :

Example 1 with URIBase

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);
}
Also used : CloudantClient(com.cloudant.client.api.CloudantClient) URI(java.net.URI) URIBase(com.cloudant.client.internal.URIBase) Test(org.junit.jupiter.api.Test)

Example 2 with URIBase

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URIBase(com.cloudant.client.internal.URIBase)

Example 3 with URIBase

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();
}
Also used : CouchDbUtil.getResponse(com.cloudant.client.org.lightcouch.internal.CouchDbUtil.getResponse) URIBase(com.cloudant.client.internal.URIBase)

Example 4 with URIBase

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;
}
Also used : URIBase(com.cloudant.client.internal.URIBase)

Example 5 with URIBase

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()));
}
Also used : Response(com.cloudant.client.api.model.Response) HttpConnection(com.cloudant.http.HttpConnection) Database(com.cloudant.client.api.Database) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpConnectionResponseInterceptor(com.cloudant.http.HttpConnectionResponseInterceptor) HttpConnectionInterceptorContext(com.cloudant.http.HttpConnectionInterceptorContext) URI(java.net.URI) URIBase(com.cloudant.client.internal.URIBase)

Aggregations

URIBase (com.cloudant.client.internal.URIBase)10 URI (java.net.URI)7 InputStream (java.io.InputStream)3 CloudantClient (com.cloudant.client.api.CloudantClient)1 Database (com.cloudant.client.api.Database)1 Membership (com.cloudant.client.api.model.Membership)1 Response (com.cloudant.client.api.model.Response)1 CouchDbUtil.getResponse (com.cloudant.client.org.lightcouch.internal.CouchDbUtil.getResponse)1 HttpConnection (com.cloudant.http.HttpConnection)1 HttpConnectionInterceptorContext (com.cloudant.http.HttpConnectionInterceptorContext)1 HttpConnectionResponseInterceptor (com.cloudant.http.HttpConnectionResponseInterceptor)1 JsonObject (com.google.gson.JsonObject)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.jupiter.api.Test)1