Here’s how to get CGI working in a Grails app.
(more…)
Posts Tagged ‘grails’
Grails and CGI
Monday, October 24th, 2011Grails standalone classes need package
Tuesday, June 28th, 2011I was reminded again today that standalone classes in Grails must belong to a package. That is, a class in src/groovy or src/java needs to be in a package. For example:
file: src/groovy/mypackage/MyClass.groovypackage mypackage
class MyClass { ... }
If the class is without a package (appearing as src/groovy/MyClass.groovy), it will compile correctly but no Grails classes (like your controller or service) will be able to find it, generating an org.codehaus.groovy.control.MultipleCompilationErrorsException with the message unable to resolve class MyClass
GORM nullables and unsaved transient instance
Tuesday, April 5th, 2011I have nullable one-to-many relations in Grails/GORM and started getting “object references an unsaved transient instance” exceptions from Hibernate. In the Grails forms, selecting a blank/no-selection value for the field sent params.myOtherObject.id==''. GORM then tries to create a new empty object and during the save(flush:true), it complains with the exception:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: MyOtherClass
This stackoverflow answer gave me the clue about params and I now remove the nullable field from params when it’s blank.
def myObject = MyClass.get(params.id) if (null == params.myOtherObject.id || '' == params.myOtherObject.id) { myObject.myOtherObject = null params.remove('myOtherObject') } myObject.properties = params if (!myObject.hasErrors() && myObject.save(flush: true)) { ...
Security policy permissions for Grails in Tomcat
Thursday, June 4th, 2009Here are the permissions I’ve used for Grails apps deployed to Tomcat running the Java security manager. The Grails 1.0.x permissions are for a simple CRUD app. So far the Grails 1.1 permissions are just for a Hello World app. They’re not cut-and-paste: some thought is required to apply to individual server setups and some duplication is present. The grants go in the conf/catalina.policy file and restarting Tomcat is required. Unfortunately, it seems impossible to completely isolate these per-webapp since the Groovy and Grails code presents itself in funny ways.
I’m using Tomcat 6.0.18 and used both JDK 1.6.0_12 and 1.6.0_13 running on some sort of Linux.
(more…)
Grails error.gsp security
Wednesday, October 1st, 2008The default generated error.gsp view in Grails displays the stacktrace for any exceptions that occur. That’s nice for debugging in a development environment but it is a security issue for production as it is information leakage. We can easily turn this off when not in development, and do something useful like redirect to the application homepage.
(more…)
Grails stacktrace.log
Tuesday, September 30th, 2008Grails 1.0.x started creating a stacktrace.log file in the directory where the servlet container starts. In a development environment, using grails run-app, that’s simple enough— it appears in the top level of your application. In a production environment, this becomes a problem. Your production container (e.g. Tomcat) may start someplace where it can’t create files, like /. Thus you get exceptions sent to your container’s log files like:
java.io.FileNotFoundException: stacktrace.log (Permission denied)
Also, messages are appended to stacktrace.log– so it will continue to grow if you don’t do something about it. One option is to change where your container starts, e.g. have the startup script change to its logs directory. You can also configure your grails app to change the location of the stacktrace.log file or turn it off completely.
(more…)
Grails logging
Wednesday, September 24th, 2008To turn on display of debug log messages in Grails 1.0.2, add this to the bottom of grails-app/conf/Config.groovy:
environments {
development {
log4j {
logger {
grails."app"="debug,stdout"
//grails="debug,stdout" // maybe need this too
}
}
}
}
Info on other versions continues below.
(more…)
Grails testing
Tuesday, September 23rd, 2008The Grails docs talk about testing and have some example test methods but fail to describe some simple but necessary mechanics to get it going. The test methods should be in a class that extends GroovyTestCase (that word doesn’t appear at all when searching the Grails website). The class name must end with Tests since it must be in a file with a name ending in Tests.groovy under the test directory of your grails project.
(more…)
Grails .gitignore
Thursday, September 18th, 2008I’ve started playing with git for source code revision management. Here is my first cut at a .gitignore for a Grails 1.0.3 project. Note that for previous versions you will also need (at least) a line /plugins/core
# .gitignore for Grails 1.0.3
# web application files that are overwritten by "grails upgrade"
# cf. GRAILS_HOME/scripts/Upgrade.groovy, target( upgrade )
/web-app/WEB-INF
# IDE support files that are overwritten by "grails upgrade"
# cf. GRAILS_HOME/scripts/CreateApp.groovy, target( createIDESupportFiles )
# to be specific, you could replace "/*" below with your project name,
# e.g. "foobar.launch" (no slash)
.classpath
.project
.settings
/*.launch
/*.tmproj
# logs
stacktrace.log
/test/reports
# project release file
*.war
Edit: took out build.xml since grails won’t overwrite it. The eclipse dot files .classpath, .project, and .settings will also not be overwritten if they exist, but I’m still ignoring them for now.
Update: I’ve made a few additions for Grails 1.1: gitignore11