001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo 016 */ 017 018package org.nuxeo.ecm.blob.azure; 019 020import java.io.IOException; 021import java.net.URI; 022 023import javax.servlet.http.HttpServletRequest; 024 025import org.nuxeo.ecm.core.blob.ManagedBlob; 026 027/** 028 * @author <a href="mailto:ak@nuxeo.com">Arnaud Kervern</a> 029 * @since 7.10 030 */ 031public class AzureCDNBinaryManager extends AzureBinaryManager { 032 033 // Resolved using AzureBinaryManager#PROPERTIES_PREFIX as prefix 034 public static final String AZURE_CDN_PROPERTY = "cdn.host"; 035 036 protected String host; 037 038 @Override 039 protected void setupCloudClient() throws IOException { 040 super.setupCloudClient(); 041 host = getProperty(AZURE_CDN_PROPERTY); 042 } 043 044 @Override 045 protected URI getRemoteUri(String digest, ManagedBlob blob, HttpServletRequest servletRequest) throws IOException { 046 URI azure = super.getRemoteUri(digest, blob, servletRequest); 047 048 // Just replace default Azure storage host with the CDN one 049 String cdn = azure.toString().replace(azure.getHost(), host); 050 return URI.create(cdn); 051 } 052}