<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.4" -->
<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/"
	>

<channel>
	<title>Elliott's Development Blog</title>
	<link>http://enfinitystudios.thaposse.net/blog</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Fri, 03 Aug 2007 18:58:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>
	<language>en</language>
			<item>
		<title>Fix for ColdFusion 8 Broken Exception HTTP Response</title>
		<link>http://enfinitystudios.thaposse.net/blog/2007/08/01/fix-for-coldfusion-8-broken-exception-http-response/</link>
		<comments>http://enfinitystudios.thaposse.net/blog/2007/08/01/fix-for-coldfusion-8-broken-exception-http-response/#comments</comments>
		<pubDate>Wed, 01 Aug 2007 07:44:46 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
		
	<category>Java</category>
	<category>Adobe</category>
	<category>ColdFusion</category>
		<guid isPermaLink="false">http://enfinitystudios.thaposse.net/blog/2007/08/01/fix-for-coldfusion-8-broken-exception-http-response/</guid>
		<description><![CDATA[Here&#8217;s a quick and dirty solution for the issue described in: ColdFusion 8 Exception Handling Breaks HTTP Requests.
&#60;cffunction name="onError" access="public" returntype="void" output="false"&#62;
&#160;&#60;cfargument name="exception" type="any" required="true"&#62;
&#160;&#60;cfargument name="eventname" type="string" required="false"&#62;
&#160;
&#160;&#60;cfset var error = getMetaData(exception)&#62;
&#160;&#60;cfset var message = left(reReplace(reReplace(exception.message,"\r&#124;\n"," ","all"),"\s\s+"," ","all"),500)&#62;
&#160;&#60;cfset var msg = ""&#62;
&#160;
&#160;&#60;cfloop condition="true"&#62;
&#160;&#60;cfif not isDefined("error") or error.getName() eq "coldfusion.runtime.NeoException"&#62;
&#160;&#60;cfbreak&#62;
&#160;&#60;/cfif&#62;
&#160;&#60;cfset error = error.getSuperClass()&#62;
&#160;&#60;/cfloop&#62;
&#160;
&#160;&#60;cfif isDefined("error")&#62;
&#160;&#160;&#60;cfset msg = [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick and dirty solution for the issue described in: <a href="http://enfinitystudios.thaposse.net/blog/2007/08/01/coldfusion-8-exception-handling-breaks-http-requests/">ColdFusion 8 Exception Handling Breaks HTTP Requests</a>.</p>
<p><code>&lt;cffunction name="onError" access="public" returntype="void" output="false"&gt;<br />
&nbsp;&lt;cfargument name="exception" type="any" required="true"&gt;<br />
&nbsp;&lt;cfargument name="eventname" type="string" required="false"&gt;<br />
&nbsp;<br />
&nbsp;&lt;cfset var error = getMetaData(exception)&gt;<br />
&nbsp;&lt;cfset var message = left(reReplace(reReplace(exception.message,"\r|\n"," ","all"),"\s\s+"," ","all"),500)&gt;<br />
&nbsp;&lt;cfset var msg = ""&gt;<br />
&nbsp;<br />
&nbsp;&lt;cfloop condition="true"&gt;<br />
&nbsp;&lt;cfif not isDefined("error") or error.getName() eq "coldfusion.runtime.NeoException"&gt;<br />
&nbsp;&lt;cfbreak&gt;<br />
&nbsp;&lt;/cfif&gt;<br />
&nbsp;&lt;cfset error = error.getSuperClass()&gt;<br />
&nbsp;&lt;/cfloop&gt;<br />
&nbsp;<br />
&nbsp;&lt;cfif isDefined("error")&gt;<br />
&nbsp;&nbsp;&lt;cfset msg = error.getDeclaredField("msg")&gt;<br />
&nbsp;&nbsp;&lt;cfset msg.setAccessible(true)&gt;<br />
&nbsp;&nbsp;&lt;cfset msg.set(exception,message)&gt;</p>
<p>&nbsp;&nbsp;&lt;cfif exception.getClass().getName() eq "coldfusion.runtime.CustomException"&gt;<br />
&nbsp;&nbsp;&lt;cfset msg = getMetaData(exception).getDeclaredField("userMessage")&gt;<br />
&nbsp;&nbsp;&lt;cfset msg.setAccessible(true)&gt;<br />
&nbsp;&nbsp;&lt;cfset msg.set(exception,message)&gt;<br />
&nbsp;&nbsp;&lt;/cfif&gt;<br />
&nbsp;&lt;/cfif&gt;<br />
&nbsp;<br />
&nbsp;&lt;cfthrow object="#exception#"&gt;<br />
&lt;/cffunction&gt;</code></p>
<p>Place that in your Application.cfc and CF won&#8217;t break the http requests anymore. Of course this won&#8217;t work if you have the Java Access Control enabled in the CF8 Administrator.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://enfinitystudios.thaposse.net/blog/2007/08/01/fix-for-coldfusion-8-broken-exception-http-response/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>ColdFusion 8 Exception Handling Breaks HTTP Requests</title>
		<link>http://enfinitystudios.thaposse.net/blog/2007/08/01/coldfusion-8-exception-handling-breaks-http-requests/</link>
		<comments>http://enfinitystudios.thaposse.net/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>Programming</category>
	<category>Adobe</category>
	<category>ColdFusion</category>
		<guid isPermaLink="false">http://enfinitystudios.thaposse.net/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>&lt;cfthrow message="foo #chr(10)##chr(10)##chr(10)# bar"&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>&lt;cfset json = '
{
    "foo": [
        {}
        "",
        {
            "f": {}
        }
    ]
}
'&gt;

&lt;cfset deserializeJSON(json)&gt;</pre>
<p>And the server responds with:</p>
<h3>HTTP Response</h3>
<pre>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>
<p><code>foo bar baz&lt;cfthrow message="foo #chr(10)##chr(10)#bar"&gt;</code></p>
<p>Will generate the following right after the http headers:</p>
<pre><code>b
foo bar baz
1f27</code><code></code></pre>
<p>I hope this saves someone some time trying to figure out what&#8217;s going on on their code! <img src='http://enfinitystudios.thaposse.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
]]></content:encoded>
			<wfw:commentRSS>http://enfinitystudios.thaposse.net/blog/2007/08/01/coldfusion-8-exception-handling-breaks-http-requests/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Getting the Expected Results for GetCurrentTemplatePath() in a Custom Tag.</title>
		<link>http://enfinitystudios.thaposse.net/blog/2007/07/17/getting-the-expected-results-for-getcurrenttemplatepath-in-a-custom-tag/</link>
		<comments>http://enfinitystudios.thaposse.net/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>Programming</category>
	<category>Java</category>
	<category>Adobe</category>
	<category>ColdFusion</category>
		<guid isPermaLink="false">http://enfinitystudios.thaposse.net/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>
<p><code>
<pre>&lt;cfscript&gt;
function getCallerTemplatePath() {
    return getCurrentTemplatePath();
}
caller.getCallerTemplatePath = getCallerTemplatePath;
path = caller.getCallerTemplatePath();
&lt;/cfscript&gt;</pre>
<p></code></p>
<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>
<p><code>
<pre>/**
    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></code></p>
<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>
<p><code>
<pre>/** 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></code></p>
<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>
<p><code>
<pre>function getCurrentTemplatePath() {
    return getPageContext().getPage().getCurrentTemplatePath();
}</pre>
<p></code></p>
<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://enfinitystudios.thaposse.net/blog/2007/07/17/getting-the-expected-results-for-getcurrenttemplatepath-in-a-custom-tag/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>ActionSctipt 3.0 Array Access Woes</title>
		<link>http://enfinitystudios.thaposse.net/blog/2007/03/25/actionsctipt-30-array-access-woes/</link>
		<comments>http://enfinitystudios.thaposse.net/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>Flex</category>
	<category>ActionSctipt 3.0</category>
	<category>Adobe</category>
	<category>OS X</category>
		<guid isPermaLink="false">http://enfinitystudios.thaposse.net/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:<br />
<code>
<pre>
    &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></code></p>
<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>
<p><code>
<pre>
    Dictionary {
        "Foods" => Array [
              Dictionary {
                   "Chocolate" => true
              }
         ]
    }
</pre>
<p></code></p>
<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>
<p><code>function object get():*</code><br />
<code>function object set( key:*, value:* ):void</code><br />
<code>function object delete( key:* ):void</code><br />
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. <img src='http://enfinitystudios.thaposse.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
]]></content:encoded>
			<wfw:commentRSS>http://enfinitystudios.thaposse.net/blog/2007/03/25/actionsctipt-30-array-access-woes/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>I Object!</title>
		<link>http://enfinitystudios.thaposse.net/blog/2007/02/26/i-object/</link>
		<comments>http://enfinitystudios.thaposse.net/blog/2007/02/26/i-object/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 08:15:02 +0000</pubDate>
		<dc:creator>Elliott</dc:creator>
		
	<category>Ruby</category>
	<category>Programming</category>
	<category>Java</category>
		<guid isPermaLink="false">http://enfinitystudios.thaposse.net/blog/?p=3</guid>
		<description><![CDATA[While doing some casual web surfing I came across a rather interesting blog entry about Ruby&#8217;s types and looping. I started typing a reply, and then I realized it was really long, so I&#8217;m putting it here:
One reason I think methods like this are great is that Ruby is intended to be read! Which actually [...]]]></description>
			<content:encoded><![CDATA[<p>While doing some casual web surfing I came across a rather interesting blog entry about <a href="http://www.ditchnet.org/wp/2007/02/07/3times-erh-links/">Ruby&#8217;s types and looping</a>. I started typing a reply, and then I realized it was really long, so I&#8217;m putting it here:</p>
<p>One reason I think methods like this are great is that Ruby is intended to be <strong>read</strong>! Which actually makes 5.times(&#038;block) make much more sense than a C style 3 part for loop (that&#8217;s where it came from, not Java).</p>
<p><code>5.times do |i|; end</code> can be read as &#8220;5 times do this&#8221; or better &#8220;do this 5 times&#8221;</p>
<p>for on the other hand looks more like: <code>for( i=0; i < 5; i++ ) {}</code> which has no such linear meaning, &#8220;for set i equal to 0, i less than 5, i plus one do this&#8221;, its all out of order. At best you can rearrange it in your head as &#8220;set i to 0, while i is less than 5 do do this, add one to i after each iteration&#8221;</p>
<p>for() is also prone to error with the condition operator, was that supposed to be < or <= ? Plenty of applications have had bugs because of this, and where something loops to isn't always clear. If you really don't like 5.times, there's other methodologies though, in fact you can use a 'for' loop:</p>
<p><code>for i in (0...5); end</code><br />
Read as &#8220;For i in the range of [0, 5) do this&#8221;</p>
<p><code>(0...5).each do |i|; end</code><br />
Read as &#8220;for each in the range [0, 5) do this&#8221;</p>
<p><code>0.upto(4) do |i|; end</code><br />
Again it reads linearly, from &#8220;from 0 up to 4 do this&#8221;.</p>
<p>I definitely think this makes Ruby more OO; Java suffers quite a lot from the distinction between primitive types and regular types. Want to design a collection in Java and store both objects and primitive types? You can&#8217;t declare:</p>
<pre>
<code>
class Collection&lt;T&gt; {
...
     public void add( T elem );
...
}
</code>
</pre>
<p>Instead you need to declare methods for each primitive type, and that method. This bloats Java types with many extra methods, or requires object wrappers that are a nasty hit on performance (something that&#8217;s totally unnecessary with a decent compiler). Other languages deal with this much more elegantly; by making numbers objects all you need to declare is the method that accepts the type T.</p>
<p>The Java API is greatly bloated because of this. Look at java.util.Arrays which has 9 methods to join() an array, one for each primitive type, and another for Object because of the Object#toString() and String.valueOf() distinction, even the String.valueOf() method has 9 signatures to deal with this limitation.</p>
<p>In ruby to get a string I can call to_s on *any* object, there is no null that causes exceptions, or special case primitives. I think Ruby unified all these types into a single Object hierarchy quite elegantly. <img src='http://enfinitystudios.thaposse.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
]]></content:encoded>
			<wfw:commentRSS>http://enfinitystudios.thaposse.net/blog/2007/02/26/i-object/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>
