Package org.jclouds.http

Examples of org.jclouds.http.HttpException


public class ParseMultipartUploadTreeHashHeader implements Function<HttpResponse, HashCode> {
   @Override
   public HashCode apply(HttpResponse from) {
      String treehash = from.getFirstHeaderOrNull(GlacierHeaders.TREE_HASH);
      if (treehash == null)
         throw new HttpException("Did not receive Tree hash");
      return HashCode.fromString(treehash);
   }
View Full Code Here


   @Override
   public String apply(HttpResponse from) {
      String id = from.getFirstHeaderOrNull(GlacierHeaders.ARCHIVE_ID);
      if (id == null)
         throw new HttpException("Did not receive ArchiveId");
      return id;
   }
View Full Code Here

         ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(creds.get().credential.getBytes(UTF_8)));
         signature = base64().encode(readBytes(toInputStream(toSign), hmacSHA256));
         if (signatureWire.enabled())
            signatureWire.input(toInputStream(signature));
      } catch (Exception e) {
         throw new HttpException("error signing request", e);
      }
      return signature;
   }
View Full Code Here

   protected HttpRequest request;

   public URI apply(HttpResponse from) {
      if (from.getStatusCode() > 206)
         throw new HttpException(String.format("Unhandled status code  - %1$s", from));
      if ("text/uri-list".equals(from.getFirstHeaderOrNull(CONTENT_TYPE))) {
         try {
            if (from.getPayload().getInput() == null)
               throw new HttpResponseException("no content", null, from);
            String toParse = Strings2.toString(from.getPayload());
View Full Code Here

            InputStream payload = from.getPayload().getInput();
            String toReturn = null;
            try {
               toReturn = Strings2.toStringAndClose(payload);
            } catch (IOException e) {
               throw new HttpException(String.format(
                        "Couldn't receive response %1$s, payload: %2$s ", from, toReturn), e);
            }
            return toReturn;
         } else {
            throw new HttpException(String.format("Unhandled status code  - %1$s", from));
         }
      } finally {
         releasePayload(from);
      }
   }
View Full Code Here

         eTag = from.getFirstHeaderOrNull("Etag");
      }
      if (eTag != null) {
         return eTag;
      }
      throw new HttpException("did not receive ETag");
   }
View Full Code Here

   void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException {
      String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED);
      if (lastModified == null) {
         // scaleup-storage uses the wrong case for the last modified header
         if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null)
            throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from);
      }

      // Walrus
      if (lastModified.startsWith("20")) {
         metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z")));
      } else {
         metadata.setLastModified(dateParser.rfc822DateParse(lastModified));
      }

      if (metadata.getLastModified() == null)
         throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified);
   }
View Full Code Here

   public String signString(String toSign) {
      try {
         ByteProcessor<byte[]> hmacSHA256 = asByteProcessor(crypto.hmacSHA256(base64().decode(creds.get().credential)));
         return base64().encode(readBytes(toInputStream(toSign), hmacSHA256));
      } catch (Exception e) {
         throw new HttpException("error signing request", e);
      }
   }
View Full Code Here

   @VisibleForTesting
   void parseLastModifiedOrThrowException(HttpResponse from, MutableContainerPropertiesWithMetadata metadata)
         throws HttpException {
      String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED);
      if (lastModified == null)
         throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from);
      metadata.setLastModified(dateParser.rfc822DateParse(lastModified));
      if (metadata.getLastModified() == null)
         throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified);
   }
View Full Code Here

      try {
         Signature signer = signerCache.get(checkNotNull(creds.get(), "credential supplier returned null"));
         signer.update(stringToSign.getBytes(UTF_8));
         signed = base64().withSeparator("\n", 61).encode(signer.sign());
      } catch (SignatureException e) {
         throw new HttpException("error signing request", e);
      } catch (ExecutionException e) {
         throw new HttpException("couldn't load key for signing request", e);
      }
      return signed;
   }
View Full Code Here

TOP

Related Classes of org.jclouds.http.HttpException

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.