EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.aws.handlers]

COVERAGE SUMMARY FOR SOURCE FILE [AWSRedirectionRetryHandler.java]

nameclass, %method, %block, %line, %
AWSRedirectionRetryHandler.java0%   (0/1)0%   (0/2)0%   (0/102)0%   (0/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSRedirectionRetryHandler0%   (0/1)0%   (0/2)0%   (0/102)0%   (0/20)
AWSRedirectionRetryHandler (Provider, BackoffLimitedRetryHandler, AWSUtils): ... 0%   (0/1)0%   (0/8)0%   (0/3)
shouldRetryRequest (HttpCommand, HttpResponse): boolean 0%   (0/1)0%   (0/94)0%   (0/17)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.aws.handlers;
20 
21import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
22 
23import javax.inject.Inject;
24import javax.inject.Provider;
25import javax.inject.Singleton;
26import javax.ws.rs.HttpMethod;
27import javax.ws.rs.core.HttpHeaders;
28import javax.ws.rs.core.UriBuilder;
29 
30import org.jclouds.aws.domain.AWSError;
31import org.jclouds.aws.util.AWSUtils;
32import org.jclouds.http.HttpCommand;
33import org.jclouds.http.HttpResponse;
34import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
35import org.jclouds.http.handlers.RedirectionRetryHandler;
36 
37/**
38 * Handles Retryable responses with error codes in the 3xx range
39 * 
40 * @author Adrian Cole
41 */
42@Singleton
43public class AWSRedirectionRetryHandler extends RedirectionRetryHandler {
44   private final AWSUtils utils;
45 
46   @Inject
47   public AWSRedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider,
48         BackoffLimitedRetryHandler backoffHandler, AWSUtils utils) {
49      super(uriBuilderProvider, backoffHandler);
50      this.utils = utils;
51   }
52 
53   @Override
54   public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
55      if (response.getFirstHeaderOrNull(HttpHeaders.LOCATION) == null
56            && (response.getStatusCode() == 301 || response.getStatusCode() == 307)) {
57         if (command.getCurrentRequest().getMethod() == HttpMethod.HEAD) {
58            command.setCurrentRequest(command.getCurrentRequest().toBuilder().method("GET").build());
59            return true;
60         } else {
61            command.incrementRedirectCount();
62            closeClientButKeepContentStream(response);
63            AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response);
64            String host = error.getDetails().get("Endpoint");
65            if (host != null) {
66               if (host.equals(command.getCurrentRequest().getEndpoint().getHost())) {
67                  // must be an amazon error related to
68                  // http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287&#72287
69                  return backoffHandler.shouldRetryRequest(command, response);
70               } else {
71                  UriBuilder builder = uriBuilderProvider.get().uri(command.getCurrentRequest().getEndpoint());
72                  builder.host(host);
73                  command.setCurrentRequest(command.getCurrentRequest().toBuilder().endpoint(builder.build()).build());
74               }
75               return true;
76            } else {
77               return false;
78            }
79         }
80      } else {
81         return super.shouldRetryRequest(command, response);
82      }
83   }
84}

[all classes][org.jclouds.aws.handlers]
EMMA 2.0.5312 (C) Vladimir Roubtsov