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

COVERAGE SUMMARY FOR SOURCE FILE [ParseS3ErrorFromXmlContent.java]

nameclass, %method, %block, %line, %
ParseS3ErrorFromXmlContent.java100% (1/1)100% (2/2)71%  (95/134)72%  (15.9/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseS3ErrorFromXmlContent100% (1/1)100% (2/2)71%  (95/134)72%  (15.9/22)
refineException (HttpCommand, HttpResponse, Exception, AWSError, String): Exc... 100% (1/1)69%  (85/124)66%  (11.9/18)
ParseS3ErrorFromXmlContent (AWSUtils, boolean, String): void 100% (1/1)100% (10/10)100% (4/4)

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.s3.handlers;
20 
21import static com.google.common.base.Predicates.equalTo;
22import static com.google.common.base.Predicates.not;
23import static com.google.common.collect.Iterables.filter;
24import static com.google.common.collect.Lists.newArrayList;
25import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH;
26import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS;
27 
28import java.util.List;
29 
30import javax.inject.Inject;
31import javax.inject.Named;
32import javax.inject.Singleton;
33 
34import org.jclouds.aws.domain.AWSError;
35import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
36import org.jclouds.aws.util.AWSUtils;
37import org.jclouds.blobstore.ContainerNotFoundException;
38import org.jclouds.blobstore.KeyNotFoundException;
39import org.jclouds.http.HttpCommand;
40import org.jclouds.http.HttpResponse;
41import org.jclouds.rest.ResourceNotFoundException;
42 
43import com.google.common.base.Joiner;
44import com.google.common.base.Splitter;
45 
46/**
47 * @author Adrian Cole
48 * 
49 */
50@Singleton
51public class ParseS3ErrorFromXmlContent extends ParseAWSErrorFromXmlContent {
52 
53   private final String servicePath;
54   private final boolean isVhostStyle;
55 
56   @Inject
57   ParseS3ErrorFromXmlContent(AWSUtils utils, @Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
58            @Named(PROPERTY_S3_SERVICE_PATH) String servicePath) {
59      super(utils);
60      this.servicePath = servicePath;
61      this.isVhostStyle = isVhostStyle;
62   }
63 
64   protected Exception refineException(HttpCommand command, HttpResponse response, Exception exception, AWSError error,
65            String message) {
66      switch (response.getStatusCode()) {
67         case 404:
68            if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
69               exception = new ResourceNotFoundException(message, exception);
70               if (isVhostStyle) {
71                  String container = command.getCurrentRequest().getEndpoint().getHost();
72                  String key = command.getCurrentRequest().getEndpoint().getPath();
73                  if (key == null || key.equals("/"))
74                     exception = new ContainerNotFoundException(container, message);
75                  else
76                     exception = new KeyNotFoundException(container, key, message);
77               } else if (command.getCurrentRequest().getEndpoint().getPath().indexOf(servicePath + "/") == 0) {
78                  String path = command.getCurrentRequest().getEndpoint().getPath().substring(servicePath.length());
79                  List<String> parts = newArrayList(filter(Splitter.on('/').split(path), not(equalTo(""))));
80                  if (parts.size() == 1) {
81                     exception = new ContainerNotFoundException(parts.get(0), message);
82                  } else if (parts.size() > 1) {
83                     exception = new KeyNotFoundException(parts.remove(0), Joiner.on('/').join(parts), message);
84                  }
85               }
86            }
87            return exception;
88         default:
89            return super.refineException(command, response, exception, error, message);
90      }
91   }
92}

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