001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo 018 */ 019 020package org.nuxeo.ecm.blob.azure; 021 022import java.io.IOException; 023import java.net.URI; 024 025import javax.servlet.http.HttpServletRequest; 026 027import org.nuxeo.ecm.core.blob.ManagedBlob; 028 029/** 030 * @author <a href="mailto:[email protected]">Arnaud Kervern</a> 031 * @since 7.10 032 */ 033public class AzureCDNBinaryManager extends AzureBinaryManager { 034 035 // Resolved using AzureBinaryManager#PROPERTIES_PREFIX as prefix 036 public static final String AZURE_CDN_PROPERTY = "cdn.host"; 037 038 protected String host; 039 040 @Override 041 protected void setupCloudClient() throws IOException { 042 super.setupCloudClient(); 043 host = getProperty(AZURE_CDN_PROPERTY); 044 } 045 046 @Override 047 protected URI getRemoteUri(String digest, ManagedBlob blob, HttpServletRequest servletRequest) throws IOException { 048 URI azure = super.getRemoteUri(digest, blob, servletRequest); 049 050 // Just replace default Azure storage host with the CDN one 051 String cdn = azure.toString().replace(azure.getHost(), host); 052 return URI.create(cdn); 053 } 054}