private SharedSignatureServiceResponse getSssResponse(AzureStrategyContext context) throws Exception { if (sssResponse == null) { HttpUri uri = getUriForSharedSignatureService(context); AzureHttpHeader headers = getHeadersForSharedAccessSignatureService(context); XmlHttpResult xmlHttpResult = XmlHttp.GetSSL(authenticationToken.getHost(), uri.toString(), headers); sssResponse = new SharedSignatureServiceResponseDOMAdapter(xmlHttpResult).build(); } return sssResponse; }
private HttpUri getUriForSharedSignatureService(AzureStrategyContext context) { HttpUri uri = new HttpUri(authenticationToken.getSharedAccessSignatureServicePath()); uri.addParameterWithoutEncoding("IncrementalSeed", Long.toString(new Date().getTime())); AzureOperation operation = context.getOperation(); switch (operation) { case GetBlob: case GetBlobMetadata: case GetBlobProperties: case GetBlockList: case GetPageRegions: case PutPage: uri.appendPath("/blob"); break; default: uri.appendPath("/container"); break; } return uri; }
@Override protected HttpUri getPath(AzureStrategyContext context) throws Exception { AzureOperation operation = context.getOperation(); String blobName = context.getBlobName(); String blockId = context.getBlockId(); String delimiter = context.getDelimiter(); Set<EnumerationFilter> enumerationFilter = context.getEnumerationFilter(); String marker = context.getMarker(); int maxResults = context.getMaxResults(); String prefix = context.getPrefix(); String snapshot = context.getSnapshot(); SharedSignatureServiceResponse sssResponse = getSssResponse(context); HttpUri uri = null; switch (operation) { case DeleteBlob: uri = sssResponse.getAnyUri(); uri.appendPath("/" + blobName); if (snapshot != null) uri.addParameterWithoutEncoding("snapshot", snapshot); break; case GetBlob: case GetBlobProperties: uri = sssResponse.getBlobCollection().getUriForBlob(blobName); if (snapshot != null) uri.addParameterWithoutEncoding("snapshot", snapshot); break; case GetBlobMetadata: uri = sssResponse.getBlobCollection().getUriForBlob(blobName); uri.addParameterWithoutEncoding("comp", "metadata"); if (snapshot != null) uri.addParameterWithoutEncoding("snapshot", snapshot); break; case GetBlockList: uri = sssResponse.getBlobCollection().getUriForBlob(blobName); uri.addParameterWithoutEncoding("comp", "blocklist"); if (snapshot != null) uri.addParameterWithoutEncoding("snapshot", snapshot); uri.addParameterWithoutEncoding("blocklisttype", "all"); break; case LeaseBlob: uri = sssResponse.getAnyUri(); uri.addParameterWithoutEncoding("comp", "lease"); break; case ListBlobs: uri = sssResponse.getAnyUri(); uri.addParameterWithoutEncoding("restype", "container"); uri.addParameterWithoutEncoding("comp", "list"); if (!Util.isStringNullOrEmpty(prefix)) uri.addParameterWithoutEncoding("prefix", prefix); if (!Util.isStringNullOrEmpty(delimiter)) uri.addParameterWithoutEncoding("delimiter", delimiter); if (!Util.isStringNullOrEmpty(marker)) uri.addParameterWithoutEncoding("marker", marker); uri.addParameterWithoutEncoding("maxresults", Integer.toString(maxResults)); if (enumerationFilter != null) uri.addParameterWithoutEncoding("include", EnumerationFilter.toString(enumerationFilter)); break; case PutBlob: uri = sssResponse.getAnyUri(); uri.appendPath("/" + blobName); break; case PutBlock: uri = sssResponse.getAnyUri(); uri.addParameterWithoutEncoding("comp", "block"); uri.addParameterWithoutEncoding("blockid", blockId); break; case PutBlockList: uri = sssResponse.getAnyUri(); uri.addParameterWithoutEncoding("comp", "blocklist"); break; case SetBlobMetadata: uri = sssResponse.getAnyUri(); uri.appendPath("/" + blobName); uri.addParameterWithoutEncoding("comp", "metadata"); break; case SetBlobProperties: uri = sssResponse.getAnyUri(); uri.appendPath("/" + blobName); uri.addParameterWithoutEncoding("comp", "properties"); break; case SnapshotBlob: uri = sssResponse.getAnyUri(); uri.addParameterWithoutEncoding("comp", "snapshot"); break; default: throw new Exception("Missing case for operation " + operation); } return uri; }