Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] embedded welcomefiles+http2-push+gzip-static-content+rest-api configuration

revising the servletcontextholder changes the result:   https://gist.github.com/jnorthrup/792a43d73178ee38d686035fca3d146d

class JettyStarter(

        /**
         *
         */
        private vararg val args: String) : AutoCloseable {

    private val server: Server =

            Server().apply {
                val httpFactory = HttpConnectionFactory(HttpConfiguration().apply {
                    addCustomizer(SecureRequestCustomizer())
                })
                val http2Factory = HTTP2ServerConnectionFactory(HttpConfiguration().apply {
                    secureScheme = "https"
                    securePort = SSL_PORT
                    sendXPoweredBy = false
                    sendServerVersion = false
                    addCustomizer(SecureRequestCustomizer())
                })
                val alpn1 = ALPNServerConnectionFactory().apply {
                    defaultProtocol = httpFactory.protocol
                }
                requestLog = AsyncNCSARequestLog()

                // HTTP Configuration

                connectors = arrayOf(
                        //Create a connector on port 80 to listen for HTTP requests (that will get redirected)... fail
                        ServerConnector(this, httpFactory).apply {
                            setPort(8080)
                        },

                        ServerConnector(this, SslConnectionFactory(SslContextFactory().apply {
                            keyStorePath = JettyStarter::class.java.getResource("/keystore").toExternalForm()
                            setKeyStorePassword("changeit")
                            cipherComparator = HTTP2Cipher.COMPARATOR
                            isUseCipherSuitesOrder = true
                        }, alpn1.protocol),
                                        alpn1,
                                        http2Factory,
                                        httpFactory
                        ).apply { port = SSL_PORT })
                //setup the constraint that causes all http requests to return a !403 error

                handler = ConstraintSecurityHandler().apply {
                    //makes the constraint apply to all uri paths
                    addConstraintMapping(ConstraintMapping().apply {
                        pathSpec = "/*"
                        constraint = Constraint().apply { dataConstraint = DC_CONFIDENTIAL }
                    })
                    handler = GzipHandler().apply {
                        handler = ContextHandlerCollection(
                                org.eclipse.jetty.servlet.ServletContextHandler().apply {
                                    contextPath = "/"
                                    handler = ResourceHandler().apply {
                                        welcomeFiles = arrayOf("index.html")
                                        baseResource = Resource.newResource(
                                                args.firstOrNull() ?: AdapterServlet.resourceBase.toString())

                                    }
                                servletContext.addFilter("push", PushCacheFilter::class.java).apply {
                                    initParameters = mapOf("maxAssociations" to "32",
                                                           "ports" to Objects.toString(SSL_PORT )
                                    )
                                }
                                    //TODO: repair http2 PUSH
                                    // where do I slip this in?

                                },
                                ServletContextHandler().apply {
                                    addServlet(AdapterServlet::class.java, "/*")
                                }

                        )
                    }
                }


            }

    /**
     *
     */
    @Throws(Exception::class)
    fun start() {
        server.start()
    }

    /**
     *
     */
    @Throws(Exception::class)
    override fun close() {
        server.stop()
    } 
}



On Fri, Feb 15, 2019 at 12:21 PM James Northrup <jim@xxxxxxxxxxx> wrote:
this is the uncommented outome 

Server@732f6050{STOPPED}[9.4.14.v20181114]

12:00:07.222 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - o.e.j.s.h.ContextHandler@20eaeaf8{/,null,UNAVAILABLE} added {ResourceHandler@748ac6f3{STOPPED},MANAGED}
12:00:07.223 [main] WARN org.eclipse.jetty.server.handler.ContextHandler - Unimplemented - use org.eclipse.jetty.servlet.ServletContextHandlerException in thread "main" java.lang.NullPointerException at id.kbr.prime.JettyStarter.<init>(JettyStarter.kt:86)

 
i read, and re-read the jetty examples for embedding and tried to infer the simplest one that could add http2/push with static, a rest api, and gzip.  i feel like there's a linkage or an explanation page for all this that's not among the quickstart



On Wed, Feb 13, 2019 at 6:06 PM Simone Bordet <sbordet@xxxxxxxxxxx> wrote:
Hi,

On Wed, Feb 13, 2019 at 11:01 AM James Northrup <jim@xxxxxxxxxxx> wrote:
>
> i have a dillema where my jetty configs led me to a certain configuration but the PushCacheFilter does not work on launch, it throws an NPE.

Jetty version?
Stack trace of the NPE?

> i use a restapi that previously inheritted defaultservlet and served the static content itself, and this worked well for PushCacheFilter though i did not want to duplicate the welcomefiles functionality and so refactored to this now.

Code seems ok, provided you uncomment the PushCacheFilter.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top