Package org.jclouds.http

Examples of org.jclouds.http.HttpResponseException


      try {
         imageApi.list();
         fail("Request should have failed after retrying");
      } catch (Exception ex) {
         assertTrue(ex instanceof HttpResponseException, "Exception should be an HttpResponseException");
         HttpResponseException exception = HttpResponseException.class.cast(ex);
         assertEquals(exception.getResponse().getStatusCode(), 500);
         assertEquals(exception.getMessage(), "No Image Found");
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here


               break;
            case 404:
               exception = new ResourceNotFoundException(response.getMessage(), exception);
               break;
            default:
               exception = new HttpResponseException(response.getMessage(), command, response);
               break;
         }
      } finally {
         command.setException(exception);
      }
View Full Code Here

   }

   public void testFalseIf5xx() throws Exception {
      FalseIfNotAvailable function = new FalseIfNotAvailable();
      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

   }

   public void testExceptionIfNot5xx() {
      FalseIfNotAvailable function = new FalseIfNotAvailable();
      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

   }

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

      // Status code is called once
      expect(response.getStatusCode()).andReturn(303);
      // 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);

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

   }

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

      // Status code is called once
      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

   }

   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

   }

   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

      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

            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

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.