Package org.jclouds.http

Examples of org.jclouds.http.HttpException


   private 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


   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

      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

   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

         request = request.toBuilder()
               .addHeader(GlacierHeaders.LINEAR_HASH, hash.getLinearHash().toString())
               .addHeader(GlacierHeaders.TREE_HASH, hash.getTreeHash().toString())
               .build();
      } catch (IOException e) {
         throw new HttpException("Error hashing the payload", e);
      }
      return request;
   }
View Full Code Here

         his = new HashingInputStream(Hashing.sha256(),
               request.getPayload() == null ? ByteSource.empty().openStream() : request.getPayload().openStream());
         ByteStreams.copy(his, ByteStreams.nullOutputStream());
         return his.hash();
      } catch (IOException e) {
         throw new HttpException("Error signing request", e);
      } finally {
         Closeables.closeQuietly(his);
      }
   }
View Full Code Here

   private byte[] hmacSha256(byte[] key, String s) {
      try {
         Mac hmacSHA256 = crypto.hmacSHA256(key);
         return hmacSHA256.doFinal(s.getBytes());
      } catch (Exception e) {
         throw new HttpException("Error signing request", e);
      }
   }
View Full Code Here

public class GetPayloadFromHttpContent implements Function<HttpResponse, Payload> {

   @Override
   public Payload apply(HttpResponse from) {
      if (from.getPayload() == null)
         throw new HttpException("Did not receive payload");
      return from.getPayload();
   }
View Full Code Here

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

public class ParseMultipartUploadIdHeader implements Function<HttpResponse, String> {
   @Override
   public String apply(HttpResponse from) {
      String id = from.getFirstHeaderOrNull(GlacierHeaders.MULTIPART_UPLOAD_ID);
      if (id == null)
         throw new HttpException("Did not receive Multipart upload Id");
      return id;
   }
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.