Entries for month: April 2009

ColdBox Training At Cf.Objective Register Now

Conferences , Training No Comments »

This is a reminder that we will be holding a CBOX-100 Training session at CF.Objective this year.  This 1 day course is an intense 8 hours of ColdBox.  You will get to understand the ColdBox Platform and get some amazing training materials to help you get started in your ColdBox Development.  So if you have not registered for CF.Objective yet, then please follow this link to register and also register for the ColdBox class.


If you have already registered and want to sign up for the ColdBox training, then please contact Cathy at cathy@bestmeetings.com

SES Routing Hidden Gem: Route Variables

Interceptors , Tips & Tricks 1 Comment »

When using ColdBox's SES routing mechanisms you will come to a point where you would like to create variables depending on when a specific route matches or not.  You can do so very easily by using the argument called matchVariables, which is a simple string of name-value pairs you want to create in the request collection (This was added in version 2.6.3).  However, a hidden feature that we just documented that has been enabled since version 2.6.0, is that you can also pass named arguments to the addCourse() method and have them created on the request collection when the route matches.  This makes it much much easier to create simple or complex variables than a simple string of name-value pairs.

Example using matchVariables:

<cfset addRoute(pattern="space/:space",handler="page",action="show",matchVariables="spaceUsed=true,foundAt=#now()#")> That route will create the spaceUsed,foundAt variables in the request collection when the route matches. However, let's see how easy it is to do it using by convention name-value pairs in the method. <cfset addRoute(pattern="page/:page",handler="page",action="show",foundAt=now(),internalNamespace="_internal",hashMap=structnew())> I just added the foundAt,internalNamespace, and HashMap variables just by adding them as virtual arguments. It gets even better if you are running Railo because you can use implicit Array/Structure notation to create very complex variables. Again, this is now a documented feature in the wiki, so enjoy.

ColdBox Presents: Groovy Integration

Plugins , Releases 3 Comments »
We are releasing a 1.0 version of our GroovyLoader plugin for ColdBox Applications today.  This plugin can be found in the extra downloads section of the ColdBox Website as part of the projects pack.  So what did we do, well, based on Barney Boisvert's inspiration on CFGroovy, we decided to create a plugin that would leverage ColdBox users with the Groovy Scripting Language.  We took some different approaches to the integration and we still have many things planned for it.  But as of now, these are the features that our GroovyLoader exhibits
  • Drop and Play functionality on ANY ColdBox application running on Railo 3.0 >, Adobe CF 8 >, or Open BD
  • Load a groovy environment (1.6.0) into any ColdBox application without modifying the running CF engine.  It uses our integrated JavaLoader to load all necessary libraries without modifying the CF engine.  It can also, load up ANY library you place in the GroovyLoader's lib directory automatically.  So if you kids start fooling around with packaged groovy libraries or java libraries like Hibernate, Spring, Gorm, etc. You can do so, by just dropping the files in that pre-configured folder.
  • Setup of a directory that will hold groovy classes/scripts, that the GroovyLoader will try to load at runtime. Uses the configureClassPath() method of the plugin and usually called once.
  • Integration with the ColdBox cache to provide resolution of parsed groovy-to-java classes for all parsed groovy source, including custom groovy source compilations
  • Ability to clean the parsed class cache from the ColdBox cache
  • Ability to clean the groovy classloader cache of parsed bits
  • Ability to handle complex groovy/java relationships and hierarchies
  • Easily extend/decorate the plugin to meet your needs or enhance it
  • Create groovy classes: create(clazz)
  • Execute groovy scripts: runScript(scriptName,varCollection)
  • Execute groovy source code: runSource(scriptSource,varCollection)
  • Execute groovy source code using a custom tag import
  • Groovy scripts and source code executions will be binded with the following variables. This means that the groovy scripts that are executed using runScript() and runSource() will have the following variables IMPLICITLY created at runtime. This creates a data bridge between ColdFusion and Groovy.
    • A custom passed structure called varCollection. This can have anything you like.
    • The coldbox request collection: coldbox_rc
    • The following coldfusion variables:
      • cf_pagecontext : The coldfusion pagecontext object
      • cf_application : The coldfusion application scope
      • cf_server : The coldfusion server scope
      • cf_session : The coldfusion session scope (if available)
So how does it work. Well, first of all, the download includes a very simple application that you can replicate and learn from.  As our integration progresses we will be adding more functionality and some extra surprises our very own Sana Ullah has been working on for quite a while now. Step1: Install the custom plugin in your application or as a core plugin, basically drop the GroovyLoader folder in your plugins directory of your app Step 2: Init the plugin on application start, usually the application start handler: <cffunction name="onAppInit" access="public" returntype="void" output="false">
   <cfargument name="Event" type="any">
   
   <!--- Init the Groovy Loader with my model/groovy folder --->
   <cfset getMyPlugin("GroovyLoader.GroovyLoader").configureClassPath(getSetting("ApplicationPath") & "model/groovy")>
   
</cffunction>
Step 3: That's it, you can now use it a la carte to create groovy classes, run scripts, or run on deman source code via the method or the imported tag. You can see some sample handler methods below: <cfcomponent name="groovy" extends="coldbox.system.eventhandler" output="false" autowire="true">
   
   <!--- Dependencies --->
   <cfproperty name="GroovyLoader" type="coldbox:myplugin:GroovyLoader.GroovyLoader" scope="instance">

   <!--- Import GScript --->
   <cfimport prefix="groovy" taglib="../plugins/GroovyLoader/tags" />

   <cffunction name="index" access="public" returntype="void" output="false">
      <cfargument name="Event" type="any">
      <cfscript>
         var rc = event.getCollection();
         rc.oHello = instance.GroovyLoader.create("Hello");
         
         event.setView("home");
      </cfscript>
   </cffunction>
   
   <cffunction name="clearcache" access="public" returntype="void" output="false" hint="">
      <cfargument name="Event" type="any" required="yes">
      <cfscript>   
         var rc = event.getCollection();         
         
         instance.GroovyLoader.clearClazzCache();
         
         setNextEvent('groovy');
      </cfscript>
   </cffunction>

   <!--- runscript --->
   <cffunction name="runscript" access="public" returntype="void" output="false" hint="">
      <cfargument name="Event" type="any" required="yes">
      <cfset var rc = event.getCollection()>
      <cfscript>   
         rc.varCollection = {createdAt=now()};

         instance.GroovyLoader.runScript('Test',rc.varCollection);
         
         event.setView("runscript");
      </cfscript>
   </cffunction>
   
   <!--- runscript --->
   <cffunction name="runsource" access="public" returntype="void" output="false" hint="">
      <cfargument name="Event" type="any" required="yes">
      <cfscript>   
         var rc = event.getCollection();
         /* Source */
         var source = "varCollection.GroovyArray = [1,2,3,4]";
         
         rc.varCollection = {createdAt=now()};
         
         instance.GroovyLoader.runSource(source,rc.varCollection);
         
         event.setView("runSource");
      </cfscript>
   </cffunction>
   
   <!--- runTagSource --->
   <cffunction name="runTagSource" access="public" returntype="void" output="false" hint="">
      <cfargument name="Event" type="any" required="yes">
      <cfset var rc = event.getCollection()>
      
      <!--- Place Date --->
      <cfset rc.today = now()>
      
      <!--- Groovy Script --->
      <groovy:script>
      <cfoutput>
         def today = coldbox_rc["today"]
         def SubjectLine = ["Hello","my","name","is","Luis Majano.","Expressed at",today]
         //Place in ColdBox event context
         coldbox_rc["SubjectLine"] = SubjectLine.join("_")
      </cfoutput>
      </groovy:script>
      
      <cfset event.setView("runTagSource")>
   </cffunction>
   
</cfcomponent>
I hope you enjoy this plugin and you help make it even better and better.

ColdBox Presentation Recordings at OCDEV

Presentations , Community 1 Comment »

I had the pleasure of getting to speak at the Orange County User Group last night and it was a great night.  We had a full night of ColdBox and even some incredible Ping Pong tournament.  Thanks guys for inviting me over.  You can find the recordings for the presentations below.  You will be surprised to see some of the new ColdBox projects, especially our new ColdBox Lookup Manager that has been silently released.  Expect more on it soon.

 * Part 1: http://experts.na3.acrobat.com/p11367888/
 * Part 2: http://experts.na3.acrobat.com/p99167668/

Pictures

 

ColdBox and URL Rewrites with IIS 7

Tips & Tricks , Tutorials No Comments »

This is a post to help people know that there is a free URL rewrite for IIS7 that microsoft has built and it is pretty darn snazzy. You can get the download from here: http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1691.

The documentation for the rewrite tool is here: http://learn.iis.net/page.aspx/460/using-url-rewrite-module/

A nice video of how to configure the tool is here: http://learn.iis.net/page.aspx/506/url-rewrite-module---video-walkthrough/

After downloading and installing, you need to configure the rewrite for a specific website you have created.  You can do that by using the included web.config in the SESRewriteRules folder of the installation directory of the ColdBox download.  Below is the contents of the file that you can use to import right in to enable Full SES rewriting within IIS7 and any servlet container. As always when using code from somebody else, please try it out first. So try out the following rules and tweak as desired. <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.cfm" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="SQL Injection - EXEC" stopProcessing="true">
<match url="^.*EXEC\(@.*$" />
<action type="CustomResponse" url="/includes/templates/404.html" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="SQL Injection - CAST" stopProcessing="true">
<match url="^.*CAST\(.*$" />
<action type="CustomResponse" url="/includes/templates/404.html" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="SQL Injection - DECLARE" stopProcessing="true">
<match url="^.*DECLARE.*$" />
<action type="CustomResponse" url="/includes/templates/404.html" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="SQL Injection - DECLARE%20" stopProcessing="true">
<match url="^.*DECLARE%20.*$" />
<action type="CustomResponse" url="/includes/templates/404.html" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="SQL Injection - NVARCHAR" stopProcessing="true">
<match url="^.*NVARCHAR.*$" />
<action type="CustomResponse" url="/includes/templates/404.html" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="SQL Injection - sp_password" stopProcessing="true">
<match url="^.*sp_password.*$" />
<action type="CustomResponse" url="/includes/templates/404.html" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="SQL Injection - xp" stopProcessing="true">
<match url="^.*%20xp_.*$" />
<action type="CustomResponse" url="/includes/templates/404.html" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
            <rule name="Application Adminsitration" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{SCRIPT_NAME}" pattern="^/(.*(CFIDE|cfide|CFFormGateway|jrunscripts|railo-context|fckeditor)).*$" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Flash and Flex Communication" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{SCRIPT_NAME}" pattern="^/(.*(flashservices|flex2gateway|flex-remoting)).*$" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.cfm/{PATH_INFO}" appendQueryString="true" />
</rule>
<rule name="Static Files" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{SCRIPT_NAME}" pattern="\.(bmp|gif|jpe?g|png|css|js|txt|pdf|doc|xls|xml)$" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<rule name="Insert index.cfm" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.cfm/{PATH_INFO}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>