conn.responseInterceptors.remove(this); HttpConnection connection = conn.execute(); int responseCode = connection.getConnection().getResponseCode();
public static boolean isCouchDBV2(URI uri) throws URISyntaxException, IOException { URI root = new URI(uri.getScheme() + "://" + uri.getAuthority()); HttpConnection connection = Http.GET(root); String response = connection.execute().responseAsString(); return response.contains("\"version\":\"2."); }
inputStream = connection.execute().responseAsInputStream(); } catch (IOException ioe) { cause = ioe;
public static List<String> getRemoteRevisionIDs(URI uri, CouchConfig config) throws Exception{ HttpConnection connection = Http.GET(uri); connection.requestInterceptors.addAll(config.getRequestInterceptors()); connection.responseInterceptors.addAll(config.getResponseInterceptors()); InputStream in = connection.execute().responseAsInputStream(); Map<String, Object> m = JSONUtils.fromJson(new InputStreamReader(in)); List<Object> revsInfo = (List<Object>)m.get("_revs_info"); List<String> revisions = new ArrayList<String>(revsInfo.size()); for(Object rev : revsInfo){ revisions.add(((Map<String, String>)rev).get("rev")); } return revisions; }
connection = connection.execute(); } catch (HttpConnectionInterceptorException e) { CouchDbException exception = new CouchDbException(connection.getConnection()
@Test public void testExpect100Continue() throws Exception { CouchConfig config = getCouchConfig("no_such_database"); HttpConnection conn = postAndAssertNothingReadBeforeSettingBodyGenerator(config); boolean thrown = false; try { conn.execute(); } catch (IOException ioe) { // ProtocolException with message "Server rejected operation" on JDK 1.7 thrown = true; } if (thrown) { // still nothing read from stream Assert.assertEquals(bis.available(), data.getBytes().length); } }
public static int executeHttpPostRequest(URI uri, String payload, CouchConfig config) { HttpConnection connection = Http.POST(uri, "application/json"); connection.requestInterceptors.addAll(config.getRequestInterceptors()); connection.responseInterceptors.addAll(config.getResponseInterceptors()); try { connection.setRequestBody(payload); connection.execute(); } catch (Exception e) { ; // ignore exception } try { return connection.getConnection().getResponseCode(); } catch (Exception e) { System.out.println("*** got ex "+e); return 0; } }
@TestTemplate public void testWriteToServerOk() throws Exception { HttpConnection conn = new HttpConnection("POST", new URL(dbResource.getDbURIWithUserInfo()), "application/json"); ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes()); // nothing read from stream assertEquals(data.getBytes().length, bis.available()); conn.setRequestBody(bis); HttpConnection response = conn.execute(); // Consume response stream String responseStr = response.responseAsString(); String okPattern = ".*\"ok\"\\s*:\\s*true.*"; assertTrue(Pattern.compile(okPattern, Pattern.DOTALL).matcher(responseStr).matches(), "There should be an ok response: " + "" + responseStr); // stream was read to end assertEquals(0, bis.available()); assertEquals(2, response.getConnection().getResponseCode () / 100, "Should be a 2XX response code"); }
@TestTemplate @RequiresCloudant public void testCookieAuthWithoutRetry() throws IOException { CookieInterceptor interceptor = new CookieInterceptor(CloudantClientHelper.COUCH_USERNAME, CloudantClientHelper.COUCH_PASSWORD, clientResource.get().getBaseUri().toString()); HttpConnection conn = new HttpConnection("POST", dbResource.get().getDBUri().toURL(), "application/json"); conn.responseInterceptors.add(interceptor); conn.requestInterceptors.add(interceptor); ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes()); // nothing read from stream assertEquals(data.getBytes().length, bis.available()); conn.setRequestBody(bis); HttpConnection responseConn = conn.execute(); // stream was read to end assertEquals(0, bis.available()); assertEquals(2, responseConn.getConnection().getResponseCode() / 100); //check the json Gson gson = new Gson(); InputStream is = responseConn.responseAsInputStream(); try { JsonObject response = gson.fromJson(new InputStreamReader(is), JsonObject.class); assertTrue(response.has("ok")); assertTrue(response.get("ok").getAsBoolean()); assertTrue(response.has("id")); assertTrue(response.has("rev")); } finally { is.close(); } }
HttpConnection responseConn = conn.execute();
conn.responseInterceptors.add(interceptor); conn.requestInterceptors.add(interceptor); conn.execute();
@Test public void testWriteToServerOk() throws Exception { CouchConfig config = getCouchConfig("httptest" + System.currentTimeMillis()); CouchClient client = new CouchClient(config.getRootUri(), config.getRequestInterceptors() , config.getResponseInterceptors()); client.createDb(); HttpConnection conn = postAndAssertNothingReadBeforeSettingBodyGenerator(config); conn.execute(); // stream was read to end Assert.assertEquals(bis.available(), 0); client.deleteDb(); }
conn = conn.execute();