tag:blogger.com,1999:blog-24194635931386319292024-02-22T09:20:51.567+01:00CFDEEPGoing beneath the surface of ColdFusionmichael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-2419463593138631929.post-5544505799235588412014-03-12T17:59:00.000+01:002014-03-12T17:59:47.012+01:00Using FIFO with cacheSetPropertiesAlthough it is not explicitly stated in the CF10 docs, some testing today verified that a "FIFO" algorithm does function when provided as part of a cache property configuration.<br />
<br />
FIFO is a "first-in, first out" algorithm, which means the oldest object in my cache will be the first one to be flushed out once my cache reaches its maximum size.<br />
<br />
First let's create a cache with FIFO.<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfscript></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CacheRegionNew(</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>"testfifo",</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>DISKPERSISTENT=false,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MAXELEMENTSINMEMORY=7,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>STATISTICS=true,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>OBJECTTYPE='object',</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>MEMORYEVICTIONPOLICY='fifo'</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfscript></span><br />
<div>
<br />
Note that we have set our cache up with a policy of FIFO, and given it a maximum of 7 elements.<br />
<br />
Next, add some objects to our cache. Here, test2 is an old test object I happen to have laying around. :)<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfscript></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">for (i=1;i LTE 7; i=i+1) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>objname="obj_#i#";</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cacheput(</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>objname,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new test2(),</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>1,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>1,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'testfifo',</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>true</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sleep(100);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfscript></span></div>
<div>
<br /></div>
<div>
Let's dump the cache. </div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfscript></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if (CacheRegionExists("testfifo"))</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>writedump(</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CacheGetAllIds('testfifo')</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfscript></span></div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
We should see this.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPc2ansS2MyuK5RkUG2hWcJNovvWkegLCjXONabCkRC27tdt2Xgx_LNoZjhbdJotJshieoAVCsDVbPn_Ku0dDsSJ9DIBhm8bc4bRW70SPVJr9dPAdtJ0P02BpWd_xN23GeUelMpsSj_VE/s1600/blog15.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPc2ansS2MyuK5RkUG2hWcJNovvWkegLCjXONabCkRC27tdt2Xgx_LNoZjhbdJotJshieoAVCsDVbPn_Ku0dDsSJ9DIBhm8bc4bRW70SPVJr9dPAdtJ0P02BpWd_xN23GeUelMpsSj_VE/s1600/blog15.jpg" /></a></div>
<div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPc2ansS2MyuK5RkUG2hWcJNovvWkegLCjXONabCkRC27tdt2Xgx_LNoZjhbdJotJshieoAVCsDVbPn_Ku0dDsSJ9DIBhm8bc4bRW70SPVJr9dPAdtJ0P02BpWd_xN23GeUelMpsSj_VE/s1600/blog15.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPc2ansS2MyuK5RkUG2hWcJNovvWkegLCjXONabCkRC27tdt2Xgx_LNoZjhbdJotJshieoAVCsDVbPn_Ku0dDsSJ9DIBhm8bc4bRW70SPVJr9dPAdtJ0P02BpWd_xN23GeUelMpsSj_VE/s1600/blog15.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
We now have 7 objects in our cache. Just to prove that our cache is not running with a different algorithm, do a cacheGet on the oldest object. ('OBJ_1'). </div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfscript></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>x<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>cacheGet(</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'obj_1',</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'testfifo'</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfscript></span></div>
</div>
<div>
<br /></div>
<div>
If you wish, you can dump our first object and verify it has received a cache hit.</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfscript></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>writeDump(</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cacheGetMetaData(</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'obj_1',</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'object',</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'testfifo'</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>)</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfscript></span></div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhok8gfSoexZOhxEw6vkShZ-ePMhv3csLEU81OoqBYd66yBwDmWK_uc4ugMC2pKhuNpXmJwcw3M8P7WIbYZAgxXibtYBJJjf0mttwto62vRFrvxQ69wF1n0C-TIP_PF81UwlOi7wygMS6M/s1600/blog16.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhok8gfSoexZOhxEw6vkShZ-ePMhv3csLEU81OoqBYd66yBwDmWK_uc4ugMC2pKhuNpXmJwcw3M8P7WIbYZAgxXibtYBJJjf0mttwto62vRFrvxQ69wF1n0C-TIP_PF81UwlOi7wygMS6M/s1600/blog16.jpg" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
We are now ready to begin implicitly evicting items from the cache. We do this by adding a new object to the cache.</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfscript></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>objname="cacheitem_#getTickCount()#";</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cacheput(</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>objname,</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>new test2(),</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>1,</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>1,</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>'testfifo',</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>true</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfscript></span></div>
</div>
<div>
<br /></div>
<div>
If our FIFO cache is working correctly, our first object "OBJ_1" should now be gone from the cache since the cache is full and it was our oldest object.</div>
<div>
<br /></div>
<div>
Dump the region again.</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfscript></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if (CacheRegionExists("testfifo"))</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>writedump(</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>CacheGetAllIds('testfifo')</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>);</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfscript></span></div>
</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBFyuCK-xRc3-eLprrSyhNTQ4Rl9-VK_T7krcBkY-QlS6UoCh-P-j4CeFvFCam56tL04RkX9aFaUqyraMTs6vIErT9hr00o51zGDvzzEaANMC0M6Ngh28pv_Ga1i1Zx9t8MrMe6jM6F2s/s1600/blog17.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBFyuCK-xRc3-eLprrSyhNTQ4Rl9-VK_T7krcBkY-QlS6UoCh-P-j4CeFvFCam56tL04RkX9aFaUqyraMTs6vIErT9hr00o51zGDvzzEaANMC0M6Ngh28pv_Ga1i1Zx9t8MrMe6jM6F2s/s1600/blog17.jpg" /></a></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
That's it. Our oldest object has been evicted from the cache. If our cache had been running with LRU (Least Recently Used) or LFU (Less Frequently Used), a different object would have been flushed. In both of those scenarios "OBJ_1" would have been maintained in the cache because of the cache hit it received.</div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com8tag:blogger.com,1999:blog-2419463593138631929.post-49768558368945868572014-01-10T08:08:00.001+01:002014-01-10T08:08:52.054+01:00cfprocessingdirectiveFor years we have been using the tag cfprocessingdirective Tag at the top of our templates like this.<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfprocessingdirective suppresswhitespace="yes" pageencoding="utf-8"></span><br />
<br />
Then one of our colleagues found this in the Adobe Docs<br />
<br />
<span style="background-color: white; font-family: myriad-pro-1, myriad-pro, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 17.328125px;">"The </span><code style="background-color: white; font-size: 12px; line-height: 17.328125px;">cfprocssingdirective</code><span style="background-color: white; font-family: myriad-pro-1, myriad-pro, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 17.328125px;"> tag has limitations that depend on the attribute you use. For this reason, Adobe recommends that you include either the </span><code style="background-color: white; font-size: 12px; line-height: 17.328125px;">pageencoding</code><span style="background-color: white; font-family: myriad-pro-1, myriad-pro, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 17.328125px;"> or </span><code style="background-color: white; font-size: 12px; line-height: 17.328125px;">suppresswhitespace</code><span style="background-color: white; font-family: myriad-pro-1, myriad-pro, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 17.328125px;"> attribute in a </span><code style="background-color: white; font-size: 12px; line-height: 17.328125px;">cfprocessingdirective</code><span style="background-color: white; font-family: myriad-pro-1, myriad-pro, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 17.328125px;"> tag, not both." </span><br />
<span style="background-color: white; font-family: myriad-pro-1, myriad-pro, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 17.328125px;"><br /></span>
Ah hah. Afterwards we began to modify the templates.<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfprocessingdirective pageEncoding="utf-8" /></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><cfprocessingdirective suppressWhitespace="true"></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">...[some code]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"></cfprocessingdirective></span><br />
<br />
It struck me however after playing around with the tag that the suppressWhitespace attribute did not seem to have an effect on the white space emitted. The white space was being stripped out regardless whether the tag was present or not. A quick check showed me that the "Enable Whitespace Management" Option on the server was active.<br />
<br />
Thus it appears this setting essentially replicates at the page level the global setting for Whitespace Management.michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com2tag:blogger.com,1999:blog-2419463593138631929.post-80692699128351113592013-01-25T13:27:00.000+01:002013-01-25T13:27:00.927+01:00cfhttp in javaWe had some problems with CF8 not recognizing SANs SSL certificates. The certificates were valid and properly configured, but cfhttp constantly delivered an "I/O Exception:".<br />
<br />
The only way I could find around this was to make the calls in Java. In case it helps someone, the Java I used to make a post to a soap web service was basically as follows: <br />
<br />
<span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;"><cfsavecontent variable="requestXML"><?xml version="1.0" encoding="utf-8"?></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <soap:Header></span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </soap:Header></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <soap:Body></span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </soap:Body></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></soap:Envelope></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></cfsavecontent></span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"><cfscript></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> myUrl = "xxx"; // web service url</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> objUrl = createobject("java","java.net.URL").init(myUrl);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> conn = objUrl.openConnection();</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> //configure the request</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> conn.setDoOutput(true);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> conn.setUseCaches(false);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> conn.setRequestMethod("POST");</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> conn.setRequestProperty("SOAPAction", "xxx my soap action"); </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> //output stream actions</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ostream = conn.getOutputStream();</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ostream.write(Javacast("String",requestxml).toString().getBytes());</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ostream.flush();</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ostream.Close();</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> // set input</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> inS =createobject("java","java.io.InputStreamReader").init(conn.getInputStream());</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> inVar = createObject("java","java.io.BufferedReader").init(inS);</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> builder = createObject("java","java.lang.StringBuilder").init(javacast("int",1000));</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> line = "";</span></span><br />
<span style="font-size: x-small;"></span><br />
<span style="font-size: x-small;"><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> do</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> {</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> line = inVar.readLine();</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> lineCheck = isDefined("line");</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> if(lineCheck)</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> {</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> builder.append(line);</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> }</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> } while(lineCheck);</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> retvar = builder.toString();</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></cfscript></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfoutput>#retvar#</cfoutput></span></span><br />
<br />
<br />
The problems seems to be fixed in newer versions of CF. In CF 10 I was able to make the requests to the servers with SANs certificates without a problem.michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com2tag:blogger.com,1999:blog-2419463593138631929.post-59986635103390162522012-11-28T08:46:00.000+01:002012-11-28T08:46:25.406+01:00Using cfproperty to reduce java class filesI haven't seen much blogged about this, so I thought it would be worth bringing up.<br />
<br />
As
part of our jump from CF8 to CF10 I've been experimenting with
cfproperty and the concept of implicit getters/setters. Due to the way
ColdFusion compiles these implicit functions it seems to me you can
significantly reduce the number of java class files that ColdFusion
creates. Obviously the effect is very noticeable in OO applications with
lots of beans and hundreds of getter/setter functions.<br />
<br />
To
prove this let's take the following CFC with the old school explicit
declarations for all of our getters & setters. I'll call it
"explicit.cfc"<br />
<br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"><cfcomponent output="false"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cffunction name="init" output="false" returntype="any" hint="our formal constructor block."></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfset variables.instance.id =1></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfset variables.instance.name=""></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfset variables.instance.title=""></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </cffunction></span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cffunction name="getID" output="false" returntype="string"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfreturn variables.instance.id /></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </cffunction></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cffunction name="setID" output="false"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfargument name="ID" type="string" required="true"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfset variables.instance.id=arguments.id></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </cffunction></span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cffunction name="getName" output="false" returntype="string"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfreturn variables.instance.name /></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </cffunction></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cffunction name="setName" output="false"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfargument name="Name" type="string" required="true"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfset variables.instance.Name=arguments.Name></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </cffunction></span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cffunction name="getTitle" output="false" returntype="string"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfreturn variables.instance.title /></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </cffunction></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cffunction name="setTitle" output="false"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfargument name="Title" type="string" required="true"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> <cfset variables.instance.Title=arguments.Title></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> </cffunction></span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></cfcomponent></span></span><br />
<br />
It is a bean-like object with accessors for three variables: id, name, and title.<br />
<br />
Now let's write a file that uses our object.<br />
<br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"><cfprocessingdirective pageEncoding="utf-8" suppressWhitespace="true"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"><cfscript></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ex = new explicit();</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ex.init(); </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ex.setName('Tester'); </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> writeOutput("<p> ID:#ex.getID()# Name:#ex.getName()# </p>" ); </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></cfscript></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></cfprocessingdirective> </span></span><br />
<br />
Finally, go into the CF administrator and check "<b><label for="scf">Save class files</label></b>
" in the Caching menu.<br />
<br />
Now call up that page we created
in your browser, then check in the .class files directory for CF and
see what the server compiled. It will look like this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPHPZEniO-KrrRTajO0wZeUUoNbfTEBlYRDnMqyaEvz-ZO2ug89BDXppNIWbUjjDjyiAv5eyu_3xkFmKyvk5y2JL379jD0F074h5YLqj3TZI-sk0_lUN76c6DzJyo8HR6NzP-NiFAPgLA/s1600/blog12.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPHPZEniO-KrrRTajO0wZeUUoNbfTEBlYRDnMqyaEvz-ZO2ug89BDXppNIWbUjjDjyiAv5eyu_3xkFmKyvk5y2JL379jD0F074h5YLqj3TZI-sk0_lUN76c6DzJyo8HR6NzP-NiFAPgLA/s640/blog12.jpg" width="640" /></a></div>
<br />
As
we can see, CF has created a class file for our CFC itself, and every
function inside of it. It also created a class file for our calling
page.<br />
<br />
Now let's take a CFC with the new style implicit cfproperty declarations for our getters & setters. Let's call it "implicit.cfc"<br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
<span style="font-size: small;"><cfcomponent output="false" accessors="true"><br /><br /> <cfproperty name="id" /><br /> <cfproperty name="name" /><br /> <cfproperty name="title" /><br /> <br /> <cffunction name="init" output="false" returntype="any" hint="our formal constructor block."><br /> <cfset setID(1)><br /> <cfset setName('Tester')> <br /> </cffunction><br /><br /></cfcomponent></span></div>
<br />
Go back and edit our file. We now create an implicit.cfc object.<br />
<br />
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"><cfprocessingdirective pageEncoding="utf-8" suppressWhitespace="true"></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"><cfscript></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ex = new implicit();</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ex.init(); </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ex.setName('Tester'); </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> writeOutput("<p> ID:#ex.getID()# Name:#ex.getName()# </p>" ); </span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></cfscript></span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"></cfprocessingdirective> </span></span><br />
<br />
And what gets created now for java class files?<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDz4tN52kbh0c18-0yygJLV8OUeGB5cjQpY_ig0zAmshj4UZVLGyvMDDEz-iZmlF8g9hSoKYgpxLDL7PlVqueS6gInMdDa4qdixtCVvj_SaG8irqPiPbsYxU0a9FCbEqIAvQRciorfn7M/s1600/blog13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="146" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDz4tN52kbh0c18-0yygJLV8OUeGB5cjQpY_ig0zAmshj4UZVLGyvMDDEz-iZmlF8g9hSoKYgpxLDL7PlVqueS6gInMdDa4qdixtCVvj_SaG8irqPiPbsYxU0a9FCbEqIAvQRciorfn7M/s640/blog13.jpg" width="640" /></a></div>
<br />
Just three files: one for the CFC itself, one for the Init() function inside of it, and one for the calling page.<br />
<br />
Obviously the effect of this in a large application is that you're going to save yourself from creating a lot of 3kb class files for every getter/setter.<br />
<br />
You may be asking if all if this matters, and it most cases it probably is not of great concern. In my experience it only really matters if you are seeing java.lang.OutOfMemoryError: PermGen space errors on your server. This is the space in the java heap where your class definitions are stored and it is possible to fill it up if you're running a lot of big applications on the server. Fewer classes should result in a reduced PermGen usage.<br />
<br />
I've seen the PermGen error a number of times on a 32 bit machine with CF8. We got around it in the end by increasing the size of our perm-gen space in the JVM to 256mb, but even then we kept bumping up on the limit in some cases. On a 64 bit machine this should be even less of a problem though due to the ability to run with a much larger JVM.<br />
<br />
The fact that each ColdFusion function results in a Java class file has always bugged me, and I'm glad this is no longer always the case. In theory fewer classes should also result in a performance gain, although, to be fair, I suspect in most cases the practical effect will be marginal.<br />
<br />
<br />michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com0tag:blogger.com,1999:blog-2419463593138631929.post-78109404141893083272012-11-20T20:20:00.000+01:002012-11-20T20:20:20.099+01:00Using MAT with ColdfusionI spend a lot of time doing optimization and performance analysis on our sites, and over the years I've developed or used a lot of tools to help with this.<br />
<br />
The simplest is probably a simple jstat reporting tool. We take snapshots of our servers with jstat about once a minute, and save the results in the database. With the results I can generate a lot of useful information about our JVM. To do this I use a few basic cfchart commands and get some basic results like the following, detailing heap usage in the server.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihbWXCK84XgFlH-jlcfSbyMSfY4IoL5rl7rD0ftAFtTBVv65rQLr7GdxtqL71lWJuiV71nWM3wHLJhB7lfQbAWeMBPaTPXq_WWIISrv76XSGg9WAEV_H2n_awp_4Nren77BSSguA4rq2U/s1600/blog7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="309" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihbWXCK84XgFlH-jlcfSbyMSfY4IoL5rl7rD0ftAFtTBVv65rQLr7GdxtqL71lWJuiV71nWM3wHLJhB7lfQbAWeMBPaTPXq_WWIISrv76XSGg9WAEV_H2n_awp_4Nren77BSSguA4rq2U/s400/blog7.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
This little peak into the JVM is useful, and with it we get some basic statistics as to the health of our runtime environment. The key figures for us have always been how much memory is occupied by our tenured generation objects. If we have a memory leak somewhere in our application or server scope, then that yellow line in the middle will make a relentless march upward, eventually flatlining when no more memory can be reclaimed through garbage collection.<br />
<br />
The chart is useful, but it doesn't tell you exactly WHAT is contributing to instability with the Heap.<br />
This brings us to a fun little tool: the <a href="http://www.eclipse.org/mat/" target="_blank">Eclipse Memory Analyzer</a> (MAT). <br />
<br />
MAT is a tool for analyzing Heap Dumps. What's a heap dump? It's a snapshop of everything in your heap at the point in time the heap dump was made.<br />
<br />
Heap Dumps are made with the jmap utility, which comes in the bin directory of every JDK as of Java 5. To do a heap dump just on a Windows machine with a Coldfusion Server running, do as follows:<br />
<br />
<ol>
<li>Go to the task managerr and find the processID (pid) of the coldfusion server. </li>
<li>Execute "C:\mypathtojdk\bin\jmap" -dump:format=b,file=C:\MyPathToHeapDumps\heap.bin xxxx, replacing the paths where noted and the xxx will need to be replaced with the pid. </li>
</ol>
That's it. Now let's fire up MAT. You'll want to go to File / Open Heap Dump and pick out that binary file you've just generated. The very first time you open the heap dump it may take awhile depending on the size of your file -- MAT parses your file and caches the results so future views will proceed more quickly.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbF0MHqyixf6U14vbovbGToiuphxuK0jBnQcrCbSOqgjbgaBMJsyrgh9bQw4ONAELglLWqWDdb95RDC_d7RD3x5rob84ONOseT69sSysLvZ69NSjoTTbMuWG_C1NqLFdb-AP9otZy_QbE/s1600/blog9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="486" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbF0MHqyixf6U14vbovbGToiuphxuK0jBnQcrCbSOqgjbgaBMJsyrgh9bQw4ONAELglLWqWDdb95RDC_d7RD3x5rob84ONOseT69sSysLvZ69NSjoTTbMuWG_C1NqLFdb-AP9otZy_QbE/s640/blog9.jpg" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
The default option is a report that automatically checks for "Leak Suspects". This is sometimes useful, but not always. With Coldfusion you'll find in any case that you need to drill down through all of the java objects that are part of the CF library before you get to the true offenders.<br />
<br />
Here's the leak report; and yeah I know there's not much in that JVM right now. :)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-WEMDZ0ZRQqncN4HuvqkVWIuyc0XJ6NC1PesRNIiZp1Jiuwoyxw8m3OKYUq0lZ3cAD-Z8RU8bfqdKfKbZNXn5qM3hr-g0I-v9n02e-Gvfoyir0Tu1rSqfX8fNOuYI3YSShiAv7gAaNHw/s1600/blog10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="496" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-WEMDZ0ZRQqncN4HuvqkVWIuyc0XJ6NC1PesRNIiZp1Jiuwoyxw8m3OKYUq0lZ3cAD-Z8RU8bfqdKfKbZNXn5qM3hr-g0I-v9n02e-Gvfoyir0Tu1rSqfX8fNOuYI3YSShiAv7gAaNHw/s640/blog10.jpg" width="640" /></a></div>
<br />
<br />
<br />
There are a number of reports, and you'll just have to play around to see which one tells you the most. It varies, and depends to some extent on preference. I generally go into the Histogram, sort my objects by retained Heap, look for possible suspects, and begin following the paths to garbage collection.<br />
<br />
<br />
<br />
<br />
One tip: at least as of CF 8 you will find that Coldfusion Applications are represented as FastHashTables in the JVM. In the following screenshot I've opened one of these FastHashTables. Inside of it is an object of coldfusion.runtime.ApplicationScope, and we can see which application it is by looking at the attributes on the left.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8jWz1-WyqxENMmgU0AypKbTiykRUYiKESupX7oZPCFgyyxYj3H_5nN0YSvCrNJNpu1GwE-Hj9Tj8Qqimd792f51M6K3lOsrbMDKlZ8XwZY1eAvJH7vHWYs0kE1Q1u_u4A7AVjSInMRZ8/s1600/blog11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8jWz1-WyqxENMmgU0AypKbTiykRUYiKESupX7oZPCFgyyxYj3H_5nN0YSvCrNJNpu1GwE-Hj9Tj8Qqimd792f51M6K3lOsrbMDKlZ8XwZY1eAvJH7vHWYs0kE1Q1u_u4A7AVjSInMRZ8/s640/blog11.jpg" width="640" /></a></div>
<br />
Obviously if one of these is consuming a lot of memory in your "retained Heap" column, then you know where the culprit lies.michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com3tag:blogger.com,1999:blog-2419463593138631929.post-79928133542230135772012-09-21T14:55:00.001+02:002012-09-21T14:55:17.752+02:00Undefined elements in structs returned from web serviceI was accessing some functions remotely today in CF10 when I came across some weird behavior. Namely, the values returned by StructkeyList, StructkeyExists, and a Dump of a Struct are consistent with each other.<br />
<br />
Take the following code and place it somewhere in a CFC to be accessed remotely.<br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
<cffunction name="getTest" output="no" returntype="struct" access="remote"><br /><br /> <cfset result=structnew()><br /> <cfset result.testvar = "some var"><br /> <cfset result.fuseactions = ArrayNew(1)><br /> <br /> <cfreturn result><br /> <br /> </cffunction></div>
<br />
Now access it from a calling page. You'll need to put in your own server and CFC name.<br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
<cfinvoke<br /> webservice="http://xxx/mycfc.cfc?wsdl"<br /> returnvariable = "response"<br /> refreshWSDL = "true"<br /> method="gettest"<br />/></div>
<br />
This is where it gets interesting. Let's do a dump of our return variable.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWrAoh3bCgzGkZG34dLAE4VhmkYNbhOcrXVCCbvWTD5Ed3qhyAPclivrjplLCxtqBIfg0ev3Vyy5XJ69uPYRQopHaPPRJqohyIvqP5visqFf6P7OvWhkDZEXLr2eAs-P0Fm6BuU2iK8H8/s1600/blog4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWrAoh3bCgzGkZG34dLAE4VhmkYNbhOcrXVCCbvWTD5Ed3qhyAPclivrjplLCxtqBIfg0ev3Vyy5XJ69uPYRQopHaPPRJqohyIvqP5visqFf6P7OvWhkDZEXLr2eAs-P0Fm6BuU2iK8H8/s1600/blog4.jpg" /></a></div>
Notice that the "FUSEACTIONS" key in our struct seems interesting. Here we see "undefined" where we would have expected an empty array. I'm guessing the empty array goes missing during the serialization. <br />
<br />
Ok, but let's go further. Let's do #structKeyList(response)# on the struct. We see, as expected, our two elements.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxFJPkbwE0VLtCx0HLsRWLgzX5X0z23j2_3IVdnD88LhIeV5rYotS0FowkuCl82Ay2K4BV3rIJ3jFIczwV-_Rkizz5Wytf2OaoRBjyJHx5NcMbe3Gc4t-vbztO11J-359v-Tw1a7FvKag/s1600/blog5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxFJPkbwE0VLtCx0HLsRWLgzX5X0z23j2_3IVdnD88LhIeV5rYotS0FowkuCl82Ay2K4BV3rIJ3jFIczwV-_Rkizz5Wytf2OaoRBjyJHx5NcMbe3Gc4t-vbztO11J-359v-Tw1a7FvKag/s1600/blog5.jpg" /></a></div>
<br />Now it gets strange. Try to do a StructKeyExists on the FUSEACTIONS key.<br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
#structkeyExists(response,'FUSEACTIONS')#</div>
<br />
It delivers "NO". Trying to dump the struct element results in an error.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_QcbSEi1NARNh9ICawxnlihkN0aItgGcEajEhk806t2kI6ZmiFOeEWuJTvGQywEWPXG9uO4TykR7TVbuSAdm1RQv_TuRAVP02aeqTXQ2sHEvapS0DX7TZbC_i52o2_1ei3UQ8UwbkXFY/s1600/blog6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="113" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_QcbSEi1NARNh9ICawxnlihkN0aItgGcEajEhk806t2kI6ZmiFOeEWuJTvGQywEWPXG9uO4TykR7TVbuSAdm1RQv_TuRAVP02aeqTXQ2sHEvapS0DX7TZbC_i52o2_1ei3UQ8UwbkXFY/s640/blog6.jpg" width="640" /></a></div>
<br />
Now I know that the concept of NULL values was introduced in CF9. (Something I missed, still toddling along with CF8). So let's try:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#isnull(response.FUSEACTIONS)# </span><br />
<br />
Sure enough, it delivers YES.<br />
<br />
Still, this seems a little weird to me. Intuitively I would expect to see an empty array inside the Struct, since that was how the variable was declared. In any case, the inconsistency between StructKeyExists and StructKeyList is a change from CF8 and it broke some old code of ours.<br />
<br />
I've filed this as bug 3334756 by Adobe. Let's see what they say.<br />
<br />
<br />
<br />michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com0tag:blogger.com,1999:blog-2419463593138631929.post-20287550319362361572012-09-12T17:08:00.004+02:002012-09-12T17:08:48.886+02:00filexists() with a url equals a hung requestI had a bug in one spot where a url was being given to the fileexists() function instead of an absolute path.<br />
According to the documentation this should not work. Sure enough it really doesn't, but instead of returning NO the thread seems to hang. (CF 10 , version 10,282462). Not exactly sure why, more investigation is needed here.<br />
<br />
I've never worked on version 9 before, but according to this thread, it was actually possible to do a fileexists on a url as of 9.0.1<br />
<br />
<a href="http://forums.adobe.com/thread/765614">http://forums.adobe.com/thread/765614</a>
michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com0tag:blogger.com,1999:blog-2419463593138631929.post-71201706064268741822012-09-07T14:45:00.000+02:002012-09-07T14:45:20.140+02:00getApplicationSettings() Part 2In the last post I talked about the getApplicationSettings() method, and how we previously used it to look inside the application scopes of other applications in Coldfusion 8. Well one of the first things I noticed when working with our application administration tool in CF10 is that this function changed in version 10, which was leading to errors.<br />
<br />
That's the danger of relying too much on undocumented features!<br />
<br />
Most specifically, in CF8 the getApplicationSettings returned us a struct, now it returns a class of type coldfusion.runtime.ApplicationSettings.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4WfxeEWkTLyxKbZ9AeMbYoGPA-7Pz3tQQxrxFt4XG0L8ddMyramLgkk6zoUcjohw4j11j6nUEMfBfwuYLTM5HHAHYbTyX_wjllSg_ptOkJWAQHTcUo4wYs5YHx5qBcSoBnDCddZ9jyRs/s1600/blog2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4WfxeEWkTLyxKbZ9AeMbYoGPA-7Pz3tQQxrxFt4XG0L8ddMyramLgkk6zoUcjohw4j11j6nUEMfBfwuYLTM5HHAHYbTyX_wjllSg_ptOkJWAQHTcUo4wYs5YHx5qBcSoBnDCddZ9jyRs/s640/blog2.jpg" width="584" /></a></div>
<br />
<br />
This was rather bad for me, because in the old CF8 version the struct contained, among other things, a further struct with all the custom mappings for the application. A quick glance at the new object showed that my mappings were nowhere to be found.<br />
<br />
So now what? I created an object of type applicationScope and sniffed around.<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"> <cfset app = createObject("java","coldfusion.runtime.ApplicationScope") /> </span><br />
<span style="font-family: Courier New, Courier, monospace;"> <cfdump var="#app#"></span><br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsyDNIxYXRtwQcVUeAcr3_Ugu2oG0oy1W6zQtzBQyteKVbaDAPC0u2iFUh4id9Bmm5b1-Zj4mj0U2JWd875iCmP7wQTmyZglDhbGBeTZkGuQPpeJMGmz2qIjmffp7O_k54pw_tExJUc3Y/s1600/blog3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="610" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsyDNIxYXRtwQcVUeAcr3_Ugu2oG0oy1W6zQtzBQyteKVbaDAPC0u2iFUh4id9Bmm5b1-Zj4mj0U2JWd875iCmP7wQTmyZglDhbGBeTZkGuQPpeJMGmz2qIjmffp7O_k54pw_tExJUc3Y/s640/blog3.jpg" width="640" /></a></div>
<br />
<br />
The answer was pretty easy to find. The new getApplicationSettingsMap() function returns the struct that I used to use in CF8. One quick fix and my tool was back up and running.<br />
<br />
Of course it is worth pointing out that this whole change probably happened because of the new getApplicationMetaData function, which gives me a "documented" way to get at some of the things I could only see through sneaky means in the past.<br />
<br />
If you just need to see the meta data of the application of the calling template, use that instead.<br />
michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com0tag:blogger.com,1999:blog-2419463593138631929.post-6327270692127811542012-09-07T13:34:00.001+02:002012-09-07T13:34:36.085+02:00getApplicationSettings()Years ago we built an administration tool for our servers that allows us to view and administer all of the CF applications currently running. With it we reach into the application scope of each app and can do a number of things, like refreshing objects cached in the application scope, clearing cached files, and so on.<br />
<br />
Anyway, the key behind this magic is the ApplicationScopeTracker object, which lives in the coldfusion runtime.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><cfset apptracker = createObject("java","coldfusion.runtime.ApplicationScopeTracker") /></span><br />
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div>
Above, I have created the variable "apptracker". Let's make a dump of this.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt8WB7D7vxkqUXbvuk1NDXrj8WTVTtVDC9SfgyslDN1_VfINFHSEagiw85heSzOSDpjNxEQPr-bZ-8VKVG4fI8J9Rvl-Wsadtr9zZ_Wwna3tel6mKgvs50rLPy89iAkgii9NKpfB3MtoM/s1600/apptracker.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="204" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt8WB7D7vxkqUXbvuk1NDXrj8WTVTtVDC9SfgyslDN1_VfINFHSEagiw85heSzOSDpjNxEQPr-bZ-8VKVG4fI8J9Rvl-Wsadtr9zZ_Wwna3tel6mKgvs50rLPy89iAkgii9NKpfB3MtoM/s640/apptracker.jpg" width="640" /></a></div>
<br /></div>
<div>
The only method I've ever really played around here with is getApplicationScope(). This function takes the name of an application as argument, and returns the entire application scope of that app.<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><cfset appscope = apptracker.getApplicationScope('someappname') /></span><br />
<span style="font-family: Courier New, Courier, monospace;"><cfdump var="#appscope#"></span><br />
<br />
<br /></div>
<div>
That will give you a dump of your entire application scope. I'll spare you a picture of that since my application scopes tend to be pretty big. :)<br />
<br />
What you may not realize at first when looking at the dump though, is that actually we are dealing with an object of type coldfusion.runtime.ApplicationScope, and not a struct. To prove this we can execute a method on it.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><cfdump var="#appscope.getApplicationSettings()#"></span><br />
<br />
And we see this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4WfxeEWkTLyxKbZ9AeMbYoGPA-7Pz3tQQxrxFt4XG0L8ddMyramLgkk6zoUcjohw4j11j6nUEMfBfwuYLTM5HHAHYbTyX_wjllSg_ptOkJWAQHTcUo4wYs5YHx5qBcSoBnDCddZ9jyRs/s1600/blog2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4WfxeEWkTLyxKbZ9AeMbYoGPA-7Pz3tQQxrxFt4XG0L8ddMyramLgkk6zoUcjohw4j11j6nUEMfBfwuYLTM5HHAHYbTyX_wjllSg_ptOkJWAQHTcUo4wYs5YHx5qBcSoBnDCddZ9jyRs/s640/blog2.jpg" width="584" /></a></div>
<br />
<br />
Now these functions have been around a pretty long time, and they're pretty well documented on a lot of other blogs around the web. They can be pretty useful too, although it's important to remember that when working with these underlying java functions we are using unofficial and thus unsupported parts of the Coldfusion engine.<br />
<br />
These functions are subject to change and sometimes do. In fact such a change gave me my first CF10 "ouch", which I'll get to in the next post.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com0tag:blogger.com,1999:blog-2419463593138631929.post-35350774178874585472012-09-07T12:32:00.001+02:002012-09-07T12:33:15.736+02:00The UpgradeWhere I work in Frankfurt there is a lot of Coldfusion. In fact we're probably one of the biggest Coldfusion users in Germany. For the last few years we've been using CF8, but that will be changing during our upcoming upgrade to CF10.<br />
<br />
I'm creating this blog to track our experiences for this big leap!michael.imighttp://www.blogger.com/profile/01241417314905829966noreply@blogger.com0