Sunday, March 19, 2017

Configuring Lucee to take over http error handling instead of IIS

By default, Lucee seems to be configured with it's http://boncode.net/connector/webdocs/Tomcat_Connector.htm configured to hand-off all non-200 response codes to IIS to display using whatever setting you've enabled in web.config

Which is great... except, you need detailed errors enabled for your site in order for Lucee to render its own error messages... which means any request for a static file, like a missing image ( or static non cfc /cfm ) will get handled directly by IIS... and show DETAILED errors... no good!

Just read in the Lucee forum the following from @bilal: https://groups.google.com/forum/#!searchin/lucee/error$20messages$20iis$20%7Csort:relevance/lucee/nSahG_wXzPk/Ck545qZbCwAJ

Step 0) Throw a 500 in Lucee. IIS will take over with a bland 500 error stripe message. Poop!

Step 1) Skip IIS Custom Errors

In C:\Windows\BonCodeAJP13.settings file, add 'SkipIISCustomErrors' ( See Tomcat Connector Docs for details )


<SkipIISCustomErrors>True</SkipIISCustomErrors>

This will let you control status codes other than 200 with custom messages from Lucee. IIS will still be able to use the standard 404-custom error page for non-cfm related error handling, e.g. when a non-existing image file is requested etc.

Step 2) Set IIS errors to return "Custom Error Pages"

Step 3) Throw a 500 in Lucee. You should see your error ( And you should render it properly for security )

Tuesday, August 18, 2015

Sql server full text search performance slow with additional conditions or clauses

We had a performance problem with SQL Server (2012 Web). When we have additional where conditions to our full-text Contains search it becomes over 1000x slower, the execution plan changes to a nested loop around the full-text search, and "Actual Rebinds" on the "Table Valued function [FulltextMatch]" went from 1 to 3628.

We noticed that it only happens when full-text searching newly uploaded data; and furthermore, when the full-text search had an additional where clause selecting only the batch of newly inserted records.


Diag 1. Notice the "Table Valued function [FulltextMatch]" is inside a nested loop, with 3628 rebinds. This isn't going to end well.





Our first thought: The full text index hasn't done an incremental update; so we did a Full repopulate index... No Change in performance.

Then I finally found an article that seemed relevant: "First: Make sure that your statistics for the table's index are up to date."

So, I looked up how to do it: 

https://msdn.microsoft.com/en-us/library/ms187348.aspx
https://msdn.microsoft.com/en-CA/library/ms174384.aspx

Steps:
#1) Check when the tables index statistics were last updated on one of the table's indexes:

DBCC SHOW_STATISTICS ( "Table_Name_Here", PK_Table_Name_Here_Index) ;

And found that the date the stats were last updated was before  we had inserted our new 3000 record set into the table. ( The index stats showed there was about ~3000 fewer rows than "actual" )

#2) We updated the index stats manually via:

UPDATE STATISTICS Table_Name_Here

And now, our full-text queries are all lightning fast, regardless of any added where clause and in the execution plan, our "Actual Rebinds" on the "Table Valued function [FulltextMatch]" went back to 1.


Diag 2.  "Table Valued function [FulltextMatch]" now with a rebind count of 1 ( Its not inside a nested loop any more )





And now, to answer the underlying question: 
Why weren't the tables index stats recalculated after the new data was entered? We're assuming at this point that it wasn't a sufficiently large insert to trigger the stats recalculation ( we inserted around 3% new rows ).

Perhaps in this case, the table just needs to have its stats recalculated manually since its a relatively small insert, but has a really high impact on full text search speed when not completed.


Monday, January 13, 2014

How to specify a single subdomain for a non-wildcard SSL certificate

Thanks:

http://blog.goodcoresoft.com/host-name-ssl-bindings-iis7/

Although not very well documented, IIS does support multiple host headers for SSL bindings. Following are the steps to configure it.
  1. Install the SSL certificate on IIS (http://www.sslshopper.com/article-installing-an-ssl-certificate-in-windows-server-2008-iis-7.0.html)
  2. From the start menu select “Run”.
  3. Type “MMC” and hit enter; this will launch the Microsoft Management Console.
  4. Select File –> Add / Remove Snap-in.
  5. Select Certificates from the “Available snap-ins” list and hit the add button.
  6. Select the “Computer Account” option when asked which certificates the snap-in will manage.
  7. Click “OK”
  8. Look in the appropriate folder the certificate was originally installed in, if the certificate is self signed it can be found under “Personal”.
  9. Right click on the certificate name and select properties.
  10. Change the friendly name such that it starts with *

And voila, now you can specify a host name in the bindings box, specifically for the single sub-domain your certificate is actually valid for

Friday, August 30, 2013

Make your own seamless background in Photoshop

All this time, I thought this was graphic designer dark-magic, and it turns out its mostly knowing how to use photoshop!

- Create a pattern in photoshop,
- Go to Filter -> Offset -> Set both sliders to 1/2 of your image size
- Use the Clone tool to fix the seam down the middle if it exists
- Voila!!

Totally thanks to: http://designshack.net/articles/css/create-seamless-web-background-textures-in-minutes/

Tuesday, June 18, 2013

CFWheels: SQL Counting rows with specific values

In SQL, you can count up rows that have a certain criteria, which means in one query you can count up multiple kinds of things:

select
   SUM(CASE WHEN dateResolved IS NULL THEN 1 ELSE 0 END) as itemsOutstanding,
   SUM(CASE WHEN dateResolved IS NOT NULL THEN 1 ELSE 0 END) as itemsResolved,
   COUNT(*) as total
from tableName
group by Year(InspectionDate) AS inspectedYear, Month(inspectionDate) AS inspectedMonth

Monday, May 27, 2013

Update the JRE on Railo

Railo's Excellent guide link is below, but for my reference; to summarize


1) Download the most current JRE (Which at the time of this blog post was Java SE 7u21)

http://www.oracle.com/technetwork/java/javase/downloads/index.html

2) Install it to an easy to remember folder, such as C:\jre\

3) Stop the Tomcat Railo service ( while it is not busy )

4) Rename Railo's JDK folder:  railo/jdk   --> railo/jdk_old   ( In my case, C:\railo\jdk )

5) Make a new railo/jdk folder

5) Copy the contents of C:\jre  from step 2 into the railo/jdk folder

6) Restart Tomcat Railo & Test your world. You can display the jre version in coldfusion via:

<cfoutput>#CreateObject("java", "java.lang.System").getProperty("java.version")#</cfoutput>



7) Recycle railo/jdk_old

https://github.com/getrailo/railo/wiki/Installation%3AInstallerDocumentation%3AMSUpgradingJRE

Thursday, April 18, 2013

Railo SQL, Amazon Cloud and Time Zones

We've been working today with localizing time stamps, where a web server, a database server, and the client using the application are all in different time zones respectively.

Setup:

  1. Select the time zone in Railo Admin to match the time zone of your server's OS.  Server Administrator tab -> Regional -> Time Zone pull down
  2. Configure your data source's time zone. Datasource -> [ Pencil beside data source ] -> Time Zone.  ( For Amazon Web Services, all RDS instances are UTC )
  3. In our case, we're specifying in the users account what time zone they are in, so we can use the underlying java.util.TimeZone

The test:

Doing a sql insert of railo's "#now()#" timestamp, and reading it again from the database should be the same value, as well, the now() timestamp should be the same in the database as returned from your browser when output. ( They should all be in sync.. and do their dark magic across time zones properly and seamlessly )
 

From Michael Offner See the Railo blog post here

"If Railo has set the the Timezone CST and the DB Server is running in PST you run into problems for a very simple reason. the Timestamp produced ({ts '2012-07-25 16:20:14'}) is based on the CST Timezone, this means it is "2012-07-25 16:20:14 CST", BUT the TimeZone information is not present in the timestamp.
so if the DB server is reading the string timestamp from the SQL String, it has no timezone information and the DB Server simply takes it own timezone for the timestamp, because it has no idea from whitch timezone the request is coming from, this means the db server interpret the timestamp as "2012-07-25 16:20:14 PST" what is 2 hours later.
then when you get this date back you get "2012-07-25 18:20:14 CST" what is exactly the same as "2012-07-25 16:20:14 PST", this means the failure happens when you send the string timestamp to the db server in a different timezone without the timezone information. this conversion problem does not happen when you get the date back via a select statement, simply because in this case the date is send in a timezone independent format."


Notes: 


Tuesday, April 9, 2013

It's like SQL Import Export wizard... only it actually WORKS

Getting data into Amazon RDS http://aws.amazon.com/rds/
 
This tool does ALL the work for you: http://sqlazuremw.codeplex.com/ 
 
Its a GUI wrapper for the BCP utility. It will generate all objects, store the objects and the data as local files, then it will import everything to your target RDS server in the correct order (always a pain to do manually with PK's / FK's). It's designed with Azure in mind, but allows selection of SQL Server and it works!



Tuesday, March 26, 2013

How can you put uncommitted changes to a branch TEST when I am at the branch master

Every once in a while, I start changing code before switching to a new branch... then.... nuts!

I need to move these uncommitted changes to a new branch, or ... throw them away and start again.

Two Options:
 
1) You can just checkout to the new branch and then commit. You don't lose your uncommitted changes when moving to another branch.


git checkout -b new-branch-name
git add . 


2) Use Git Stash as a copy & paste:
 
git stash
git checkout other-branch-name
git stash apply


Thanks to Here

Monday, March 11, 2013

Git Production Server Updating

A quick note,

If you want to update a production server's versioned files, and discard local changes (which there shouldn't be any... right?)

discard local changes, and replace them with the most recent commit that exists on the github server (origin) on branch production:

> git reset --hard origin/production

Thanks for help on this from: Here

Thursday, February 21, 2013

Coldfusion Web Application Saving to DropBox

Every now and again, I'm working on a project that renders something that an administrative user needs to take with them; be it a pdf, or a csv representation of a report. Either way, once it is completed, I used to use coldfusion's cfcontent tag to dump the stream to the browser....which I've always thought of as pulling a fast-one on the browser, tricking it into thinking it is a physical file on disk to be downloaded, and Bob's your uncle.

This works, but let's be honest, cfcontent seems a bit of a sketchy way of delivering a file.... but it works... unless you're on shared hosting, in which case it's disabled... or will be, or should be, or will-be-until-you're-in-production.

I started out looking through the API for Dropbox, to try and figure out how to get a web application to create a new file in dropbox, which is totally possible... but much too complicated, as it has to be keyed to a specific dropbox account.

Then it dawned on me... I can create files on the disk... cfdocument allows you to specify a file name, so does cfimage, and cffile lets you create almost anything... Dropbox (and Google Drive) , are after all just a folder on the disk.. which is controlled by dark magic :-)

And this idea actually works... you just target the Dropbox folder, get your web app to store the generated file here, and the cloud-storage mechanisms do the heavy lifting for you. You could even create a dropbox folder hierarchy to keep things tidy.

Monday, January 14, 2013

CFEclipse Stack Overflow org.cfeclipse.cfml.editors.CFMLEditor



In an attempt to import the CFWheels project from GITHub into Eclipse today, I was unable to open a couple of files without getting "Unable to create editor ID org.cfeclipse.cfml.editors.CFMLEditor: Editor could not be initialized"

After some quick searches, I found this post I've edited my eclipse.ini files last line to be:

-Xss10m

I tired it initially with the suggested -Xss2048k but it didn't fix the problem... since I have more ran that I know what to do with... I figured what the heck if 2 megs didn't work, here's 10 megs... and now its working again.

Tuesday, January 8, 2013

Railo and Fusion Reactor Trouble with Datasource Wrapper


I came across a bug I thought was in Fusion-Reactor recently wrapping a data-source with Railo 3.3.4.003. It was actually that Railo wasn't putting the resultant primary key from an SQL insert statement into the correct structure key in the returned query object... at any rate, it's now fixed... but in Railo 4.0.3.000

https://issues.jboss.org/browse/RAILO-2178

How To: Upgrade Railo 3 to 4

Amongst other things, today I'm pushing forward on upgrading Railo from 3.x to 4.x. To begin with, I'm going to switch over my desktop workstation (IIS 7, Windows 7x64, SQL Express 2012, CF-Wheels, Fusion-Reactor) to see how it goes.

The big push for me is that I can't activate my Fusion Reactor's JDBC request monitoring easily in Railo 3.x because of the issue in this blog post which causes CF-Wheels to have no idea what a newly inserted row's primary key is. I've posted some feedback about possible work arounds at cf-wheels community site thread here: https://groups.google.com/forum/?fromgroups=#!topic/cfwheels/JJ-VrEE85ok

1) Uninstalled exising Railo 3.x, which removes the jakarta/isapi connector from IIS

2) Double check that jakarta ISAPI filter entry is removed from IIS.

3) Install Railo 4.Walk Thru:    https://github.com/getrailo/railo/wiki/How-To%3A-Upgrade-from-Railo-3.x-to-Railo-4.x

Railo admin required the removal of the following JAR files from Railo/lib before it could apply the patch to 4.0.3.001 because they were in use. I specifically patched to this version because of the issue in this blog post

  • ehcache.jar
  • slf4j.jar
  • railo-sl4j.jar

4) Update SQL Driver. Railo 4.x ships with JDBC 3, I needed JDBC 4, as JDBC 3 has a known bug, which in my case, using Coldfusion CFDBINFO doesn't work.. which only matters.. because CF-Wheels is built around this tag.

5) At this point, the Railo 4.x installer did its magic nicely, and was up and running... of course, without any of my data sources... since I don't want to re-enter them:
- Copy your data sources ( The <data-source /> nodes ) from the xml file at \Railo Inst Folder\lib\railo-server\context\railo-server.xml into your new installation at the same location.

6) So, everything is good now.. except: I need Paul Klinkenberg's most excellent CFCSV tag installed. (url below) Railo 4.x has changed the way extensions are installed. Download the ZIP and upload it to your railo admin.

7) Have you done this yet. how did it go?

Notes:

  • If you want to patch to upgrade your Railo to 4.x just get the Jar files. This solution doesn't however update your world to the Boncode connector, which fixes the bug which makes url rewriting almost impossible as far as I could figure out.   https://issues.jboss.org/browse/RAILO-1712
  • Tomcat's Server.xml mapping... no longer needed? Is this related to the new Boncode connector? I never moved over my mappings to the new railo installation... but it works.



Reference Links:

Railo 4.x Jar Files: http://www.getrailo.org/index.cfm/download/

Specifically, under "Railo 4 Installers" in the bottom right-hand corner: http://www.getrailo.org/down.cfm?item=/railo/remote/download/4.0.2.002/custom/all/railo-4.0.2.002-jars.zip&thankyou=false

SQL JDBC 4.0 Driver Jar's: http://www.microsoft.com/en-us/download/details.aspx?id=11774

Paul Klinkenberg's most excellent CFCSV tag (Thanks Paul.. you Rock!!): http://www.getrailo.org/index.cfm/extensions/browse-extensions/cfcsv/ 

Monday, January 7, 2013

SQL Exclusion Join

So, what if you want to see if records in one table exist in another one?   For example, two mail lists.. with tables that may not even have similar layouts, but have similar-ish fields, like first, last, email.... LEFT OUTER JOIN to the rescue.

Special thanks to: http://www.xaprb.com/blog/2005/09/23/how-to-write-a-sql-exclusion-join/

Fields that have shown up on the right-hand side of the join exist in both tables, and you can filter them out using a where clause.

Monday, November 5, 2012

CFWheels FindAll using Aliases Note

So, I typically use SQL Servers MMC (Management console) to create complex queries and visualize relationships between tables, since it has such a fantastic GUI for doing this.

 I have a query that brings in a second(and third) table via wheels include="secondModel(thirdModel)", and counts up how many rows are in the third table... long story short.. there is a SUPER EXCELLENT feature of wheels where it allows you to use the DATABASE column names and table names.. effectively giving you control again for this case... you just have to:

 http://cfwheels.org/docs/1-1/function/findall 

SELECT: 
Determines how the SELECT clause for the query used to return data will look. You can pass in a list of the properties (which map to columns) that you want returned from your table(s). If you don't set this argument at all, Wheels will select all properties from your table(s). If you specify a table name (e.g. users.email) or alias a column (e.g. fn AS firstName) in the list, then the entire list will be passed through unchanged and used in the SELECT clause of the query. By default, all column names in tables JOINed via the include argument will be prepended with the singular version of the included table name.

So, if you have a complicated select statement, you don't have to try and figure out what wheels has mapped your column names to now that there are multiple tables involved, you can just use their actual names. I've being using wheels for quite a while now, and never knew that it had this behaviour. No wonder I got frustrated with wheels when doing complex joins and aliases... it was switching to un-wheelsy mode.. and not telling me!!

Caveat: I really like cfwheels' built in ORM. I enjoy not needing using sql servers' table and column names, along with the table prefixes in my queries. But, in some cases...you know them.. the cases where you threaten wheels that you're going to break out a <CFQUERY> tag and just paste in the answer... its nice to just be able to go half-way.

Thursday, October 25, 2012

Git-er done.

I'm updating my world into GIT this week. Our version control system was SVN (via VisualSVNServer), but branching and tagging were always ominous.

- GitHub for windows. http://windows.github.com/

- EGit for Eclipse. The setup docs are at: http://wiki.eclipse.org/EGit/User_Guide#Setting_up_the_Home_Directory_on_Windows

- Git Issue Tracker mobile (Ipad) http://mobile.github.com/


Thursday, October 4, 2012

Railo Websockets Gateway Conflict with CFWheels

So, apparently, the Railo Websockets Gateway Extension conflicts with CFWheels.

The doc to get you started is at: http://wiki.getrailo.org/wiki/Extensions:WebSockets_Gateway#Sample_Apps

Which was giving me the error: "Gateway:my_websocket_gateway","key [WHEELS] doesn't exist in struct (keys:applicationname)"

Documented by another user here: http://code.google.com/p/cfwheels/issues/detail?id=860

The fix I found is similar, although less dramatic than "commenting out the $abortInvalidRequest();in both the events/onapplictionstart.cfm and also the events/onrequeststart.cfm allowed me to at get passed the point of the gateway not starting up."

I looked into the cfwheels code for  /wheels/global/internal.cfm --> $abortInvalidRequest  and, in my working copy, I've changed line 261 to not cause a 404 when the file in the calling path is from WebSocket.cfc, leaving wheels core functionality in place.

if ( (ListLen(callingPath, "/") GT ListLen(applicationPath, "/") || GetFileFromPath(callingPath) == "root.cfm" ) && ( GetFileFromPath(callingPath) != "WebSocket.cfc" )  )


Now.. on to WebSockets for Railo... I hope its more straight forward than having to compile java classes for Red5 ;-)

Friday, August 10, 2012

Coldfusion Session Tracker Object

I just discovered a fantastic blog post mentionning that Coldfusion (& Railo) have a java object that keeps track of sessions (that you can instantiate).. no more trying to count active sessions.


<cfset sessionTracker = createObject("java","coldfusion.runtime.SessionTracker")>
<cfdump var="#sessionTracker#">


Tuesday, July 10, 2012

CFWheels 1.1.8 Url Rewriting

CFWheels 1.1.8, IIS 7.5 on Win 7x64, Apache Tomcat running Railo 3.3

It seems url rewriting has been a tough nut to crack... and of course, now that I've figured it out... not so much :-)

- Add rewrite module to IIS 7.5 (Reboot your server.. I couldn't get the Rewrite module to show in the IIS control panel.)
- Enable rewriting by un-commenting out lines in your web.config that comes with cfwheels (This makes the rule appear in the IIS rewrite panel as a rule btw)

-  Review guide about rewrite configuration in IIS Console directly (nice for testing & understanding what's going on)
- Enable logging for starters (helpful) Hunt around in here for the log: C:\inetpub\logs\LogFiles\
- In tomcat's \tomcat\conf\web.xml 

Around line 429 "<!-- The mapping for the Railo servlet -->"   make sure this is NOT commented out:

<servlet-mapping>
    <servlet-name>GlobalCFMLServlet</servlet-name>
    <url-pattern>/rewrite.cfm/*</url-pattern>
</servlet-mapping>