Created
August 11, 2014 20:36
-
-
Save kramer/c15ada4fca127d251506 to your computer and use it in GitHub Desktop.
ratpack "error" handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
maven { url "http://oss.jfrog.org/repo" } | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'io.ratpack:ratpack-gradle:0.9.7' | |
} | |
} | |
repositories { | |
maven { url "http://oss.jfrog.org/repo" } | |
mavenCentral() | |
maven { url "http://repo.springsource.org/repo" } // for springloaded | |
} | |
apply plugin: "io.ratpack.ratpack-groovy" | |
apply plugin: "idea" | |
idea { | |
project { | |
jdkName "1.7" | |
languageLevel "1.7" | |
} | |
} | |
configurations.all { | |
exclude module: "groovy" | |
} | |
applicationDefaultJvmArgs = ["-Xmx=64mb"] | |
dependencies { | |
springloaded "org.springsource.springloaded:springloaded-core:1.1.4" | |
compile 'io.ratpack:ratpack-rx:0.9.7' | |
compile 'com.ning:async-http-client:1.8.13' | |
compile 'ch.qos.logback:logback-classic:1.1.2' | |
compile 'ch.qos.logback:logback-core:1.1.2' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.crypto.Cipher | |
import javax.crypto.spec.IvParameterSpec | |
import javax.crypto.spec.SecretKeySpec | |
import static ratpack.groovy.Groovy.ratpack | |
import static ratpack.rx.RxRatpack.initialize | |
import static ratpack.rx.RxRatpack.observe | |
class FaultyClass { | |
static final Integer PI = { | |
throw new Error("test") | |
} as Integer | |
} | |
ratpack { | |
bindings { | |
initialize() | |
bind FaultyClass.class | |
} | |
handlers { | |
get("single") { FaultyClass faulty -> | |
observe(blocking({ | |
// simulate some blocking load | |
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE"); | |
SecretKeySpec key = new SecretKeySpec("0123456789abcdef".bytes, "AES"); | |
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec("AAAAAAAAAAAAAAAA".bytes)); | |
160.times { cipher.update(it.byteValue()) } | |
cipher.doFinal("0123456789ABCDEF".bytes).toString() | |
})).subscribe({ | |
render "ok $it - $faulty" | |
}) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0.9.8 has improved error handling. This setup produces a definite result with a stack trace, can you confirm?
I have
ratpack.groovy
insrc/ratpack/ratpack.groovy
andbuild.gradle
sitting right next tosrc
.