本文整理了Java中org.jclouds.rest.HttpClient.invoke()
方法的一些代码示例,展示了HttpClient.invoke()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.invoke()
方法的具体详情如下:
包路径:org.jclouds.rest.HttpClient
类名称:HttpClient
方法名:invoke
暂无
代码示例来源:origin: org.apache.jclouds.labs/abiquo
@Override
public String apply(final Credentials input) {
logger.info(">> Requesting an authentication token for user: %s...", input.identity);
HttpResponse response = http.invoke(HttpRequest.builder() //
.method("GET") //
.endpoint(URI.create(provider.getEndpoint() + "/login")) //
.addHeader(AUTHORIZATION, basic(input.identity, input.credential)) //
.build());
Optional<HttpCookie> token = readAuthenticationToken(response);
if (!token.isPresent()) {
throw new AuthorizationException("Could not obtain a new authentication token");
}
return token.get().getValue();
}
代码示例来源: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: jclouds/legacy-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, 3 /* seconds */);
assertEquals(request.getFilters().size(), 0);
Strings2.toString(view.utils().http().invoke(request).getPayload());
assertConsistencyAwareContainerSize(container, 1);
view.getBlobStore().removeBlob(container, name);
assertConsistencyAwareContainerSize(container, 0);
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("signPutUrl with a time limit is not supported on " + provider);
} 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
@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 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
@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
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: 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);
}
}
内容来源于网络,如有侵权,请联系作者删除!