org.jclouds.http.HttpRequest.builder()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中org.jclouds.http.HttpRequest.builder()方法的一些代码示例,展示了HttpRequest.builder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.builder()方法的具体详情如下:
包路径:org.jclouds.http.HttpRequest
类名称:HttpRequest
方法名:builder

HttpRequest.builder介绍

暂无

代码示例

代码示例来源:origin: jclouds/legacy-jclouds

@Test
void testCreateStringToSignWithBrackets() {
 // This test asserts that key *names* are not URL-encoded - only values
 // should be encoded, according to "CloudStack API Developer’s Guide".
 QuerySigner filter = INJECTOR.getInstance(QuerySigner.class);
 assertEquals(
    filter.createStringToSign(HttpRequest.builder().method("GET")
       .endpoint("http://localhost:8080/client/api?command=deployVirtualMachine&iptonetworklist[0].ip=127.0.0.1&iptonetworklist[0].networkid=1").build()),
    "apikey=apikey&command=deployvirtualmachine&iptonetworklist[0].ip=127.0.0.1&iptonetworklist[0].networkid=1");
}

代码示例来源: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

public void testEndpoint() {
 HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://foo").build();
 assertEquals(request.toBuilder()
           .endpoint("http://bar").build(), 
     HttpRequest.builder()
           .method("GET")
           .endpoint("http://bar").build());
}

代码示例来源: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

@Test(invocationCount = 5, timeOut = 5000)
public void testGetStringViaRequest() throws IOException {
 HttpResponse getStringResponse = client.invoke(HttpRequest.builder().method("GET")
    .endpoint(format("http://localhost:%d/objects/", testPort)).build());
 assertEquals(Strings2.toString(getStringResponse.getPayload()).trim(), XML);
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testListServersWhenReponseIs404IsEmpty() throws Exception {
 HttpRequest listServers = HttpRequest
    .builder()
    .method("GET")
    .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/detail")
    .addHeader("Accept", "application/json")
    .addHeader("X-Auth-Token", authToken).build();
 HttpResponse listServersResponse = HttpResponse.builder().statusCode(404).build();
 ComputeService apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
    responseWithKeystoneAccess, listServers, listServersResponse);
 assertTrue(apiWhenNoServersExist.listNodes().isEmpty());
}

代码示例来源: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

public void testGetApiMetaDataFailNotFound() {
 KeystoneApi api = requestsSendResponses(
    keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess,
    HttpRequest.builder().method("GET").endpoint(endpoint + "/v2.0/").addHeader("Accept", APPLICATION_JSON).build(),
    HttpResponse.builder().statusCode(404).build());
 assertNull(api.getApiMetadata());
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
public void testExtendedPropertiesBind() {
 ObjectMetadata md = ObjectMetadataBuilder.create().key("foo").cacheControl("no-cache").userMetadata(
      ImmutableMap.of("foo", "bar")).build();
 HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
 BindObjectMetadataToRequest binder = injector.getInstance(BindObjectMetadataToRequest.class);
 assertEquals(binder.bindToRequest(request, md), HttpRequest.builder().method("POST").endpoint("http://localhost").headers(
      ImmutableMultimap.of("Cache-Control", "no-cache", "x-amz-meta-foo", "bar", "Content-Type",
          "binary/octet-stream")).build());
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testListExtensionsWhenReponseIs404IsEmpty() throws Exception {
 HttpRequest listExtensions = HttpRequest
    .builder()
    .method("GET")
    .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/extensions")
    .addHeader("Accept", "application/json")
    .addHeader("X-Auth-Token", authToken).build();
 HttpResponse listExtensionsResponse = HttpResponse.builder().statusCode(404).build();
 NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
    responseWithKeystoneAccess, listExtensions, listExtensionsResponse);
 assertTrue(apiWhenNoServersExist.getExtensionApiForZone("az-1.region-a.geo-1").list().isEmpty());
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
void testConvertRequestSetsHeaders() throws IOException {
 HttpRequest request = HttpRequest.builder()
                  .method(HttpMethod.GET)
                  .endpoint(endPoint)
                  .addHeader("foo", "bar").build();
 HTTPRequest gaeRequest = req.apply(request);
 assertEquals(gaeRequest.getHeaders().get(0).getName(), "foo");
 assertEquals(gaeRequest.getHeaders().get(0).getValue(), "bar");
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testStartupHost() {
 HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
    responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
    HttpRequest.builder().method("GET")
          .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu/startup")
          .addHeader("Accept", "application/json")
          .addHeader("X-Auth-Token", authToken).build(),
    HttpResponse.builder().statusCode(200)
       .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"startup\"}", MediaType.APPLICATION_JSON))
       .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
 assertTrue(api.startup("ubuntu"));
}

代码示例来源:origin: jclouds/legacy-jclouds

public void test() {
 HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build();
 request = binder.bindToRequest(request, new String[] { "alpha", "omega" });
 assertEquals(request.getPayload().getRawContent(), "BundleId.1=alpha&BundleId.2=omega");
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testDNSEndpointApplied() {
 KeystoneAuth keystoneAuth = new KeystoneAuth();
 DNSApi api = requestsSendResponses(
    keystoneAuth.getKeystoneAuthWithUsernameAndPassword(),
    keystoneAuth.getResponseWithKeystoneAccess(),
    HttpRequest.builder().method("HEAD").endpoint("http://172.16.0.1:8776/v1/3456/zones/foo.com").build(),
    HttpResponse.builder().statusCode(200).build());
 assertTrue(api.zoneExists("foo.com"));
}

代码示例来源: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: jclouds/legacy-jclouds

@Test(expectedExceptions = {ResourceNotFoundException.class})
  public void testDeleteDomainWhenResponseIs4xxThrows() throws Exception {
   DomainApi api = requestSendsResponse(
      HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/domain/delete/format/json")
            .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
            .addFormParam("domainname", "x").build(),
      HttpResponse.builder().statusCode(404).build()).getDomainApi();

   api.delete("x");
  }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
public void testListHostsEmptyOn404() {
 HttpRequest request = HttpRequest.builder()
   .method("GET")
   .endpoint("http://localhost:8080/client/api?response=json&command=listHosts&listAll=true&apiKey=identity&signature=NnYyyEy30G3V2dcIt7w4WZ68AU8%3D")
   .addHeader("Accept", "application/json").build();
 HttpResponse response = HttpResponse.builder().statusCode(404).build();
 GlobalHostClient client = requestSendsResponse(request, response);
 assertEquals(client.listHosts(), ImmutableSet.of());
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testListArchivesWhenResponseIs4xxReturnsEmpty() {
 ArchiveApi api = requestSendsResponse(
    HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/archive/list/format/json")
          .addHeader("Accept", "application/json")
          .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(),
    HttpResponse.builder().statusCode(404).build()).getArchiveApi();
 assertTrue(api.list().isEmpty());
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
public void testJAXBResponseParserAnnotationWithCustomValue() throws SecurityException, NoSuchMethodException {
 TestJAXBApi api = requestSendsResponse( //
    HttpRequest.builder().method("GET").endpoint("http://mock/jaxb/custom").build(), //
    HttpResponse.builder().statusCode(200).payload("<test><elem>Hello World</elem></test>").build());
 Object result = api.jaxbGetWithAnnotationAndCustomClass();
 assertTrue(result instanceof TestJAXBDomain);
 assertEquals(TestJAXBDomain.class.cast(result).getElem(), "Hello World");
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testArchiveDetailsWhenResponseIs4xxReturnsNull() {
 ArchiveApi api = requestSendsResponse(
    HttpRequest.builder().method("POST").endpoint("https://api.glesys.com/archive/details/format/json")
          .addHeader("Accept", "application/json")
          .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
          .addFormParam("username", "xxxxxx_test1").build(),
    HttpResponse.builder().statusCode(404).build())
    .getArchiveApi();
 assertNull(api.get("xxxxxx_test1"));
}

相关文章