Grails configuration in views

I don’t know why it’s taken me this long to figure this out, but… injecting the Grails configuration object in to the view layer is pretty simple.

In a Grails filter, make an ‘after’ handler like this:

after = { Map model ->
model.config = grailsApplication.config


That’s pretty much it.  In your views, you can access ${config} directly.

This *seems* to be safe.  Are there any downsides to this approach?

grails configuration taglib

I sort of can’t believe something like this doesn’t exist, but I’ve not been able to find one (I’ll find it 10 minutes after posting this I bet!)

package com.kimsal

class ConfigTagLib {

def grailsApplication

static namespace = “config”
static defaultEncodeAs = [taglib: ‘none’]

def show = {a->
String value = a.key.tokenize( ‘.’ ).inject( grailsApplication.config ) { cfg, pr -> cfg[ pr ] }
out << value


This will allow you to do something like

And you’ll get the value for in your GSP.

Did I just miss this and it’s already out there someplace?

Also, props to for helping out with the dynamic accessing…

Grails MySQL memory leak with Tomcat

I’ve been plagued with these for a while:

SEVERE [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoader.clearReferencesThreads The web application [##10379] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

Using MySQL 5.1.29 driver in Grails apps (various versions of each over the years). Any time a new app is deployed, or undeployed, this shows up.

I use ‘parallel deployment’ in Tomcat a lot, but after several deployments, we hit an ‘out of memory error’.

I *think* I’ve found the fix – I think I found it last year, but never documented it. So, this morning, I ‘fixed’ this in an app again, and am watching. So far, no leaks in the new deployment.

How did I fix it?

In Grails, in the ‘/src/groovy’ directory, I created MysqlThreadsListener.groovy

package com.myapp

import com.mysql.jdbc.AbandonedConnectionCleanupThread

import javax.servlet.ServletContextEvent
import javax.servlet.ServletContextListener
import javax.servlet.annotation.WebListener

public class MysqlThreadsListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
//Nothing to do
public void contextDestroyed(ServletContextEvent arg0) {
try {
} catch (InterruptedException e) {

And that’s… it? Will repost here if there’s still an issue…


I’ve needed to run the ‘grails install-templates’ function to get a stock web.xml file which I then modified with a custom listener reference. The @WebListener annotation didn’t seem to work.

In src/templates/war/web.xml, in the web-app tag, add:


Dealing with an incorrect security report

A colleague of mine has had his company’s code “security audited” by one of their clients; specifically, the client hired a firm to do security testing for many (all?) of that company’s services, and my colleague’s company was one of the services.

They’re told they’re in danger of losing the account unless all of the “security holes” are patched. The problem is, some of the things that are being reported don’t seem to be security holes, but their automated scanner is saying that they are, and people can’t understand the difference.

Here’s an example – you tell me if this is crazy or not.

For URL:"><script>alert(1407385165.6523)</script>&id=104

Output contains:
<input type="hidden" name="app_id" id="app_id" value="&quot;&gt;&lt;script&gt;alert(1407385165.6523)&lt;/script&gt;">

Report coming back is:
Cross-Site Scripting vulnerability found
Injected item: GET: app_id
Injection value: "><sCrIpT>alert(14073726.2017)</ScRiPt><input "
Detection value: 14073726.2017
This is a reflected XSS vulnerability, detected in an alert that was an immediate response
to the injection.

When you pass in a value, it is escaped; there is no alert box that pops up (in any browser at all). I’m *thinking* that the reporting tool is simply seeing that the number exists on the resulting page (“detection value”) and is flagging this as “bad”. That seems way too naive for a security tool, though.

Is there some other explanation for why a security tool would look at this and still report that this was ‘insecure’?

Is your code portable to subfolders?

Have been dealing with a couple of PHP projects recently which have been a far bigger pain in the backside than I anticipated, and both had some of the same stumbling blocks.

In both cases, and in other projects I’ve seen, there’s a huge assumption that the code will be run from the root of a domain, and all url and routing management have this assumption baked in to everything they touch. What’s the answer? “Just make a new vhost!” typically. Quite a pain, and seems to be a real shortcoming of all(?) major frameworks I’ve looked at of late. I remember being a bit surprised at Zend Framework as far back as 2006(!) having this be the recommended way of building with the framework.

I’ve gotten more used to Java web stuff (or, at least Spring) which respects whatever pathing your app is deployed to.


will redirect to if the code is deployed to, but it will redirect to if the code is deployed to

I recently hit this snag in a PHP project I picked up which uses Slim framework. There are dozens and dozens of URL and route references in multiple files, like

$app->get('/sample-url-path(/)', function() use ($app) {

and there’s no way to just have the code work normally under something like “http://localhost/slimdev/”. I *have* to create a new hostname and vhost just to get this to run. Am I missing a simple global config option someplace that wouldn’t require me to rewrite dozens of lines of code?

Are there any PHP frameworks that can work relatively from a non-root-domain URL invocation?

Perhaps I just need to roll with things, but it makes working with anyone else’s code (even based on a framework) that much harder.

Maybe try grabbing your own code sometime and reinstalling it in a ‘non-traditional’ way, and see how many assumptions you’ve baked in are really necessary, vs just using defaults.

Titanium debug breaking app

I did a quick prototype of a mobile iOS app using Titanium yesterday, and hit a weird issue/bug, but not sure how to report it. Putting it here for now in case it helps someone else.

I’d run the app from Titanium Studio (3.4.0, but happened in 3.3.0 as well – both using 3.3 and 3.2.3 SDK), and when clicking a button, the app would just *die*. There was no logging in the log window – in fact, the app restarted. Well, the log window cleared and the startup logs from a new run would repopulate, but the app didn’t actually restart. Very weird.

Tracked it down to one stupid line. In the function called by the button click, I was


That was it. Took way too long to track down, but removing that one line made it run just fine again.

What’s even weirder is that I hadn’t seen it yesterday. I wasn’t running from Titanium Studio (well, actually, IIRC, using the ‘debug’ runner), but running from the command line with ‘ti build’ and the ‘–shadow’ Ti-Shadow reloader project. For some reason the debug line is fine there, but if the code is debugging inside Studio, and that debug line was hit, it just died.

I hope this helps someone else out there…

iPhone 5s, iOS 7.0.4, jailbroken, and using Skype

I got a iPhone 5s recently, and took advantage of the evasi0n jailbreak. I got Cydia, and reinstalled pdanet for tethering. But.. Skype wouldn’t work. It sort of hung. Googled around a bit – needed to update Cydia substrate. OK – did that. Still didn’t work. I’d read someplace that ‘xcon’ did the trick. Tried it – it actually made it worse. Skype wouldn’t load at all – just crashed on boot. Uninstalled xcon – everything worked. I’d read somewhere to try that, and I did, and it worked great. Not sure what happened there, but if you’ve got the setup I have in my post title, try it.

MySQL speed boost

I hit a problem the other day with concurrent queries causing deadlocks.  Using innodb gives you a lot of protection with respect to transaction support, but it carries a moderate amount of overhead, and unless you’re aware of what’s going on, you may be paying a higher price which can eventually cause performance or deadlock issues.

FWIW, I thought I knew what was going on, and I *sort of* did, but not entirely.

This article at high scalability has some good introductory info, but I’ll cut to the chase as to what made a huge improvement for me.

Instead of standard BEGIN to start a transaction, I set a specific isolation level for just *one* query:


This took my combined queries from 18 seconds down to 3. In addition to the 18 seconds average time, those 18 seconds were often going to 30-60 depending on what other concurrent queries were going on. The default ‘REPEATABLE_READ’ transaction level in InnoDB does a lot of locking (or waiting to be able to lock) data, and this was the root of my problems.

You need to understand what transaction isolation levels are doing, of course, but changing some queries to READ COMMITTED is still pretty safe for what I was doing there, and made a *HUGE* difference in speed. Of course, your mileage may vary, but definitely something to research if you haven’t yet and are facing performance issues.

Facebook app permissions bummer…

When building any site that will interact with Facebook, you need to have a user connect their Facebook account with your site.  You create an app listing on Facebook, get some handshake tokens, put them in your code, then have a user initiate a connection between your site and their Facebook account.

The initiation is usually a button that says something like “Connect with Facebook”.  Behind the button is some code that indicates your token and what permissions your site wants from the requesting user.  Usually you’ll want your site to have their email address, maybe some permissions to read their wall posts or perhaps even post on their wall.  For many types of sites (like a couple I’ve worked on over the last year) you *really* are only using Facebook as an authentication system, and you’re not planning on doing any interaction with Facebook at all, so you don’t really want any permissions to their data or wall or anything else.

However… Facebook *requires* that you get access to certain aspects of the users’ data.  Even if you don’t ask for it.  It’s confusing, poorly documented, and certainly causes many people to abandon signups partway through the process.

Specifically, Facebook will always tell the user that your site/app wants access to the user’s friends list.  Always.

The Facebook developer guide says

“The public profile and friend list is the basic information available to an app. All other permissions and content must be explicitly asked for.”

But… it doesn’t indicate that there will be a popup asking for this.

Screen Shot 2013-10-11 at 8.06.37 AM












The only “permission scope” being requested is “email”.  But Facebook insists on presenting this warning that MY SITE is REQUESTING “friend list” permissions.  We’re *not* doing this – we do not want the friends list, but have no way of *not* getting it.

Even more confusing, really, is the Facebook documentation on this (their docs have always been an unholy mess, imo)

“When a user logs into your app and you request no additional permissions, the app will have access to only the user’s public profile and also their friend list.”

What happens when you *do* in face request “additional permissions” is that you still are presented to the user as asking for permission for their friend list.  I suppose the word “additional” has an implication there, but really, this is dealing with computery/programmery stuff – be explicit about what happens in both situations.

More to the point, give people a way to *not* have access to friend lists.  This is offputting to users, and in an age where privacy is a bigger concern than ever, requiring access to data that is not needed or wanted is negligent.  I suppose it would disrupt all the farmville and candy crush clones from making a living by not requiring people to spam their friends.

I know this has been dealt with on stackoverflow more than a few times, but feel compelled to add my 2c.


The indieconf story…

I’ve told people this story enough that I figured I should write it down for posterity.

I quit working a “regular” job in mid/late 2007 – just as the global economy was going in to meltdown.  :)  For the next couple years I networked, networked and networked trying to “work for myself”, all the while the economy was growing grimmer.  When I’d told people I’d quit my job earlier, it sounded ridiculous, and I got a lot of weird looks.

Fast forward to 2009/2010, as we were slowly starting to bottom out, I would meet people who’d say “wow, you survived all that”, and I’d say “yes, I did”.  Almost always, it was followed up with “I’d like to work for myself, but I’m just too scared – how do you find clients?”  or… “How do you handle taxes?”  or “How do you write a contract?”

I was certainly no expert at any of these issues, but gave my best answers.  After finding a pattern, I realized my answers weren’t as good as other experts I knew who focused on particular areas and/or had more experience than I did, so I began to reach out to those people for better answers.

In May 2010, at a Triangle JavaScript presentation, I was speaking with some of the folks there over dinner (at Trali, IIRC), and we got to talking about conferences.  The idea for a conference focused on web freelancers came to me out of the blue, and a few people said “sure, I’d go to that”, and the idea started to take shape.  I had a broader network of more experienced business and consultant folks who “knew the ropes” so to speak, and I asked some of them if they’d be willing to present.  When enough said “yes”, I started things in earnest.

The focus has always been on the non-tech side of working for yourself as a technically-oriented person.  Don’t let that scare you off – the conference is not just rooms of tech geeks – we have attendees from many backgrounds, but the common denominator is part or full time self-employment (or small team) working primarily on the web.  Developers, certainly, but graphic designers, bloggers, SEO and marketing consultants, drop shippers and more are part of the indieconf family.

What’s the ‘non-tech’ side?  Exactly what got the conference started: the business side of things – contracts, finances, marketing, personal growth and more.  It’s pretty easy to Google an answer for a troubling CSS question, but much harder to know if your pricing strategy is sound, or what your alternatives are.  Learning from experts who’ve “been there, done that” you can save yourself years of headaches and money problems by finding clients and projects that play to your strengths, and avoiding the “clients from hell” that almost every freelancer deals with at some point.

indieconf 2013 will be held November 23 in Raleigh, NC, with a full day of speakers, networking and learning to help build your business efforts to the next level.  Get your ticket today at