You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Magnus Kvalheim (JIRA)" <ji...@apache.org> on 2013/05/23 20:31:23 UTC

[jira] [Commented] (TAP5-2019) AssetPathConverter is not called for javascript stacks

    [ https://issues.apache.org/jira/browse/TAP5-2019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13665461#comment-13665461 ] 

Magnus Kvalheim commented on TAP5-2019:
---------------------------------------

Found a workaround as discussed in the thread - http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Why-is-AssetPathConverter-not-called-for-javascript-stacks-td5716629.html
Will post back here for reference.

Decorator:

public static JavaScriptStackPathConstructor decorateJavaScriptStackPathConstructor(
		final JavaScriptStackPathConstructor delegate,
		@Local final AssetPathConverter assetPathConverter) {
	
	return new JavaScriptStackPathConstructor() {

		public List<String> constructPathsForJavaScriptStack(String stackName) {

			List<String> paths = delegate.constructPathsForJavaScriptStack(stackName);
			
			if (Validator.isNullOrEmpty(paths)) return paths;

			List<String> newList = new ArrayList<>(paths.size());
			for (String path : paths) {
				newList.add(assetPathConverter.convertAssetPath(path));
			}
			return newList;
		}
	};
}
                
> AssetPathConverter is not called for javascript stacks
> ------------------------------------------------------
>
>                 Key: TAP5-2019
>                 URL: https://issues.apache.org/jira/browse/TAP5-2019
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-core
>    Affects Versions: 5.3.4
>            Reporter: Magnus Kvalheim
>              Labels: AssetPathConverter, assets, cdn
>
> (related thread: http://tapestry.1045711.n5.nabble.com/Why-is-AssetPathConverter-not-called-for-javascript-stacks-td5716629.html)
> We use assetpathconverter in order to get assets from CDN(cloudfront).
> However it looks like it's not working for stack assets (but it is for other assets).
> Module:
> binder.bind(AssetPathConverter.class, CDNAssetPathConverter.class).withId("CDNAssetPathConverter");
> public static void contributeServiceOverride(MappedConfiguration<Class,Object> configuration,
> 	@Local AssetPathConverter assetPathConverter) {				
> 	configuration.add(AssetPathConverter.class, assetPathConverter);
> }
> CDNAssetPathConverter:
> public class CDNAssetPathConverter implements AssetPathConverter {
> 	private IParameter ip;
> 	private String applicationVersion;
>     public CDNAssetPathConverter(@Inject @Symbol(SymbolConstants.APPLICATION_VERSION) String applicationVersion,
>                     @Inject IParameter ip){
>         this.applicationVersion = applicationVersion;
>         this.ip = ip;
>     }    
>     String getCDNDomain() {
>     	return ip.getString(PKey.DOMAIN_CDN_VERSIONED, null);
>     }    
>     @Override
>     public String convertAssetPath(String assetPath) {
>     	String domain = getCDNDomain();
>     	if(domain==null) return assetPath;
>     	
>     	String result = convertToCDN(assetPath, domain);
>     	return result;
>     }
>     private String convertToCDN(String path, String domain) {
>         String _path = path.replaceFirst("^/+", "");
>         return String.format("http://%s/%s", domain, _path);
>     }
>     @Override
>     public boolean isInvariant() {
>         return false;
>     }
> } 
> Howard thought it might be an oversight

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira