Package org.jclouds.http

Examples of org.jclouds.http.HttpResponseException


      // 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


               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

      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

   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 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 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

   @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

      @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

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.