Package org.jclouds.http

Examples of org.jclouds.http.HttpResponseException


   @Resource
   protected Logger logger = Logger.NULL;
   public static final Pattern RESOURCE_PATTERN = Pattern.compile(".*/v[^/]+/([^/]+)/([0-9]+)");

   public void handleError(HttpCommand command, HttpResponse response) {
      Exception exception = new HttpResponseException(command, response);

      try {
         String content = parseErrorFromContentOrNull(command, response);
         if (content != null)
             exception = new HttpResponseException(command, response, content);
         if (response.getMessage() != null
                  && ((response.getMessage().indexOf("because there is a pending task running") != -1)
                           || (response.getMessage().indexOf("because it is already powered off") != -1)
                           || (response.getMessage().indexOf("exists") != -1)))
            exception = new IllegalStateException(response.getMessage(), exception);
         else if (response.getMessage() != null
                  && ((response.getMessage().indexOf("There are no additional Public IPs available") != -1)))
            exception = new  InsufficientResourcesException(response.getMessage(), exception);
         else
            switch (response.getStatusCode()) {
               case 400:
                  exception = new IllegalArgumentException(response.getMessage(), exception);
                  break;
               case 401:
                  exception = new AuthorizationException(exception.getMessage(), exception);
                  break;
               case 403: // TODO temporary as terremark mistakenly uses this for vApp
                  // not found.
               case 404:
                  String path = command.getCurrentRequest().getEndpoint().getPath();
View Full Code Here


      while (keyPair == null) {
         try {
            keyPair = trmkClient.generateKeyPairInOrg(org, getNextName(keyPairName), false);
            logger.debug("<< created keyPair(%s)", keyPair.getName());
         } catch (RuntimeException e) {
            HttpResponseException ht = Throwables2.getFirstThrowableOfType(e, HttpResponseException.class);
            if (ht == null || ht.getContent() == null
                  || ht.getContent().indexOf("Security key with same name exists") == -1)
               throw e;
         }
      }
      return keyPair;
   }
View Full Code Here

   public void handleError(HttpCommand command, HttpResponse response) {
      // it is important to always read fully and close streams
      byte[] data = closeClientButKeepContentStream(response);
      String message = data != null ? new String(data) : null;

      Exception exception = message != null ? new HttpResponseException(command, response, message)
               : new HttpResponseException(command, response);
      message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
               response.getStatusLine());
      switch (response.getStatusCode()) {
         case 401:
            exception = new AuthorizationException(exception.getMessage(), exception);
View Full Code Here

   public void testArbitraryExceptionDoesntConvert(){
      fn.create(new RuntimeException());
   }
  
   public void testHttpResponseExceptionWithoutResponseDoesntPropagate(){
      fn.create(new HttpResponseException("message", command, null));
   }
View Full Code Here

   public void testHttpResponseExceptionWithoutResponseDoesntPropagate(){
      fn.create(new HttpResponseException("message", command, null));
   }

   public void testHttpResponseExceptionWithoutRetryAfterHeaderDoesntPropagate(){
      fn.create(new HttpResponseException(command, HttpResponse.builder().statusCode(500).build()));
   }
View Full Code Here

   public void testHttpResponseExceptionWithoutRetryAfterHeaderDoesntPropagate(){
      fn.create(new HttpResponseException(command, HttpResponse.builder().statusCode(500).build()));
   }

   public void testHttpResponseExceptionWithMalformedRetryAfterHeaderDoesntConvert(){
      fn.create(new HttpResponseException(command,
            HttpResponse.builder()
                        .statusCode(503)
                        .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 ZBW").build()));
   }
View Full Code Here

                        .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 ZBW").build()));
   }
  
   @Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry now")
   public void testHttpResponseExceptionWithRetryAfterDate() {
      fn.create(new HttpResponseException(command,
            HttpResponse.builder()
                        .statusCode(503)
                        .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 GMT").build()));
   }
View Full Code Here

                        .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 GMT").build()));
   }
  
   @Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 700 seconds")
   public void testHttpResponseExceptionWithRetryAfterOffset(){
      fn.create(new HttpResponseException(command,
            HttpResponse.builder()
                        .statusCode(503)
                        .addHeader(HttpHeaders.RETRY_AFTER, "700").build()));
   }
View Full Code Here

                        .addHeader(HttpHeaders.RETRY_AFTER, "700").build()));
   }
  
   @Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 86400 seconds")
   public void testHttpResponseExceptionWithRetryAfterPastIsZero(){
      fn.create(new HttpResponseException(command,
            HttpResponse.builder()
                        .statusCode(503)
                        .addHeader(HttpHeaders.RETRY_AFTER, "Sun, 2 Jan 2000 00:00:00 GMT").build()));
   }
View Full Code Here

      if (location == null)
         location = from.getFirstHeaderOrNull("location");
      if (location != null) {
         return new TaskImpl(URI.create(location), null, TaskStatus.QUEUED, new Date(), null, null, null, null);
      } else {
         throw new HttpResponseException("no uri in headers or content", null, from);
      }

   }
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.