Installing BlazeDS into ColdFusion 8

I have been a huge fan of BlazeDS ever since Adobe MAX 2009 where I attended a BYOL session given by Aaron West.  However, I have never had a production use for it.  I have always been looking for a way to use it but nothing ever cam up.  Then recently we wanted to replace the alert system in our system with something more real-time.  This was a perfect opportunity to use BlazeDS.

The only issue we had was our system was still running ColdFusion 8.  BlazeDS was baked into ColdFusion 9.  ColdFusion 8 uses LCDS.  So I did some digging and found a presentation from Aaron on getting BlazeDS working inside ColdFusion 8.  What this basically does is replace LCDS with BlazeDS.  Since I was not using LCDS this would not be an issue.

So, a about a month ago I tackled getting it running on our development server.  The install was a breeze.  Aaron's video walk though was perfect and allowed me to follow right along.  After only a few minutes I was able to get it all running.  I ran into a couple configuration issues but with some assistance from Aaron those were quickly worked out.

Fast forward to now.  Using the same steps from installing BlazeDS on our dev server I went about getting it running in test.  This time I ran into a major issue that kept BlazeDS from running.  ColdFusion was throwing the following error when trying to start up after getting BlazeDS in place.

03/21 08:29:49 user MessageBrokerServlet: init
[BlazeDS]BlazeDS - Community Edition: 3.3.0.17659
[BlazeDS]No login command was found for 'JRun/4.0'. Please ensure that
the login-command tag has the correct server attribute value, or use
'all' to use the login command regardless of the server.
[BlazeDS]Endpoint cf-longpolling-amf created with security: None
at URL: http://{server.name}:{server.port}/{context.root}/flex2gateway/cfamflongpolling
[BlazeDS]Endpoint my-amf created with security: None
at URL: http://{server.name}:{server.port}/{context.root}/messagebroker/amf
**** MessageBrokerServlet failed to initialize due to runtime
exception:   Exception: flex.messaging.MessageException: Cannot create
class of type 'coldfusion.flex.CFEventGatewayAdapter'. Type
'coldfusion.flex.CFEventGatewayAdapter' not found.
       at flex.messaging.util.ClassUtil.createClass(ClassUtil.java:66)
       at flex.messaging.Destination.createAdapter(Destination.java:337)
       at flex.messaging.config.MessagingConfiguration.createAdapter(MessagingConfiguration.java:372)
       at flex.messaging.config.MessagingConfiguration.createDestination(MessagingConfiguration.java:364)
       at flex.messaging.config.MessagingConfiguration.createServices(MessagingConfiguration.java:332)
       at flex.messaging.config.MessagingConfiguration.configureBroker(MessagingConfiguration.java:100)
       at flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:129)
       at coldfusion.flex.ColdFusionMessageBrokerServlet.init(ColdFusionMessageBrokerServlet.java:24)

 

Basically, what this error means is that one of the jars could not be found.  Also, this error didn't prevent ColdFusion from starting.

So, after searching the interwebs I asked Aaron if he had seen this before.  After some back and forth this issue was new to Aaron as well. 

For some reason this server wanted some of the jars to be in a different place then the instructions stated.  This seemed strange since both servers were installed with the same features and both running the same OS (win2003 ent).

Here I spent a while trying to see if maybe the jars were corrupt or there were permissions issues.  None of these worked out.  What ended up working as a based on pure luck and a guess.

What was hanging it up was the placement of 2 jars and where they resided.  The instructions state to put 2 jars from the BlazeDS install here: {CF_install_dir}/wwwroot/WEB-INF/flex/jars.  The jars in question are cfgatewayadapter.jar and concurrent.jar. 

I ended up taking those 2 jars and placeing them here: {CF_install_dir}/lib . 

Once I did that ColdFusion would start without error.  Then ran some sample code I had and BlazeDS was working perfectly. 

I have not been able to determine why this server had to be configured this way.  Nor did I find any documentation supporting this change as they way it should be done.

So there you have it.  I hope that this may help someone if they run into this issue.

Till next time,

--Dave

Creating text image with ColdFusion 8

I thought this would be a trivial task. Create an image based on some text. I wanted the image to be the size of the text. I also wanted the image to be transparent. Sounds straight forward and not very complicated considering I have cfimage at my disposal.

However, in attempting to do this I found it to be rather complicated. The process to figure out the text size and then size the image is not so trivial. Then creating the transparency was another challenge.

Lucky I had done part of this before. I previously created a process to watermark images with cfimage. Thankfully I was able to take that code and re-purpose it for what my new need.

[More]

Inserting XML w/ unicode data

I ran into an issue recently while trying to insert XML data into a MS SQL 200 DB. The XML being inserted contained Cyrillic characters. The DB type was setup as XML and the stored procedure was also setup with the var set as XML so it should store the data without issue. The XML data type can store this type of data without issue according to the MS SQL docs. However, the Cyrillic data in the XML being inserted was shown in the DB as "?????".

So, remembering work I did prior when dealing with this type of data I changed the proc call.

Original call:

view plain print about
1<CFQUERY name="XXXXX" datasource="XXXX">
2    xmlData_INS
3    @item_id = 99999,
4    @user_id = 99999,
5    @xml_data = '#theXML#'
6</CFQUERY>

Updated call (notice the "N" before the data):

view plain print about
1<CFQUERY name="XXXXX" datasource="XXXX">
2    xmlData_INS
3    @item_id = 99999,
4    @user_id = 99999,
5    @xml_data = N'#theXML#'
6</CFQUERY>

In making this change I then started getting a CF error:

view plain print about
1Error Executing Database Query.[Macromedia][SQLServer JDBC Driver][SQLServer]XML parsing: line 1, character 38, unable to switch the encoding

This is where I slammed my head against my desk. I then checked out the encoding of the XML and found something interesting. The XML source was from Adobe Acrobat and was posted in UTF-16 encoding. However, XMLParse() changed the encoding to UTF-8.

While investigating a solution I came across this blog entry from Jared Rypka-Hauers's blog: http://www.web-relevant.com/blogs/cfobjective/index.cfm?mode=entry&entry=05CA3562-BDB9-5320-E197F12577FB92ED which was just about the same issue I was having except there was no db insert.

Using what I learned from Jared's blog entry; I added this piece of code and the XML was then inserted correctly. I also had to keep the "N" in the stored procedure call so that CF passed the data to the database correctly.

view plain print about
1<CFSET theXML = replace(theXML,'UTF-8','UTF-16')>

Hopefully this will be corrected in newer versions of CF

Till next time...

--Dave

Google Analytics breaks CFWINDOW

I recently posted that the CFHOUR() website was broken in IE8. It turned out that the break I saw there was also happening in Chrome and Firefox. I finally tracked down the break to the footer in the site. More specifically Google ad in the footer.

The actual break was only in CFWINDOW. On top of that it was only broken if you loaded a window more than once without refreshing the screen. I put in some code to detect that we were loading in to a CFWINDOW and to bypass the load of the footer.

Just something else to keep an eye out for when using dynamic windows.

Till next time...

--Dave

Insufficient system resources; huh???

While working on a project to integrated Adobe LiveCycle and ColdFusion I ran into an odd issue. I was calling a LiveCycle service that returns a PDF document. That document is then written to the file system and then delivered to the client.

Everything was working fine then I started getting a strange error.

view plain print about
1AxisFault
2 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
3 faultSubcode:
4 faultString: coldfusion.xml.rpc.CFCInvocationException:
5 [coldfusion.tagext.io.FileTag$SingleFileOperationException : An error occurred when performing a file operation write on file \\serverpath\tempMarkup\C1E254134EE109A1D312B01C5A2F7EFA.pdf.][java.io.IOException : Insufficient system resources exist to complete the requested service]
6 faultActor:
7 faultNode:
8 faultDetail:
9 {http://xml.apache.org/axis/}stackTrace:coldfusion.xml.rpc.CFCInvocationException: [coldfusion.tagext.io.FileTag$SingleFileOperationException : An error occurred when performing a file operation write on file \\serverpath\tempMarkup\C1E254134EE109A1D312B01C5A2F7EFA.pdf.][java.io.IOException : Insufficient system resources exist to complete the requested service]
10 at coldfusion.xml.rpc.CFComponentSkeleton.__createCFCInvocationException(CFCo... ''

This error would happen directly after the web service ran at the point where the file would be written. What was actually written was a zero (0) byte file and an error message was displayed. I was sure that the error was not in the web service as the error was after the service ran and returned. But at the same time the error said it was an AxisFault which usually points to web services.

After doing some trial and error, contacting a few people that may have a solution, praying, and doing a quick chant I was able to figure it out. I changed the code to write the file locally then move it to the shared storage. (Notice the UNC path in the error message?).

I have no idea why this threw this error as I was able to move the file from local to remote. I have a feeling it has something to do with Windows and it's ability to write the file to the remote storage.

till next time,

--Dave

CFHOUR() crashes IE 8

Well.. I succumbed to the marketing pressure and installed IE 8. First thing I did was start checking my sites against it.

My blog seems to work just fine. I did not find any apparent issues with it.

I have a couple other sites I have worked on and they were all ok. These were a peppering of CF8 sites that used JQuery, and EXT.

Then I got to the CFHOUR.com site. The site loaded just fine and the layout was correct. The windows for comments and subscribe loaded fine. The site appeared to work as expected.

[More]

Duplicate columns in select query

I ran into this interesting issue this morning. I had this query to return some data.

view plain print about
1<CFQUERY NAME="getData" DATASOURCE="myDSN">
2 SELECT col1, col2, col3, othertable.*
3 FROM firsttable
4 JOIN othertable ON firsttable.id = othertable.id
5 where firsttable.id = #id#
6</CFQUERY>

I added the join to "othertable" table and just returned the other tables full content. I intended to shrink the column return once I figured out what I wanted to use.

For some reason in the return the "col1" column was always empty. I looked into the table's data and there was data there. So, after a bit of poking around I found the issue.

In the "otherTable" there was a column called "col1". This column had no data. For some reason ColdFusion was overwriting the data of the first column with data from the 2nd. I ran the same query outside of CF and the data was returned correctly. Each column still retained is own data.

As a quick test, you can use the code below. The output is very interesting. No matter what you change the data to in the first column it is always overwritten with the data from the 2nd.

view plain print about
1<cfset myQuery = QueryNew("Name, Name")>
2<cfset newRow = QueryAddRow(MyQuery, 2)>
3<cfset temp = QuerySetCell(myQuery, "Name", "Sample Data col 1", 1)>
4<cfset temp = QuerySetCell(myQuery, "Name", "Sample Data col 2", 1)>
5<CFDUMP var="#myQuery#">

Granted, I don't expect anyone to actually do this. You should always name our columns in your query returns and never return "*".

Till next time...

--Dave

ColdFusion PDF support needs work

So,

Lately I have been living in the world of dynamic PDF generation with ColdFusion. It has been a fun project to say the least. I have learned a lot about how to generate PDFs and how not to. So here is a short list of the fun things I have learned during the project.

1: CFPDF does not generate thumbnails with great accuracy. More often than not there is huge discrepancy between the source and the thumbnail. The issues are usually in the area of color correctness. There are also issues with artifacting, and speed.

2: CFDOCUMENT does not like to make a PDF from a source file. This happens when you use the sourcefile attribute. The issue is that CFDOCUMENT does not correctly determine mime type. If you set the mime type it will work. You will also have to do a bunch of tweaking to the params to get the correct out put.

3: CFPDF will break pdf security that was inserted via LiveCycle. Use CFFILE to write the PDF and dont use CFPDF to do it.

4: CFPDF's getinfo action stinks. The info returned is much less than is actually available. Thanks to PDFUtils I was able to get the info I needed from PDF files. CFPDF's function in this area should seriously be increased.

5: activePDF is a better tool to create PDF files than CFPDF. For a bunch of reasons I actually prefer to use the activePDF toolkit to create PDF documents. The downside is that it is not free.

That is all I have so far. I only hope that the next version of ColdFusion has better PDF support.

Till Next time...

--Dave

CFFUNCTION adds space to return

You may have seen this one before but I just saw it for the first time. Probably because I typically don't use CFFUNCTION in this method.

I had the following code:

view plain print about
1<attrib name="#param#" type="#attrType(vals)#">

and the function:

view plain print about
1<CFFUNCTION NAME="attrType" RETURNTYPE="STRING">
2    <CFARGUMENT NAME="vals">    
3    <CFIF len(vals)>
4        <CFRETURN "Enumerated"/>
5    <CFELSE>
6        <CFRETURN "TEXT"/>
7    </CFIF>
8</CFFUNCTION>

The problem was my output was...

view plain print about
1<attrib name="keys" type=" TEXT" />

Notice the extra space before "text". It was breaking what I was trying to do. So, I changed the function to this and the space was gone.

view plain print about
1<CFSCRIPT>
2    function attrType(vals){
3        if lenn(vals)){
4            return 'Enumerated';    
5        } else {
6            return 'Text';
7        }
8    }
9
</CFSCRIPT>

So this got me curious and I started digging. I figured out that if I add the OUTPUT="NO" param to the CFFUNCTION tag the space goes away.

Just something to look out for.

Till next time.

--Dave

Javascript try/catch does not supress ColdFusion error message

While working with some ajax stuff this morning I can across an interesting issue. I have a dynamic form where fields could or could not be defined based on user action. So the function that processed the form was nimble in the fact that it could account for missing fields. Well, it was supposed to be. I kept getting an error message alert that said a field did not exist. I found this strange since the try/catch should have prevented the alert. Here is a strip down of the code I was using:

view plain print about
1<script language="javascript">    
2    try {
3        t = ColdFusion.getElementValue('user_eml');
4    } catch (err){
5        t = '';
6    }
7</script>

Since the form field with an id of "user_eml" did not exist ColdFusion.getElementValue threw an alert that the field did not exist. The try/catch did nothing to suppress the alert. I ended up changing the code to use getElementById and the try/catch worked as expected.

Till next time,

--Dave

More Entries