@Override public void close() throws IOException { if (httpResponse == null) { return; } httpResponse.disconnect(); }
} finally { if (response != null) { response.disconnect();
fileContents.disconnect();
private static void disconnectQuietly(HttpResponse response) { if (response != null) { try { response.disconnect(); } catch (IOException ignored) { // ignored } } }
@Override public void close() throws IOException { if (httpResponse == null) { return; } httpResponse.disconnect(); }
@Override public void close() throws IOException { if (httpResponse == null) { return; } httpResponse.disconnect(); }
private static void disconnectQuietly(HttpResponse response) { if (response != null) { try { response.disconnect(); } catch (IOException ignored) { // ignored } } }
private static void disconnectQuietly(HttpResponse response) { if (response != null) { try { response.disconnect(); } catch (IOException ignored) { // Ignored. } } }
protected void disconnectQuitely(HttpResponse httpResponse) { if (httpResponse != null) { try { httpResponse.disconnect(); } catch (IOException exc) { //ignore } } } }
public void content(HttpResponse response) throws IOException { //Result result = response.parseAs(Result.class); System.out.println(response.getStatusCode()); System.out.println(response.getStatusMessage()); System.out.println(response.getContentType()); InputStream is = response.getContent(); int ch; while ((ch = is.read()) != -1) { System.out.print((char) ch); } response.disconnect(); }
private HttpResponse executeHttpRequest(HttpRequest httpRequest) throws IOException { HttpResponse httpResponse = null; try { httpRequest.setThrowExceptionOnExecuteError(false); return httpResponse = httpRequest.execute(); } finally { if (httpResponse != null) { try { httpResponse.disconnect(); } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to disconnect HTTP request: " + e.getMessage(), e); } } } } }
@Override public Boolean load(String bucketName) throws Exception { try { gcs.buckets() .testIamPermissions(bucketName, iamPermissions) .executeUnparsed() .disconnect(); } catch (IOException e) { return errorExtractor.userProjectMissing(e); } return false; } });
@Override public byte[] sign(byte[] payload) throws IOException { String encodedUrl = String.format(IAM_SIGN_BLOB_URL, serviceAccount); HttpResponse response = null; String encodedPayload = BaseEncoding.base64().encode(payload); Map<String, String> content = ImmutableMap.of("bytesToSign", encodedPayload); try { HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(encodedUrl), new JsonHttpContent(jsonFactory, content)); request.setParser(new JsonObjectParser(jsonFactory)); request.setResponseInterceptor(interceptor); response = request.execute(); SignBlobResponse parsed = response.parseAs(SignBlobResponse.class); return BaseEncoding.base64().decode(parsed.signature); } finally { if (response != null) { try { response.disconnect(); } catch (IOException ignored) { // Ignored } } } }
IOUtils.copy(response.getContent(), outputStream); } finally { response.disconnect();
return OAuth2Utils.headersContainValue(headers, "Metadata-Flavor", "Google"); } finally { response.disconnect();
return OAuth2Utils.headersContainValue(headers, "Metadata-Flavor", "Google"); } finally { response.disconnect();
static boolean runningOnComputeEngine(HttpTransport transport, SystemEnvironmentProvider environment) { // If the environment has requested that we do no GCE checks, return immediately. if (Boolean.parseBoolean(environment.getEnv("NO_GCE_CHECK"))) { return false; } GenericUrl tokenUrl = new GenericUrl(getMetadataServerUrl(environment)); for (int i = 1; i <= MAX_COMPUTE_PING_TRIES; ++i) { try { HttpRequest request = transport.createRequestFactory().buildGetRequest(tokenUrl); request.setConnectTimeout(COMPUTE_PING_CONNECTION_TIMEOUT_MS); HttpResponse response = request.execute(); try { HttpHeaders headers = response.getHeaders(); return headersContainValue(headers, "Metadata-Flavor", "Google"); } finally { response.disconnect(); } } catch (SocketTimeoutException expected) { // Ignore logging timeouts which is the expected failure mode in non GCE environments. } catch (IOException e) { LOGGER.log( Level.WARNING, "Failed to detect whether we are running on Google Compute Engine.", e); } } return false; }
if (response != null) { try { response.disconnect(); } catch (IOException ignored) {
} finally { if (!responseProcessed) { response.disconnect();
/** * This method sends a POST request with empty content to get the unique upload URL. * * @param initiationRequestUrl The request URL where the initiation request will be sent */ private HttpResponse executeUploadInitiation(GenericUrl initiationRequestUrl) throws IOException { updateStateAndNotifyListener(UploadState.INITIATION_STARTED); initiationRequestUrl.put("uploadType", "resumable"); HttpContent content = metadata == null ? new EmptyContent() : metadata; HttpRequest request = requestFactory.buildRequest(initiationRequestMethod, initiationRequestUrl, content); initiationHeaders.set(CONTENT_TYPE_HEADER, mediaContent.getType()); if (isMediaLengthKnown()) { initiationHeaders.set(CONTENT_LENGTH_HEADER, getMediaContentLength()); } request.getHeaders().putAll(initiationHeaders); HttpResponse response = executeCurrentRequest(request); boolean notificationCompleted = false; try { updateStateAndNotifyListener(UploadState.INITIATION_COMPLETE); notificationCompleted = true; } finally { if (!notificationCompleted) { response.disconnect(); } } return response; }