Updated jetty adapter to newest ring and removed all reflection warnings.

This commit is contained in:
Alexander K. Hudek 2014-10-04 22:15:44 -04:00
parent c59c58aa6f
commit 0a483b802d
2 changed files with 19 additions and 23 deletions

View file

@ -1,13 +1,14 @@
(ns net.thegeez.jetty-async-adapter (ns net.thegeez.jetty-async-adapter
"BrowserChannel adapter for the Jetty webserver, with async HTTP." "BrowserChannel adapter for the Jetty webserver, with async HTTP."
(:import (org.eclipse.jetty.server.handler AbstractHandler) (:import [org.eclipse.jetty.server.handler AbstractHandler]
(org.eclipse.jetty.server Server Request Response) [org.eclipse.jetty.server Server Request Response]
(org.eclipse.jetty.server.nio SelectChannelConnector) [org.eclipse.jetty.server.nio SelectChannelConnector]
(org.eclipse.jetty.server.ssl SslSelectChannelConnector) [org.eclipse.jetty.server.ssl SslSelectChannelConnector]
(org.eclipse.jetty.util.ssl SslContextFactory) [org.eclipse.jetty.util.ssl SslContextFactory]
(org.eclipse.jetty.continuation Continuation ContinuationSupport ContinuationListener) [org.eclipse.jetty.continuation Continuation ContinuationSupport ContinuationListener]
(org.eclipse.jetty.io EofException) [org.eclipse.jetty.io EofException]
(javax.servlet.http HttpServletRequest)) [javax.servlet.http HttpServletRequest]
[java.security KeyStore])
(:require [ring.util.servlet :as servlet] (:require [ring.util.servlet :as servlet]
[net.thegeez.async-adapter :as async-adapter])) [net.thegeez.async-adapter :as async-adapter]))
@ -15,17 +16,15 @@
;; (https://github.com/mmcgrana/ring/tree/jetty-async) ;; (https://github.com/mmcgrana/ring/tree/jetty-async)
;; This has failed write support ;; This has failed write support
(deftype JettyAsyncResponse [continuation] (deftype JettyAsyncResponse [^Continuation continuation]
async-adapter/IAsyncAdapter async-adapter/IAsyncAdapter
(head [this status headers] (head [this status headers]
(doto (.getServletResponse continuation) (doto (.getServletResponse continuation)
(servlet/set-status status) (servlet/update-servlet-response {:status status, :headers (assoc headers "Transfer-Encoding" "chunked")})
(servlet/set-headers (assoc headers
"Transfer-Encoding" "chunked"))
(.flushBuffer))) (.flushBuffer)))
(write-chunk [this data] (write-chunk [this data]
(doto (.getWriter (.getServletResponse continuation)) (doto (.getWriter (.getServletResponse continuation))
(.write data) (.write ^String data)
(.flush)) (.flush))
(when (.checkError (.getWriter (.getServletResponse continuation))) (when (.checkError (.getWriter (.getServletResponse continuation)))
(throw async-adapter/ConnectionClosedException))) (throw async-adapter/ConnectionClosedException)))
@ -43,7 +42,7 @@
(.setKeyStorePath (options :keystore)) (.setKeyStorePath (options :keystore))
(.setKeyStorePassword (options :key-password))) (.setKeyStorePassword (options :key-password)))
(when (options :truststore) (when (options :truststore)
(.setTrustStore ssl-context-factory (options :truststore))) (.setTrustStore ssl-context-factory ^KeyStore (options :truststore)))
(when (options :trust-password) (when (options :trust-password)
(.setTrustStorePassword ssl-context-factory (options :trust-password))) (.setTrustStorePassword ssl-context-factory (options :trust-password)))
(when (options :include-cipher-suites) (when (options :include-cipher-suites)
@ -67,19 +66,16 @@
(.setHandled base-request true)) (.setHandled base-request true))
:http :http
(let [reactor (:reactor response-map) (let [reactor (:reactor response-map)
;; continuation lives until written to! continuation ^Continuation (.startAsync request) ;; continuation lives until written to!
continuation (.startAsync request)
emit (JettyAsyncResponse. continuation)] emit (JettyAsyncResponse. continuation)]
(.addContinuationListener continuation (.addContinuationListener continuation
(proxy [ContinuationListener] [] (proxy [ContinuationListener] []
(onComplete [c] nil) (onComplete [c] nil)
(onTimeout [c] (onTimeout [^Continuation c] (.complete c))))
(.complete c))))
;; 4 minutes is google default ;; 4 minutes is google default
(.setTimeout continuation (get options :response-timeout (* 4 60 1000))) (.setTimeout continuation (get options :response-timeout (* 4 60 1000)))
(reactor emit) (reactor emit)))))))
))))))
(defn- create-server (defn- create-server
"Construct a Jetty Server instance." "Construct a Jetty Server instance."

View file

@ -1,4 +1,4 @@
(defproject net.thegeez/clj-browserchannel-server "0.0.7" (defproject net.thegeez/clj-browserchannel-server "0.0.7-SNAPSHOT"
:description "BrowserChannel server implementation in Clojure" :description "BrowserChannel server implementation in Clojure"
:dependencies [[org.clojure/clojure "1.6.0" :scope "provided"] :dependencies [[org.clojure/clojure "1.6.0" :scope "provided"]
[ring/ring-core "1.3.1"] [ring/ring-core "1.3.1"]