Package org.jclouds.http

Examples of org.jclouds.http.HttpCommand


  
   NovaErrorHandler fn = new NovaErrorHandler(HeaderToRetryAfterException.create(y2k, iso8601Seconds),
         new OverLimitParser(new GsonWrapper(new Gson())));

   private HttpCommand command() {
      return new HttpCommand(HttpRequest.builder().method("POST").endpoint("https://nova/v1.1/servers").build());
   }
View Full Code Here


   public void testHandler() {
      InputStream is = getClass().getResourceAsStream("/test_error_handler.json");

      GoGridErrorHandler handler = Guice.createInjector(new GsonModule()).getInstance(GoGridErrorHandler.class);

      HttpCommand command = createHttpCommand();
      handler.handleError(command, HttpResponse.builder().statusCode(200).message("ok").payload(is).build());

      Exception createdException = command.getException();

      assertNotNull(createdException, "There should've been an exception generated");
      String message = createdException.getMessage();
      assertTrue(message.contains("No object found that matches your input criteria."),
            "Didn't find the expected error cause in the exception message");
View Full Code Here

         // this is the excepted output
      }
   }

   HttpCommand createHttpCommand() {
      return new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://localhost").build());
   }
View Full Code Here

   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
           String content, String copyObjectSourcePath, Class<? extends Exception> expected) {
    ParseSwiftErrorFromHttpResponse function = new ParseSwiftErrorFromHttpResponse();

    HttpCommand command = createMock(HttpCommand.class);
    Builder<?> requestBuilder = HttpRequest.builder().method(method).endpoint(uri);
   
    if (!Strings.isNullOrEmpty(copyObjectSourcePath)) {
      requestBuilder.addHeader(SwiftHeaders.OBJECT_COPY_FROM, copyObjectSourcePath);
    }
   
    HttpRequest request = requestBuilder.build();
    HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
    response.getPayload().getContentMetadata().setContentType(contentType);

    expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
    command.setException(classEq(expected));

    replay(command);

    function.handleError(command, response);
View Full Code Here

    * applies a {@link #getFallback(String, Invocation, HttpCommand) fallback}
    * if a {@code Throwable} is encountered.
    */
   public Object invoke(Invocation invocation) {
      String commandName = config.getCommandName(invocation);
      HttpCommand command = toCommand(commandName, invocation);
      Function<HttpResponse, ?> transformer = getTransformer(commandName, command);
      org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command);

      logger.debug(">> invoking %s", commandName);
      try {
View Full Code Here

    *            if the time limit is reached
    * @see TimeLimiter#callWithTimeout(Callable, long, TimeUnit, boolean)
    */
   public Object invokeWithTimeout(final Invocation invocation, final long limitNanos) {
      String commandName = config.getCommandName(invocation);
      HttpCommand command = toCommand(commandName, invocation);
      org.jclouds.Fallback<?> fallback = getFallback(commandName, invocation, command);

      logger.debug(">> blocking on %s for %s", invocation, limitNanos);
      try {
         return timeLimiter
View Full Code Here

   private HttpCommand toCommand(String commandName, Invocation invocation) {
      logger.trace(">> converting %s", commandName);
      HttpRequest request = annotationProcessor.apply(invocation);
      logger.trace("<< converted %s to %s", commandName, request.getRequestLine());
      return new HttpCommand(request);
   }
View Full Code Here

   public void testCode0SetsUltraDNSWSResponseException() throws IOException {
      HttpRequest request = HttpRequest.builder().method(POST)
                                                 .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
                                                 .addHeader(HOST, "ultra-api.ultradns.com:8443")
                                                 .payload(payloadFromResource("/list_tasks.xml")).build();
      HttpCommand command = new HttpCommand(request);
      HttpResponse response = HttpResponse.builder()
                                          .message(INTERNAL_SERVER_ERROR.getReasonPhrase())
                                          .statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
                                          .payload(payloadFromResource("/server_fault.xml")).build();

      function.handleError(command, response);

      assertEquals(command.getException().getClass(), UltraDNSWSResponseException.class);
      assertEquals(command.getException().getMessage(), "Error 0");

      UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException());

      assertEquals(exception.getError().getCode(), 0);
   }
View Full Code Here

   public void testCode0ForDescriptionMatchingCannotFindSetsResourceNotFoundException() throws IOException {
      HttpRequest request = HttpRequest.builder().method(POST)
                                                 .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
                                                 .addHeader(HOST, "ultra-api.ultradns.com:8443")
                                                 .payload(payloadFromResource("/list_tasks.xml")).build();
      HttpCommand command = new HttpCommand(request);
      HttpResponse response = HttpResponse.builder()
                                          .message(INTERNAL_SERVER_ERROR.getReasonPhrase())
                                          .statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
                                          .payload(payloadFromResource("/task_doesnt_exist.xml")).build();

      function.handleError(command, response);

      assertEquals(command.getException().getClass(), ResourceNotFoundException.class);
      assertEquals(command.getException().getMessage(), "Cannot find task with guid AAAAAAAAAAAAAAAA");

      UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause());

      assertEquals(exception.getMessage(), "Error 0: Cannot find task with guid AAAAAAAAAAAAAAAA");
      assertEquals(exception.getError().getDescription().get(), "Cannot find task with guid AAAAAAAAAAAAAAAA");
      assertEquals(exception.getError().getCode(), 0);
   }
View Full Code Here

   public void testCode2401SetsResourceNotFoundException() throws IOException {
      HttpRequest request = HttpRequest.builder().method(POST)
                                                 .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
                                                 .addHeader(HOST, "ultra-api.ultradns.com:8443")
                                                 .payload(payloadFromResource("/list_zones_by_account.xml")).build();
      HttpCommand command = new HttpCommand(request);
      HttpResponse response = HttpResponse.builder()
                                          .message(INTERNAL_SERVER_ERROR.getReasonPhrase())
                                          .statusCode(INTERNAL_SERVER_ERROR.getStatusCode())
                                          .payload(payloadFromResource("/account_doesnt_exist.xml")).build();

      function.handleError(command, response);

      assertEquals(command.getException().getClass(), ResourceNotFoundException.class);
      assertEquals(command.getException().getMessage(), "Account not found in the system. ID: AAAAAAAAAAAAAAAA");

      UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause());

      assertEquals(exception.getMessage(), "Error 2401: Account not found in the system. ID: AAAAAAAAAAAAAAAA");
      assertEquals(exception.getError().getDescription().get(), "Account not found in the system. ID: AAAAAAAAAAAAAAAA");
      assertEquals(exception.getError().getCode(), 2401);
   }
View Full Code Here

TOP

Related Classes of org.jclouds.http.HttpCommand

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.