use of com.google.api.client.http.ByteArrayContent in project google-api-java-client by google.
the class BatchRequestTest method testExecute_checkWriteTo.
public void testExecute_checkWriteTo() throws Exception {
String request1Method = HttpMethods.POST;
String request1Url = "http://test/dummy/url1";
String request1ContentType = "application/json";
String request1Content = "{\"data\":{\"foo\":{\"v1\":{}}}}";
String request2Method = HttpMethods.GET;
String request2Url = "http://test/dummy/url2";
final StringBuilder expectedOutput = new StringBuilder();
expectedOutput.append("--__END_OF_PART__\r\n");
expectedOutput.append("Content-Length: 118\r\n");
expectedOutput.append("Content-Type: application/http\r\n");
expectedOutput.append("content-id: 1\r\n");
expectedOutput.append("content-transfer-encoding: binary\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("POST http://test/dummy/url1 HTTP/1.1\r\n");
expectedOutput.append("Content-Length: 26\r\n");
expectedOutput.append("Content-Type: " + request1ContentType + "\r\n");
expectedOutput.append("\r\n");
expectedOutput.append(request1Content + "\r\n");
expectedOutput.append("--__END_OF_PART__\r\n");
expectedOutput.append("Content-Length: 39\r\n");
expectedOutput.append("Content-Type: application/http\r\n");
expectedOutput.append("content-id: 2\r\n");
expectedOutput.append("content-transfer-encoding: binary\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("GET http://test/dummy/url2 HTTP/1.1\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("\r\n");
expectedOutput.append("--__END_OF_PART__--\r\n");
MockHttpTransport transport = new MockHttpTransport();
HttpRequest request1 = transport.createRequestFactory().buildRequest(request1Method, new GenericUrl(request1Url), new ByteArrayContent(request1ContentType, request1Content.getBytes(UTF_8)));
HttpRequest request2 = transport.createRequestFactory().buildRequest(request2Method, new GenericUrl(request2Url), null);
subtestExecute_checkWriteTo(expectedOutput.toString(), request1, request2);
}
use of com.google.api.client.http.ByteArrayContent in project google-api-java-client by google.
the class MediaHttpUploaderTest method testDirectUploadServerErrorWithBackOffDisabled.
public void testDirectUploadServerErrorWithBackOffDisabled() throws Exception {
int contentLength = MediaHttpUploader.DEFAULT_CHUNK_SIZE * 2;
MediaTransport fakeTransport = new MediaTransport(contentLength);
fakeTransport.testServerError = true;
fakeTransport.directUploadEnabled = true;
ByteArrayContent mediaContent = new ByteArrayContent(TEST_CONTENT_TYPE, new byte[contentLength]);
MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
uploader.setDirectUploadEnabled(true);
uploader.upload(new GenericUrl(TEST_DIRECT_REQUEST_URL));
// should be 1 call made: 1 upload request with server error
assertEquals(1, fakeTransport.lowLevelExecCalls);
}
use of com.google.api.client.http.ByteArrayContent in project google-api-java-client by google.
the class MediaHttpUploaderTest method testDirectMediaUploadWithZeroContent.
public void testDirectMediaUploadWithZeroContent() throws Exception {
int contentLength = 0;
MediaTransport fakeTransport = new MediaTransport(contentLength);
fakeTransport.directUploadEnabled = true;
ByteArrayContent mediaContent = new ByteArrayContent(TEST_CONTENT_TYPE, new byte[contentLength]);
MediaHttpUploader uploader = new MediaHttpUploader(mediaContent, fakeTransport, null);
uploader.setDirectUploadEnabled(true);
uploader.upload(new GenericUrl(TEST_DIRECT_REQUEST_URL));
// There should be only 1 call made for direct media upload.
assertEquals(1, fakeTransport.lowLevelExecCalls);
}
use of com.google.api.client.http.ByteArrayContent in project halyard by spinnaker.
the class GoogleWriteableProfileRegistry method writeTextObject.
private void writeTextObject(String name, String contents) {
try {
byte[] bytes = contents.getBytes();
StorageObject object = new StorageObject().setBucket(spinconfigBucket).setName(name);
ByteArrayContent content = new ByteArrayContent("application/text", bytes);
storage.objects().insert(spinconfigBucket, object, content).execute();
} catch (IOException e) {
log.error("Failed to write new object " + name, e);
throw new HalException(new ProblemBuilder(Severity.FATAL, "Failed to write to " + name + ": " + e.getMessage()).build());
}
}
use of com.google.api.client.http.ByteArrayContent in project wildfly-camel by wildfly-extras.
the class GoogleDriveIntegrationTest method uploadTestFile.
private static File uploadTestFile(ProducerTemplate template, String testName) {
File fileMetadata = new File();
fileMetadata.setTitle(GoogleDriveIntegrationTest.class.getName() + "." + testName + "-" + UUID.randomUUID().toString());
final String content = //
"Camel rocks!\n" + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()) + //
"\n" + "user: " + System.getProperty("user.name");
HttpContent mediaContent = new ByteArrayContent("text/plain", content.getBytes(StandardCharsets.UTF_8));
final Map<String, Object> headers = new HashMap<>();
// parameter type is com.google.api.services.drive.model.File
headers.put("CamelGoogleDrive.content", fileMetadata);
// parameter type is com.google.api.client.http.AbstractInputStreamContent
headers.put("CamelGoogleDrive.mediaContent", mediaContent);
return template.requestBodyAndHeaders("google-drive://drive-files/insert", null, headers, File.class);
}
Aggregations