space.setProperties(extractPropertiesFromHeaders(response)); String responseText = response.getResponseBody(); if (responseText != null) { InputStream is =
"error: Response was null."); int statusCode = response.getStatusCode(); if (statusCode != expectedCode) { String errorMessage; try { errorMessage = response.getResponseBody(); } catch(IOException e) { errorMessage = "";
private void retryFromNextByte() throws IOException { log.info( "Failed to read byte at position {} (space: {}, contentId: {}, startByte:{}, endByte: {}. " + "Starting attempts to re-acquire stream from current position.", nextBytePos, spaceId, contentId, startByte, endByte); try { //exponential backoff on retries new Retrier(5, 4000, 3).execute(() -> { RestHttpHelper.HttpResponse response = contentStore.doGetContent(spaceId, contentId, nextBytePos, endByte); currentStream = response.getResponseStream(); log.info( "Successfully re-acquired stream (space: {}, contentId: {}, nextBytePos:{}," + " endByte: {}. ", spaceId, contentId, nextBytePos, endByte); return null; }); } catch (Exception e) { log.warn( "Exhausted max retries to re-acquire stream (space: {}, contentId: {}, nextBytePos:{}," + " endByte: {}. ", spaceId, contentId, nextBytePos, endByte, e); throw new IOException(e.getMessage(), e); } }
checkResponse(response, HttpStatus.SC_CREATED); Header checksum = response.getResponseHeader(HttpHeaders.CONTENT_MD5); if (checksum == null) { checksum = response.getResponseHeader(HttpHeaders.ETAG);
checkResponse(response, HttpStatus.SC_CREATED); Header checksum = response.getResponseHeader(HttpHeaders.CONTENT_MD5); if (checksum == null) { checksum = response.getResponseHeader(HttpHeaders.ETAG);
HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); String responseText = response.getResponseBody(); if (responseText != null) { List<String> spaceIds = new ArrayList<String>();
@Override public BitIntegrityReport getBitIntegrityReport(String spaceId) throws ContentStoreException { String task = "get bit integrity report"; String url = buildBitIntegrityReportURL(spaceId); try { HttpResponse response = restHelper.get(url); if (hasNoContent(response)) { return null; } checkResponse(response, HttpStatus.SC_OK); //This is a workaround for duracloud-1137 //for reasons that are not clear, in the beanstalk environment //the httpclient is swallowing the Content-Length header //leading the BitIntegrityReportProperties.getSize() method to //return 0. This appears to be the case only on the GET call. //To work around it, we are loading the properties with a separate //call that uses the HEAD path. BitIntegrityReportProperties properties = getBitIntegrityReportProperties(spaceId); BitIntegrityReport report = new BitIntegrityReport(response.getResponseStream(), properties); return report; } catch (UnauthorizedException e) { throw new UnauthorizedException(task, spaceId, e); } catch (Exception e) { throw new ContentStoreException(task, spaceId, e); } }
try { response = getRestHelper().get(url); if (response.getStatusCode() == HttpStatus.SC_OK) { String storesXML = response.getResponseBody(); if (storesXML != null) { InputStream xmlStream = error += "Response code was " + response.getStatusCode() + ", expected value was " + HttpStatus.SC_OK + ". Response Body: " + response.getResponseBody(); throw new StorageException(error);
throw new ContentStoreException("Response content was null."); int responseCode = response.getStatusCode(); if (responseCode != expectedCode) { String errMsg = ""; try { errMsg += response.getResponseBody(); } catch (IOException e) {
headers.put(HttpHeaders.CONTENT_TYPE, "application/json"); RestHttpHelper.HttpResponse response = restHelper.put(snapshotURL, snapshotBody, headers); int statusCode = response.getStatusCode(); if (statusCode != 200 && statusCode != 201) { String responseStr = response.getResponseBody(); return response.getResponseBody();
@Override public String scheduleStorageReport(Date startTime, long frequency) throws ReportException { if(null == startTime) { throw new ReportException("Start time may not be null"); } if(startTime.before(new Date())) { throw new ReportException("Start time must be in the future"); } if(frequency < 600000) { throw new ReportException("Frequency must be higher than " + "600000 milliseconds (10 minutes)"); } String url = buildScheduleStorageReportURL(startTime.getTime(), frequency); try { RestHttpHelper.HttpResponse response = getRestHelper() .post(url, null, null); checkResponse(response, HttpStatus.SC_OK); return response.getResponseBody(); } catch (Exception e) { String error = "Could not schedule storage report due to: " + e.getMessage(); throw new ReportException(error, e); } }
protected String callBridge(RestHttpHelper restHelper, String snapshotURL, String snapshotBody) { log.info("Making RESTORE call to URL {} with body {}", snapshotURL, snapshotBody); try { Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, "application/json"); RestHttpHelper.HttpResponse response = restHelper.put(snapshotURL, snapshotBody, headers); int statusCode = response.getStatusCode(); if (statusCode != 201) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "initiate snapshot request. " + "Error reported: " + e.getMessage(), e); } }
private Map<String, String> extractNonPropertiesHeaders(HttpResponse response) { Map<String, String> headers = new HashMap<String, String>(); for (Header header : response.getResponseHeaders()) { String name = header.getName(); if (!name.startsWith(HEADER_PREFIX)) { if (name.equals(HttpHeaders.CONTENT_TYPE)) { headers.put(CONTENT_MIMETYPE, header.getValue()); } else if (name.equals(HttpHeaders.CONTENT_MD5) || name.equals(HttpHeaders.ETAG)) { headers.put(CONTENT_CHECKSUM, header.getValue()); } else if (name.equals(HttpHeaders.CONTENT_LENGTH)) { headers.put(CONTENT_SIZE, header.getValue()); } else if (name.equals(HttpHeaders.LAST_MODIFIED)) { headers.put(CONTENT_MODIFIED, header.getValue()); } else if (name.equals(CONTENT_ENCODING)) { headers.put(CONTENT_ENCODING, header.getValue()); } } } return headers; }
@Override public List<String> getStorageReportList() throws ReportException { String url = buildGetStorageReportListURL(); try { RestHttpHelper.HttpResponse response = getRestHelper().get(url); checkResponse(response, HttpStatus.SC_OK); InputStream listXml = response.getResponseStream(); StorageReportList reportList = new StorageReportListSerializer().deserialize(listXml); List<String> reportIds = reportList.getStorageReportList(); if(null == reportIds) { reportIds = new ArrayList<String>(); } return reportIds; } catch (Exception e) { String error = "Could not get storage report list due to: " + e.getMessage(); throw new ReportException(error, e); } }
protected String callBridge(RestHttpHelper restHelper, String snapshotURL, String snapshotBody) { log.info("Making RESTORE call to URL {} with body {}", snapshotURL, snapshotBody); try { Map<String, String> headers = new HashMap<>(); headers.put(HttpHeaders.CONTENT_TYPE, "application/json"); RestHttpHelper.HttpResponse response = restHelper.put(snapshotURL, snapshotBody, headers); int statusCode = response.getStatusCode(); if (statusCode != 201) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "initiate snapshot request. " + "Error reported: " + e.getMessage(), e); } }
private void validate(RestHttpHelper.HttpResponse response, String name) { if (null == response || response.getStatusCode() != 200) { String body = null; try { body = response.getResponseBody(); } catch (IOException e) { } finally { StringBuilder msg = new StringBuilder("error initializing "); msg.append(name); msg.append(" (" + response.getStatusCode() + ")"); if (null != body) { msg.append("\n"); msg.append(body); } log.error(msg.toString()); throw new DuraCloudRuntimeException(msg.toString()); } } }
@Override public SpaceStatsDTOList getStorageProviderStats(Date start, Date end) throws ContentStoreException { String url = buildStorageProviderStatsURL(start, end); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); String body = response.getResponseBody(); JaxbJsonSerializer<SpaceStatsDTOList> serializer = new JaxbJsonSerializer<>(SpaceStatsDTOList.class); return serializer.deserialize(body); } catch (NotFoundException e) { throw new NotFoundException("storeId = " + getStoreId()); } catch (UnauthorizedException e) { throw new UnauthorizedException(getStoreId(), e); } catch (Exception e) { throw new ContentStoreException("failed to retrieve storage provider stats for " + getStoreId(), e); } }
private BitIntegrityReportProperties extractBitIntegrityProperties(HttpResponse response) throws ParseException { BitIntegrityReportProperties properties = new BitIntegrityReportProperties(); for (Header header : response.getResponseHeaders()) { String name = header.getName(); if (name.equals(HttpHeaders.BIT_INTEGRITY_REPORT_RESULT)) { properties.setResult(BitIntegrityReportResult.valueOf(header.getValue())); } else if (name.equals(HttpHeaders.BIT_INTEGRITY_REPORT_COMPLETION_DATE)) { SimpleDateFormat format = new SimpleDateFormat(DateFormat.DEFAULT_FORMAT.getPattern()); properties.setCompletionDate(format.parse(header.getValue())); } else if (name.equals(HttpHeaders.CONTENT_LENGTH)) { properties.setSize(Long.valueOf(header.getValue())); } } return properties; }
@Override public InputStream getAuditLog(String spaceId) throws ContentStoreException { String task = "get manifest"; String url = buildAuditLogURL(spaceId); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); return response.getResponseStream(); } catch (NotFoundException e) { throw new NotFoundException(task, spaceId, e); } catch (UnauthorizedException e) { throw new UnauthorizedException(task, spaceId, e); } catch (Exception e) { throw new ContentStoreException(task, spaceId, e); } }
@Override public InputStream getManifest(String spaceId, ManifestFormat format) throws ContentStoreException { String task = "get manifest"; String url = buildManifestURL(spaceId, format); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); return response.getResponseStream(); } catch (NotFoundException e) { throw new NotFoundException(task, spaceId, e); } catch (UnauthorizedException e) { throw new UnauthorizedException(task, spaceId, e); } catch (Exception e) { throw new ContentStoreException(task, spaceId, e); } }