Having two modules use the same interception points results in one not working

I had discussed this once before, and we found that the modules do run and we thought that the htmlhead might be the problem, but I can now confirm that this is not the problem.

It appears to me that appendToBuffer() is being trashed or cleared after being run on the first attempt, in my first module. However I am not doing anything to do this, all I am doing is doing a appendToBuffer(“test”) in both scenarios.

If I switch both modules off, and enable one at a time the content is added. When both modules are switched on only one is added to the page output.

Luis, this looks like a bug.

What would be the fix?

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

To be honest Luis I do not know, after tracking it through I am unable to see why this is happening.

When I opened up the interceptorService and had a look at the processState method, I dumped the state before the output of the content, and low and behold it is showing that it is only calling the process once.

Which is kinda not true, because the logs show that both points are being called. So I am not familiar enough at the moment with how the requestContext works in this case, but there is a problem here, I just do not know how to track it down.

Ok this may help you out here Luis, I am not sure how this fully works so I can only show you what my tests are showing.

Module A

has appendToBuffer(“test from Module A”);

Module B

has appendToBuffer(“test from Module B”);

Now only Module B will show up, as it is the last interception that was run, so I did further tests and did the following in Module B.

if( log.canDebug() ) {
log.debug("-----------------> Running interception point cbui_beforeHeadEnd #getBufferString()#");
}

appendToBuffer( addAssets(event, interceptData) );

if( log.canDebug() ) {
log.debug("-----------------> Running interception point cbui_beforeHeadEnd after appendtobuffer #getBufferString()#");
}

The logs clearly show that the buffer has the information from the previous interception, however after the appendToBuffer, the buffer string no longer has that information.

And the process state I put logs in there, and it shows that it was only ever called once, so that means it gets the buffer at that point in time, which happens to be what is defined in the last interceptor point.

Hope this helps some more.

Ok the problem is in the AddAsset, I thought it might have been the $htmlHead() that was causing the issue so I passed the false flag to return a string. But it still cleared the buffer.

It is my strong belief that it is because the string buffer is reinitialise in the AddAsset which is causing this issue.

Ok so is the problem in the add asset or interceptor service

Luis,

The more I look into this the more I don’t understand what is going on, it seems that if I make a call to anything that is not in the interceptor then this problem exists.

For example I have the following in my interceptor now.

public void function cbui_beforeHeadEnd(event, interceptData) {
appendToBuffer(addAssets(event, interceptData));
}

private string function addAssets(event, interceptData) {
var assetRoot = event.getModuleRoot(‘syntaxHighlighter’) & “/assets/”;
var assets = [];
var shBrushes = settingService.getBrushSettings();
var shTheme = settingService.getThemeSettings();

arrayAppend(assets, assetRoot & ‘styles/shCore.css’);
arrayAppend(assets, assetRoot & ‘styles/#shTheme#’);
arrayAppend(assets, assetRoot & ‘scripts/shCore.js’);

var brushes = listToArray(shBrushes);
for (var brush in brushes) {
arrayAppend(assets, assetRoot & ‘scripts/#brush#’);
}
return addAsset(arrayToList(assets), false);
}

If I modify the return to something like this in the AddAssets it still fails.

return ‘something’;

if I then modify the AddAssets to this it works.

private string function addAssets(event, interceptData) {
var assetRoot = event.getModuleRoot(‘syntaxHighlighter’) & “/assets/”;
var assets = [];

arrayAppend(assets, assetRoot & ‘styles/shCore.css’);
arrayAppend(assets, assetRoot & ‘scripts/shCore.js’);

return ‘something’;
}

Now from what I can tell it is a combination of these missing and changed pieces that are effecting the requestBuffer. If I make the calls to settingService to return just what they are supposed to as a string even will not work so it appears that a call to anything outside of this method causes issues.

I am now dumb founded where to go from here, I am not even sure this is either a ContentBox or ColdBox problem now.

Any ideas Luis?

To prove my theory even more I placed the following into AddAssets and nothing more

writeDump(getBufferString());
var setting = entityLoad( ‘shsetting’, {name=‘settings’}, true );
writeDump(getBufferString()); abort;

The first dump had the information in the buffer, the second dump was an empty string. So it appears that ORM trashes this, and the AddAsset() in HTMLHelper() is also trashing the buffer.

I can’t do any more testing than this Luis, as entityLoad() is now ColdFusion doing this.

Luis, I have a work around. Just not sure why it is a problem in the first place.

http://www.andyscott.id.au/2012/4/14/ContentBox-problem-with-modules-and-interceptors