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

COVERAGE SUMMARY FOR SOURCE FILE [AWSClientErrorRetryHandler.java]

nameclass, %method, %block, %line, %
AWSClientErrorRetryHandler.java100% (1/1)100% (2/2)46%  (31/68)53%  (8/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AWSClientErrorRetryHandler100% (1/1)100% (2/2)46%  (31/68)53%  (8/15)
shouldRetryRequest (HttpCommand, HttpResponse): boolean 100% (1/1)34%  (19/56)30%  (3/10)
AWSClientErrorRetryHandler (AWSUtils): void 100% (1/1)100% (12/12)100% (5/5)

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.annotation.Resource;
24import javax.inject.Named;
25 
26import org.jclouds.Constants;
27import org.jclouds.aws.domain.AWSError;
28import org.jclouds.aws.util.AWSUtils;
29import org.jclouds.http.HttpCommand;
30import org.jclouds.http.HttpResponse;
31import org.jclouds.http.HttpRetryHandler;
32import org.jclouds.logging.Logger;
33 
34import com.google.inject.Inject;
35 
36/**
37 * Handles Retryable responses with error codes in the 4xx range
38 * 
39 * @author Adrian Cole
40 */
41public class AWSClientErrorRetryHandler implements HttpRetryHandler {
42 
43   @Inject(optional = true)
44   @Named(Constants.PROPERTY_MAX_RETRIES)
45   private int retryCountLimit = 5;
46 
47   private final AWSUtils utils;
48 
49   @Resource
50   protected Logger logger = Logger.NULL;
51 
52   @Inject
53   public AWSClientErrorRetryHandler(AWSUtils utils) {
54      this.utils = utils;
55   }
56 
57   public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
58      if (command.getFailureCount() > retryCountLimit)
59         return false;
60      if (response.getStatusCode() == 400 || response.getStatusCode() == 403
61               || response.getStatusCode() == 409) {
62         command.incrementFailureCount();
63         // Content can be null in the case of HEAD requests
64         if (response.getPayload() != null) {
65            closeClientButKeepContentStream(response);
66            AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response);
67            if (error != null
68                     && ("RequestTimeout".equals(error.getCode())
69                              || "OperationAborted".equals(error.getCode()) || "SignatureDoesNotMatch"
70                              .equals(error.getCode()))) {
71               return true;
72            }
73         }
74      }
75      return false;
76   }
77 
78}

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