Package org.jclouds.http

Examples of org.jclouds.http.HttpResponseException


   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 400:
            break;
View Full Code Here


   protected Logger logger = Logger.NULL;

   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 400:
View Full Code Here

         }
      } finally {
         releasePayload(from);
      }
      throw new HttpResponseException("not found ", null, from);
   }
View Full Code Here

            if (ms.find() && mm.find()) {
               String status = ms.group(1);
               String errorMessage = mm.group(1);
               // revert status code to 200 to match actual server's return status
               response = response.toBuilder().statusCode(200).build();
               exception = refineException(new HttpResponseException(command, response, status + ": " + errorMessage));
            }
         }
      } catch (UnsupportedEncodingException e) {
         // should never happen as UTF-8 is always supported
      } finally {
         if (exception == null) {
            exception = new HttpResponseException(command, response);
         }
         command.setException(exception);
         releasePayload(response);
      }
   }
View Full Code Here

      // Create default exception
      String message = data != null
            ? new String(data)
            : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine());
      Exception exception = new HttpResponseException(command, response, message);
     
      // Try to create a VCloudDirectorException from XML payload, if it exists
      if (response.getPayload() != null && response.getPayload().getContentMetadata().getContentType().startsWith(VCloudDirectorMediaType.ERROR)) {
        try {
           Error error = JAXB.unmarshal(new ByteArrayInputStream(data), Error.class);
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 400:
            break;
View Full Code Here

   protected Logger logger = Logger.NULL;

   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 400:
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(message, exception);
            break;
         case 404:
            if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
               exception = new ResourceNotFoundException(message, exception);
            }
            break;
         default:
            exception = new HttpResponseException(command, response, message);
            break;
      }
      command.setException(exception);
   }
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

      this.errorParser = errorParser;
   }

   public void handleError(HttpCommand command, HttpResponse response) {
      String message = errorParser.apply(response);
      Exception exception = new HttpResponseException(command, response, message);
      try {
         message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
               response.getStatusLine());
         switch (response.getStatusCode()) {
            case 401:
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.