本文整理了Java中org.jclouds.http.HttpRequest
类的一些代码示例,展示了HttpRequest
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest
类的具体详情如下:
包路径:org.jclouds.http.HttpRequest
类名称:HttpRequest
[英]Represents a request that can be executed within HttpCommandExecutorService
[中]表示可以在HttpCommandExecutorService中执行的请求
代码示例来源:origin: org.apache.jclouds.labs/fgcp
@VisibleForTesting
HttpRequest addQueryParamsToRequest(HttpRequest request, String accessKeyId, String signature, String lang) {
Multimap<String, String> decodedParams = queryParser().apply(request.getEndpoint().getRawQuery());
Builder<?> builder = request.toBuilder().endpoint(request.getEndpoint()).method(request.getMethod());
if (!decodedParams.containsKey("Version")) {
builder.addQueryParam(RequestParameters.VERSION, apiVersion);
}
builder.addQueryParam(RequestParameters.LOCALE, lang).addQueryParam(RequestParameters.ACCESS_KEY_ID, accessKeyId)
.addQueryParam(RequestParameters.SIGNATURE, signature);
return builder.build();
}
代码示例来源:origin: stackoverflow.com
uri = new URI(location);
} catch (URISyntaxException ex) {
throw new ProtocolException("Invalid redirect URI: " + location, ex);
if (!uri.isAbsolute()) {
if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
throw new ProtocolException("Relative redirect location '"
URI requestURI = new URI(request.getRequestLine().getUri());
URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
uri = URIUtils.resolve(absoluteRequestURI, uri);
代码示例来源:origin: jclouds/legacy-jclouds
HttpRequest setPayload(HttpRequest request, Multimap<String, String> decodedParams) {
String queryLine = buildQueryLine(decodedParams);
request.setPayload(queryLine);
request.getPayload().getContentMetadata().setContentType("application/x-www-form-urlencoded");
return request;
}
代码示例来源:origin: jclouds/legacy-jclouds
/**
* build a shell script that invokes the contents of the http request in bash.
*
* @return a shell script that will invoke the http request
*/
public static Statement execHttpResponse(HttpRequest request) {
return pipeHttpResponseToBash(request.getMethod(), request.getEndpoint(), request.getHeaders());
}
代码示例来源:origin: jclouds/legacy-jclouds
void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) {
// note that we fall back to headers, and some requests such as ?uploads do not have a
// payload, yet specify payload related parameters
buffer.append(
request.getPayload() == null ? Strings.nullToEmpty(request.getFirstHeaderOrNull("Content-MD5")) :
HttpUtils.nullToEmpty(request.getPayload() == null ? null : request.getPayload().getContentMetadata()
.getContentMD5())).append("\n");
buffer.append(
Strings.nullToEmpty(request.getPayload() == null ? request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)
: request.getPayload().getContentMetadata().getContentType())).append("\n");
for (String header : FIRST_HEADERS_TO_SIGN)
buffer.append(HttpUtils.nullToEmpty(request.getHeaders().get(header))).append("\n");
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
public HttpResponse apply(HttpRequest input) {
// on first request, throw an SSL close_notify exception
if (counter.getAndIncrement() == 0)
throw propagate(new SSLException("Received close_notify during handshake"));
// on other requests, just validate and return 200
assertEquals(renderRequest(input), renderRequest(HttpRequest.builder().method("HEAD").endpoint(
URI.create("http://mock/objects/rabbit")).build()));
return HttpResponse.builder().statusCode(200).build();
}
});
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testPassWithMinimumDetailsAndPayload5GB() {
SwiftObject object = injector.getInstance(SwiftObject.Factory.class).create(null);
Payload payload = Payloads.newStringPayload("");
payload.getContentMetadata().setContentLength(5 * 1024 * 1024 * 1024l);
object.setPayload(payload);
object.getInfo().setName("foo");
HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
BindSwiftObjectMetadataToRequest binder = injector.getInstance(BindSwiftObjectMetadataToRequest.class);
assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT").endpoint(
URI.create("http://localhost")).build());
}
代码示例来源:origin: apache/jclouds
@Test(timeOut = TEST_SAFE_TIMEOUT)
public void testRequestIsDelayed() {
HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://localhost").build());
HttpResponse response = HttpResponse.builder().statusCode(429).addHeader(RETRY_AFTER, "5").build();
long start = System.currentTimeMillis();
assertTrue(rateLimitRetryHandler.shouldRetryRequest(command, response));
// Should have blocked the amount of time configured in the header. Use a
// smaller value to compensate the time it takes to reach the code that
// computes the amount of time to wait.
assertTrue(System.currentTimeMillis() - start > 2500);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testListSecurityGroupsWhenReponseIs404IsEmpty() throws Exception {
HttpRequest listListSecurityGroups = HttpRequest.builder().method("GET").endpoint(
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups")).headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
authToken).build()).build();
HttpResponse listListSecurityGroupsResponse = HttpResponse.builder().statusCode(404).build();
NovaApi apiWhenNoSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listListSecurityGroups,
listListSecurityGroupsResponse);
assertTrue(apiWhenNoSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
.list().isEmpty());
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testEncodesOnlyOnce() throws Exception {
URI uri = URI.create("http://goo.com:443?header=value1");
HttpRequest request = HttpRequest.builder().method("GET").endpoint(uri).build();
assertEquals(request.toBuilder().replaceQueryParam("header", "hello?").build(),
HttpRequest.builder().method("GET").endpoint("http://goo.com:443?header=hello%3F").build());
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testAddingBase64EncodedQueryParamCausingPlusToUrlEncodedSpaceConversion() {
String base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
URI uri = URI
.create("http://goo.com:443?header1=valueWithUrlEncoded%2BPlus");
HttpRequest request = HttpRequest.builder().method("GET").endpoint(uri)
// addQueryParam invocation causes %2B's in prev. params to
// convert to %20.
.addQueryParam("header2", base64Chars).build();
assertEquals(
request.getRequestLine(),
"GET http://goo.com:443?header1=valueWithUrlEncoded%20Plus&header2=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%20/%3D HTTP/1.1");
}
代码示例来源: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
public void testGetSecurityGroupWhenResponseIs404() throws Exception {
HttpRequest getSecurityGroup = HttpRequest.builder().method("GET").endpoint(
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-security-groups/0")).headers(
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
authToken).build()).build();
HttpResponse getSecurityGroupResponse = HttpResponse.builder().statusCode(404).build();
NovaApi apiWhenNoSecurityGroupsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getSecurityGroup,
getSecurityGroupResponse);
assertNull(apiWhenNoSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
.get("0"));
}
代码示例来源:origin: jclouds/legacy-jclouds
private void assertConfigMakesPayload(Map<String, Object> config, String expectedPayload) {
BindNodeConfigurationToXmlPayload binder = injector.getInstance(BindNodeConfigurationToXmlPayload.class);
HttpRequest request = createMock(HttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
request.setPayload(expectedPayload);
replay(request);
binder.bindToRequest(request, config);
verify(request);
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
void testFilter() {
QuerySigner filter = INJECTOR.getInstance(QuerySigner.class);
assertEquals(
filter.filter(
HttpRequest.builder().method("GET")
.endpoint("http://localhost:8080/client/api?command=listZones").build())
.getRequestLine(),
"GET http://localhost:8080/client/api?command=listZones&apiKey=apiKey&signature=2UG8AcnMaozL3BINdjgkJ%2BRzjEY%3D HTTP/1.1");
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
@SuppressWarnings("unchecked")
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
checkNotNull(payload, "hostprefix");
checkArgument(isValid(request.getEndpoint().getHost()), "this is only valid for hostnames: " + request);
InternetDomainName name = from(request.getEndpoint().getHost()).child(payload.toString());
return (R) request.toBuilder().endpoint(uriBuilder(request.getEndpoint()).host(name.name()).build()).build();
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testListClustersEmptyOn404() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=listClusters&listAll=true&apiKey=identity&signature=lbimqg0OKIq8sgQBpNmi4oQNFog%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
GlobalHostClient client = requestSendsResponse(request, response);
assertEquals(client.listClusters(), ImmutableSet.of());
}
代码示例来源:origin: apache/jclouds
@Override
public HttpResponse invoke(HttpCommand command) {
assertEquals(
command.getCurrentRequest().getPayload().getContentMetadata().getContentType(),
APPLICATION_XML);
assertTrue(command.getCurrentRequest().getHeaders().get("Accept").contains(APPLICATION_XML));
return HttpResponse.builder().build();
}
});
代码示例来源:origin: com.amysta.jclouds/jclouds-core
@Override
@SuppressWarnings("unchecked")
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
checkNotNull(payload, "hostprefix");
checkArgument(isValid(request.getEndpoint().getHost()), "this is only valid for hostnames: " + request);
InternetDomainName name = from(request.getEndpoint().getHost()).child(payload.toString());
URI newEndpoint = uriBuilder(request.getEndpoint()).host(name.toString()).build();
return (R) request.toBuilder().endpoint(newEndpoint).replacePath(request.getEndpoint().getRawPath()).build();
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testApply() {
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost").build();
request = filter.filter(request);
assertEquals(request.getHeaders().size(), 2);
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.COOKIE), "vcloud-token=token");
assertEquals(request.getFirstHeaderOrNull("x-vcloud-authorization"), "token");
}
内容来源于网络,如有侵权,请联系作者删除!