grails

Steve Dalton's picture

Beware "grails set-proxy" and http client call

Just a quick gotcha we found today. Took us a while to work it out and we ended up fixing it on a hunch, so thought we would share here.

We are using Grails 1.2.1 on a client site and had used "grails set-proxy" to allow us to download grails plugins. Our application made a http client connection using the built in groovy new URL(url).openStream() to another web service (also Grails application). Anyway when running the application in dev mode the client application was failing on the openStream() call with a http status code 503. The meaning of this status code is:

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.

We had no idea what was going on, the code had worked before. On a hunch we removed the proxy configuration and Voila! it worked again. This confused me a bit as:

1. I thought grails set-proxy was only for the grails runtime and not the internal tomcat server?
2. The 503 message was very confusing - didn't seem to describe what was really happening, although this was possibly the way our Microsoft proxy server was interpreting the request.

Anyone else experienced this. Is this a bug?

Lee Butts's picture

Grails, Shiro, IE8 and RememberMe

UPDATE: We're still having RememberMe issues under IE8 so there more to this bug than the solution posted here. I will update this when we get to the bottom of it.

I've recently been looking at a bug we had with IE8 and RememberMe cookies not persisting at ShareYourLove.com when users closed their browsers.

The crux of it was that Shiro was not explicitly setting a domain on the cookie which apparently is a no-no as far as IE8 is concerned.

The fix is to configure Shiro's SecurityManager via resources.groovy:

beans = {
    shiroSecurityManager(DefaultWebSecurityManager) {bean ->
        realms = [ref('JsecDbRealmWrapper')]
        //override remember me expiry to 30 days
        rememberMeCookieMaxAge = 60 * 60 * 24 * 30
        switch (Environment.current.name) {
            case 'beta':     
                rememberMeCookieDomain = '.beta.shareyourlove.com'
                break      
            case 'production':
                rememberMeCookieDomain = '.www.shareyourlove.com'
                break
            default:
                rememberMeCookieDomain = null
        }
    }
}

Steve Dalton's picture

Grails log4j configuration and custom environments

If like me, you have different appenders depending on the grails environment - you might not have realised that custom environments don't work with the log4j config DSL. So code like this doesn't work:

log4j = {
     appenders {
         development {
             rollingFile name: "mylog",
                     file: 'mylog.log', layout: pattern(conversionPattern: '%d{ISO
         }
         test {
             rollingFile name: "mylog",
                     file: 'mylog.log', layout: pattern(conversionPattern: '%d{ISO
         }
         beta {
             rollingFile name: "mylog",
                     file: '/tmp/mylog-beta.log',
                     layout: pattern(conversionPattern: '%d{ISO8601} [%t] %p %c
         }
         production {
            rollingFile name: "mylog",
                     file: '/tmp/mylog-beta.log',
                     layout: pattern(conversionPattern: '%d{ISO8601} [%t] %p %c
         }
    }

The beta environment won't be picked up and you will get some error in your logs about it for other environments. In any case the configuration doesn't look very DRY to me. Probably better to just have the filename into a separate config param in your Config.groovy, then just refer to it from a single appender

myapp.logLocation = 'mylog.log'

environments {
    production {
        myapp.logLocation = '/tmp/mylog.log'
    }
    beta {
        myapp.logLocation = '/tmp/mylog.log'
    }
}

log4j = {
    appenders {
            rollingFile name: "mylog",
                    file: myapp.logLocation, layout: pattern(conversionPattern: '%d{ISO8601} [%t] %p %c %x - %m%n')
    }

Still not completely very DRY, wish I could do something like

environments {
     production, beta {
         somesharedconfig = 'foo'
     }

Hopefully they'll come up with some way to do this nicely in future grails releases.

Steve Dalton's picture

Groovy around the Globe - Australia & New Zealand

This article is the first in a series that will examine the Groovy/Grails/Griffon community around the world - it first appeared in the November issue of GroovyMag.

We all love the technology, and this series will focus on the people that help to make technology great – colleagues from the farthest flung corners of the globe. This first article focuses on one of the the most remote regions: Australia & New Zealand.

A far-flung land

Tucked away in a oft-forgotten corner of the Southern Pacific are the sparsely-populated countries of Australia and New Zealand. Despite the relative isolation from the rest of the development community (and each other), there's been a long history of innovation and contribution to Open Source projects from the Aussie and Kiwi developers over the years.

Australia in particular is a very urban society: 82% of the citizens live primarily in the eight state and territorial capitals. However, the population of 22 million is spread over an area the size of Europe, which makes face-to-face meetings of the tech community a pretty rare thing. Despite the long and dusty distances separating the capitals, a great sense of community and collaboration prevails. New Zealand has an even smaller population (about two million) and the development community is even more thinly dispersed; however, there is also a surprising amount of activity coming from this remote land.

Conferences

Despite the geographic challenges, in the Open Source area there are two successful annual conferences in the region: Open Source Developers Conference (OSDC), and Linux Conference Australia (LCA).

Lee Butts's picture

Grails WebTest Plugin Version 2.0 Released

The latest version of the WebTest plugin for Grails is now available in the central repository.

This is a release to update the plugin to work correctly with 1.2-RC2 and to removed the old run-webtest script in favour of the new test-app -functional integration. If your build server is using run-webtest you will need to change it to test-app -functional

The only known loss of functionality between run-webtest and test-app is the custom test suite behaviour. If you need this functionality do not upgrade (you should also add a Jira to Grails core requesting custom suite functionality from test-app!).

The create-webtest script now re-uses the generation code that comes with Grails and as such supports packages properly but does not generate as much sample code as before (it's basically just a test skeleton). The old method of attempting to generate a basic test for the given domain was not reliable and providing little benefit (imo).

A list of fixed issues is here: http://jira.codehaus.org/browse/GRAILSPLUGINS/fixforversion/16068

Steve Dalton's picture

Grails set-proxy and authenticated proxy servers

Quick tip.

If your company uses an authenticating NTLM proxy server and your login includes your domain name, eg:

internal\joebloggs

The \ in the username will cause some trouble for "grails set-proxy". Once set this way you will then get

Error executing script SetProxy: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script1.groovy: 2: unexpected char: '\' @ line 2, column 66.

If you try and set it again (you'll have to remove the proxy script in your .grails directory to be able to set it again)

Simple solution - just make sure you use a \\ in the username and it will all work

internal\\joebloggs

Wasted a bit of time for me - so just wanted to share in case it helps others.

Steve Dalton's picture

IntelliJ Grails Plugin and importing existing Grails projects

Something has been really annoying me for last couple of weeks.

Whenever I import a grails project from existing sources into IntelliJ (8.1.4), even though I had installed the Grails facet correctly - the Grails project view features would not be visible (eg. easy switching between controllers and views etc). New Grails projects created in IDEA were fine - so my setup was good.

Anyway, after searching the forums and lists I could find a lot of people complaining about the IDEA Grails plugin but no solution to my problem.

I finally gave up and thought maybe I could make some sense of the Intellij .iml file. It wasn't as bad as I expected there is a line:

<module relativePaths="true" type="JAVA_MODULE" version="4">

I noticed that in the "created from scratch" version it was:

<module relativePaths="true" type="GRAILS_MODULE" version="4">

So - I changed it in my none-working projects - and Voila! it worked.

Hope this helps others and saves some time - I wasted a fair bit looking for a solution.

Steve Dalton's picture

Open Source Developers Conference - Day 1

Well it's that time of the year again, and one of the highlights of my year. Open Source Developers Conference Australia - this year just up the road in Brisbane.

The drive up from Gold Coast pretty slow. It's been a while since I drove up in peak hour. Train is much faster, but we needed the car to get the last few kms to Bardon.

The venue is right in the bush near Mt-Cootha.... nice spot. Bit far from the pubs and civilisation, but I am warming to it.

I set up an OSIA stand for the day - we didn't actually have a stand, but I put up some posters to give a bit of visibility. Gave away a lot of badges that CustomTees did for us - saw a few people wearing them or attached to their lanyards which was good. Everyone really liked my polo shirt I was wearing - so hopefully I am going to get some more made and give one to each member. Lots of people knew about OSIA, lot's didn't - a few people were very interesting in joining - and I have to live up to my promise of activity this year now! Watch this space.

The opening Keynote on Volunteers by Karen Pauley was really really interesting. I sat next to Paul O'Keeffe and had a lot to think about there in relation to Barcamp, Legion of Tech and the various groups we run. I found what she said about leaders so true - there are a lot of groups that rely on 1 person, if that person stops, then the group usually stops. We need to future-proof our groups so that they are sustainable... a lot of good things happening, but we need to keep them going.

Lee Butts's picture

Grails Amazon S3 0.7.4 Released

A new version of the S3 plugin is now available. This was primarily a Hibernate mapping update to improve performance after excessive querying was noticed in a client application using the old version. As such, there are some database schema changes to required when you upgrade your application.

Release Notes

  • Versioning has been removed from S3Asset, as such you should drop the version column from the s3asset table
  • Versoning was added to the S3Asset options collection. You will need to add a version column (bigint) with a default of zero to s3asset_options
  • A foreign key on the options column and index on options_idx have been added to the s3asset_options table. This should increase performance for applications with a large number of assets.
    You may need to remove old rows from s3asset_options that do not reference a valid S3Asset due to the previous mapping not properly cascading deletes in some cases
  • Hibernate second level caching is now enabled for S3Asset and it's options. If you are not using second level caching (you'll get an error if you're not), you can disable this by setting aws.disableHibernateCaching to true in Config.groovy
Lee Butts's picture

Grails WebTest Plugin 1.2.0 Released

Update: latest version is now 1.2.3 containing some installer improvements and test generation bug fixes

The latest version of the Grails WebTest plugin is now available in the main repository. It is a major update to integrate better with the grails test-app hooks and is built using Grails 1.2-M2 (it is backwards compatible with 1.1+). As such there are some manual upgrade steps required (see release notes below). On the plus side, tests will now run as part of test-app and can also access domain classes and plugin code via the groovy step provided by WebTest

There are some trade-offs between using the old run-webtest script and the new test-app support which are outlined below. Hopefully subsequent releases can move all functionality over to the test-app script. Please raise any issues in JIRA against the webtest plugin component.

Syndicate content