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

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

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

HttpResponse.getPayload介绍

暂无

代码示例

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

String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
   if (response.getPayload() != null) {
     try {
      return Strings2.toString(response.getPayload());
     } catch (IOException e) {
      logger.warn(e, "exception reading error from response", response);
     }
   }
   return null;
  }
}

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

public void handleError(HttpCommand command, HttpResponse from) {
   String content;
   try {
     content = from.getPayload() != null ? Strings2.toString(from.getPayload()) : null;
     command.setException(new HttpResponseException(command, from, content));
   } catch (IOException e) {
     command.setException(new HttpResponseException(command, from));
   } finally {
     releasePayload(from);
   }
  }
}

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

public Blob apply(HttpResponse from) {
 checkNotNull(from, "request");
 MutableBlobMetadata metadata = metadataParser.apply(from);
 Blob blob = blobFactory.create(metadata);
 blob.getAllHeaders().putAll(from.getHeaders());
 blob.setPayload(from.getPayload());
 return blob;
}

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

/**
  * parses the http response headers to create a new {@link BoundedSet} object.
  */
  public BoundedSet<DirectoryEntry> apply(HttpResponse from) {
   checkNotNull(from, "http response");
   String token = from.getFirstHeaderOrNull(AtmosHeaders.TOKEN);
   return new BoundedLinkedHashSet<DirectoryEntry>(factory.create(listHandlerProvider.get()).parse(
      from.getPayload().getInput()), token);
  }
}

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

public S3Object apply(HttpResponse from) {
 MutableObjectMetadata metadata = metadataParser.apply(from);
 S3Object object = objectProvider.create(metadata);
 object.getAllHeaders().putAll(from.getHeaders());
 object.setPayload(from.getPayload());
 return object;
}

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

public AzureBlob apply(HttpResponse from) {
 MutableBlobProperties metadata = metadataParser.apply(from);
 AzureBlob blob = blobFactory.create(metadata);
 blob.getAllHeaders().putAll(from.getHeaders());
 blob.setPayload(from.getPayload());
 return blob;
}

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

public SwiftObject apply(HttpResponse from) {
 MutableObjectInfoWithMetadata metadata = infoParser.apply(from);
 if (metadata.getHash() != null)
   from.getPayload().getContentMetadata().setContentMD5(metadata.getHash());
 SwiftObject object = objectProvider.create(metadata);
 object.getAllHeaders().putAll(from.getHeaders());
 object.setPayload(from.getPayload());
 return object;
}

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

@Test
public void test413MakesInsufficientResourcesException() {
 fn.handleError(command, tooLarge);
 assertEquals(command.getException().getClass(), InsufficientResourcesException.class);
 assertEquals(command.getException().getMessage(), tooLarge.getPayload().getRawContent());
}

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

@Test
public void test400MakesInsufficientResourcesExceptionOnQuotaExceeded() {
 fn.handleError(command, quotaExceeded);
 assertEquals(command.getException().getClass(), InsufficientResourcesException.class);
 assertEquals(command.getException().getMessage(), quotaExceeded.getPayload().getRawContent());
}

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

@Test
public void test413WithBadRetryAtFormatFallsBack() {
 fn.handleError(command, badRetryAt);
 assertEquals(command.getException().getClass(), InsufficientResourcesException.class);
 assertEquals(command.getException().getMessage(), badRetryAt.getPayload().getRawContent());
}

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

@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 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",
      TerremarkVCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}

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

@Test
public void testApplyTerremark() {
 HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
                   .payload(getClass().getResourceAsStream("/orglist.xml"))
                   .addHeader("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").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(), "37ce2715-9aba-4f48-8e45-2db8a8da702d");
 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 testApplyTerremark() {
 HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
                   .payload(getClass().getResourceAsStream("/orglist.xml"))
                   .addHeader("Set-Cookie", "vcloud-token=37ce2715-9aba-4f48-8e45-2db8a8da702d; path=/").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(), "37ce2715-9aba-4f48-8e45-2db8a8da702d");
 assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
      TerremarkVCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}

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

@Test
public void testApply() {
 HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
                   .payload(getClass().getResourceAsStream("/orglist.xml"))
                   .addHeader("x-vcloud-authorization", "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/").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(), "9er4d061-4bff-48fa-84b1-5da7166764d2");
 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 testApply() {
 HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
                   .payload(getClass().getResourceAsStream("/orglist.xml"))
                   .addHeader("x-vcloud-authorization", "vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/").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(), "9er4d061-4bff-48fa-84b1-5da7166764d2");
 assertEquals(reply.getOrgs(), ImmutableMap.of("adrian@jclouds.org", new ReferenceTypeImpl("adrian@jclouds.org",
      TerremarkVCloudMediaType.ORG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"))));
}

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

@Test(expectedExceptions = HttpResponseException.class)
public void testNoThrowsHttpResponseException() {
 HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
                   .payload(getClass().getResourceAsStream("/orglist.xml")).build();
 response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
 response.getPayload().getContentMetadata().setContentLength(307l);
 parser.apply(response);
}

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

@Test(expectedExceptions = HttpResponseException.class)
public void testUnmatchedCookieThrowsHttpResponseException() {
 HttpResponse response = HttpResponse.builder().statusCode(200).message("OK")
                   .payload(getClass().getResourceAsStream("/orglist.xml"))
                   .addHeader("Set-Cookie", "NSC_ESUO_21654_72.46.239.132_443=fooo;expires=Thu, 02-Jun-2011 17:19:26 GMT;path=/;secure;httponly").build();
 response.getPayload().getContentMetadata().setContentType("Content-Type: application/xml; charset=utf-8");
 response.getPayload().getContentMetadata().setContentLength(307l);
 parser.apply(response);
}

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

@Test
public void testApplySetsName() {
 HttpResponse from = HttpResponse.builder()
                 .statusCode(200).message("ok")
                 .payload("")
                 .addHeader(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT").build(); 
 from.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON);
 from.getPayload().getContentMetadata().setContentLength(100l);
 BlobMetadata metadata = parser.apply(from);
 assertEquals(metadata.getName(), "key");
}

相关文章