NotInServiceRegistryException on accessing TemplateRenderer

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

NotInServiceRegistryException on accessing TemplateRenderer

marco.vermeulen
I've recently been seeing some horrible stacktraces appearing when trying to access the TemplateRenderer from within the the handler closure of the Ratpack script.

It seems that the TemplateRenderer is not present in the service registry, throws the exception, but then still picks up the DefaultTemplateRenderer and works fine. I also spun up Dan's FOAAS app and saw the same behaviour.

Anyone else seeing this?

My code looks something like this:

get(TemplateRenderer).render(model, "index.html")

which yields a lovely:

org.ratpackframework.service.NotInServiceRegistryException: No object for type 'org.ratpackframework.groovy.templating.TemplateRenderer' in service registry: LazyHierarchicalServiceRegistry{org.ratpackframework.session.Session} -> [email protected]
	at org.ratpackframework.service.internal.ServiceRegistrySupport.get(ServiceRegistrySupport.java:43)
	at org.ratpackframework.handling.internal.DefaultExchange.get(DefaultExchange.java:67)
	at org.ratpackframework.groovy.templating.internal.TemplateRenderingServerErrorHandler.error(TemplateRenderingServerErrorHandler.java:26)
	at org.ratpackframework.handling.internal.DefaultExchange.error(DefaultExchange.java:108)
	at org.ratpackframework.groovy.templating.internal.DefaultTemplateRenderer$2.execute(DefaultTemplateRenderer.java:62)
	at org.ratpackframework.groovy.templating.internal.DefaultTemplateRenderer$2.execute(DefaultTemplateRenderer.java:59)
	at org.ratpackframework.groovy.templating.internal.GroovyTemplateRenderingEngine.render(GroovyTemplateRenderingEngine.java:77)
	at org.ratpackframework.groovy.templating.internal.GroovyTemplateRenderingEngine.renderError(GroovyTemplateRenderingEngine.java:65)
	at org.ratpackframework.groovy.templating.internal.DefaultTemplateRenderer.error(DefaultTemplateRenderer.java:59)
	at org.ratpackframework.groovy.templating.internal.TemplateRenderingServerErrorHandler.error(TemplateRenderingServerErrorHandler.java:27)
	at org.ratpackframework.handling.internal.DefaultExchange.error(DefaultExchange.java:108)
	at org.ratpackframework.error.internal.ErrorCatchingHandler.handle(ErrorCatchingHandler.java:36)
	at org.ratpackframework.server.internal.NettyHandlerAdapter.messageReceived(NettyHandlerAdapter.java:86)
	at org.ratpackframework.server.internal.NettyHandlerAdapter.messageReceived(NettyHandlerAdapter.java:45)
	at io.netty.channel.ChannelHandlerUtil.handleInboundBufferUpdated(ChannelHandlerUtil.java:60)
	at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:100)
	at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:1031)
	at io.netty.channel.DefaultChannelHandlerContext.access$1500(DefaultChannelHandlerContext.java:39)
	at io.netty.channel.DefaultChannelHandlerContext$13.run(DefaultChannelHandlerContext.java:1005)
	at io.netty.util.concurrent.Defaultecutor.run(DefaultEventExecutor.java:36)
	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:114)
	at java.lang.Thread.run(Thread.java:724)
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

Luke Daley
Administrator
Just tried FOAAS and can't reproduce.

The exception tells me that somehow the Guice layer didn't get into the registry.

You may have outdated ratpack libs, run the build with the --refresh-dependencies option to ensure you have the latest.
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

marco.vermeulen
Okay, I tried that but with no joy. I even went hardcore and nuked the gradle cache, no luck. It seems to be doing this on both my own app and FOAAS.

I also tried it with both Java 6 and 7, same thing.
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

Luke Daley
Administrator
Are you just hitting the front page on foaas?
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

Luke Daley
Administrator
In reply to this post by marco.vermeulen
Actually, I see it now.

Working on a fix.
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

marco.vermeulen
Cool, thanks.
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

Luke Daley
Administrator
This is the fix.

https://github.com/alkemist/ratpack-foaas/commit/8c2b5a6ce0a620c4b0527dd29ba12d1d8911724b

You need to make sure you stop the handler after sending a response.

There's a deeper problem in Ratpack which is trickier, but making that change will workaround it in your app.
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

Luke Daley
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: NotInServiceRegistryException on accessing TemplateRenderer

marco.vermeulen
In reply to this post by Luke Daley
Okay, that's done the trick thanks.