Package org.jclouds.atmos.domain

Examples of org.jclouds.atmos.domain.AtmosError


   @Inject
   Provider<ErrorHandler> errorHandlerProvider;

   public AtmosError parseAtmosErrorFromContent(HttpCommand command, HttpResponse response, InputStream content)
            throws HttpException {
      AtmosError error = factory.create(errorHandlerProvider.get()).parse(content);
      if (error.getCode() == 1032) {
         error.setStringSigned(signer.createStringToSign(command.getCurrentRequest()));
      }
      return error;

   }
View Full Code Here


      if (response.getStatusCode() == 500) {
         byte[] content = HttpUtils.closeClientButKeepContentStream(response);
         // Content can be null in the case of HEAD requests
         if (content != null) {
            try {
               AtmosError error = utils.parseAtmosErrorFromContent(command, response,
                        new String(content));
               if (error.getCode() == 1040) {  // The server is busy. Please try again.
                  return backoffHandler.shouldRetryRequest(command, response);
               }
               // don't increment count before here, since backoff handler does already
               command.incrementFailureCount();
            } catch (HttpException e) {
View Full Code Here

      HttpCommand command = createMock(HttpCommand.class);
      String content = String.format(HTTP_MESSAGE_FORMAT, 1040, "The server is busy. Please try again");
      HttpResponse response = HttpResponse.builder().statusCode(500).payload(content).build();

      expect(command.getFailureCount()).andReturn(0).once();
      expect(utils.parseAtmosErrorFromContent(command, response, content)).andReturn(new AtmosError(1040, "The server is busy. Please try again")).once();
      expect(backoffLimitedRetryHandler.shouldRetryRequest(command, response)).andReturn(true).once();

      replay(utils, backoffLimitedRetryHandler, command);

      AtmosServerErrorRetryHandler retry = new AtmosServerErrorRetryHandler(backoffLimitedRetryHandler, utils);
View Full Code Here

   public static final Pattern DIRECTORY_KEY_PATH = Pattern.compile("^/rest/namespace/?([^/]+)/(.*)");

   public void handleError(HttpCommand command, HttpResponse response) {
      Exception exception = new HttpResponseException(command, response);
      try {
         AtmosError error = null;
         if (response.getPayload() != null) {
            try {
               String content = Strings2.toString(response.getPayload());
               if (content != null && content.indexOf('<') >= 0) {
                  error = utils.parseAtmosErrorFromContent(command, response, Strings2.toInputStream(content));
               } else {
                  exception = content != null ? new HttpResponseException(command, response, content) : exception;
               }
            } catch (IOException e) {
               logger.warn(e, "exception reading error from response", response);
            }
         }
         if (error != null && error.getCode() == 1016) {
            File file = new File(command.getCurrentRequest().getEndpoint().getPath());
            exception = new KeyAlreadyExistsException(file.getParentFile().getAbsolutePath(), file.getName());
         } else {
            switch (response.getStatusCode()) {
            case 401:
               exception = new AuthorizationException(exception.getMessage(), exception);
               break;
            case 404:
               if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
                  String message = error != null ? error.getMessage() : String.format("%s -> %s", command.getCurrentRequest()
                        .getRequestLine(), response.getStatusLine());
                  String path = command.getCurrentRequest().getEndpoint().getPath();
                  Matcher matcher = DIRECTORY_PATH.matcher(path);
                  if (matcher.find()) {
                     exception = new ContainerNotFoundException(matcher.group(1), message);
View Full Code Here

   }

   public void testApplyInputStream() {
      InputStream is = getClass().getResourceAsStream("/error.xml");
      ParseSax<AtmosError> parser = createParser();
      AtmosError result = parser.parse(is);
      assertEquals(result.getCode(), 1003);
   }
View Full Code Here

   @Inject
   Provider<ErrorHandler> errorHandlerProvider;

   public AtmosError parseAtmosErrorFromContent(HttpCommand command, HttpResponse response, InputStream content)
            throws HttpException {
      AtmosError error = factory.create(errorHandlerProvider.get()).parse(content);
      if (error.getCode() == 1032) {
         error.setStringSigned(signer.createStringToSign(command.getCurrentRequest()));
      }
      return error;

   }
View Full Code Here

      } else if (response.getStatusCode() == 409) {
         byte[] content = HttpUtils.closeClientButKeepContentStream(response);
         // Content can be null in the case of HEAD requests
         if (content != null) {
            try {
               AtmosError error = utils.parseAtmosErrorFromContent(command, response,
                        new String(content));
               if (error.getCode() == 1006) {
                  return backoffHandler.shouldRetryRequest(command, response);
               }
               // don't increment count before here, since backoff handler does already
               command.incrementFailureCount();
            } catch (HttpException e) {
View Full Code Here

   private StringBuilder currentText = new StringBuilder();
   private int code;
   private String message;

   public AtmosError getResult() {
      return new AtmosError(code, message);
   }
View Full Code Here

   @Inject
   Provider<ErrorHandler> errorHandlerProvider;

   public AtmosError parseAtmosErrorFromContent(HttpCommand command, HttpResponse response, InputStream content)
            throws HttpException {
      AtmosError error = factory.create(errorHandlerProvider.get()).parse(content);
      if (error.getCode() == 1032) {
         error.setStringSigned(signer.createStringToSign(command.getCurrentRequest()));
      }
      return error;

   }
View Full Code Here

   private StringBuilder currentText = new StringBuilder();
   private int code;
   private String message;

   public AtmosError getResult() {
      return new AtmosError(code, message);
   }
View Full Code Here

TOP

Related Classes of org.jclouds.atmos.domain.AtmosError

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.