本文整理了Java中org.jclouds.io.Payload
类的一些代码示例,展示了Payload
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Payload
类的具体详情如下:
包路径:org.jclouds.io.Payload
类名称:Payload
暂无
代码示例来源:origin: gaul/s3proxy
@Override
public String putBlob(String containerName, Blob blob,
PutOptions options) {
long length;
try (InputStream is = blob.getPayload().openStream()) {
length = ByteStreams.copy(is, ByteStreams.nullOutputStream());
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
byte[] array = Longs.toByteArray(length);
ByteSourcePayload payload = new ByteSourcePayload(
ByteSource.wrap(array));
payload.setContentMetadata(blob.getPayload().getContentMetadata());
payload.getContentMetadata().setContentLength((long) array.length);
payload.getContentMetadata().setContentMD5((HashCode) null);
blob.setPayload(payload);
return super.putBlob(containerName, blob, options);
}
代码示例来源:origin: rackerlabs/blueflood
public String call() throws Exception {
Blob blob = store.getBlob(container, name);
Payload payload = blob.getPayload();
InputStream is = payload.getInput();
File tempFile = new File(downloadDir, name + ".tmp");
Timer.Context downloadContext = downloadTimer.time();
try {
long read = 0;
long length = payload.getContentMetadata().getContentLength();
OutputStream out = new FileOutputStream(tempFile, false);
byte[] buf = new byte[BUF_SIZE];
tempFile.delete();
} finally {
payload.release();
downloadContext.stop();
代码示例来源:origin: jclouds/legacy-jclouds
public void testSimple() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build();
i.getInstance(BindServerToPlainTextString.class).bindToRequest(request, SERVER);
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
assertEquals(request.getPayload().getRawContent(), CREATED_SERVER);
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testApplyBlueLock() {
HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
.payload(getClass().getResourceAsStream("/orglist.xml"))
.addHeader("x-vcloud-authorization", "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=").build();
response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
response.getPayload().getContentMetadata().setContentLength(307l);
VCloudSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "MUKOJ2HoAfoMmLnHRp4esNb2MtWscCLLhVysnsIsCG0=");
assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
VCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testPassWithMinimumDetailsAndPayload5GB() {
S3Object object = injector.getInstance(S3Object.Factory.class).create(null);
Payload payload = Payloads.newStringPayload("");
payload.getContentMetadata().setContentLength(5368709120l);
object.setPayload(payload);
object.getMetadata().setKey("foo");
HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class);
assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT").endpoint(
URI.create("http://localhost")).build());
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testPassWithMinimumDetailsAndPayload5GB() {
HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
Payload payload = Payloads
.newStringPayload("<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>\"a54357aff0632cce46d942af68356b38\"</ETag></Part></CompleteMultipartUpload>");
payload.getContentMetadata().setContentType(MediaType.TEXT_XML);
request = binder.bindToRequest(request, ImmutableMap.<Integer, String> of(1,
"\"a54357aff0632cce46d942af68356b38\""));
assertEquals(request.getPayload().getRawContent(), payload.getRawContent());
assertEquals(request, HttpRequest.builder().method("PUT").endpoint("http://localhost").payload(
payload).build());
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testResponsePathLocationOk() {
ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x();
HttpResponse response = createMock(HttpResponse.class);
Payload payload = createMock(Payload.class);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://new/fd").build();
function.setContext(request);
expect(response.getStatusCode()).andReturn(200).atLeastOnce();
expect(response.getFirstHeaderOrNull(CONTENT_TYPE)).andReturn("text/plain");
expect(response.getFirstHeaderOrNull(LOCATION)).andReturn("path");
expect(response.getPayload()).andReturn(payload).atLeastOnce();
payload.release();
replay(payload);
replay(response);
assertEquals(function.apply(response), URI.create("http://new/path"));
verify(response);
verify(payload);
}
代码示例来源:origin: apache/jclouds
@Override
public HttpResponse invoke(HttpCommand command) {
assertEquals(
command.getCurrentRequest().getPayload().getContentMetadata().getContentType(),
APPLICATION_JSON);
assertTrue(command.getCurrentRequest().getHeaders().get("Accept").contains(APPLICATION_JSON));
return HttpResponse.builder().build();
}
});
代码示例来源:origin: apache/jclouds
@Test(groups = "live", dependsOnMethods = "testRewrite")
public void testDownload() throws IOException {
PayloadEnclosing impl = api().download(BUCKET_NAME, UPLOAD_OBJECT_NAME);
ContentMetadata meta = impl.getPayload().getContentMetadata();
assertNotNull(impl);
assertNotNull(impl.getPayload());
assertNotNull(meta);
assertEquals(meta.getContentType(), "text/plain");
testPayload.getPayload().getContentMetadata().setContentDisposition("attachment");
assertEquals(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream()),
ByteStreams2.toByteArrayAndClose(testPayload.getPayload().openStream()));
}
代码示例来源:origin: jclouds/legacy-jclouds-chef
public void testBindOnlyName() throws IOException {
HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build();
HttpRequest newRequest = binder.bindToRequest(request, new Group("foo"));
String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput());
assertEquals(payload, "{\"groupname\":\"foo\",\"actors\":{\"clients\":[],\"groups\":[],\"users\":[]}}");
}
代码示例来源:origin: apache/jclouds
@Test
public void testPayloadEnclosedWithSoapTags() {
String requestBody = "<ws:getAllDataCenters/>";
String expectedPayload = SOAP_PREFIX.concat(requestBody).concat(SOAP_SUFFIX);
HttpRequest request = HttpRequest.builder().method("POST").endpoint(ENDPOINT).payload(requestBody).build();
ProfitBricksSoapMessageEnvelope soapEnvelope = new ProfitBricksSoapMessageEnvelope();
HttpRequest filtered = soapEnvelope.filter(request);
assertEquals(filtered.getPayload().getRawContent(), expectedPayload);
assertEquals(filtered.getPayload().getContentMetadata().getContentLength(), Long.valueOf(expectedPayload.getBytes().length));
}
代码示例来源:origin: apache/jclouds
@Test
public void testGetStringViaRequest() throws Exception {
MockWebServer server = mockWebServer(new MockResponse().setBody(XML));
IntegrationTestClient client = client(server.getUrl("/").toString());
try {
HttpResponse getStringResponse = client.invoke(HttpRequest.builder().method("GET")
.endpoint(server.getUrl("/objects").toString()).build());
assertEquals(Strings2.toStringAndClose(getStringResponse.getPayload().openStream()).trim(), XML);
} finally {
closeQuietly(client);
server.shutdown();
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testCorrect() throws SecurityException, NoSuchMethodException {
BindToJsonPayloadWrappedWith binder = new BindToJsonPayloadWrappedWith(injector
.getInstance(BindToJsonPayload.class), "envelope");
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
request = binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2"));
assertEquals(request.getPayload().getRawContent(), "{\"envelope\":{\"imageName\":\"foo\",\"serverId\":\"2\"}}");
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(invocationCount = 5, timeOut = 5000)
public void testPostContentDisposition() {
Payload payload = newStringPayload("foo");
payload.getContentMetadata().setContentDisposition("attachment; filename=photo.jpg");
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
assertEquals(headers.get("x-Content-Disposition"), ImmutableList.of("attachment; filename=photo.jpg"));
payload.release();
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(invocationCount = 5, timeOut = 5000)
public void testPostContentEncoding() {
Payload payload = newStringPayload("foo");
payload.getContentMetadata().setContentEncoding("gzip");
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
assertEquals(headers.get("x-Content-Encoding"), ImmutableList.of("gzip"));
payload.release();
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(invocationCount = 5, timeOut = 5000)
public void testPostContentLanguage() {
Payload payload = newStringPayload("foo");
payload.getContentMetadata().setContentLanguage("mi, en");
Multimap<String, String> headers = client.postPayloadAndReturnHeaders("", payload);
assertEquals(headers.get("x-Content-Language"), ImmutableList.of("mi, en"));
payload.release();
}
代码示例来源:origin: apache/jclouds
public void testSinglePart() throws IOException {
assertEquals(EXPECTS.length(), 113);
BindBlobToMultipartForm binder = new BindBlobToMultipartForm();
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost:8001").build();
binder.bindToRequest(request, TEST_BLOB);
assertEquals(Strings2.toStringAndClose(request.getPayload().openStream()), EXPECTS);
assertEquals(request.getPayload().getContentMetadata().getContentLength(), Long.valueOf(113));
assertEquals(request.getPayload().getContentMetadata().getContentType(), "multipart/form-data; boundary="
+ BOUNDARY);
}
代码示例来源:origin: jclouds/legacy-jclouds
/**
* clones or proxies can mess up the error message.
*/
@Test
public void testNoExceptionParsingTextPlain() {
HttpResponse response = HttpResponse.builder().statusCode(BAD_REQUEST.getStatusCode()).payload("foo bar").build();
response.getPayload().getContentMetadata().setContentType(TEXT_PLAIN);
assertNull(utils.parseAWSErrorFromContent(command.getCurrentRequest(), response));
}
代码示例来源:origin: jclouds/legacy-jclouds
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
String content, Class<? extends Exception> expected) {
GleSYSErrorHandler function = Guice.createInjector().getInstance(GleSYSErrorHandler.class);
HttpCommand command = createMock(HttpCommand.class);
HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
response.getPayload().getContentMetadata().setContentType(contentType);
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
command.setException(classEq(expected));
replay(command);
function.handleError(command, response);
verify(command);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testAddFormParamAddsAnotherValue() {
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://foo")
.payload("foo=bar").build();
Payload payload = Payloads.newStringPayload("foo=bar&foo=baz");
payload.getContentMetadata().setContentType(FORM_DATA.toString());
assertEquals(request.toBuilder().addFormParams(ImmutableMultimap.of("foo", "baz")).build(), HttpRequest
.builder().method("GET").endpoint("http://foo").payload(payload).build());
}
内容来源于网络,如有侵权,请联系作者删除!