use of com.cloudant.http.HttpConnection in project java-cloudant by cloudant.
the class CouchDbClient method get.
/**
* Performs a HTTP GET request.
*
* @return Class type of object T (i.e. {@link Response}
*/
public <T> T get(URI uri, Class<T> classType) {
HttpConnection connection = Http.GET(uri);
InputStream response = executeToInputStream(connection);
try {
return getResponse(response, classType, getGson());
} finally {
close(response);
}
}
use of com.cloudant.http.HttpConnection 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()));
}
use of com.cloudant.http.HttpConnection in project java-cloudant by cloudant.
the class Database method deleteIndex.
/**
* Delete an index with the specified name and type in the given design document.
*
* @param indexName name of the index
* @param designDocId ID of the design doc (the _design prefix will be added if not present)
* @param type type of the index, valid values or "text" or "json"
*/
public void deleteIndex(String indexName, String designDocId, String type) {
assertNotEmpty(indexName, "indexName");
assertNotEmpty(designDocId, "designDocId");
assertNotNull(type, "type");
if (!designDocId.startsWith("_design")) {
designDocId = "_design/" + designDocId;
}
URI uri = new DatabaseURIHelper(db.getDBUri()).path("_index").path(designDocId).path(type).path(indexName).build();
InputStream response = null;
try {
HttpConnection connection = Http.DELETE(uri);
response = client.couchDbClient.executeToInputStream(connection);
getResponse(response, Response.class, client.getGson());
} finally {
close(response);
}
}
use of com.cloudant.http.HttpConnection in project java-cloudant by cloudant.
the class Search method queryForStream.
// Query options
/**
* Performs a Cloudant Search and returns the result as an {@link InputStream}
*
* @param query the Lucene query to be passed to the Search index
* <p>The stream should be properly closed after usage, as to avoid connection
* leaks.
* @return The result as an {@link InputStream}.
*/
public InputStream queryForStream(String query) {
key(query);
URI uri = databaseHelper.build();
HttpConnection get = Http.GET(uri);
get.requestProperties.put("Accept", "application/json");
return client.couchDbClient.executeToInputStream(get);
}
use of com.cloudant.http.HttpConnection in project java-cloudant by cloudant.
the class HttpTest method inputStreamRetryString.
@TestTemplate
public void inputStreamRetryString() throws Exception {
HttpConnection request = Http.POST(mockWebServer.url("/").url(), "application/json");
String content = "abcde";
request.setRequestBody(content);
testInputStreamRetry(request, content.getBytes("UTF-8"));
}
Aggregations