use of com.google.api.client.http.GenericUrl in project google-cloud-java by GoogleCloudPlatform.
the class HttpBigQueryRpc method open.
@Override
public String open(JobConfiguration configuration) {
try {
Job loadJob = new Job().setConfiguration(configuration);
StringBuilder builder = new StringBuilder().append(BASE_RESUMABLE_URI).append(options.getProjectId()).append("/jobs");
GenericUrl url = new GenericUrl(builder.toString());
url.set("uploadType", "resumable");
JsonFactory jsonFactory = bigquery.getJsonFactory();
HttpRequestFactory requestFactory = bigquery.getRequestFactory();
HttpRequest httpRequest = requestFactory.buildPostRequest(url, new JsonHttpContent(jsonFactory, loadJob));
httpRequest.getHeaders().set("X-Upload-Content-Value", "application/octet-stream");
HttpResponse response = httpRequest.execute();
return response.getHeaders().getLocation();
} catch (IOException ex) {
throw translate(ex);
}
}
use of com.google.api.client.http.GenericUrl in project beam by apache.
the class UploadIdResponseInterceptor method interceptResponse.
@Override
public void interceptResponse(HttpResponse response) throws IOException {
if (!LOG.isDebugEnabled()) {
return;
}
String uploadId = response.getHeaders().getFirstHeaderStringValue(UPLOAD_HEADER);
if (uploadId == null) {
return;
}
GenericUrl url = response.getRequest().getUrl();
// The check for upload type makes sure this is an upload and not a read.
if (url.get(UPLOAD_ID_PARAM) == null && url.get(UPLOAD_TYPE_PARAM) != null) {
LOG.debug("Upload ID for url {} on worker {} is {}", url, System.getProperty("worker_id"), uploadId);
}
}
use of com.google.api.client.http.GenericUrl in project beam by apache.
the class UploadIdResponseInterceptorTest method buildHttpResponse.
/**
* Builds a HttpResponse with the given string response.
*
* @param header header value to provide or null if none.
* @param uploadId upload id to provide in the url upload id param or null if none.
* @param uploadType upload type to provide in url upload type param or null if none.
* @return HttpResponse with the given parameters
* @throws IOException
*/
private HttpResponse buildHttpResponse(String header, String uploadId, String uploadType) throws IOException {
MockHttpTransport.Builder builder = new MockHttpTransport.Builder();
MockLowLevelHttpResponse resp = new MockLowLevelHttpResponse();
builder.setLowLevelHttpResponse(resp);
resp.setStatusCode(200);
GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
if (header != null) {
resp.addHeader("X-GUploader-UploadID", header);
}
if (uploadId != null) {
url.put("upload_id", uploadId);
}
if (uploadType != null) {
url.put("uploadType", uploadType);
}
return builder.build().createRequestFactory().buildGetRequest(url).execute();
}
use of com.google.api.client.http.GenericUrl in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method downloadAllFiles.
public void downloadAllFiles(String path) {
List<File> files = listOwnerFiles();
for (File file : files) {
try {
String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
InputStream input = resp.getContent();
java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + ".xlsx");
FileUtils.copyInputStreamToFile(input, f);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.google.api.client.http.GenericUrl in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method downloadFilesAfterDate.
public void downloadFilesAfterDate(String path, String stringDateLastChange) {
List<File> files = listOwnerFilesAfterDate(stringDateLastChange);
for (File file : files) {
try {
String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
InputStream input = resp.getContent();
java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + ".xlsx");
FileUtils.copyInputStreamToFile(input, f);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations