Posted At : Feb 18, 2010 17:49 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects

ColdFusion is at version 9 already but we still seem to have problems where i would believe all has to be nice for years. I'm talking about CFHTTP tag here.
Yesterday i had to make for a client a script that will
  1. connect to a site
  2. login
  3. move to other internal page from where data should be taken

So what the usual process would be in such a case?
  1. make a CFHTTP request
  2. using the cookies from previous step, if any exists, make the CFHTTP call with login credentials
  3. using the cookies from previous step (here should be present session cookies), make the CFHTTP call to the internal page
  4. do with the data whatever you need
Sometimes step 1 may not be needed.

Everything looks fine so far and in most of the cases works as supposed, but NOT everytime. Sometimes on step 3 instead of going to the internal page it "lose the session" and as result you get there the login page instead. This is exactly what happened for me for this particular client. I have no idea what the problem is but i remember such an issue even back in 2003. I tried all i could think of: passing cookies in CFHTTPPARAMs, puttin the heder with cookies and all in USERAGENT parameter of CFHTTP (yes this one looks a bit weird, but i remember this solving the problem for some sites within last 7-8 years). Nothing helped. Then i tried CFX_HTTP that i was using years ago in such situations and of course everything worked great.

So the question is - WHAT THE HECK ?!
After so many years we still should have such problems with CFHTTP? Weird.

For this particular client it happened there to be a 64-bit system, so instead of CFX_HTTP i had to rewrite the script to use CFX_HTTP5. But this doesn't change the fact that it wasn't possible to be done with CFHTTP itself. Googling for solutions from other's experience didn't help. So i thought - if ColdFusion is Java, why not try a Java solution?
Another half day in googling, trying, testing and i've created a function that not only do a GET HTTP connection, but also works fine for the situation described above. It's far from being universal enough, but it worked well for my situation. So if anyone need it, here is the code:
<cffunction name="makeHTTPRequest" output="yes" returntype="any">
   <cfargument name="requestURL" required="Yes" type="any">
   <cfargument name="requestCookies" required="No" type="any" default="">
   
   <cfset var result = StructNew()>
   <cfset var i = 1>
   <cfset var urlConnection = createObject("java", "java.net.URL").init("#arguments.requestURL#").openConnection()>
   <cfset var inputReader = "">
   <cfset var bufferedReader = "">
   <cfif Len(arguments.requestCookies)>
      <cfset urlConnection.setRequestProperty("Cookie", arguments.requestCookies)>
   </cfif>
   <cfset urlConnection.connect()>
   
   <cfset inputReader = createObject("java", "java.io.InputStreamReader").init(urlConnection.getInputStream())>
   <cfset bufferedReader = createObject("java", "java.io.BufferedReader").init(inputReader)>

   <cfset result.headers = "">
   <cfset result.headerNoCookie = "">
   <cfset result.cookies = "">
   <cfset result.content = "">

   <cfscript>
      do
      {
         headerName = urlConnection.getHeaderFieldKey(i);
         lineCheck = IsDefined("headerName");
         if (lineCheck)
         {
            if (Len(result.headers))
            {
               result.headers = result.headers & "|" & headerName & "=" & urlConnection.getHeaderField(i);
            }
            else
            {
               result.headers = headerName & "=" & urlConnection.getHeaderField(i);
            }
            if (headerName.equals("Set-Cookie"))
            {
               result.cookies = result.cookies & ListGetAt(urlConnection.getHeaderField(i), 1, ";") & "; ";
            }
            else
            {
               if (Len(result.headerNoCookie))
               {
                  result.headerNoCookie = result.headerNoCookie & "|" & headerName & "=" & urlConnection.getHeaderField(i);
               }
               else
               {
                  result.headerNoCookie = headerName & "=" & urlConnection.getHeaderField(i);
               }
            }
         }
         i = i + 1;
      } while(lineCheck);
      
      do
      {
         line = bufferedReader.readLine();
         lineCheck = IsDefined("line");
         if(lineCheck)
         {
            result.content = result.content & line;
         }
      } while(lineCheck);
   </cfscript>
   
   <cfreturn result>
</cffunction>

It takes at input the URL and optionally a string with cookies and returns a structure with 4 keys headers, headerNoCookie, cookies, content

And here is an usage example:
<!--- make first request to firstURL with login credentials --->
<cfset firstCall = makeHTTPRequest(firstURL)>
<!--- make second request to secondURL using the cookiens from the first request --->
<cfset secondCall = makeHTTPRequest(secondURL, firstCall.cookies)>

Hope it will help somebody.

HAPPY CODING !!!

P.S.: If anyone want to comment on it, please do so.

Comments Comments (2) | Print Print | Email Send | 344 Views | 2% / 13% Popularity


Posted At : Feb 01, 2010 18:10 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, cfHSSF, My Projects

After over 2 years, cfHSSF has been updated. It has been done by Steven Durette and he did a really great job!

From his email:
I made a couple more additions and I set it up so that it would degrade gracefully if the version of POI isn't high enough to support the features.
I also made a change to the way values are set in cells. Before a row was created every time a cell value was set. With newer versions of POI if a cell already existed in a row, it was wiped out when another cell in the same row was set. The new method first checks to see if the row exists and uses that. If the row doesn't exist then it creates it.
The ability to put JPEG and PNG images into workbooks was added. This works with the POI included with CF9. If someone tries to use it that doesn't have a new enough version, it takes the cell where the image was to reside and places a message that the POI version doesn't support it.
You can now stream the workbook directly to the browser instead of having to create a file first by using one of the new functions.

Basicaly there has been done the following changes:
  1. Added options for XLSX (Office 2007) files if the POI is the right version.
  2. Added getRow function. This function will get a row or create it if it doesn't already exist.
  3. Added getCell function. This function will get a cell or create it if it doesn't already exist.
  4. Changed multiple functions to use getRow and getCell functions.
  5. Added AddImage function to place an image in the spreadsheet.
  6. Added AddJPGImage function to put a JPEG image in the spreadsheet.
  7. Added AddPNGImage function to put a PNG image in the spreadsheet.
  8. Added createBookVar to allow for streaming workbook to the browser without creating a file.
  9. Updated create region to allow creation of regions in xlsx workbooks.

If anyone interested, you may download it here.

Comments Comments (0) | Print Print | Email Send | 527 Views | 3% / 0% Popularity


Posted At : Jan 26, 2010 17:13 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects, Fun

Right now HERE are not too many tests, but it's a start.
So, have fun!

Comments Comments (0) | Print Print | Email Send | 472 Views | 2% / 0% Popularity


Posted At : Jan 05, 2010 18:12 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects, 1ssBlog

Posts - 56 (29 of them being in december)
Comments - 60 (18 being my answers)
Total views - 118758 (15280 in december)
Unique views - 25415 (2910 in december)

My open source projects downloads: 1939
  • 1ssBlog - 351
  • cfWatcher2.1 - 324
  • cfFirewall - 256
  • cfWatcher1 - 203
  • cfHSSF - 201
  • cfSQLMaster - 138
  • mollom - 115
  • robots - 114
  • defensio - 79
  • yahooSiteExplorer - 75
  • 1ssBlog1Update1 - 43
  • 1ssBlog1Update2 - 40

Top 10 posts by views:

Top 10 posts by unique IP views:


Comments Comments (0) | Print Print | Email Send | 345 Views | 2% / 0% Popularity


Posted At : Dec 24, 2009 18:10 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects

As promised, i updated the Mollom component based on recent recommendations from Dries Buytaert. Anyone that use this component, please upload the updated version. It will change nothing in your work process (except: if you do not pass the IP when checking the content, please do so) so it will be an easy change.
And now on testing results. After doing the updates, i've run that exact 747 spam records through the changed process and here are the results:
Mollom:
  • ham - 5
  • spam - 271
  • unsure - 471

As you may see no more "no answer" there and the number of spam went to 271 from 24, while ham from 49 went to 5. But it still show 471 as unsure. I've been told by Dries taht that's a weirdly high amount of unsure records, but... that's what i have got.

Comments Comments (5) | Print Print | Email Send | 700 Views | 4% / 31% Popularity


Posted At : Dec 22, 2009 16:55 PM | Posted By : Ed Tabara
Related Categories: ColdFusion, My Projects

After a couple emails back and forth with Mollom guys (have to say they was really trying to help finding where the issue may be) it seem like there is an issue in the way my plugin handles the client side load balancing and server list updates. As result it hits an older Mollom server instead of the main one. Also i was told that providing the IP information on each call would increase performance as they "build IP-based reputation models on the server side".

So, i am going to work on this changes and then will try to pass through all past spam records and compare the results.
Stay tuned!

Comments Comments (0) | Print Print | Email Send | 465 Views | 2% / 0% Popularity


Posted At : Dec 21, 2009 18:34 PM | Posted By : Ed Tabara
Related Categories: My Projects

There are almost 11 months from when i started to use Defensio and Mollom side by side on this blog to protect it from spam comments. And here are some results:

Total spam records: 747

Defensio:
  • spam - 740
  • not spam - 7

Mollom:
  • ham - 49
  • spam - 24
  • unsure - 389
  • no answer - 285

Note that i use the free version of Mollom so it does not provide any guarantees on performance and that may be the reason for 285 of the "no answers" from their server.

Still, based on this results i would say that for my particular blog Defensio got to be a MUCH better spam filter.

Did anyone else used any of this 2 or any other solutions and have results to share?

UPDATE: What i REALLY like about Mollom is how willing are they to help. So was when i was creating the plugin and so is now when they contacted me in order to find out what/where the issue may be and to help me to improve the plugin if/where needed or to give advices how better to use returned results. Way to go guys!!!

Comments Comments (3) | Print Print | Email Send | 841 Views | 4% / 19% Popularity