Package org.jclouds.http

Examples of org.jclouds.http.HttpResponseException


   }

   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

      @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

      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

   }

   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.newByteSourcePayload(ByteSource.wrap(xmlParser.toXML(movedRef).getBytes()));

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

   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

   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

            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

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.