Package org.jclouds.rest

Examples of org.jclouds.rest.HttpClient


   public InputStream getBlobInputStream(BlobStore blobStore, String containerName, String blobName, boolean signedRequest)
         throws Exception {
      if (signedRequest) {
         BlobStoreContext context = blobStore.getContext();
         HttpRequest request = context.getSigner().signGetBlob(containerName, blobName);
         HttpClient httpClient = context.utils().http();
         HttpResponse response = httpClient.invoke(request);
         int statusCode = response.getStatusCode();
         if (statusCode != 200) {
            throw new IOException(response.getStatusLine());
         }
         return response.getPayload().openStream();
View Full Code Here


      }

      if (signedRequest) {
         BlobStoreContext context = blobStore.getContext();
         HttpRequest request = context.getSigner().signPutBlob(bucket, blob);
         HttpClient httpClient = context.utils().http();
         HttpResponse response = httpClient.invoke(request);
         int statusCode = response.getStatusCode();
         if (statusCode != 200 && statusCode != 201) {
            throw new IOException(response.getStatusLine());
         }
      } else {
View Full Code Here

   public InputSupplier<InputStream> getBlobInputStream(BlobStore blobStore, String containerName, String blobName, boolean signedRequest)
         throws Exception {
      if (signedRequest) {
         BlobStoreContext context = blobStore.getContext();
         HttpRequest request = context.getSigner().signGetBlob(containerName, blobName);
         HttpClient httpClient = context.utils().http();
         HttpResponse response = httpClient.invoke(request);
         int statusCode = response.getStatusCode();
         if (statusCode != 200) {
            throw new IOException(response.getStatusLine());
         }
         return response.getPayload();
View Full Code Here

      }

      if (signedRequest) {
         BlobStoreContext context = blobStore.getContext();
         HttpRequest request = context.getSigner().signPutBlob(bucket, blob);
         HttpClient httpClient = context.utils().http();
         HttpResponse response = httpClient.invoke(request);
         int statusCode = response.getStatusCode();
         if (statusCode != 200 && statusCode != 201) {
            throw new IOException(response.getStatusLine());
         }
      } else {
View Full Code Here

    // TODO: why does this hang for 30 seconds?
    @Ignore
    @Test
    public void testHttpClient() throws Exception {
        HttpClient httpClient = context.utils().http();
        // TODO: how to interpret this?
        URI uri = URI.create(s3Endpoint + "/container/blob");
        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        Payload payload = new ByteSourcePayload(byteSource);
        payload.getContentMetadata().setContentLength(byteSource.size());
        httpClient.put(uri, payload);
        try (InputStream actual = httpClient.get(uri);
             InputStream expected = byteSource.openStream()) {
            assertThat(actual).hasContentEqualTo(expected);
        }
    }
View Full Code Here

    // TODO: this test fails since S3BlobRequestSigner does not implement the
    // same logic as AWSS3BlobRequestSigner.signForTemporaryAccess.
    @Ignore
    @Test
    public void testUrlSigning() throws Exception {
        HttpClient httpClient = s3Context.utils().http();
        BlobRequestSigner signer = s3Context.getSigner();

        String blobName = "blob";
        ByteSource byteSource = ByteSource.wrap(new byte[1]);
        Blob blob = s3BlobStore.blobBuilder(blobName)
                .payload(byteSource)
                .contentLength(byteSource.size())
                .build();
        HttpRequest putRequest = signer.signPutBlob(containerName, blob, 10);
        HttpResponse putResponse = httpClient.invoke(putRequest);
        assertThat(putResponse.getStatusCode())
                .isEqualTo(HttpServletResponse.SC_OK);

        HttpRequest getRequest = signer.signGetBlob(containerName, blobName,
                10);
        HttpResponse getResponse = httpClient.invoke(getRequest);
        assertThat(getResponse.getStatusCode())
                .isEqualTo(HttpServletResponse.SC_OK);
    }
View Full Code Here

            return new MockResponse();
         }
      });
      server.play();

      HttpClient client =  api(HttpClient.class, server.getUrl("/").toString());

      // Make a fake payload that has no data, but says there's a lot!
      Payload fakePayload = new StringPayload("");
      fakePayload.getContentMetadata().setContentLength(reallyLongContent);

      try {
         try {
            client.post(server.getUrl("/").toURI(), fakePayload);
            fail("Should have errored since we didn't sent that much data!");
         } catch (HttpResponseException expected) {
         }
         assertEquals(server.takeRequest().getHeader(CONTENT_LENGTH), String.valueOf(reallyLongContent));
      } finally {
View Full Code Here

            continue;
         }
         String containerName = Iterables.getLast(containers).getName();

         final ByteSource input = ByteSource.wrap("str".getBytes());
         final HttpClient client = ctx.utils().http();

         // test signed put
         String blobName = "test-" + UUID.randomUUID();
         Blob blob2 = region.blobBuilder(blobName).forSigning()
               .contentLength(input.size())
               .contentMD5(input.hash(Hashing.md5()).asBytes())
               .contentType(MediaType.OCTET_STREAM.toString()).build();
         BlobRequestSigner signer = ctx.getSigner(regionId);
         HttpResponse response;
         try {
            HttpRequest putRequest;
            putRequest = signer.signPutBlob(containerName, blob2, 600);
            MutableContentMetadata metadata = blob2.getMetadata()
                  .getContentMetadata();
            HttpRequest.Builder<?> putRequestBuilder = putRequest.toBuilder()
                  .addHeader(HttpHeaders.CONTENT_TYPE,
                        metadata.getContentType());
            putRequestBuilder.addHeader(HttpHeaders.CONTENT_LENGTH,
                  String.valueOf(input.size()));
            putRequestBuilder.payload(input);
            putRequest = putRequestBuilder.build();
            Payload payload = Payloads.newPayload(input.read());
            putRequest.setPayload(payload);
            assertNotNull(putRequest, "regionId=" + regionId + ", container="
                  + containerName + ", blob=" + blobName);
            response = client.invoke(putRequest);
            if (response.getStatusCode() != 200
                  && response.getStatusCode() != 201) {
               fail("Signed PUT expected to return 200 or 201 but returned "
                     + response.getStatusCode());
            }
         } catch (Exception e) {
            fail("Failed signed put test: " + e);
         }

         // test signed get
         try {
            HttpRequest getRequest = signer.signGetBlob(containerName,
                  blobName);
            assertNotNull(getRequest, "regionId=" + regionId + ", container="
                  + containerName + ", blob=" + blobName);
            response = client.invoke(getRequest);
            if (response.getStatusCode() != 200) {
               fail("Signed GET expected to return 200 but returned "
                     + response.getStatusCode());
            }
            Payload payload = response.getPayload();
View Full Code Here

TOP

Related Classes of org.jclouds.rest.HttpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.