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

COVERAGE SUMMARY FOR SOURCE FILE [TransientBlobRequestSigner.java]

nameclass, %method, %block, %line, %
TransientBlobRequestSigner.java100% (1/1)80%  (4/5)77%  (114/149)85%  (11/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TransientBlobRequestSigner100% (1/1)80%  (4/5)77%  (114/149)85%  (11/13)
signGetBlob (String, String, GetOptions): HttpRequest 0%   (0/1)0%   (0/35)0%   (0/2)
TransientBlobRequestSigner (BasicAuthentication, BlobToHttpGetOptions, URI): ... 100% (1/1)100% (19/19)100% (5/5)
signGetBlob (String, String): HttpRequest 100% (1/1)100% (28/28)100% (2/2)
signPutBlob (String, Blob): HttpRequest 100% (1/1)100% (39/39)100% (2/2)
signRemoveBlob (String, String): HttpRequest 100% (1/1)100% (28/28)100% (2/2)

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.blobstore;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.net.URI;
24 
25import javax.inject.Inject;
26import javax.inject.Singleton;
27 
28import org.jclouds.blobstore.domain.Blob;
29import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
30import org.jclouds.blobstore.options.GetOptions;
31import org.jclouds.http.HttpRequest;
32import org.jclouds.http.HttpUtils;
33import org.jclouds.http.filters.BasicAuthentication;
34import org.jclouds.location.Provider;
35 
36/**
37 * 
38 * @author Adrian Cole
39 */
40@Singleton
41public class TransientBlobRequestSigner implements BlobRequestSigner {
42 
43   private final BasicAuthentication basicAuth;
44   private final BlobToHttpGetOptions blob2HttpGetOptions;
45   private final String endpoint;
46 
47   @Inject
48   public TransientBlobRequestSigner(BasicAuthentication basicAuth, BlobToHttpGetOptions blob2HttpGetOptions, @Provider URI endpoint) {
49      this.basicAuth = checkNotNull(basicAuth, "basicAuth");
50      this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
51      this.endpoint = endpoint.toString();
52   }
53 
54   @Override
55   public HttpRequest signGetBlob(String container, String name) {
56      HttpRequest request = new HttpRequest("GET", URI.create(String.format("%s/%s/%s", endpoint, container, name)));
57      return basicAuth.filter(request);
58   }
59 
60   @Override
61   public HttpRequest signPutBlob(String container, Blob blob) {
62      HttpRequest request = HttpRequest.builder().method("PUT").endpoint(
63               URI.create(String.format("%s/%s/%s", endpoint, container, blob.getMetadata().getName()))).payload(
64               blob.getPayload()).headers(
65               HttpUtils.getContentHeadersFromMetadata(blob.getMetadata().getContentMetadata())).build();
66      return basicAuth.filter(request);
67   }
68 
69   @Override
70   public HttpRequest signRemoveBlob(String container, String name) {
71      HttpRequest request = new HttpRequest("DELETE", URI.create(String.format("%s/%s/%s", endpoint, container,
72               name)));
73      return basicAuth.filter(request);
74   }
75 
76   @Override
77   public HttpRequest signGetBlob(String container, String name, GetOptions options) {
78      HttpRequest request = HttpRequest.builder().method("GET").endpoint(
79               URI.create(String.format("%s/%s/%s", endpoint, container, name))).headers(
80               blob2HttpGetOptions.apply(options).buildRequestHeaders()).build();
81      return basicAuth.filter(request);
82   }
83 
84}

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