EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.http.handlers]

COVERAGE SUMMARY FOR SOURCE FILE [DelegatingErrorHandler.java]

nameclass, %method, %block, %line, %
DelegatingErrorHandler.java100% (1/1)100% (5/5)80%  (49/61)88%  (14/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DelegatingErrorHandler100% (1/1)100% (5/5)80%  (49/61)88%  (14/16)
handleError (HttpCommand, HttpResponse): void 100% (1/1)67%  (24/36)75%  (6/8)
DelegatingErrorHandler (): void 100% (1/1)100% (16/16)100% (5/5)
getClientErrorHandler (): HttpErrorHandler 100% (1/1)100% (3/3)100% (1/1)
getRedirectionHandler (): HttpErrorHandler 100% (1/1)100% (3/3)100% (1/1)
getServerErrorHandler (): HttpErrorHandler 100% (1/1)100% (3/3)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.http.handlers;
20 
21import javax.inject.Singleton;
22 
23import org.jclouds.http.HttpCommand;
24import org.jclouds.http.HttpErrorHandler;
25import org.jclouds.http.HttpResponse;
26import org.jclouds.http.annotation.ClientError;
27import org.jclouds.http.annotation.Redirection;
28import org.jclouds.http.annotation.ServerError;
29 
30import com.google.common.annotations.VisibleForTesting;
31import com.google.inject.Inject;
32 
33/**
34 * Delegates to {@link HttpErrorHandler HttpErrorHandlers} who are annotated according to the
35 * response codes they relate to.
36 * 
37 * @author Adrian Cole
38 */
39@Singleton
40public class DelegatingErrorHandler implements HttpErrorHandler {
41 
42   @VisibleForTesting
43   @Inject(optional = true)
44   @Redirection
45   HttpErrorHandler redirectionHandler;
46 
47   @VisibleForTesting
48   @Inject(optional = true)
49   @ClientError
50   HttpErrorHandler clientErrorHandler;
51 
52   @VisibleForTesting
53   @Inject(optional = true)
54   @ServerError
55   HttpErrorHandler serverErrorHandler;
56 
57   @Inject
58   DelegatingErrorHandler() {
59      this.redirectionHandler = new CloseContentAndSetExceptionErrorHandler();
60      this.clientErrorHandler = redirectionHandler;
61      this.serverErrorHandler = redirectionHandler;
62   }
63 
64   public void handleError(HttpCommand command, HttpResponse response) {
65      int statusCode = response.getStatusCode();
66      if (statusCode >= 300 && statusCode < 400) {
67         getRedirectionHandler().handleError(command, response);
68      } else if (statusCode >= 400 && statusCode < 500) {
69         getClientErrorHandler().handleError(command, response);
70      } else if (statusCode >= 500) {
71         getServerErrorHandler().handleError(command, response);
72      }
73   }
74 
75   public HttpErrorHandler getRedirectionHandler() {
76      return redirectionHandler;
77   }
78 
79   public HttpErrorHandler getClientErrorHandler() {
80      return clientErrorHandler;
81   }
82 
83   public HttpErrorHandler getServerErrorHandler() {
84      return serverErrorHandler;
85   }
86}

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