Skip to content

Commit ba8274c

Browse files
authored
adds http-kit (client & server) (#27)
* update http-kit and tests * add new http-kit
1 parent 2dfee9d commit ba8274c

File tree

4 files changed

+26
-112
lines changed

4 files changed

+26
-112
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Here the list of libraries tested:
3030
| :white_check_mark: | [datascript](./datascript) | Immutable database and Datalog query engine | |
3131
| :warning: | [fastmath](./fastmath) | Fast and primitive math and stats library | *See README* |
3232
| :white_check_mark: | [hiccup](./hiccup) | Fast library for rendering HTML in Clojure | |
33-
| :white_check_mark: | [http-kit](./http-kit) | Web server | *Web client :x:* |
33+
| :white_check_mark: | [http-kit](./http-kit) | Web server and server | |
3434
| :x: | [monger](./monger) | An idiomatic Clojure MongoDB driver with sane defaults | |
3535
| :white_check_mark: | [next.jdbc + honeysql](./next-jdbc) | Database driver and SQL-in-Clojure | |
3636
| :warning: | [nippy](./nippy) | Clojure serialization/deserialization library | *Can't serialize exceptions* |

Diff for: http-kit/README.md

+3-92
Original file line numberDiff line numberDiff line change
@@ -6,101 +6,12 @@ Testing whether [http-kit](https://github.com/http-kit/http-kit) library can be
66

77
Currently testing:
88

9-
[http-kit "2.3.0"]
9+
[http-kit "2.5.0-alpha2"]
1010

1111
Test with:
1212

1313
lein do clean, uberjar, native, run-native
1414

15-
On a separate terminal:
16-
17-
``` text
18-
$ curl -i http://localhost:3000/
19-
HTTP/1.1 200 OK
20-
Content-Type: text/html
21-
Content-Length: 13
22-
Server: http-kit
23-
Date: Sun, 22 Mar 2020 12:39:33 GMT
24-
25-
Hello GraalVM
26-
```
27-
2815
## Results
29-
`[org.httpkit.server :as server]` :white_check_mark:.
30-
`[org.httpkit.client :as client]` :x:
31-
32-
## Notes on http-kit server
33-
**GraalVM-CE-Java8-20.0.0** is preferred when using `http-kit` as a server.
34-
The native image compilation succeed with both **GraalVM-CE-Java11-20.0.0** and **GraalVM-CE-Java8-20.0.0** in this example project, however in a fully fledged application **GraalVM-CE-Java11-20.0.0** fails to compile.
35-
**GraalVM-CE-Java8-20.0.0** succeeds in both cases.
36-
37-
```
38-
Error: No instances of java.io.FilePermission are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
39-
Detailed message:
40-
Trace: Object was reached by
41-
reading field java.util.concurrent.ConcurrentHashMap$Node.val of
42-
constant java.util.concurrent.ConcurrentHashMap$Node@8dde7265 reached by
43-
indexing into array
44-
constant java.util.concurrent.ConcurrentHashMap$Node[]@6c77f2c9 reached by
45-
reading field java.util.concurrent.ConcurrentHashMap.table of
46-
constant java.util.concurrent.ConcurrentHashMap@8dde7265 reached by
47-
reading field java.io.FilePermissionCollection.perms of
48-
constant java.io.FilePermissionCollection@6cd327ba reached by
49-
reading field java.util.concurrent.ConcurrentHashMap$Node.val of
50-
constant java.util.concurrent.ConcurrentHashMap$Node@1b3aa7c5 reached by
51-
indexing into array
52-
constant java.util.concurrent.ConcurrentHashMap$Node[]@4ade4a40 reached by
53-
reading field java.util.concurrent.ConcurrentHashMap.table of
54-
constant java.util.concurrent.ConcurrentHashMap@1b3aa7c5 reached by
55-
reading field java.security.Permissions.permsMap of
56-
constant java.security.Permissions@4005e013 reached by
57-
reading field java.security.ProtectionDomain.permissions of
58-
constant java.security.ProtectionDomain@23282c25 reached by
59-
indexing into array
60-
constant java.security.ProtectionDomain[]@13f78d05 reached by
61-
reading field java.security.AccessControlContext.context of
62-
constant java.security.AccessControlContext@23282c25 reached by
63-
reading field java.net.URLClassLoader.acc of
64-
constant clojure.lang.DynamicClassLoader@323323e3 reached by
65-
reading field java.lang.Class.classLoader of
66-
constant java.lang.Class@6d8f5a95 reached by
67-
Hub
68-
69-
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
70-
Error: Image build request failed with exit status 1
71-
```
72-
73-
## Notes on http-kit client
74-
Currently using GraalVM 20, the `http-kit` client fails to compile.
75-
76-
```
77-
Warning: Aborting stand-alone image build. Unsupported features in 2 methods
78-
Detailed message:
79-
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of javax.net.ssl.SSLContext are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
80-
Trace:
81-
at parsing org.httpkit.client.HttpClient.exec(HttpClient.java:347)
82-
Call path from entry point to org.httpkit.client.HttpClient.exec(String, RequestConfig, SSLEngine, IRespListener):
83-
at org.httpkit.client.HttpClient.exec(HttpClient.java:269)
84-
at org.httpkit.client$request.invokeStatic(client.clj:258)
85-
at org.httpkit.client$request.doInvoke(client.clj:152)
86-
at clojure.lang.RestFn.applyTo(RestFn.java:139)
87-
at simple.main.main(Unknown Source)
88-
at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:151)
89-
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:186)
90-
at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)
91-
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of javax.net.ssl.SSLContext are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
92-
Trace:
93-
at parsing org.httpkit.client.SslContextFactory.trustAnybody(SslContextFactory.java:36)
94-
Call path from entry point to org.httpkit.client.SslContextFactory.trustAnybody():
95-
at org.httpkit.client.SslContextFactory.trustAnybody(SslContextFactory.java:36)
96-
at org.httpkit.client$coerce_req.invokeStatic(client.clj:68)
97-
at org.httpkit.client$coerce_req.invoke(client.clj:59)
98-
at clojure.instant.proxy$java.lang.ThreadLocal$ff19274a.hashCode(Unknown Source)
99-
at java.util.HashMap.hash(HashMap.java:339)
100-
at java.util.HashMap.get(HashMap.java:552)
101-
at com.oracle.svm.jni.access.JNIReflectionDictionary.getFieldNameByID(JNIReflectionDictionary.java:278)
102-
at com.oracle.svm.jni.functions.JNIFunctions.ToReflectedField(JNIFunctions.java:856)
103-
at com.oracle.svm.core.code.IsolateEnterStub.JNIFunctions_ToReflectedField_80d8233579d5215df0227b770e5c01228a0de9b9(generated:0)
104-
105-
Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
106-
```
16+
`[org.httpkit.server :as server]` :white_check_mark:
17+
`[org.httpkit.client :as client]` :white_check_mark:

Diff for: http-kit/project.clj

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
(defproject sample-project "0.1.0-SNAPSHOT"
1+
(defproject http-kit "0.1.0-SNAPSHOT"
22

3-
:dependencies [[org.clojure/clojure "1.10.1"]
4-
[http-kit "2.3.0"]
5-
]
3+
:dependencies [[org.clojure/clojure "1.5.1"]
4+
[http-kit "2.5.0-alpha2"]]
65

76
:main simple.main
87

@@ -14,8 +13,12 @@
1413
:aliases
1514
{"native"
1615
["shell"
17-
"native-image" "--report-unsupported-elements-at-runtime" "--no-server"
16+
"native-image"
17+
"--report-unsupported-elements-at-runtime"
18+
"--no-server"
19+
"--allow-incomplete-classpath"
1820
"--initialize-at-build-time"
21+
"--enable-url-protocols=http,https"
1922
"-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
2023
"-H:Name=./target/${:name}"]
2124

Diff for: http-kit/src/simple/main.clj

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(:gen-class))
55

66
(defn handler
7-
[request]
7+
[_]
88
{:status 200
99
:headers {"Content-Type" "text/html"}
1010
:body "Hello GraalVM"})
@@ -14,20 +14,20 @@
1414
"I don't do a whole lot ... yet."
1515
[& args]
1616
(println "server started on: http://localhost:3000/")
17-
(server/run-server handler {:port 3000})
18-
(println "visiting http://localhost:3000/")
19-
20-
;http-kit client fails to compile
21-
(comment
22-
(client/get "http://localhost:3000/" {}
23-
(fn [{:keys [status headers body error]}]
17+
(let [s (server/run-server handler {:port 3000 :legacy-return-value? false})]
18+
(println "visiting http://localhost:3000/")
19+
20+
(let [{:keys [_ _ body error]} @(client/get "http://localhost:3000/" {})]
21+
(if error
22+
(println "Failed, exception is " error)
23+
(println "Sync HTTP GET: " body)))
24+
(println "visiting https://localhost:3000/")
25+
(client/get "http://localhost:3000//" {}
26+
(fn [{:keys [_ _ body error]}]
2427
(if error
2528
(println "Failed, exception is " error)
2629
(println "Async HTTP GET: " body))))
27-
(println "visiting http://example.com/")
28-
(client/get "http://example.com/" {}
29-
(fn [{:keys [status headers body error]}]
30-
(if error
31-
(println "Failed, exception is " error)
32-
(println "Async HTTP GET: " body))))))
30+
(future (server/server-stop! s {:timeout 1000}))
31+
(Thread/sleep 1500)
32+
(shutdown-agents)))
3333

0 commit comments

Comments
 (0)