Get rid of Java wrapper

parent 9b773c89
*
!java/
!resources/
!src/
!project.clj
\ No newline at end of file
......@@ -5,7 +5,5 @@ set -ex
lein uberjar
$HOME/graalvm/bin/native-image \
-H:+ReportUnsupportedElementsAtRuntime \
--static \
-J-Xmx3G -J-Xms3G --no-server \
-jar target/jetty-graalvm-hello-world-0.1.0-SNAPSHOT-standalone.jar
-jar target/app-standalone.jar
package jetty_graalvm_hello_world;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class HandlerFunction extends AbstractHandler {
public interface Handler {
public void handle(String p, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response);
}
private final Handler actualHandler;
public HandlerFunction(Handler actualHandler) {
this.actualHandler = actualHandler;
}
@Override
public void handle(String p, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response) throws IOException, ServletException {
actualHandler.handle(p, request, httpServletRequest, response);
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.10.0"]
[org.eclipse.jetty/jetty-server "9.4.15.v20190215"]]
:java-source-paths ["java"]
:main jetty-graalvm-hello-world.core
:uberjar-name "app-standalone.jar"
:aot :all)
\ No newline at end of file
(ns jetty-graalvm-hello-world.core
(:gen-class)
(:import (org.eclipse.jetty.server Server Request)
(org.eclipse.jetty.server.handler HandlerList)
(jetty_graalvm_hello_world HandlerFunction HandlerFunction$Handler)
(org.eclipse.jetty.server.handler HandlerList AbstractHandler)
(javax.servlet.http HttpServletResponse HttpServletRequest)))
(defn handler
......@@ -16,9 +15,9 @@
(defn server [{:keys [join?]}]
(let [server (Server. 8080)
handler-list (HandlerList.)
h (HandlerFunction. (reify HandlerFunction$Handler
(handle [_ p req http-req resp]
(handler p req http-req resp))))]
h (proxy [AbstractHandler] []
(handle [path ^Request base-request ^HttpServletRequest request ^HttpServletResponse response]
(handler path base-request request response)))]
(.addHandler handler-list h)
(.setHandler server handler-list)
(.start server)
......@@ -30,4 +29,7 @@
(server {:join? true}))
(comment
(def srv (server {})))
(defonce srv (atom nil))
(swap! srv (fn [s]
(some->> s (.stop) (.join))
(server {}))))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment