Dan Mackey On ColdFusion Development

ColdFusion, Java, .NET, AJAX, DHTML development and general programming. Daniel is owner and Administrator of CFTagStore.com and works for an Application Development Company in Ireland called Digital Crew. His interests cover all areas of programming in multiple languages with a particular interest in Internet Technologies.

Last 5 Entries
2010-04-29 13:44:00.0

Getting JSP files compiling in Railo

As part of the code samples we are writing for the Teamwork Project Manager API, I needed to get JSP pages compiling. As I have switched mainly to Railo for all my ColdFusion development, I wanted to use that servlet engine and resin to test my work

My knowledge of Resin is pretty poor so this took me a while to figure out (especially the Class Path to JDK bit) but it may help someone else in the same position.

  1. Open up c:\railo\conf\resin.conf
  2. Add in the following to <class-loader> -> <tree-loader path="C:/Program Files/Java/jdk1.6.0_18/lib/"/>
  3. Open up c:\railo\conf\app-default.xml
  4. Uncomment out:
    • <servlet-mapping url-pattern="*.jsp" servlet-name="resin-jsp"/>
      <servlet-mapping url-pattern="*.jspx" servlet-name="resin-jspx"/>
      <servlet-mapping url-pattern="*.php" servlet-name="resin-php"/>

  5. Uncomment out:
    •   <servlet servlet-name="resin-jsp" servlet-class="com.caucho.jsp.JspServlet">
          <init>
            <load-tld-on-init>false</load-tld-on-init>
            <page-cache-max>1024</page-cache-max>
          </init>
          <load-on-startup/>
        </servlet>

        <servlet servlet-name="resin-jspx"
                 servlet-class="com.caucho.jsp.JspServlet">
          <init>
            <load-tld-on-init>false</load-tld-on-init>   
            <page-cache-max>1024</page-cache-max>
            <xml>true</xml>
          </init>
          <load-on-startup/>
        </servlet>

        <servlet servlet-name="resin-php"
                 servlet-class="com.caucho.quercus.servlet.QuercusServlet">
        </servlet>

        <servlet servlet-name="resin-xtp" servlet-class="com.caucho.jsp.XtpServlet"/>

  6. Wait for Railo to restart or Restart it in Services.

Bingo. JSP pages will now be processed along with CFM files

Tags: ColdFusion | Java | JSP | Railo | Tips
Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [1] - Leave a comment
2009-08-09 22:10:00.0

Adobe AIR Flex 3 HTTP Basic Authentication

I am a week into Flex 3 development building an AIR app to test the new API for Teamwork Project Manager and thought I would share an issue with HTTP Basic Authentication that I ran into.

To be honest it has been itching away at me all day today and half of yesterday and I finally solved it.

What I am trying to do:

  • Connect to the Teamworkpm.net API
  • Pass my URL, Username and Password to be authenticated
  • Catch the HTTP Status code in the response
  • Catch any IO errors if the URL can't be found
  • Catch an authorization failure for the credentials passed.
  • Use the URLLoader class in Flex 3

Sounds easy doesn't it? Well, I got everything working fine and then hit a snag. If the credentials passed did not authenticate, then the ugly browser Login dialog appeared right in my beautiful AIR app. I tried everything and eventually even re-wrote the whole thing TWICE using 2 Google Code projects for AS3 HTTP Client calls.

How I did it

I decided to scrap it all and start again. This is how I got it working.

  1. I need to send the login credentials to the server but there was no native method to do this. You need to push an authorization header into the Request Header in base64
    • import mx.utils.Base64Encoder;
    • var loader:URLLoader = new URLLoader();
      var req:URLRequest = new URLRequest(cURL);
      var headerRequests:Array = new Array(1);
      req.method="get";

      var headerRequests:Array = new Array(1);
      var encoder64:Base64Encoder = new Base64Encoder();
      encoder64.encode(cUsername + ":" + cPassword);

      var credentials:String = encoder64.toString();
      headerRequests[0] = new URLRequestHeader("Authorization", "Basic " + credentials);
      req.requestHeaders = headerRequests;
  2. This solved the first issue and after running the app with valid credentials, everything worked fine. Now I needed to supress the ugly Dialog on invalid credentials.

    • You need to set the authenticate property of your request to false.

    • req.authenticate=false
  3. I need to get the status code back now and handle the exception thrown if the URL can not be loaded. This is very easy and all that's required is to add event handlers for the following events:

    • loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS,onStatus);
      loader.addEventListener(Event.COMPLETE,onComplete);
      loader.addEventListener(IOErrorEvent.IO_ERROR,onError);

    • private function onStatus(event:HTTPStatusEvent):void {
      Alert.show(event.status.toString());
      }

      private function onComplete(event:Event):void {
      Alert.show(event.target.data);
      }

      private function onError(event:IOErrorEvent):void {
      Alert.show(event.text);
      }
    • Be aware that the event:HTTPStatusEvent is the first event handled and then the onComplete is handled.

I hope the above helps some people. Even though all I was missing was a simple property set, the Live Docs documentation was not very helpful and trying to figure out the way to accomplish the problem was difficult. I did manage to learn a heap loads of how the URLLoader, URLRequest and event handling works.

Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [9] - Leave a comment
2009-01-15 19:57:00.0

CompareHTMLComponent : JAR to compare two HTML fragments

After my initial post yesterday CFX_CompareHTML ColdFusion HTML diff custom tag I got quite a bit of feedback and one of the items raised was that some people dont like CFX tags and I should use JavaLoader to use the JAR file from within ColdFusion. (Thanks Dan Vega)

I have uploaded a JAR file called CompareHTMLComponent which allows you to do this.

To call the diff component use the following:

<cfset paths = arrayNew(1)>
<cfset paths[1] = expandPath("CompareHTMLComponent.jar")>
<cfset loader = createObject("component", "javaloader.JavaLoader").init(paths)>
<cfset compareComponent = loader.create("CompareHTMLComponent")>
<cfset diff = compareComponent.init()>

<cfoutput>#diff.compare("Some HTML","Some more HTML")#</cfoutput>

As always, feedback is most appreciated so hit me with your thoughts in the comments!

The JAR file and examples can be downloaded from here :

DOWNLOAD PACKAGE

Requires Java 1.5 JRE to be installed or it will throw an exception! ColdFusion 8 & Railo 3 should have this but CFMX7 may not.

Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [19] - Leave a comment
2009-01-14 14:29:00.0

CFX_CompareHTML ColdFusion HTML diff custom tag

Following on from my last post I have released Version 1 of my ColdFusion HTML Diff Custom Tag, CFX_CompareHTML.

When we wrote Teamwork Project Manager one of my jobs was to compare versions of Notebooks which were marked up using HTML.

I did lots of searching and found Diff.cfc which did a line for line comparison but did not represent the changes in HTML format, it only output the differences line-by-line with all the HTML viewable.

Diff.cfc is perfect for text or source code but we needed something a little bit more user-friendly.

A great start on this was DaisyDiff,  a Java library that diffs (compares) HTML files.

The problem with this was that I had to use CFExecute and some timeouts, writing to the drive etc to get some results. It soon became a nightmare on large files so I decided the best thing to do was to build a CFX tag around the main components of DaisyDiff.

CFX_CompareHTML was born.

You can call the tag using :

<cfx_CompareHTML left="Some HTML content" right="Some more HTML Content">

The tag can be downloaded from here :

DOWNLOAD CFX_COMPAREHTML

Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [8] - Leave a comment
2009-01-07 14:58:00.0

Railo 3 : Adding Java CFX Tags

I have a small project that I am working on that needs a Java custom tag that I'm writing. I need this running on ColdFusion 7/8 and Railo 3.

Adding the CFX to CF is fine and I had no problems, except that its laborious. Having to place the file in the right folder, adding that folder to the Java Classpath and restarting CF Application Server.

Railo is a little different. Infact, its a bit easier once you know.

Everytime Railo starts up it runs through the Railo/lib/ folder and adds all JAR files to the Class Path, saving you the hassle of adding them manually.

You still have to add the CFX tag using the Administrator though.

BTW : Railo 3 Community Administrator doesnt have a CFX option in the menu anymore (V2.0 had it) but you can call the page directly using:

http://localhost/railo-context/admin/web.cfm?action=resources.cfx_tags

Another thing to note is that only Jar libraries are allowed in Railo. I created a simple CFX tag using Eclipse and compiled it to TestTag.class.

In ColdFusion, I was able to place this in a Java Class Path accessible folder, restart the service and add the CFX tag using the Administrator. Bingo, tag ran when called in my CF template.

No way could I get this to work in Railo. Because the class path is built up from a folder on startup that enumerates JAR files, .class files would not get loaded.

To fix this, I exported the CFX to a JAR of its own in Eclipse and did the steps above.

Hopefully this will help someone in the same bind. I love Railo but the lack of documentation is killing me. Gert is very good responding by email but sometimes you need answers right away!

Once I finish this little project, I'll release the Java CFX on my blog. Its going to be cool ;-)

<hint>HTML Diff Tag</hint>

Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [4] - Leave a comment