private String addUris(DataSource dataSource, Collection<String> uris) throws IOException { String xml = toXml(dataSource, uris, type); log.info(format("Adding URIs:%n%s", xml)); String dataSourcesUrl = getDataSourcesUrl(); Post request = new Post(dataSourcesUrl, getCredentials()); request.addFile("file", xml.getBytes(StandardCharsets.UTF_8)); request.setAccept(APPLICATION_JSON); request.setSocketTimeout(SOCKET_TIMEOUT); String result = null; try { result = request.executeAsString(); log.info(format("Added URIs with result:%n%s", result)); addCount += uris.size(); } catch(Exception e) { log.severe(format("Cannot add URIs: %s", e)); } return result; }
private String updateUris(DatasourceType dataSourceType) throws IOException { String xml = toXml(dataSourceType); log.info(format("Updating URIs:%n%s", xml)); String dataSourcesUrl = getDataSourcesUrl(); Post request = new Post(dataSourcesUrl, getCredentials()); request.addFile("file", xml.getBytes(StandardCharsets.UTF_8)); request.setAccept(APPLICATION_JSON); request.setSocketTimeout(SOCKET_TIMEOUT); String result = null; try { result = request.executeAsString(); log.info(format("Updated URIs with result:%n%s", result)); updateCount += getDownloadableCount(dataSourceType); } catch(Exception e) { log.severe(format("Cannot update URIs: %s", e)); } return result; }
public String sendErrorReport(String logOutput, String description, java.io.File file) throws IOException { log.fine("Sending error report with log \"" + logOutput + "\", description \"" + description + "\"" + (file != null ? ", file " + file.getAbsolutePath() : "")); Post request = new Post(getErrorReportUrl(), credentials); request.addString("log", logOutput); request.addString("description", description); if (file != null) request.addFile("file", file); String result = request.executeAsString(); if (request.isUnAuthorized()) throw new UnAuthorizedException("Cannot send error report " + (file != null ? ", file " + file.getAbsolutePath() : ""), getErrorReportUrl()); if (!request.isSuccessful()) throw new IOException("POST on " + getErrorReportUrl() + " with log " + logOutput.length() + " characters" + ", description \"" + description + "\", file " + file + " not successful: " + result); return request.getLocation(); }
String addFile(File file) throws IOException { log.info(format("Adding file %s", file)); String fileUrl = rootUrl + FILE_URI; Post request = new Post(fileUrl, credentials); request.setAccept(APPLICATION_JSON); request.addString("name", file.getName()); request.addFile("file", file); String result = request.executeAsString(); if (request.isUnAuthorized()) throw new UnAuthorizedException("Not authorized to add file " + file, fileUrl); if (request.isForbidden()) throw new ForbiddenException("Forbidden to add file " + file, fileUrl); if (request.isPreconditionFailed()) throw new ServiceUnavailableException("File " + file + " is too large", fileUrl, result); if (!request.isSuccessful()) throw new IOException("POST on " + fileUrl + " with file " + file + " not successful: " + result); return request.getLocation(); }