Skip to content

Commit bd4a0b7

Browse files
committed
httpserver initial release
0 parents  commit bd4a0b7

File tree

140 files changed

+21621
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+21621
-0
lines changed

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gradle/
2+
build/
3+
bin/
4+
gradle/
5+
gradle.properties
6+
.vscode
7+
.DS_Store
8+
fileserver/

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# httpserver
2+
3+
A simple http server designed for embedding based on the JDK sun.net.httpserver.
4+
5+
It adds websocket support using modified source from nanohttpd.
6+
7+
All async functionality has been removed. Most synchronized blocks were removed in favor of other Java concurrency concepts.
8+
9+
The end result is an implementation that supports adoption of Virtual Threads available in JDK 21.
10+
11+
## using
12+
13+
Set the default HttpServer provider when starting the jvm:
14+
15+
<code>-Dcom.sun.net.httpserver.HttpServerProvider=robaho.net.httpserver.DefaultHttpServerProvider</code>
16+
17+
## future work
18+
19+
There is no http2 support.

build.gradle

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
plugins {
2+
id 'java-library'
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
10+
java {
11+
toolchain {
12+
languageVersion = JavaLanguageVersion.of(21)
13+
}
14+
withSourcesJar()
15+
withJavadocJar()
16+
}
17+
18+
tasks.withType(JavaCompile) {
19+
options.compilerArgs += "--enable-preview"
20+
}
21+
22+
tasks.withType(Test) {
23+
jvmArgs += "--enable-preview"
24+
jvmArgs += "--add-opens=jdk.httpserver/com.sun.net.httpserver=ALL-UNNAMED"
25+
systemProperty("java.util.logging.config.file","logging.properties")
26+
systemProperty("com.sun.net.httpserver.HttpServerProvider","robaho.net.httpserver.DefaultHttpServerProvider")
27+
// systemProperty("javax.net.debug","ssl:handshake:verbose:keymanager:trustmanager")
28+
}
29+
30+
tasks.withType(JavaExec) {
31+
jvmArgs += "--enable-preview"
32+
systemProperty("java.util.logging.config.file","logging.properties")
33+
systemProperty("com.sun.net.httpserver.HttpServerProvider","robaho.net.httpserver.DefaultHttpServerProvider")
34+
}
35+
36+
tasks.withType(JavaExec).configureEach {
37+
javaLauncher.set(javaToolchains.launcherFor(java.toolchain))
38+
}
39+
40+
dependencies {
41+
testImplementation 'org.testng:testng:7.8.0'
42+
}
43+
44+
configurations {
45+
testMainsCompile.extendsFrom testCompile
46+
testMainsRuntime.extendsFrom testMainsCompile
47+
}
48+
49+
test {
50+
useTestNG()
51+
testLogging {
52+
events "passed", "skipped", "failed", "standard_out", "standard_error"
53+
showStandardStreams = true
54+
}
55+
}
56+
57+
sourceSets {
58+
test {
59+
java {
60+
srcDirs = [
61+
'src/test/extras',
62+
'src/test/java',
63+
'src/test/java_default/bugs',
64+
'src/test/java_default/HttpExchange'
65+
]
66+
}
67+
}
68+
testMains {
69+
java {
70+
srcDirs = ['src/test/test_mains']
71+
compileClasspath = test.output + main.output + configurations.testMainsCompile
72+
runtimeClasspath = output + compileClasspath + configurations.testMainsRuntime
73+
}
74+
resources {
75+
srcDirs = [ 'src/test/resources' ]
76+
}
77+
}
78+
}
79+
80+
task testMainsTest(type: Test) {
81+
dependsOn testMainsClasses
82+
doLast {
83+
def files = sourceSets.testMains.allJava
84+
def is = System.in
85+
files.each { file ->
86+
def fileWithoutExt = file.name.take(file.name.lastIndexOf('.'))
87+
def props = systemProperties
88+
println " *** $fileWithoutExt ***"
89+
javaexec {
90+
classpath sourceSets.testMains.runtimeClasspath
91+
main fileWithoutExt
92+
systemProperties props
93+
standardInput is
94+
}
95+
}
96+
}
97+
}
98+
99+
/** used for developmet to run a single test */
100+
task testSingleTest(type: Test) {
101+
dependsOn testMainsClasses
102+
doLast {
103+
def testname = "Test1"
104+
println jvmArgs
105+
println systemProperties
106+
def props = systemProperties
107+
javaexec {
108+
classpath sourceSets.testMains.runtimeClasspath
109+
main testname
110+
systemProperties = props
111+
// debug true
112+
}
113+
}
114+
}
115+
116+
task runSimpleFileServer(type: Test) {
117+
dependsOn testClasses
118+
doLast {
119+
def props = systemProperties
120+
props.put("-Xshare","off")
121+
mkdir 'fileserver'
122+
javaexec {
123+
classpath sourceSets.test.runtimeClasspath
124+
main "SimpleFileServer"
125+
systemProperties = props
126+
args = ['fileserver','8888','fileserver/logfile.txt']
127+
// debug true
128+
}
129+
}
130+
}

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
2+
org.gradle.java.installations.paths=/site/drw/java/jdk-21
3+
# org.gradle.java.home=/site/drw/java/jdk-21

0 commit comments

Comments
 (0)