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

COVERAGE SUMMARY FOR SOURCE FILE [AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.java]

nameclass, %method, %block, %line, %
AssignCorrectHostnameAndBindAsHostPrefixIfConfigured.java100% (1/1)100% (2/2)100% (54/54)100% (10/10)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AssignCorrectHostnameAndBindAsHostPrefixIfConfigured100% (1/1)100% (2/2)100% (54/54)100% (10/10)
AssignCorrectHostnameAndBindAsHostPrefixIfConfigured (BindAsHostPrefix, boole... 100% (1/1)100% (13/13)100% (4/4)
bindToRequest (HttpRequest, Object): HttpRequest 100% (1/1)100% (41/41)100% (6/6)

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.s3.binders;
20 
21import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH;
22import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS;
23 
24import java.net.URI;
25import java.util.Map;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Provider;
30import javax.inject.Singleton;
31import javax.ws.rs.core.UriBuilder;
32 
33import org.jclouds.http.HttpRequest;
34import org.jclouds.http.utils.ModifyRequest;
35import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
36import org.jclouds.rest.binders.BindAsHostPrefix;
37import org.jclouds.s3.Bucket;
38import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured;
39 
40/**
41 * 
42 * @author Adrian Cole
43 */
44@Singleton
45public class AssignCorrectHostnameAndBindAsHostPrefixIfConfigured extends BindAsHostPrefixIfConfigured {
46   private final Map<String, String> bucketToRegion;
47   private final RegionToEndpointOrProviderIfNull r2;
48 
49   @Inject
50   public AssignCorrectHostnameAndBindAsHostPrefixIfConfigured(BindAsHostPrefix bindAsHostPrefix,
51         @Named(PROPERTY_S3_VIRTUAL_HOST_BUCKETS) boolean isVhostStyle,
52         @Named(PROPERTY_S3_SERVICE_PATH) String servicePath, RegionToEndpointOrProviderIfNull r2,
53         Provider<UriBuilder> uriBuilderProvider, @Bucket Map<String, String> bucketToRegion) {
54      super(bindAsHostPrefix, isVhostStyle, servicePath, uriBuilderProvider);
55      this.bucketToRegion = bucketToRegion;
56      this.r2 = r2;
57   }
58 
59   @Override
60   public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
61      String bucket = payload.toString();
62      String region = bucketToRegion.get(bucket);
63      if (region != null) {
64         URI endpoint = r2.apply(region);
65         request = ModifyRequest.endpoint(
66               request,
67               uriBuilderProvider.get().uri(endpoint).path(request.getEndpoint().getPath())
68                     .replaceQuery(request.getEndpoint().getQuery()).build());
69      }
70      return super.bindToRequest(request, payload);
71   }
72}

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