Entries Tagged as “Adobe ColdFusion”

ColdFusion 11 Update 6 and ColdFusion 10 Update 17 now available

August 27, 2015 / Piyush Kumar Nayak

  Security | Adobe ColdFusion | Adobe ColdFusion 10 | Adobe ColdFusion 11 | ColdFusion | ColdFusion 11

The following ColdFusion updates are now available for download. These updates address a common XXE vulnerability in BlazeDS. For details refer the security bulletin hyperlinks in the sections below.

Users who are using LCDS with ColdFusion, should refer this technote, for updating their LCDS installation.

ColdFusion 11 Update 6

This Update addresses a vulnerability mentioned in the security bulletin APSB15-21. This update is cumulative and includes fixes from previous ColdFusion 11 updates.

For details, refer this technote.

ColdFusion 10 Update 17

This Update addresses a vulnerability mentioned in the security bulletin APSB15-21. This update is cumulative and includes fixes from previous ColdFusion 10 updates. 

For details, refer this technote.


Machine Learning in ColdFusion

August 25, 2015 / Avinash Bukkittu

  Adobe ColdFusion | General

Machine learning has been a buzz word in recent times. I often hear people talking about this and their profound interest to learn more and gain expertise in this field. As a consequence, many programming languages are now having machine learning libraries available in their toolbox. For example, Java has ML libraries like WEKA, C++ has Encog (Encog is available for Java as well), PyBrain for Python etc.  These libraries come in handy and obviates the need to write basic algorithms from scratch. One such tool is WEKA (http://www.cs.waikato.ac.nz/ml/weka/)-  A data mining software in Java. You can use it as a standalone application or use it's APIs in your own Java program.

 

In this article, I will show you how to use WEKA library in ColdFusion. I am going to write a very simple Java program and add wrappers to it in ColdFusion. These wrappers can then be called from ColdFusion pages. In short, I am making the WEKA library available to ColdFusion. 

 

I will be using weather dataset located at data/weather.numeric.arff  in downloaded weka package. Weka uses ARFF format for datasets. Below is the dataset

@relation weather

@attribute outlook {sunny, overcast, rainy}
@attribute temperature numeric
@attribute humidity numeric
@attribute windy {TRUE, FALSE}
@attribute play {yes, no}

@data
sunny,85,85,FALSE,no
sunny,80,90,TRUE,no
overcast,83,86,FALSE,yes
rainy,70,96,FALSE,yes
rainy,68,80,FALSE,yes
rainy,65,70,TRUE,no
overcast,64,65,TRUE,yes
sunny,72,95,FALSE,no
sunny,69,70,FALSE,yes
rainy,75,80,FALSE,yes
sunny,75,70,TRUE,yes
overcast,72,90,TRUE,yes
overcast,81,75,FALSE,yes
rainy,71,91,TRUE,no


The above dataset contains five attributes namely outlook , temperature, humidity, windy & play. outlook is a categorical variable(it can take only three values - sunny,overcast, rainy) temperature and humidity are numeric variables, windy is again a categorical variable(it can take two values - TRUE, FALSE) and play is a categorical variable(it can take two values - yes,no). play is the class variable in our problem which means we have to predict the value of this variable for given test datapoint which contains remaining four values. 

 

So the problem at hand is a classification problem. We are given a training dataset which can be used to train a classifier and then use this model to predict the label for a test datapoint. There are many classifiers which can be used to solve this problem. But I am going to use naïve Bayes to solve this problem. It's a very simple classifier based on probability and it assumes that features are independent of one another. This means that the value outlook takes is independent of the values other attributes take.  I will not explain the mathematical background of naïve Bayes but rather provide an implementation for it. To understand the theory behind naïve Bayes, check this link.

 

Here is the Java program

 

import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.trees.J48;
import weka.core.Attribute;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.SparseInstance;
import java.util.*;


public class Demo {

	public static Classifier naiveBayesClassifierTrainedWithCV(Instances data, int numFolds) throws Exception
	{
		Classifier cls = new NaiveBayes();
		Evaluation eval = new Evaluation(data);
		
		if(data.classAttribute().isNominal())
			data.stratify(numFolds);
		
		for(int i=0;i outlookValues = new ArrayList();
		outlookValues.add("sunny");
		outlookValues.add("overcast");
		outlookValues.add("rainy");
		Attribute outlook = new Attribute("outlook", outlookValues); 
		
		//Create numeric attribute
		Attribute temperature = new Attribute("temperature");
		Attribute humidity = new Attribute("humidity");
		
		List windyValues = new ArrayList();
		windyValues.add("TRUE");
		windyValues.add("FALSE");
		
		Attribute windy = new Attribute("windy",windyValues); 
		
		
		Instance testSample = new SparseInstance(5);
		
		testSample.setDataset(data);
		testSample.setValue(outlook, outlookValue);
		testSample.setValue(temperature, temp);
		testSample.setValue(humidity, hum);
		testSample.setValue(windy, wind);
		
		return testSample;
	}
	
	public static double[] getDistributionInstanceForATestSample(Classifier cls, Instance data) throws Exception	{
		
		return cls.distributionForInstance(data);
	}
}


Download weka.jar from http://www.cs.waikato.ac.nz/ml/weka/downloading.html. Add this jar to the classpath and compile the above program.

 

In the above program, naiveBayesClassifierTrainedWithCV is used to train a naïve Bayes classifier with the dataset that is passed as an argument. The second argument numFolds is used to mentioned the number of folds for cross-validation. For e.g., 10-fold cross-validation requires numFolds = 10. generateTestSample is used to generate a test sample for which a class label will be predicted by the classifier. getDistributionInstanceForATestSample is used to get the probability distribution for a test sample predicted by the classifier.

 

Following is a wrapper for these methods in ColdFusion. I have created a CFC for the same

component output=false
{
	property name="demo";
	property name="bufferedReference";
	property name="fileReference";
	property name="fileObj";
	property name="bufferedObj";
	property name="instanceReference";
	property name="instanceObj";
	property name="model";
	
	//This function loads ARFF file
	function Init()
	{
		demo = CreateObject("java","Demo");
		
		//Create a buffered reference
		bufferedReference = CreateObject("java","java.io.BufferedReader");
		
		//Create a file reference
		fileReference = CreateObject("java","java.io.FileReader");
		
		//Create a file object
		fileObj = fileReference.init("C:/ColdFusion11/cfusion/wwwroot/weka/weather.numeric.arff");
		
		//Create a buffered reader object
		bufferedObj = bufferedReference.init(fileObj);
			
		instanceReference = CreateObject("java","weka.core.Instances");
		instanceObj = instanceReference.init(bufferedObj);
		
		instanceObj.setClassIndex(instanceObj.numAttributes() - 1);
	
	}
	
	function naiveBayesClassifierTrainedWithCV()	{
		
		model = demo.naiveBayesClassifierTrainedWithCV(instanceObj,10);
		return model;
	}
	
	function  getDistributionInstanceForATestSample(required string outlook, required numeric temp, required numeric humidity, required string windy)	{
		
		sample = demo.generateTestSample(JavaCast("string",outlook),JavaCast("int",temp),JavaCast("int",humidity),JavaCast("string",windy),instanceObj);
		distribution = demo.getDistributionInstanceForATestSample(model,sample);
		return distribution;
	}
}

Above file is named as MachineLearning.cfc. Init() method is used to load the ARFF file. Rest of the methods are just wrappers around the corresponding Java methods. This CFC is used as follows

<cfset mlObj = CreateObject("MachineLearning")>
<cfset mlObj.Init()>
<cfset NB = mlObj.naiveBayesClassifierTrainedWithCV()>
<cfset distributionForTestSample = mlObj.getDistributionInstanceForATestSample("sunny",80,95,"TRUE")>
<cfsavecontent variable="html">
	<cfoutput>
		<html>
			<head>
				<title>WEKA Demo</title>
			</head>
			<body>
				<h3>Naive Bayes</h3>
				<p><pre>#NB#</pre></p>
				<hr />
				<h3>Classifying a sample</h3>
				<h4>t = (Outlook = "sunny", Temperature = 76, Humidity = 95, Windy = "TRUE")</h4>
				<p>
					Yes = #distributionForTestSample[1]#, No = #distributionForTestSample[2]#
				</p>
			</body>
		</html>
	</cfoutput>
</cfsavecontent>
<cfoutput>#html#</cfoutput>

MachineLearning object is created and naïve Bayes classifier is called on that object. Once the model is trained, a test sample is created and we want to know what is the label that is predicted by the classifier. Instead of getting the label, probability distribution of the test sample over the class labels is calculated i.e. probability of test sample being yes and probability of the sample being no. This is achieved by calling getDistributionInstanceForATestSample method. Below is the output that we get

As you can see, for test sample("sunny",76,95,"TRUE") the classifier predicts with 60% probability that play=yes and with 40% that play=no.

 

So this was a simple example on how to use Weka in ColdFusion. Perhaps, this idea can extended and a ML library for ColdFusion can be created.


Changes in Filter Methods

August 14, 2015 / Nikhil Siddhartha

  Adobe ColdFusion | Adobe ColdFusion 11

There has been a recent change in the way callback functions of the various filter functions work. Earlier, the callback functions used to take only one element at a time. Following were the syntaxes for the 3 most commonly used filter functions.

ArrayFilter - arrayFilter(array,function(arrayElement){return true|false;});
ListFilter - listFilter(list,function(listElement){return true|false;});
StructFilter - structFilter(struct,function(key, value){return true|false;});

 

As we can see, for all of these filters, the callback function has access to only one item at a time. Effectively this means that, all the filters that can be applied have to be independent of all the other elements of the array/list/struct. This was done keeping in mind that, for filtering an array/list/struct, we can access the structure element by element and apply the common test on each of them and thereby return true/false depending on the passing/failure of the element in the conditions written in the callback function.

 

 But, this limits the functionality of the filter function to a great extent. There can be a lot of real life scenarios, where the filtering of one element has clear dependency on one or more of the other elements of the array/list/struct. For example, suppose we want to filter out all the elements of a list that are greater than the first element. Previously, this was not possible.

 

Thus, we brought a change in the design of the filter functions. Now, the callback functions of all the three filters have access to the entire array/list/struct apart from the current element. This enhances the power of filters to a great extent. Much more sophisticated filters can be written for each of them especially for the cases which have dependency on other element(s) apart from the current element. For example, we can now easily write filters such as: Filter out all the elements of the list which are greater than the next element.

 

The updated syntaxes of filters are:

ArrayFilter - arrayFilter(array,function(arrayElement, [,index, array]){return true|false;});
ListFilter - listFilter(list,function(listElement, [,index, list, delimiter, includeEmptyFields]){return true|false;});
StructFilter - structFilter(struct,function(key, value, [, struct]){return true|false;});

Edit: This change has gone out in ColdFusion11-Update5. Thanks to @Charlie and @Adam for bringing it up.


getHeaders - a new attribute in the cfexchangemail tag

August 14, 2015 / Piyush Kumar Nayak

  Adobe ColdFusion | Adobe ColdFusion 11 | ColdFusion | ColdFusion 11 | exchange | General

With ColdFusion 11 Update 3, we have introduced a new parameter called "getHeaders", in the "cfExchangeMail" tag. It accepts a boolean value. When set to true, cfExchangeMail returns a query with an additional "InternetHeader" column. This column contains a struct containing key-value pairs of the email-headers associated with each message.

Email message headers provide technical details about the message, such as who sent it, the software used to compose it, the version of the MIME protocol used by the sender etc. 

On Exchange 2010, the fields that are returned are: CC, Content-Transfer-Encoding, Content-Type, Date, From, MIME-Version, Message-ID, Received, Return-Path, Subject, To, X-MS-Exchange-Organization-AuthAs, X-MS-Exchange-Organization-AuthSource, X-Mailer.

You may reference this weblink for the detailed list of the fields and their description.

You can put this new feature to any good use that suites your purpose. I will dwell on one such use case below.

In MS Exchange 2010 and later, the "ToId" column in the retrieved messages query contains the primary email address of the sender. A primary email address can have multiple aliases. If you need to retrieve the email-alias the message was sent to, you can make use of this new attribute.

Here's an example that demonstrates the usage the tag in the context of the use case discussed above:

<cfmail from="#frm_usr_email#" to="#to_usr_alias#" cc="#cc_usr_alias#" subject="#msg_sub#"  server= "#exchangeServerIP#" port = "25">

----------- testing mail to an alias address ------------

</cfmail>

<cfset sleep(5000)>

<cfexchangeConnection action="open" username ="#to_usr#" password="#password#" server="#exchangeServerIP#" serverversion="#version#" protocol="#protocol#" connection="excon">

<cfexchangemail action="get" name="usr_msgs" connection="excon" getheaders=true folder="Inbox">

<cfexchangefilter name="fromID" value='#frm_usr#'>

<cfexchangefilter name="subject" value="#msg_sub#">

</cfexchangemail>

<cfif usr_msgs.recordcount GTE 1>

info from cfexchangemail fields:<br>

<cfloop query="usr_msgs">

<cfoutput>

#usr_msgs.subject#<br> 

#usr_msgs.CC#<br> 

#usr_msgs.fromId#<br>

</cfoutput>

</cfloop>

info from cfexchangemail.internetHeaders fields:<br>

<cfloop query="usr_msgs">

<cfoutput>

#ReplaceList(usr_msgs.internetHeaders["from"][1], ">,<", ",", ",", ",")#<br>

#ReplaceList(usr_msgs.internetHeaders["to"][1], ">,<", ",", ",", ",")#<br>

#ReplaceList(usr_msgs.internetHeaders["cc"][1], ">,<", ",", ",", ",")#<br>

</cfoutput>

</cfloop>

</cfif>

 

You can reference the bugbase, for the enhancement request originally logged for this feature.



AppAdmin - A small ColdFusion app to manage your Application.cfc

August 11, 2015 / Sandeep Paliwal

  Adobe ColdFusion | Adobe ColdFusion 10 | Adobe ColdFusion 11

AppAdmin is a simple app to manage your application settings. It lists all the Application level settings available, there current values, and whether the values have been explicitly set by user or not in Application.cfc.

It also supports editing these settings from the UI and the same are updated in actual Application.cfc. It also keeps a backup of Application.cfc when updating so the same can be used to revert back in case of any issues.

It supports both tag and script based CFML code, but there can be a few hidden issues J so do watch out for them.

The app is available on github. To install it you only need to copy to folder (say “appadmin”) inside your ColdFusion Application parallel to where the Application.cfc resides. Once copied just launch in using <your application url>/appadmin.

Here is a screenshot of app admin when delpoyed.

 

 

PS: make sure to keep your app admin URL behind authentication and not make it publically accessible.

 


Blue Mango Theme Design By Mark Aplet

Super Powered by Mango Blog