本文整理了Java中org.jclouds.rest.Utils.http()
方法的一些代码示例,展示了Utils.http()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.http()
方法的具体详情如下:
包路径:org.jclouds.rest.Utils
类名称:Utils
方法名:http
[英]#see #getHttpClient
[中]#请参阅#getHttpClient
代码示例来源:origin: apache/jclouds
public void signatureV4() {
Supplier<Credentials> accessAndSecretKey = Suppliers.ofInstance(new Credentials(identity, credential));
FormSignerV4 filter = new FormSignerV4(apiVersion, accessAndSecretKey, timestamp, serviceAndRegion);
HttpRequest request = filter.filter(sampleRequest);
assertEquals(api.utils().http().invoke(request).getStatusCode(), 200);
}
代码示例来源:origin: apache/jclouds
public void signatureV4_session() {
SessionCredentials creds = api.getApi().createTemporaryCredentials(durationSeconds(MINUTES.toSeconds(15)));
Supplier<Credentials> sessionToken = Suppliers.<Credentials>ofInstance(creds);
FormSignerV4 filter = new FormSignerV4(apiVersion, sessionToken, timestamp, serviceAndRegion);
HttpRequest request = filter.filter(sampleRequest);
assertEquals(api.utils().http().invoke(request).getStatusCode(), 200);
}
}
代码示例来源:origin: apache/jclouds
@Test(groups = { "integration", "live" })
public void testSetBlobAccess() throws Exception {
BlobStore blobStore = view.getBlobStore();
String containerName = getContainerName();
String blobName = "set-access-blob-name";
try {
addBlobToContainer(containerName, blobName, blobName, MediaType.TEXT_PLAIN);
assertThat(blobStore.getBlobAccess(containerName, blobName)).isEqualTo(BlobAccess.PRIVATE);
blobStore.setBlobAccess(containerName, blobName, BlobAccess.PUBLIC_READ);
assertThat(blobStore.getBlobAccess(containerName, blobName)).isEqualTo(BlobAccess.PUBLIC_READ);
// test that blob is anonymously readable
HttpRequest request = view.getSigner().signGetBlob(containerName, blobName).toBuilder()
.replaceQueryParams(ImmutableMap.<String, String>of()).build();
HttpResponse response = view.utils().http().invoke(request);
assertThat(response.getStatusCode()).isEqualTo(200);
blobStore.setBlobAccess(containerName, blobName, BlobAccess.PRIVATE);
assertThat(blobStore.getBlobAccess(containerName, blobName)).isEqualTo(BlobAccess.PRIVATE);
} finally {
returnContainer(containerName);
}
}
代码示例来源:origin: apache/jclouds
@Test(groups = { "integration", "live" })
public void testSetContainerAccess() throws Exception {
BlobStore blobStore = view.getBlobStore();
String containerName = getContainerName();
try {
assertThat(blobStore.getContainerAccess(containerName)).isEqualTo(ContainerAccess.PRIVATE);
blobStore.setContainerAccess(containerName, ContainerAccess.PUBLIC_READ);
assertThat(blobStore.getContainerAccess(containerName)).isEqualTo(ContainerAccess.PUBLIC_READ);
String blobName = "blob";
blobStore.putBlob(containerName, blobStore.blobBuilder(blobName).payload("").build());
// test that blob is anonymously readable
HttpRequest request = view.getSigner().signGetBlob(containerName, blobName).toBuilder()
.replaceQueryParams(ImmutableMap.<String, String>of()).build();
HttpResponse response = view.utils().http().invoke(request);
assertThat(response.getStatusCode()).isEqualTo(200);
blobStore.setContainerAccess(containerName, ContainerAccess.PRIVATE);
assertThat(blobStore.getContainerAccess(containerName)).isEqualTo(ContainerAccess.PRIVATE);
} finally {
recycleContainerAndAddToPool(containerName);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testSignGetUrlWithTime() throws InterruptedException, IOException {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name, 3 /* seconds */);
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text);
TimeUnit.SECONDS.sleep(4);
try {
Strings2.toString(view.utils().http().invoke(request).getPayload());
fail("Temporary URL did not expire as expected");
} catch (AuthorizationException expected) {
}
} catch (UnsupportedOperationException ignore) {
throw new SkipException("signGetUrl with a time limit is not supported on " + provider);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testSignGetUrl() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name);
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testSignPutUrl() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
HttpRequest request = view.getSigner().signPutBlob(container, blob);
assertEquals(request.getFilters().size(), 0);
Strings2.toString(view.utils().http().invoke(request).getPayload());
assertConsistencyAwareContainerSize(container, 1);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testSignGetUrlOptions() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1));
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), "fo");
} finally {
returnContainer(container);
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testSignPutUrl() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("image/png").build();
String container = getContainerName();
try {
HttpRequest request = view.getSigner().signPutBlob(container, blob);
assertEquals(request.getFilters().size(), 0);
Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream());
blob = view.getBlobStore().getBlob(container, name);
assertThat(blob.getMetadata().getContentMetadata().getContentType()).isEqualTo("image/png");
} finally {
returnContainer(container);
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testSignPutUrlWithTime() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
HttpRequest request = view.getSigner().signPutBlob(container, blob, getSignedUrlTimeout());
assertEquals(request.getFilters().size(), 0);
// Strip Expect: 100-continue to make actual responses visible, since
// Java 7+ will throw a ProtocolException instead of setting the response code:
// http://www.docjar.com/html/api/sun/net/www/protocol/http/HttpURLConnection.java.html#1021
request = request.toBuilder().removeHeader(EXPECT).build();
Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream());
} finally {
returnContainer(container);
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testSignGetUrl() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name);
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: apache/jclouds
@Test
@Parameters( { "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" })
public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMD5) throws Exception {
httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl");
httpStreamMD5 = checkNotNull(httpStreamMD5 != null ? httpStreamMD5 : sysHttpStreamMD5, "httpStreamMd5");
HttpResponse response = view.utils().http().invoke(HttpRequest.builder().method("GET").endpoint(httpStreamUrl).build());
long length = response.getPayload().getContentMetadata().getContentLength();
String name = "hello";
byte[] md5 = base16().lowerCase().decode(httpStreamMD5);
Blob blob = view.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length)
.contentMD5(md5).build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
checkMD5(container, name, md5);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
@Parameters( { "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" })
public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMD5) throws Exception {
httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl");
httpStreamMD5 = checkNotNull(httpStreamMD5 != null ? httpStreamMD5 : sysHttpStreamMD5, "httpStreamMd5");
HttpResponse response = view.utils().http().invoke(HttpRequest.builder().method("GET").endpoint(httpStreamUrl).build());
long length = response.getPayload().getContentMetadata().getContentLength();
String name = "hello";
byte[] md5 = base16().lowerCase().decode(httpStreamMD5);
Blob blob = view.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length)
.contentMD5(md5).build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
checkMD5(container, name, md5);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testSignGetUrlWithTime() throws InterruptedException, IOException {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name, getSignedUrlTimeout());
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: apache/jclouds
@Test
public void testSignGetUrlOptions() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1));
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), "fo");
} finally {
returnContainer(container);
}
}
代码示例来源:origin: apache/jclouds
public void testSignPutUrlWithTime(final long timeout) throws InterruptedException, IOException {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
HttpRequest request = view.getSigner().signPutBlob(container, blob, 0);
assertEquals(request.getFilters().size(), 0);
// Strip Expect: 100-continue to make actual responses visible, since
// Java 7+ will throw a ProtocolException instead of setting the response code:
// http://www.docjar.com/html/api/sun/net/www/protocol/http/HttpURLConnection.java.html#1021
request = request.toBuilder().removeHeader(EXPECT).build();
try {
Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream());
fail("Temporary URL did not expire as expected");
} catch (AuthorizationException expected) {
}
} finally {
returnContainer(container);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testSignRemoveUrl() throws Exception {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signRemoveBlob(container, name);
assertEquals(request.getFilters().size(), 0);
view.utils().http().invoke(request);
assert !view.getBlobStore().blobExists(container, name);
} finally {
returnContainer(container);
}
}
}
代码示例来源:origin: jclouds/legacy-jclouds
private void runCreateContainerInLocation(String payload, Location nonDefault) throws InterruptedException,
IOException {
String blobName = "hello";
BlobStore blobStore = view.getBlobStore();
final String containerName = getScratchContainerName();
try {
Logger.getAnonymousLogger().info(
String.format("creating public container %s in location %s", containerName, nonDefault.getId()));
blobStore.createContainerInLocation(nonDefault, containerName, publicRead());
assertConsistencyAwareContainerExists(containerName);
assertConsistencyAwareContainerInLocation(containerName, nonDefault);
blobStore.putBlob(containerName, blobStore.blobBuilder(blobName).payload(payload).build());
assertConsistencyAwareContainerSize(containerName, 1);
BlobMetadata metadata = view.getBlobStore().blobMetadata(containerName, blobName);
assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), payload);
assertConsistencyAwareBlobInLocation(containerName, blobName, nonDefault);
} finally {
// this container is now public, so we can't reuse it directly
recycleContainer(containerName);
}
}
代码示例来源:origin: apache/jclouds
public void testSignGetUrlWithTime(final long timeout) throws InterruptedException, IOException {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name, timeout);
assertEquals(request.getFilters().size(), 0);
try {
Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream());
fail("Temporary URL did not expire as expected");
} catch (AuthorizationException expected) {
}
} finally {
returnContainer(container);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test(groups = "live")
public void testPublicAccess() throws InterruptedException, MalformedURLException, IOException {
final String containerName = getScratchContainerName();
try {
view.getBlobStore().createContainerInLocation(null, containerName, publicRead());
assertConsistencyAwareContainerExists(containerName);
defaultLocation = Iterables.find(view.getBlobStore().list(), new Predicate<StorageMetadata>() {
@Override
public boolean apply(@Nullable StorageMetadata input) {
return input.getName().equals(containerName);
}
}).getLocation();
view.getBlobStore().putBlob(containerName,
view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build());
assertConsistencyAwareContainerSize(containerName, 1);
BlobMetadata metadata = view.getBlobStore().blobMetadata(containerName, "hello");
assert metadata.getPublicUri() != null : metadata;
assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), TEST_STRING);
} finally {
// this container is now public, so we can't reuse it directly
recycleContainer(containerName);
}
}
内容来源于网络,如有侵权,请联系作者删除!