Package org.jclouds.vcloud.domain

Examples of org.jclouds.vcloud.domain.VCloudError


   public void handleError(HttpCommand command, HttpResponse response) {
      HttpRequest request = command.getCurrentRequest();
      Exception exception = new HttpResponseException(command, response);
      try {
         VCloudError error = null;
         String message = null;
         if (response.getPayload() != null) {
            try {
               error = utils.parseErrorFromContent(request, response);
               if (error != null) {
                  message = error.getMessage();
                  exception = new VCloudResponseException(command, response, error);
               } else {
                  message = Strings2.toString(response.getPayload());
                  exception = message != null ? new HttpResponseException(command, response, message) : exception;
               }
            } catch (IOException e) {
            } finally {
               response.getPayload().release();
            }
         }
         message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
                  .getStatusLine());

         switch (response.getStatusCode()) {
            case 400:
               if (error != null
                        && ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.BUSY_ENTITY)
                        || (error.getMessage() != null && error.getMessage().indexOf("is not running") != -1)))
                  exception = new IllegalStateException(message, exception);
               else
                  exception = new IllegalArgumentException(message, exception);
               break;
            case 401:
            case 403:
               if (error != null
                        && ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.ACCESS_TO_RESOURCE_IS_FORBIDDEN)
                        || (error.getMessage() != null && error.getMessage().indexOf("No access to entity") != -1)))
                  exception = new ResourceNotFoundException(message, exception);
               else
                  exception = new AuthorizationException(exception.getMessage(), exception);
               break;
            case 404:
View Full Code Here


   public void handleError(HttpCommand command, HttpResponse response) {
      HttpRequest request = command.getCurrentRequest();
      Exception exception = new HttpResponseException(command, response);
      try {
         VCloudError error = null;
         String message = null;
         if (response.getPayload() != null) {
            try {
               error = utils.parseErrorFromContent(request, response);
               if (error != null) {
                  message = error.getMessage();
                  exception = new VCloudResponseException(command, response, error);
               } else {
                  message = Strings2.toString(response.getPayload());
                  exception = message != null ? new HttpResponseException(command, response, message) : exception;
               }
            } catch (IOException e) {
            } finally {
               response.getPayload().release();
            }
         }
         message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
                  .getStatusLine());

         switch (response.getStatusCode()) {
            case 400:
               if (error != null
                        && ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.BUSY_ENTITY)
                        || (error.getMessage() != null && error.getMessage().indexOf("is not running") != -1)))
                  exception = new IllegalStateException(message, exception);
               else
                  exception = new IllegalArgumentException(message, exception);
               break;
            case 401:
            case 403:
               if (error != null
                        && ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.ACCESS_TO_RESOURCE_IS_FORBIDDEN)
                        || (error.getMessage() != null && error.getMessage().indexOf("No access to entity") != -1)))
                  exception = new ResourceNotFoundException(message, exception);
               else
                  exception = new AuthorizationException(exception.getMessage(), exception);
               break;
            case 404:
View Full Code Here

   public void handleError(HttpCommand command, HttpResponse response) {
      HttpRequest request = command.getCurrentRequest();
      Exception exception = new HttpResponseException(command, response);
      try {
         VCloudError error = null;
         String message = null;
         if (response.getPayload() != null) {
            try {
               error = utils.parseErrorFromContent(request, response);
               if (error != null) {
                  message = error.getMessage();
                  exception = new VCloudResponseException(command, response, error);
               } else {
                  message = Strings2.toStringAndClose(response.getPayload().openStream());
                  exception = message != null ? new HttpResponseException(command, response, message) : exception;
               }
            } catch (IOException e) {
            } finally {
               response.getPayload().release();
            }
         }
         message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
                  .getStatusLine());

         switch (response.getStatusCode()) {
            case 400:
               if (error != null
                        && ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.BUSY_ENTITY)
                        || (error.getMessage() != null && error.getMessage().indexOf("is not running") != -1)))
                  exception = new IllegalStateException(message, exception);
               else
                  exception = new IllegalArgumentException(message, exception);
               break;
            case 401:
            case 403:
               if (error != null
                        && ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.ACCESS_TO_RESOURCE_IS_FORBIDDEN)
                        || (error.getMessage() != null && error.getMessage().indexOf("No access to entity") != -1)))
                  exception = new ResourceNotFoundException(message, exception);
               else
                  exception = new AuthorizationException(exception.getMessage(), exception);
               break;
            case 404:
View Full Code Here

TOP

Related Classes of org.jclouds.vcloud.domain.VCloudError

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.