Examples of HttpResponseException


Examples of org.jclouds.http.HttpResponseException

   }

   public void testFalseIf5xx() throws Exception {
      FalseOn5xx function = new FalseOn5xx();
      HttpResponse response = EasyMock.createMock(HttpResponse.class);
      HttpResponseException exception = EasyMock.createMock(HttpResponseException.class);

      // Status code is called twice
      expect(response.getStatusCode()).andReturn(503);
      expect(response.getStatusCode()).andReturn(503);
      // Get response gets called twice
      expect(exception.getResponse()).andReturn(response);
      expect(exception.getResponse()).andReturn(response);
      // Get cause is called to determine the root cause
      expect(exception.getCause()).andReturn(null);

      replay(response);
      replay(exception);

      assertFalse(function.createOrPropagate(exception));
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

   }

   public void testExceptionIfNot5xx() {
      FalseOn5xx function = new FalseOn5xx();
      HttpResponse response = EasyMock.createMock(HttpResponse.class);
      HttpResponseException exception = EasyMock.createMock(HttpResponseException.class);

      // Status code is called twice
      expect(response.getStatusCode()).andReturn(600);
      expect(response.getStatusCode()).andReturn(600);
      // Get response gets called twice
      expect(exception.getResponse()).andReturn(response);
      expect(exception.getResponse()).andReturn(response);
      // Get cause is called to determine the root cause
      expect(exception.getCause()).andReturn(null);

      replay(response);
      replay(exception);

      try {
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

      volume.setName("Test volume");
      MovedVolumeDto movedRef = new MovedVolumeDto();
      movedRef.setVolume(volume);

      HttpResponse response = EasyMock.createMock(HttpResponse.class);
      HttpResponseException exception = EasyMock.createMock(HttpResponseException.class);
      Payload payload = Payloads.newPayload(xmlParser.toXML(movedRef));

      // Status code is called once
      expect(response.getStatusCode()).andReturn(Status.MOVED_PERMANENTLY.getStatusCode());
      // Get response gets called twice
      expect(exception.getResponse()).andReturn(response);
      expect(exception.getResponse()).andReturn(response);
      // Get payload is called three times: one to deserialize it, and twice to
      // release it
      expect(response.getPayload()).andReturn(payload);
      expect(response.getPayload()).andReturn(payload);
      expect(response.getPayload()).andReturn(payload);
      // Get cause is called to determine the root cause
      expect(exception.getCause()).andReturn(null);

      replay(response);
      replay(exception);

      function.create(exception);
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

            case 401:
            case 403:
               // Authorization exceptions do not return an errors DTO, so we
               // encapsulate a
               // generic exception
               exception = new AuthorizationException(defaultMessage, new HttpResponseException(command, response,
                     defaultMessage));
               break;
            case 404:
               exception = new ResourceNotFoundException(defaultMessage, getExceptionToPropagate(command, response,
                     defaultMessage));
               break;
            case 301:
               // Moved resources in Abiquo should be handled with the
               // ReturnMovedResource
               // exception parser to return the moved entity.
               exception = new HttpResponseException(command, response, defaultMessage);
               break;
            default:
               exception = getExceptionToPropagate(command, response, defaultMessage);
               break;
         }
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

            exception = new AbiquoException(fromStatusCode(response.getStatusCode()), errors);
         } catch (Exception ex) {
            // If it is not an Abiquo Exception (can not be unmarshalled),
            // propagate a standard
            // HttpResponseException
            exception = new HttpResponseException(command, response, defaultMessage);
         }
      } else {
         // If it is not an Abiquo Exception (there is not an errors xml in the
         // payload)
         // propagate a standard HttpResponseException
         exception = new HttpResponseException(command, response, defaultMessage);
      }

      return exception;
   }
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

      @Override
      public Object createOrPropagate(Throwable from) throws Exception {
         Throwable exception = find(getCausalChain(from), hasResponse(from), null);

         if (exception != null) {
            HttpResponseException responseException = (HttpResponseException) exception;
            HttpResponse response = responseException.getResponse();

            if (response != null && response.getStatusCode() == Status.SEE_OTHER.getStatusCode()) {
               return null;
            }
         }
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

      @Override
      public Boolean createOrPropagate(Throwable from) throws Exception {
         Throwable exception = find(getCausalChain(from), hasResponse(from), null);

         if (exception != null) {
            HttpResponseException responseException = (HttpResponseException) exception;
            HttpResponse response = responseException.getResponse();

            if (response != null && response.getStatusCode() >= 500 && response.getStatusCode() < 600) {
               return false;
            }
         }
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

      public Boolean createOrPropagate(Throwable from) throws Exception {
         Throwable exception = find(getCausalChain(from), isNotAvailableException(from), null);

         if (exception != null) {
            if (exception instanceof HttpResponseException) {
               HttpResponseException responseException = (HttpResponseException) exception;
               HttpResponse response = responseException.getResponse();

               if (response != null && response.getStatusCode() >= 500 && response.getStatusCode() < 600) {
                  return false;
               }
            } else {
View Full Code Here

Examples of org.jclouds.http.HttpResponseException

   @Override
   public VolumeManagementDto createOrPropagate(Throwable from) throws Exception {
      Throwable exception = find(getCausalChain(from), isMovedException(from), null);

      if (exception != null) {
         HttpResponseException responseException = (HttpResponseException) exception;
         HttpResponse response = responseException.getResponse();

         return parser.apply(response).getVolume();
      }

      throw propagate(from);
View Full Code Here

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());
      Status status = Status.fromStatusCode(response.getStatusCode());
      switch (status) {
         case BAD_REQUEST:
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.