[frs-366] Workaround: 0 Query Count Returned From FRAPI Request Objects

Problem

FusionRequest objects obtained using FRAPI calls including getRunningRequests() return 0 from the call jdbcTotalQueryCount(), even if queries have been run prior to the call.

This is a bug.

Workaround

The following code can be used to obtain this value until this bug is fixed.

The key operations are within the cfscript try/catch block, and use Reflection to obtain the relevant data.

<cfset frapiClass = createObject("java","com.intergral.fusionreactor.api.FRAPI") />
<cfset Thread = createObject("java", "java.lang.Thread")/>
<cfset frapi = frapiClass.getInstance() />
<cfset requests = frapi.getRunningRequests() />

<cfloop array="#requests#" index="frRequest">	    		
    <cfif frRequest.getThread() eq Thread.currentThread().getName()>	    			
        <cfscript>
            try 
            {
                txnField = frRequest.getClass().getDeclaredField("txn");
                txnField.setAccessible(true);
                txn = txnField.get(frRequest);

                if( isNull(txn.getMasterTransaction()) )
                    masterTxn = txn;
                else
                    masterTxn = txn.getMasterTransaction();

                jdbcQueries = masterTxn._getSubTransactionFlavourCount("JDBCRequest");
            } 
            catch(any e)
            {
                jdbcQueries = 0;
            }
        </cfscript>
        <cfoutput>#jdbcQueries#</cfoutput>
    </cfif>
</cfloop>

Caveats

The workaround uses Java Reflection to obtain an internal field, then queries that to obtain the count of JDBC Requests run in the context of the current request.

If Java is running in a (non-default) security mode, the Reflection calls may fail. In this case, the catch block will be used to default the query count, without causing an error in the page.

Issue Details

Type: Technote
Issue Number: FRS-366
Components: FRAPI
Environment:
Resolution: Fixed
Last Updated: 12/Nov/15 11:17 AM
Affects Version: 4.5.0, 5.0.0, 5.2.8
Fixed Version: 6.x
Server:
Platform:
Related Issues:

FRS-372: Use FRAPI To Log CFThrow Errors, and Set HTTP Response Codes

Comments are closed.