protected RestHttpHelper getRestHelper() { if (null == restHelper) { restHelper = new RestHttpHelper(this.socketTimeoutMs); } return restHelper; }
private boolean hasNoContent(HttpResponse response) { return (response.getStatusCode() == HttpStatus.SC_NO_CONTENT); }
private String addQueryParameter(String url, String name, String value) { if (value != null && !value.equals("")) { if (url.contains("?")) { url += "&"; } else { url += "?"; } url += (name + "=" + EncodeUtil.urlEncode(value)); } return url; }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot status. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get snapshot. " + "Error reported: " + e.getMessage(), e); } }
public HttpResponse initializeDurastore(String host, String port, String context) throws Exception { String baseURL = "http://" + host + ":" + port + "/" + context; String storesURL = baseURL + "/stores"; String xml = buildTestAccountXml(); RestHttpHelper restHelper = new RestHttpHelper(getRootCredential()); return restHelper.post(storesURL, xml, null); }
@Override public String startStorageReport() throws ReportException { String url = buildBaseStorageReportURL(); try { RestHttpHelper.HttpResponse response = getRestHelper() .post(url, null, null); checkResponse(response, HttpStatus.SC_OK); return response.getResponseBody(); } catch (Exception e) { String error = "Could not start storage report due to: " + e.getMessage(); throw new ReportException(error, e); } }
@Override public String cancelStorageReportSchedule() throws ReportException { String url = buildCancelStorageReportScheduleURL(); try { RestHttpHelper.HttpResponse response = getRestHelper().delete(url); checkResponse(response, HttpStatus.SC_OK); return response.getResponseBody(); } catch (Exception e) { String error = "Could not cancel storage report schedule due to: " + e.getMessage(); throw new ReportException(error, e); } }
@Override public SpaceStatsDTOList getStorageProviderStatsByDay(Date date) throws ContentStoreException { String url = buildStorageProviderStatsURL(date); 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 (UnauthorizedException e) { throw new UnauthorizedException(storeId, e); } catch (Exception e) { throw new ContentStoreException("failed to retrieve storage provider stats for " + storeId, e); } }
@Override public StorageReportInfo getStorageReportInfo() throws ReportException { String url = buildGetStorageReportInfoURL(); try { RestHttpHelper.HttpResponse response = getRestHelper().get(url); checkResponse(response, HttpStatus.SC_OK); InputStream reportInfoXml = response.getResponseStream(); StorageReportInfoSerializer serializer = new StorageReportInfoSerializer(); return serializer.deserialize(reportInfoXml); } catch (Exception e) { String error = "Could not get storage report info due to: " + e.getMessage(); throw new ReportException(error, e); } }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get restore status. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get restore. " + "Error reported: " + e.getMessage(), e); } }
protected RestHttpHelper getRestHelper() { if (null == this.restHelper) { this.restHelper = new RestHttpHelper(); } return this.restHelper; }
@Override public String cancelStorageReport() throws ReportException { String url = buildBaseStorageReportURL(); try { RestHttpHelper.HttpResponse response = getRestHelper().delete(url); checkResponse(response, HttpStatus.SC_OK); return response.getResponseBody(); } catch (Exception e) { String error = "Could not cancel storage report due to: " + e.getMessage(); throw new ReportException(error, e); } }
private String buildContentURL(String storeId, String spaceId, String contentId) { contentId = EncodeUtil.urlEncode(contentId); String url = buildURL("/" + spaceId + "/" + contentId); return addStoreIdQueryParameter(url, storeId); }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot contents. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get snapshot contents. " + "Error reported: " + e.getMessage(), e); } }
@Override public void login(Credential credential) { setRestHelper(new RestHttpHelper(credential)); }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot list. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get list of snapshots. " + "Error reported: " + e.getMessage(), e); } }
@Override public void logout() { setRestHelper(new RestHttpHelper()); }
public void logout() { log.debug("logout"); setRestHelper(new RestHttpHelper()); }
protected RestHttpHelper getRestHelper() { if (null == restHelper) { restHelper = new RestHttpHelper(new RootUserCredential()); } return restHelper; }
protected RestHttpHelper createRestHelper() { RestHttpHelper restHelper = new RestHttpHelper(new Credential(bridgeAppUser, bridgeAppPass)); return restHelper; }