public HttpClient getHttpClient() { return getHttpClient(FOLLOW_REDIRECTS,true); }
private long exportAPIALite(String dsId) throws Exception { String url = apia.describeRepository().getRepositoryBaseURL() + "/get/" + pid + "/" + dsId; HttpGet httpMethod = new HttpGet(url); httpMethod.setHeader(HttpHeaders.CONNECTION, "Keep-Alive"); HttpClient client = fedoraClient.getHttpClient(); HttpResponse response = client.execute(httpMethod); BufferedInputStream dataStream = new BufferedInputStream(response.getEntity().getContent()); long bytesRead = 0; while (dataStream.read() >= 0) { ++bytesRead; } return bytesRead; }
private String upload() throws Exception { String url = fedoraClient.getUploadURL(); HttpPost post = new HttpPost(url); post.setHeader(HttpHeaders.CONNECTION, "Keep-Alive"); post.setHeader(HttpHeaders.TRANSFER_ENCODING, "chunked"); MultipartEntity entity = new MultipartEntity(); entity.addPart("file", new InputStreamBody(new SizedInputStream(), "file")); post.setEntity(entity); HttpClient client = fedoraClient.getHttpClient(); HttpResponse response = null; try { response = client.execute(post); int status = response.getStatusLine().getStatusCode(); String body = EntityUtils.toString(response.getEntity()); if (status != HttpStatus.SC_CREATED) { throw new IOException("Upload failed: " + response.getStatusLine().getReasonPhrase() + ": " + replaceNewlines(body, " ")); } else { body = body.replaceAll("\r", "").replaceAll("\n", ""); return body; } } finally { if (response != null && response.getEntity() != null) { response.getEntity().getContent().close(); } } }
private static int getUploadCode(FedoraClient client, String url, File file, String partName) throws Exception { HttpPost post = null; try { post = new HttpPost(url); MultipartEntity entity = new MultipartEntity(); entity.addPart(partName, new FileBody(file)); post.setEntity(entity); HttpResponse response = client.getHttpClient().execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode > 299 && responseCode < 400) { String location = response.getFirstHeader(HttpHeaders.LOCATION).getValue(); LOGGER.debug("Redirected to {}", location); return getUploadCode(client, location, file, partName); } else { return responseCode; } } finally { if (post != null) { post.releaseConnection(); } } }
private static int getUploadCode(FedoraClient client, String url, File file, String partName) throws Exception { HttpPost post = null; try { post = new HttpPost(url); MultipartEntity entity = new MultipartEntity(); entity.addPart(partName, new FileBody(file)); post.setEntity(entity); HttpResponse response = client.getHttpClient().execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode > 299 && responseCode < 400) { String location = response.getFirstHeader(HttpHeaders.LOCATION).getValue(); LOGGER.info("Redirected to {}", location); return getUploadCode(client, location, file, partName); } else { return responseCode; } } finally { if (post != null) { post.releaseConnection(); } } }
private HttpClient getClient(boolean followRedirects, boolean auth) { DefaultHttpClient result = s_client.getHttpClient(followRedirects, auth); if (auth) { String host = getHost(); LOGGER.debug("credentials set for scope of {}:[ANY PORT]", host); result .getCredentialsProvider() .setCredentials( new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(getUsername(), getPassword())); } else { result.getCredentialsProvider().clear(); } return result; }
HttpResponse response = getHttpClient().execute(post); int responseCode = response.getStatusLine().getStatusCode(); String body = null;
HttpClient client = getHttpClient();
HttpClient client = getHttpClient(followRedirects, followRedirects); HttpGet getMethod = new HttpGet(urlString); HttpInputStream in = new HttpInputStream(client, getMethod);