Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Dynamic Servlet Registration


I'm the author of a Grails plugin ( that up to this point has only worked with Tomcat. I have a request to support Jetty that I'd like to implement as well.

The plugin registers the servlets programmatically using the Groovy method below (no web.xml). I've been reading up on the Jetty docs and API, but I can't figure out how to adapt the method to configure the Jetty servlets. As you can see below it's easy with Tomcat after getting ahold of a ServletRegistration object.

def doWithDynamicMethods = { applicationContext ->
    def config = ApplicationContextHolder.atmosphereMeteorConfig
    def servletContext = applicationContext.servletContext

    config?.servlets?.each { name, parameters ->
        ServletRegistration servletRegistration = servletContext.addServlet(name, parameters.className)
        def initParams = parameters.initParams
        if (initParams != "none") {
            initParams?.each { param, value ->
                servletRegistration.setInitParameter(param, value)

I assume the starting point should be the method below:

ServletHolder ServletContextHandler.addServlet(Class<? extends Servlet> servlet, String pathSpec)

The classes below look promising, but I can't figure out how to tie them all together:


Is there a similar way to do this with Jetty?

Thanks for the help,

Back to the top