<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Elliott&#039;s Development Blog &#187; Adobe</title>
	<atom:link href="http://www.elliottsprehn.com/blog/category/adobe/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.elliottsprehn.com/blog</link>
	<description>Exploring Life Through Math, Algorithms and Code</description>
	<lastBuildDate>Fri, 19 Feb 2010 17:38:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ColdFusion Mappings and Relative Paths</title>
		<link>http://www.elliottsprehn.com/blog/2010/02/19/coldfusion-mappings-and-relative-paths/</link>
		<comments>http://www.elliottsprehn.com/blog/2010/02/19/coldfusion-mappings-and-relative-paths/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 09:56:57 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.elliottsprehn.com/blog/?p=69</guid>
		<description><![CDATA[Recently one of our applications started failing inconsistently with strange errors about certain files not existing. We&#8217;d see error emails about things like the /myapplication/views/pages/survey.cfm not existing which didn&#8217;t make any sense since /myapplication is a mapping created inside the Application.cfc

&#60;cfset this.mappings["/myapplication"] = expandPath("../")&#62;

See the bug there? ExpandPath() is relative to the requested template. This [...]]]></description>
			<content:encoded><![CDATA[<p>Recently one of our applications started failing inconsistently with strange errors about certain files not existing. We&#8217;d see error emails about things like the <code>/myapplication/views/pages/survey.cfm</code> not existing which didn&#8217;t make any sense since /myapplication is a mapping created inside the Application.cfc</p>
<pre class="brush: coldfusion">
&lt;cfset this.mappings["/myapplication"] = expandPath("../")&gt;
</pre>
<p>See the bug there? ExpandPath() is relative to the requested template. This application had previously had all requests routed through <code>/public/index.cfm</code> so the mapping worked fine.</p>
<p>However, recently we had added some new web services like <code>/public/services/ScheduleService.cfc</code> and now whenever an Ajax request went through the CF mapping would change from pointing to <code>/</code> to <code>/public</code> causing all other concurrent requests to fail with confusing missing file errors.</p>
<p>I fixed this by making sure the path was no longer relative.</p>
<pre class="brush: coldfusion">
&lt;cfset this.mappings["/myapplication"] =
   getDirectoryFromPath(getCurrentTemplatePath())&gt;
</pre>
<p>So the moral of the story is to <strong>NEVER</strong> use expandPath() to create a mapping that&#8217;s relative to the webroot.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elliottsprehn.com/blog/2010/02/19/coldfusion-mappings-and-relative-paths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColdFusion arguments.callee</title>
		<link>http://www.elliottsprehn.com/blog/2009/07/16/coldfusion-argumentscallee/</link>
		<comments>http://www.elliottsprehn.com/blog/2009/07/16/coldfusion-argumentscallee/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 17:33:48 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.elliottsprehn.com/blog/2009/07/16/coldfusion-argumentscallee/</guid>
		<description><![CDATA[Last night Ben Nadel sent me an email asking if there was any way to get the currently executing function so you could get the metadata from it.
&#60;cffunction name="test" myAttribute="1"&#62;
  &#60;--- How can we get the myAttribute value? ---&#62;
&#60;/cffunction&#62;
The first obvious attempt at this is to use getMetaData(test).myAttribute, and that works fine until you [...]]]></description>
			<content:encoded><![CDATA[<p>Last night Ben Nadel sent me an email asking if there was any way to get the currently executing function so you could get the metadata from it.</p>
<pre class="brush: coldfusion">&lt;cffunction name="test" myAttribute="1"&gt;
  &lt;--- How can we get the myAttribute value? ---&gt;
&lt;/cffunction&gt;</pre>
<p>The first obvious attempt at this is to use <code>getMetaData(test).myAttribute</code>, and that works fine until you pass the function as a pointer and then it&#8217;s not called <em>test</em> anymore. Instead we need a different way to get the current function.</p>
<p>I had looked into this for implementing closures some time ago, and even talked about this at BFusion 2008. My original workaround was to create an API around the function pointer. For example <em>executeFunction</em>(func) that passes the function pointer in as an argument. Unfotunately, this also means you can&#8217;t just pass this function around transparently to anything that expects a function pointer.</p>
<p>Last night, however, I had a eureka moment and figured this one out. To get a reference to the current function we&#8217;re going to harness exceptions and the information we can get from the stack.</p>
<pre class="brush: coldfusion">&lt;cffunction name="getStackFunction" access="public" returntype="any" output="false"&gt;
   &lt;cfargument name="name" type="string" required="true"&gt;
   &lt;cfargument name="depth" type="numeric" required="false" default="1"&gt;

   &lt;cfset var TemplateClassLoader = createObject("java","coldfusion.runtime.TemplateClassLoader")&gt;
   &lt;cfset var servletContext = getPageContext().getServletContext()&gt;
   &lt;cfset var templatePath = ""&gt;
   &lt;cfset var TemplateClass = ""&gt;
   &lt;cfset var field = ""&gt;

   &lt;cftry&gt;
      &lt;cfthrow type="Exception"&gt;

   &lt;cfcatch type="any"&gt;
      &lt;cfset templatePath = cfcatch.tagContext[depth+1].template&gt;
   &lt;/cfcatch&gt;
   &lt;/cftry&gt;

   &lt;cfset TemplateClass = TemplateClassLoader.findClass(servletContext,templatePath)&gt;
   &lt;cfset field = TemplateClass.getDeclaredField(arguments.name)&gt;
   &lt;cfset field.setAccessible(true)&gt;

   &lt;cfreturn field.get(TemplateClass.newInstance())&gt;
&lt;/cffunction&gt;</pre>
<p>We can then use this code with the (<strong>case sensitive</strong>) name of the function in the current stack to get a pointer to that function.</p>
<pre class="brush: coldfusion">&lt;cffunction name="test" myAttribute="1" output="false"&gt;
   &lt;cfargument name="x" type="numeric"&gt;
   &lt;cfset arguments.callee = getStackFunction("test")&gt;
   &lt;cfreturn arguments.x + getMetaData(arguments.callee).myAttribute&gt;
&lt;/cffunction&gt;</pre>
<p>You can use the depth parameter to get functions farther down the stack as well.</p>
<p>I&#8217;ll go over how to build proper closure constructs using this technique, and some other novel ones that don&#8217;t even require runtime magic in an upcoming post.</p>
<p>Oh, and hats off to Ben for sparking my interest in this issue again! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elliottsprehn.com/blog/2009/07/16/coldfusion-argumentscallee/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>cfimage and ImageScaleToFit on Large Images Pegs CPU</title>
		<link>http://www.elliottsprehn.com/blog/2009/01/14/cfimage-and-imagescaletofit-on-large-images-pegs-cpu/</link>
		<comments>http://www.elliottsprehn.com/blog/2009/01/14/cfimage-and-imagescaletofit-on-large-images-pegs-cpu/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 11:05:07 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.elliottsprehn.com/blog/2009/01/14/cfimage-and-imagescaletofit-on-large-images-pegs-cpu/</guid>
		<description><![CDATA[I was working on the new profile picture feature of the registration and CFUnited 2009 website when I ran into an issue where a user uploaded a 2112 x 2816 (2MB) photo. 
This seemed to cause file locking issues in cfimage which I was told were addressed by CF 8.0.1 Cumulative Hot Fix 1. I [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on the new profile picture feature of the registration and CFUnited 2009 website when I ran into an issue where a user uploaded a 2112 x 2816 (2MB) photo. </p>
<p>This seemed to cause file locking issues in cfimage which I was told were addressed by CF 8.0.1 Cumulative Hot Fix 1. I applied the hot fix and everything seemed to work, but then when I started testing with the large file again the CPU would jump to 100% and the request would never seem to finish. I tried all kinds of things, and nothing I did seemed to make a difference.</p>
<p>Finally I tried the &#8220;highestPerformance&#8221; interpolation and the requests started finishing hundreds of times faster. Any other interpolation algorithm seems to cause the thread to lock up. </p>
<p>I&#8217;ve fixed this in our code with:</p>
<pre class="brush: coldfusion">&lt;!---
	CF8 will peg the CPU to 100% and this thread will seem
	to hang for minutes on large images if we don't choose
	highestPerformance.
---&gt;
&lt;cfif getSize("kilobytes") gt 375&gt;
	&lt;cfset arguments.interpolation = "highestPerformance"&gt;
&lt;/cfif&gt;
</pre>
<p>What&#8217;s most odd is that the issue only appears on Windows on the production server. On my Macbook I can choose a different algorithm and get a nice resize without hanging the request.</p>
<p>Production server is Java 1.6 u11, CF8.0.1 HF2, Windows Server 2003</p>
<p>Anyone have any ideas?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elliottsprehn.com/blog/2009/01/14/cfimage-and-imagescaletofit-on-large-images-pegs-cpu/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ColdFusion 8 Exception Handling Breaks HTTP Requests</title>
		<link>http://www.elliottsprehn.com/blog/2007/08/01/coldfusion-8-exception-handling-breaks-http-requests/</link>
		<comments>http://www.elliottsprehn.com/blog/2007/08/01/coldfusion-8-exception-handling-breaks-http-requests/#comments</comments>
		<pubDate>Wed, 01 Aug 2007 06:52:04 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.elliottsprehn.com/blog/2007/08/01/coldfusion-8-exception-handling-breaks-http-requests/</guid>
		<description><![CDATA[Just found this bug today&#8230;.  
So CF8 outputs the cfcatch.message into the Reason-Phrase portion of the HTTP Response, however it does not strip new lines (LF or CR). A web server, however, should never send new lines in the Reason-Phrase [1], and should probably be truncating that error message at a certain length. 
[1] [...]]]></description>
			<content:encoded><![CDATA[<p>Just found this bug today&#8230;.  </p>
<p>So CF8 outputs the cfcatch.message into the Reason-Phrase portion of the HTTP Response, however it does not strip new lines (LF or CR). A web server, however, should never send new lines in the Reason-Phrase [1], and should probably be truncating that error message at a certain length. </p>
<p>[1] <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html">RFC2616, Section6, HTTP Response</a></p>
<p>It&#8217;s pretty easy to reproduce this bug:</p>
<p><code>&amp;lt;cfthrow message="foo #chr(10)##chr(10)##chr(10)# bar"&amp;gt;</code></p>
<p>Another way to show this is with the new deserializeJSON() function in CF8 when the JSON is not valid. CF outputs the exception message with the JSON into the Reason-Phrase portion of the HTTP response Status-Line without stripping out new lines.</p>
<h3>ColdFusion Code</h3>
<pre class="brush: js">&lt;cfset json = '
{
    "foo": [
        {}
        "",
        {
            "f": {}
        }
    ]
}
'&gt;

&lt;cfset deserializeJSON(json)&gt;</pre>
<p>And the server responds with:</p>
<h3>HTTP Response</h3>
<pre class="brush: plain">HTTP/1.1 500 JSON parsing failure: Expected ',' or ']' at character 20:'"' in {
	"foo": [
		{}
		"",
		{
			"f": {}
		}
	]
}
Date: Wed, 01 Aug 2007 05:31:39 GMT
Server: Apache/1.3.33 (Darwin) mod_fastcgi/2.4.2 PHP/5.2.0 JRun/4.0
server-error: true
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

&lt;!-- " ---&gt;&lt;/TD&gt;&lt;/TD&gt;&lt;/TD&gt;&lt;/TH&gt;&lt;/TH&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;/TR&gt;&lt;/TR&gt;&lt;/TABLE&gt;&lt;/TABLE&gt;</pre>
<p>As it stands now, if you had <strong>100</strong> lines of JSON and there&#8217;s an error at the end, CF will dump <strong>all previous lines</strong> of JSON into the http Reason-Phrase.</p>
<p>This is particularly apparent in Safari (and WebKit based browsers) where it actually displays the HTTP headers in the body of the page because it sees new lines and assumes the HTTP headers are complete, and worse in Gecko based browsers that render the page as text/plain because the Content-Type header is never processed!</p>
<p>It should also be noted that CF7 output &#8220;Internal Server Error&#8221; for the Reason-Phrase instead of the exception message.</p>
<p>There also seems to be some other random junk thrown into the page when an exception is thrown&#8230;.</p>
<pre class="brush: coldfusion">foo bar baz&lt;cfthrow message="foo #chr(10)##chr(10)#bar"&gt;</pre>
<p>Will generate the following right after the http headers:</p>
<pre class="brush: plain">b
foo bar baz
1f27
</pre>
<p>I hope this saves someone some time trying to figure out what&#8217;s going on on their code! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elliottsprehn.com/blog/2007/08/01/coldfusion-8-exception-handling-breaks-http-requests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting the Expected Results for GetCurrentTemplatePath() in a Custom Tag.</title>
		<link>http://www.elliottsprehn.com/blog/2007/07/17/getting-the-expected-results-for-getcurrenttemplatepath-in-a-custom-tag/</link>
		<comments>http://www.elliottsprehn.com/blog/2007/07/17/getting-the-expected-results-for-getcurrenttemplatepath-in-a-custom-tag/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 21:43:39 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.elliottsprehn.com/blog/2007/07/17/getting-the-expected-results-for-getcurrenttemplatepath-in-a-custom-tag/</guid>
		<description><![CDATA[While working on the template system used for the conference websites I ran across a problem where I needed the path to the template that called a custom tag. The first thing I tried was getCurrentTemplatePath() thinking that it might return that since the documentation makes no mention of custom tags. Instead, however, the function [...]]]></description>
			<content:encoded><![CDATA[<p>While working on the template system used for the <a href="http://cfunited.com">conference websites</a> I ran across a problem where I needed the path to the template that called a custom tag. The first thing I tried was getCurrentTemplatePath() thinking that it might return that since the documentation makes no mention of custom tags. Instead, however, the function returns the path to the custom tag itself.</p>
<p><a href="http://www.bennadel.com/">Ben Nadel</a> noticed some of this <a href="http://www.bennadel.com/blog/828-Dynamic-And-Unexpected-ColdFusion-GetCurrentTemplatePath-Behavior.htm">odd behavior</a> as well.</p>
<p>I spent a long time trying to figure out how to get the caller template path, including what Ben did which was to add a special function to the caller scope.</p>
<pre class="brush: coldfusion">&lt;cfscript&gt;
function getCallerTemplatePath() {
    return getCurrentTemplatePath();
}
caller.getCallerTemplatePath = getCallerTemplatePath;
path = caller.getCallerTemplatePath();
&lt;/cfscript&gt;</pre>
<p>This doesn&#8217;t work though. Instead I still got the template path of the custom tag!</p>
<p>I dug around in the PageContext (which is returned from getPageContext() if you&#8217;re not familiar) with no luck and finally gave up resorting to this&#8230;</p>
<pre class="brush: js">/**
    Monumental hack, but the only way I could figure out how to do
    a getCurrentTemplatePath() like call that resolves to the page
    that called this custom tag.
*/
function getCallerTemplatePath() {
    try {
       error;
    } catch( any cfcatch ) {
        return cfcatch.tagContext[3].template;
    }
}</pre>
<p>Which worked but really felt like a hack since it means throwing an exception on every request. So I kept an eye out as I dug around in the internals of the CF engine for various other things, and today I was rewarded with an awesome solution.</p>
<pre class="brush: js">/** Gets the path to the page that called this custom tag. */
function getCallerTemplatePath() {
    var field = getMetaData(caller).getDeclaredField("pageContext");
    field.setAccessible(true);
    return field.get(caller).getPage().getCurrentTemplatePath();
}</pre>
<p>Now to get at why and how this kind of thing works&#8230;</p>
<p>Inside the ColdFusion runtime the foundation unit for all scripts, components and tags is the <code>coldfusion.runtime.CFPage</code> object, and the getCurrentTemplatePath() function is really identical to&#8230;</p>
<pre class="brush: js">function getCurrentTemplatePath() {
    return getPageContext().getPage().getCurrentTemplatePath();
}</pre>
<p>After realizing this it dawned on me that the custom tags, cfcs, and pages all have their own PageContext and Page objects, and as such the template path is going to be different, or rather bound, to the page in which the function is called from, not where it&#8217;s defined.</p>
<p>Knowing this I was able to grab the page context out of the caller scope, which is the page context of the caller, and not the current page, and use that to get the current template path of the page for which that page context operates.</p>
<p>Also, for those who aren&#8217;t familiar, the getMetaData() function can be used to return the java.lang.Class instance for most objects you wouldn&#8217;t normally be able to call getClass() on in ColdFusion. For instance you can call <code>getMetaData(variables).getName()</code> and you&#8217;ll get <code>coldfusion.runtime.VariableScope</code>.</p>
<p>Doing this really made my code feel less icky, so I hope this is useful to someone else.</p>
<p>(PS, Tested and works on CF6+ and CF7+, anyone have CF8?)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elliottsprehn.com/blog/2007/07/17/getting-the-expected-results-for-getcurrenttemplatepath-in-a-custom-tag/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ActionSctipt 3.0 Array Access Woes</title>
		<link>http://www.elliottsprehn.com/blog/2007/03/25/actionsctipt-30-array-access-woes/</link>
		<comments>http://www.elliottsprehn.com/blog/2007/03/25/actionsctipt-30-array-access-woes/#comments</comments>
		<pubDate>Sun, 25 Mar 2007 05:43:38 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.elliottsprehn.com/blog/2007/03/25/actionsctipt-30-array-access-woes/</guid>
		<description><![CDATA[With the recent launch of Apollo Beta I thought I&#8217;d look into Flex again for some fun and decided I&#8217;d write plist api so that Apollo applications could read and modify OS X plists in a sane maner.
PList XML is particularly problematic because of how its structured:

    &#60;dict&#62;
     [...]]]></description>
			<content:encoded><![CDATA[<p>With the recent launch of Apollo Beta I thought I&#8217;d look into Flex again for some fun and decided I&#8217;d write plist api so that Apollo applications could read and modify OS X plists in a sane maner.</p>
<p>PList XML is particularly problematic because of how its structured:</p>
<pre class="brush: xml">
    &lt;dict&gt;
        &lt;key&gt;Foods&lt;/key&gt;
        &lt;array&gt;
            &lt;dict&gt;
               &lt;key&gt;Chocolate&lt;/key&gt;
               &lt;true/&gt;
            &lt;/dict&gt;
        &lt;/array&gt;
    &lt;/dict&gt;
</pre>
<p>While this example is contrived we can see that keys are associated with the following element in dict[tionaries] and that array elements are just the elements inside array blocks. This makes tools like XPath less than stellar since nodes don&#8217;t have real ids and makes working with E4X awkward.</p>
<p>Instead I decided a layer of transparency would be best, so the previous structure could be represented as:</p>
<pre class="brush: js">
    Dictionary {
        "Foods" => Array [
              Dictionary {
                   "Chocolate" => true
              }
         ]
    }
</pre>
<p>The goal being that in the actionscript I can do <code>myPlist.Foods[0].Chocolate</code> and get true, and allow simple assignments so <code>myPlist.Foods[0] = "foo"</code> should automatically wrap that string in a PListString. Simple right?</p>
<p>Well in a language like ruby, yes, but AS3 makes it more complicated than it needs to be (in part due to the way ECMAScript works) and requires flash.utils.Proxy to be able to override the <strong>Array Access</strong> operator.</p>
<p>This is problematic as it means that PListArray cannot actually extend the Array class and still override the Array Access operator at the same time! Doh!. To add insult to injury the array access operator definition on the Array class doesn&#8217;t call a method that we can override.</p>
<p>This means making a Typed array that handles all input and output to allow wrapping is impossible, instead we&#8217;d need to resort to get() and set() methods which means you can&#8217;t actually use the PListArray in any method that requires an array in transparent manner.</p>
<p>This makes me question why Adobe chose to force a fragile base class on us for overriding the existing object operators like <code>delete</code> or the Array Access Operator.</p>
<p>Instead they should have used an interface, flash.utils.IProxy which allowed implementing methods for calling performing those actions. Then again we&#8217;re still in a bind since interface methods must all be public these new override methods would clutter the public API.</p>
<p>Seems to me the best solution would be a little syntax addition for array access such as:</p>
<pre class="brush:as3">
function object get():*
function object set( key:*, value:* ):void
function object delete( key:* ):void
</pre>
<p>And so on&#8230;</p>
<p>This would allow defining proper getters and setters for the array access and let users redefine the getter and setter methods on superclasses to implement proper Arrays without the need to extend a super class which may or may not be an option. Sweet too since we can do this without even extending the language by adding an &#8220;object&#8221; namespace. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.elliottsprehn.com/blog/2007/03/25/actionsctipt-30-array-access-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<img style='margin:0;padding:0;border:0;' width='1px' height='1px' src="http://www.elliottsprehn.com/blog/wp-content/plugins/mystat/mystat.php?act=time_load&id=9444&rnd=1534467691" /></channel>
</rss>
