Skip to content

Instantly share code, notes, and snippets.

@kramer
Created August 11, 2014 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kramer/c15ada4fca127d251506 to your computer and use it in GitHub Desktop.
Save kramer/c15ada4fca127d251506 to your computer and use it in GitHub Desktop.
ratpack "error" handling
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'
}
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"
})
}
}
}
@danhyun
Copy link

danhyun commented Sep 6, 2014

0.9.8 has improved error handling. This setup produces a definite result with a stack trace, can you confirm?

I have ratpack.groovy in src/ratpack/ratpack.groovy and build.gradle sitting right next to src.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment