You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bård Magnus Kvalheim <ma...@kvalheim.eu> on 2013/05/23 10:21:29 UTC

Re: Why is AssetPathConverter not called for javascript stacks

Hi guys.

Sorry for keep asking for this, but I've still got no good solution for it.
Would like to serve stack javascript assets from cdn.

I think I'll try to patch tapestry internals, but would like to know if you
have pointers to where the best place would be.

I'm looking at JavaScriptStackPathConstructorImpl#combinedStackURL as
possible place to call AssetPathConverter.
Could possibly advice it and modify it's return value?

Or possibly higher up in JavaScriptSupportImpl#addAssetsFromStack


Let me know if you have thoughts.

Thanks
Magnus


On Wed, Nov 7, 2012 at 4:48 PM, Bård Magnus Kvalheim <ma...@kvalheim.eu>wrote:

> I'm still searching for a way to resolve this - now in 5.3.6.
>
> Anyone have ideas on what potentially could be done? Creative ideas
> welcome :)
>
> cheers
> Magnus
>
>
> On Thu, Oct 25, 2012 at 2:13 PM, Bård Magnus Kvalheim <ma...@kvalheim.eu>wrote:
>
>>
>> Regarding AssetPathConverter - should I open a JIRA for stack assets?
>>>
>>> I just created Jira.
>> https://issues.apache.org/jira/browse/TAP5-2019
>>
>> Let me know if you know of a workaround in tap 5.3.4.
>>
>> thanks
>> Magnus
>>
>
>

Re: Why is AssetPathConverter not called for javascript stacks

Posted by Bård Magnus Kvalheim <ma...@kvalheim.eu>.
> I did try to implement my own proposed solution with Advice

>
> That's a lot of messy byte code manipulation for a single method interface.
>

Yes, I have to agree. Delegate is probably a better choice in this case.
Cleaner and also typesafe.

Tried your suggestion - and it works just as well as the advice.

Thanks - I'm quite happy with that solution and will update the Jira with
the workaround as well.

cheers
Magnus

Re: Why is AssetPathConverter not called for javascript stacks

Posted by Lance Java <la...@googlemail.com>.
> I would then get 'cdn' urls for the different scripts that make up the
stack, and not the stack url itself

Oops, I think you're right



> I did try to implement my own proposed solution with Advice

That's a lot of messy byte code manipulation for a single method interface.
I'm a bit old fashioned when it comes to using byte code manipulation. You
can also solve this with a simple delegate.

public static JavaScriptStackPathConstructor
decorateJavaScriptStackPathConstructor(

   JavaScriptStackPathConstructor delegate,

   final AssetPathConverter assetPathConverter)

{

   return new JavaScriptStackPathConstructor {

      public List<String> constructPathsForJavaScriptStack(String
stackName) {

         List<String> newList = new ArrayList<String>(paths.size());

         for (String path :
delegate.constructPathsForJavaScriptStack(stackName)) {
            new list. add(assetPathConverter.convertAssetPath(path));
         }

      }
   };
}

Re: Why is AssetPathConverter not called for javascript stacks

Posted by Bård Magnus Kvalheim <ma...@kvalheim.eu>.
Hi.
On Thu, May 23, 2013 at 11:31 AM, Lance Java <la...@googlemail.com>wrote:

> I think the easiest way would be to decorate the JavaScriptStackSource
> service. Wrap the default implementation with a version which decorates
> getStack(String name) to return a custom JavaScriptStack implementation.
>
> The custom JavaScriptStack will provide wrappers for:
> List<Asset> getJavaScriptLibraries();
> List<StylesheetLink> getStylesheets();
>
> You'll need to delegate to AssetPathConverter  in Asset.toClientURL() and
> StylesheetLink.getURL()
>

Was thinking about this and as far as I can see with this approach I would
then get 'cdn' urls for the different scripts that make up the stack, and
not the stack url itself - but could be wrong.

I did try to implement my own proposed solution with Advice - quite simple
and it seems to be working fine. Although there could be side-effects I'm
not aware of yet ...

*@Advise(serviceInterface = JavaScriptStackPathConstructor.class)*
*public static void adviseJavaScriptStackPathConstructor(*
* MethodAdviceReceiver receiver,*
* @Local final AssetPathConverter assetPathConverter) {*
*try {*
*  MethodAdvice ma = new MethodAdvice(){*
*  @Override*
*  public void advise(MethodInvocation invocation) {*
*  invocation.proceed();*
*  List<String> paths = (List<String>) invocation.getReturnValue();*
*  if(paths==null) return;*
*  *
*  List<String> newList = new ArrayList<>(paths.size());*
*  for (String path : paths) {*
*  newList.add(assetPathConverter.convertAssetPath(path));*
*  }*
*  invocation.setReturnValue(newList);*
*  }*
*  };**   *
*  Class<?> serviceInterface = receiver.getInterface();*
*  receiver.adviseMethod(serviceInterface.getMethod("constructPathsForJavaScriptStack",
String.class), ma);**   *
*  } catch (Exception e) {*
*  throw new RuntimeException("Can't find methods. Changed API?", e);*
*  }*
*}*

Let me know if you have further suggestions/ideas.

thanks
Magnus

Re: Why is AssetPathConverter not called for javascript stacks

Posted by Lance Java <la...@googlemail.com>.
I think the easiest way would be to decorate the JavaScriptStackSource
service. Wrap the default implementation with a version which decorates
getStack(String name) to return a custom JavaScriptStack implementation.

The custom JavaScriptStack will provide wrappers for:
List<Asset> getJavaScriptLibraries();
List<StylesheetLink> getStylesheets();

You'll need to delegate to AssetPathConverter  in Asset.toClientURL() and
StylesheetLink.getURL()

Lots of wrapping but it looks like it's doable.