Package org.jclouds.http

Examples of org.jclouds.http.HttpResponseException


      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());
            return URI.create(toParse.trim());
         } catch (IOException e) {
            throw new HttpResponseException("couldn't parse uri from content", null, from, e);
         } finally {
            releasePayload(from);
         }
      } else {
         releasePayload(from);
         String location = from.getFirstHeaderOrNull(LOCATION);
         if (location == null)
            location = from.getFirstHeaderOrNull("location");
         if (location != null) {
            URI locationUri = URI.create(location);
            if (locationUri.getHost() != null)
               return locationUri;
            checkState(request != null, "request should have been initialized");
            if (!location.startsWith("/"))
               location = "/" + location;
            locationUri = URI.create(location);
            return Uris.uriBuilder(request.getEndpoint()).path(locationUri.getPath()).query(locationUri.getQuery()).build();
         } else {
            throw new HttpResponseException("no uri in headers or content", null, from);
         }

      }
   }
View Full Code Here


      this.factory = factory;
      this.handlers = handlers;
   }

   public void handleError(HttpCommand command, HttpResponse response) {
      Exception exception = new HttpResponseException(command, response);
      try {
         byte[] data = closeClientButKeepContentStream(response);
         String message = data != null ? new String(data) : null;
         if (message != null) {
            exception = new HttpResponseException(command, response, message);
            String contentType = response.getPayload().getContentMetadata().getContentType();
            if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
               UltraDNSWSError error = factory.create(handlers.get()).parse(message);
               if (error != null) {
                  exception = refineException(new UltraDNSWSResponseException(command, response, error));
               }
            }
         } else {
            exception = new HttpResponseException(command, response);
         }
      } finally {
         releasePayload(response);
         command.setException(exception);
      }
View Full Code Here

      while (!created) {
         privateContainer = prefix + new SecureRandom().nextInt();
         try {
            created = getApi().createContainer(privateContainer, withMetadata(ImmutableMultimap.of("foo", "bar")));
         } catch (UndeclaredThrowableException e) {
            HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
            if (htpe.getResponse().getStatusCode() == 409)
               continue;
            throw e;
         }
      }
      Set<ContainerProperties> response = getApi().listContainers(includeMetadata());
View Full Code Here

      while (!created) {
         publicContainer = prefix + new SecureRandom().nextInt();
         try {
            created = getApi().createContainer(publicContainer, withPublicAccess(PublicAccess.BLOB));
         } catch (UndeclaredThrowableException e) {
            HttpResponseException htpe = (HttpResponseException) e.getCause().getCause();
            if (htpe.getResponse().getStatusCode() == 409)
               continue;
            throw e;
         }
      }
      // TODO
View Full Code Here

      // Non-matching ETag
      try {
         getApi().getBlob(privateContainer, object.getProperties().getName(),
               GetOptions.Builder.ifETagDoesntMatch(newEtag));
      } catch (Exception e) {
         HttpResponseException httpEx = Throwables2.getFirstThrowableOfType(e, HttpResponseException.class);
         assert (httpEx != null) : "expected http exception, not " + e;
         assertEquals(httpEx.getResponse().getStatusCode(), 304);
      }

      // Matching ETag TODO this shouldn't fail!!!
      try {
         getBlob = getApi().getBlob(privateContainer, object.getProperties().getName(),
View Full Code Here

            } catch (Exception e1) {
               command.setException(e1);
               return response;
            }
         } else {
            command.setException(new HttpResponseException(e.getMessage() + " connecting to "
                  + command.getCurrentRequest().getRequestLine(), command, null, e));
            return response;
         }
      } finally {
         if (command.getException() != null)
View Full Code Here

      }
   }

   public static HttpResponseException returnResponseException(int code) {
      HttpResponse response = HttpResponse.builder().statusCode(code).build();
      return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub")
            .build()), response);
   }
View Full Code Here

         }
         if (options.getIfModifiedSince() != null) {
            Date modifiedSince = options.getIfModifiedSince();
            if (blob.getMetadata().getLastModified().before(modifiedSince)) {
               HttpResponse response = HttpResponse.builder().statusCode(304).build();
               return immediateFailedFuture(new HttpResponseException(String.format("%1$s is before %2$s", blob
                     .getMetadata().getLastModified(), modifiedSince), null, response));
            }

         }
         if (options.getIfUnmodifiedSince() != null) {
            Date unmodifiedSince = options.getIfUnmodifiedSince();
            if (blob.getMetadata().getLastModified().after(unmodifiedSince)) {
               HttpResponse response = HttpResponse.builder().statusCode(412).build();
               return immediateFailedFuture(new HttpResponseException(String.format("%1$s is after %2$s", blob
                     .getMetadata().getLastModified(), unmodifiedSince), null, response));
            }
         }
         blob = copyBlob(blob);
View Full Code Here

public class SoftLayerErrorHandler implements HttpErrorHandler {

   public void handleError(HttpCommand command, HttpResponse response) {
      // it is important to always read fully and close streams
      String message = parseMessage(response);
      Exception exception = message != null ? new HttpResponseException(command, response, message)
               : new HttpResponseException(command, response);
      try {
         message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
                  response.getStatusLine());
         switch (response.getStatusCode()) {
            case 401:
View Full Code Here

      }

      @Override
      public Void createOrPropagate(Throwable t) throws Exception {
         if (checkNotNull(t, "throwable") instanceof HttpResponseException) {
            HttpResponseException hre = HttpResponseException.class.cast(t);
            if (hre.getResponse().getStatusCode() == 503 || hre.getResponse().getStatusCode() == 401
                  || MESSAGE_PATTERN.matcher(hre.getMessage()).matches())
               return null;
         } else if (t instanceof AuthorizationException) {
            return null;
         }
         throw propagate(t);
View Full Code Here

TOP

Related Classes of org.jclouds.http.HttpResponseException

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.