Skip to content

Instantly share code, notes, and snippets.

@skurfuerst
Created July 16, 2014 04:43
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 skurfuerst/f7621b3a0140083aee18 to your computer and use it in GitHub Desktop.
Save skurfuerst/f7621b3a0140083aee18 to your computer and use it in GitHub Desktop.
import ratpack.handling.Context
import ratpack.handling.Handler
import ratpack.server.PublicAddress
import ratpack.session.Session
import ratpack.session.SessionManager
import ratpack.session.internal.RequestSessionManager
/**
* Created by sebastian on 13.07.14.
*/
class NameBasedHostingHandler implements Handler {
private final Handler handler
def NameBasedHostingHandler(Handler handler) {
this.handler = handler
}
@Override
void handle(Context context) throws Exception {
// START of TRY 1
context.getRequest().registerLazy(PublicAddress.class, new ratpack.func.Factory<PublicAddress>() {
public PublicAddress create() {
// is not called.
return new NameBasedPublicAddress()
}
});
context.insert(handler)
// END of TRY 1
// START of TRY 2
context.getRequest().register(PublicAddress.class, new NameBasedPublicAddress())
handler.handle(context);
// END of TRY 2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment