Steve Dalton's blog

Steve Dalton's picture

Refactor now a Jetbrains Authorised Partner

We are proud to announce that Refactor is now a Jetbrains authorised partner. We've been using IntelliJ for so many years now (Rob even wrote quite a few plugins along the way), that we thought we might as well make it official. So, if you have any requirements for Jetbrains software, please contact us, we are happy to help.

We are particularly keen to hear from local South East Queensland companies that are already using the tools and might be interested in partnering with us on plugins for IntelliJ or any of the other products we resell (such as Atlassian Jira and Confluence).

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?

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).

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.

Steve Dalton's picture

Idiot's guide to Tomcat 6 & Grails with JNDI DataSource

Ok, I found information on how to do this a little bit scattered and some gotchas, so this blog post is just a quick idiot's guide on how to setup Grails with a JNDI DataSource on Tomcat 6 with Mysql.

My setup is Ubuntu Jaunty server with Tomcat 6, Sun Java, Mysql 5 & Grails 1.1.1

1. Install Tomcat 6 on Ubuntu Server

apt-get install tomcat6

2. Install Mysql, I use the excellent http://ourdelta.org release

wget -q http://ourdelta.org/deb/ourdelta.gpg -O- | apt-key add -
wget http://ourdelta.org/deb/sources/jaunty-ourdelta.list -O /etc/apt/sources.list.d/ourdelta.list
apt-get update
apt-get install mysql-server libmysql-java

3. Install mysql connector into Tomcat

ln -s /usr/share/java/mysql.jar /usr/share/tomcat6/lib/mysql.jar

4. Create a file /var/lib/tomcat6/conf/Catalina/localhost/ROOT.xml and add the following (don't put anything in main server.xml like I had in previous versions of this blog). If you are not deploying to root, then change the name of file and docBase.

<Context docBase="ROOT" path="" reloadable="true">
    <Resource
        name="jdbc/mydatasource"
        auth="Container"
        type="javax.sql.DataSource"
        username="myusername"
        password="mypassword"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost/mydatabase"
    />
</Context>

If you have a Context already - just add the above section to it. You can also put this in the context with your war - but I personally like having it in the context outside so that you easier modify.

5. Now over in your grails application, add something like this for your environment to your grails-app/conf/DataSource.groovy:

production {
    dataSource {
        pooled = false
        dbCreate = "update"
        jndiName = "jdbc/mydatasource"
    }
}
Steve Dalton's picture

Maven2 Spring & OpenJPA

I recently found myself having to do some plain old Java code, implementing some EJB3 code. It's been a while, I've been working mainly with Spring/Hibernate/Ibatis on the Java side and was hoping I wouldn't have to touch fully blown J2EE again.

I found a rather nice sample application written by David Krisch of how to do JPA using Spring, Maven and Hibernate - you can find it here: http://code.google.com/p/mvn2-spring-jpa. The sample uses native JPA DAOs so there is no dependency on on Spring in the DAOs - nice.

Anyway - my implementation uses OpenJPA, not Hibernate - so I wanted to convert this sample to work with OpenJPA. It was surprisingly simple, and to my surprise there is less config than the Hibernate version. You don't need to call hbm2ddl to create the datebase, you can just use the nice little openjpa property openjpa.jdbc.SynchronizeMappings in your persistence.xml.

My new sample is here http://github.com/spidie/mvn2-spring-openjpa (slight name change so not to confuse it with David's) I hope this of use to someone out there - I've found real samples of this kind of thing quite hard to find.

One little gotcha with the hibernate version - if you are not on Java 1.6 you have to explicitly drag in the the common-anotations library as this isn't include in J2SE 5 - I think David might have updated this by now.

Whilst writing this I just noticed that the code doesn't correctly translate persistent exceptions - so I'll go and fix that up now!

Steve Dalton's picture

IntelliJ IDEA with Grails 1.1

in

If anyone is trying to use Intellij with Grails 1.1 - just a quick post to say that the EAP release (build 9805) seems to have fixed the Grails 1.1 plugin problems.

It Worked perfectly with new projects. To get it to work with an existing project I just had to:

  • remove all unnecessary plugin source directories & libraries
  • select Tools->Run Grails Target
  • type "clean" to run a grails clean, let it do it's library update thing and magically everything seems to fix itself up.

I think there might possibly be a problem with global plugins - didn't seem to pick up those directories. Hopefully they will fix this before 8.1.1 is released.

Syndicate content