Skip to content

Instantly share code, notes, and snippets.

View olivermt's full-sized avatar

Oliver Severin Mulelid-Tynes olivermt

  • AMOI / OMT Tech AS
  • Hamar, Norway
  • 08:13 (UTC +01:00)
View GitHub Profile
@olivermt
olivermt / gist:1092930
Created July 19, 2011 16:15
Exception conundrum
/*
Problem:
I want to leak exceptions that should not happen, so that the "500" mapping simply shows an error page.
In my 500 page action, i check for ?showException=1, and if its there, I render the stock error.gsp.
Now all this is fine and dandy, except the fact that I want to embed the perpetrator into the exception
so I can list the errors.
Code so far:
*/
@olivermt
olivermt / gist:1097208
Created July 21, 2011 13:42
custom validator
confirmField(validator: { val, obj ->
def linkedField = propertyName += "Confirm"
throw new RuntimeException("validating")
if(obj.properties[linkedField] != val) {
return ['confirmField.mismatch']
}
return true
})
//mapping
"500"(controller:"foo", action:"bar")
//
class FooController {
def bar = {
response.sendError(200)
}
}
@olivermt
olivermt / gist:1104088
Created July 25, 2011 13:13
custom validator and scope
//the follow resides in Config.groovy
//custom validator that checks if a linked field is identical
confirmField(validator: { val, obj ->
String linkedField = propertyName + "Confirm" //the error line
if(obj.properties[linkedField] != val) {
return ['confirmField.mismatch']
}
return true
})
//Foo
class Foo {
String name
static hasMany = [bar:Bar]
void addSomeBars() {
(1..10).each { i ->
def bar = new Bar()
bar.name = "bar nr: ${i}"
println "Adding bar nr: ${i}"
addToBar(bar)
static namedQueries = {
searchTree { query ->
section {
query.modern ? isNotNull("modernDepositionalSetting") : isNotNull("depositionalSetting")
eq("grossDepositionalEnvironment", query.grossDepositionalEnvironment)
depositionalSetting {
if(query.basinType) 'in'("basinType", query.basinType)
if(query.paleoClimate)'in'("paleoClimate", query.paleoClimate)
}
depositionalEnvironment {
@olivermt
olivermt / 1
Created October 13, 2011 15:32
Weird behavior in grails redirecting
//controller Page, with the 404 mapping in UrlMappings.groovy: "404"(controller:"page", action:"notFound")
@Secured(['IS_AUTHENTICATED_ANONYMOUSLY'])
def notFound () {
def msg =
[code:"404",
descriptor:"page not found",
strong: "The page you requested cannot be found",
text:"If you got to this page by following a link, please notify an administrator."]
render (view: "/shared/status", model: [msg:msg])
}
INFO: Deploying web application archive ROOT.war
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/var/lib/tomcat6/webapps/ROOT/WEB-INF/lib/grails-plugin-logging-2.0.0.M2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/var/lib/tomcat6/webapps/ROOT/WEB-INF/lib/slf4j-simple-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: stacktrace.log (Permission denied)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:192)
at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/var/lib/tomcat6/webapps/ROOT/WEB-INF/lib/grails-plugin-logging-2.0.0.M2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/var/lib/tomcat6/webapps/ROOT/WEB-INF/lib/slf4j-simple-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
2011-10-14 14:18:43,330 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] ERROR StackTrace - Full Stack Trace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.web.async.api.ControllersAsyncApi
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at
chkconfig --list
glassfish 0:off 1:off 2:off 3:on 4:off 5:off 6:off
mongodb 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cat /etc/inittab
id:3:initdefault: