initial working version
This commit is contained in:
parent
a5e8126976
commit
487a7b001c
5 changed files with 66 additions and 19 deletions
|
@ -1,9 +1,15 @@
|
|||
"builder.isbpl" include
|
||||
|
||||
func dependencies {
|
||||
string! {
|
||||
"https://github.com/TudbuT/tuddylib/raw/master/TuddyLIB.jar" download
|
||||
"https://github.com/TudbuT/tuddylib/raw/master/TuddyLIB-javadoc.zip" download
|
||||
} #
|
||||
"../tuddylib/TuddyLIB.jar" file
|
||||
"../tuddylib/TuddyLIB-javadoc.zip" file
|
||||
"https://github.com/TudbuT/isbpl-random-stuff/raw/master/ISBPL.jar" download
|
||||
"https://github.com/jtidy/jtidy/releases/download/1.0.2-SNAPSHOT/jtidy-1.0.2-SNAPSHOT.jar" download
|
||||
"https://github.com/jtidy/jtidy/releases/download/1.0.2-SNAPSHOT/jtidy-1.0.2-SNAPSHOT-sources.jar" download
|
||||
}
|
||||
|
||||
"Tryumph" =name
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
example {
|
||||
main class: de.tudbut.tryumph.example.Main
|
||||
defaults {
|
||||
port: 8080
|
||||
}
|
||||
port: 8080
|
||||
}
|
||||
|
|
|
@ -2,20 +2,37 @@ package de.tudbut.tryumph;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import de.tudbut.tryumph.config.IRequestCatcher;
|
||||
import de.tudbut.tryumph.config.RequestCatcherConfig;
|
||||
import de.tudbut.tryumph.config.TryConfig;
|
||||
import de.tudbut.tryumph.err.ProjectException;
|
||||
import de.tudbut.tryumph.server.http.Server;
|
||||
import de.tudbut.tryumph.util.Bug;
|
||||
|
||||
public class Launch {
|
||||
|
||||
public static void main(String[] args) throws ProjectException, InterruptedException {
|
||||
private static TryConfig config;
|
||||
private static RequestCatcherConfig[] catchers;
|
||||
|
||||
public static void main(String[] args) throws ProjectException, InterruptedException {
|
||||
try {
|
||||
TryConfig config = new TryConfig(args, Launch.class.getClassLoader().getResourceAsStream("config.try"));
|
||||
config.getCatchers().then(resp -> {
|
||||
System.out.println(Arrays.toString(resp));
|
||||
}).ok();
|
||||
config = new TryConfig(args, Launch.class.getClassLoader().getResourceAsStream("config.try"));
|
||||
catchers = config.getCatchers().ok().await();
|
||||
} catch(Exception e) {
|
||||
throw new ProjectException("Error loading project", e);
|
||||
}
|
||||
System.out.println(Arrays.toString(catchers));
|
||||
for(int i = 0; i < catchers.length; i++) {
|
||||
try {
|
||||
RequestCatcherConfig catcher = catchers[i];
|
||||
Server server = new Server(catcher.getPort().ok().await());
|
||||
IRequestCatcher requestCatcher = catcher.load().ok().await();
|
||||
server.listen(requestCatcher);
|
||||
} catch(Throwable e) {
|
||||
throw new Bug("HTTP server died, but all errors from HTTP should usually be catched", e);
|
||||
}
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
System.exit(0);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,12 @@ import tudbut.parsing.JSON;
|
|||
import de.tudbut.async.*;
|
||||
import static de.tudbut.async.Async.*;
|
||||
|
||||
import de.tudbut.tryumph.err.ProjectException;
|
||||
import de.tudbut.tryumph.util.Compose;
|
||||
|
||||
public class RequestCatcherConfig {
|
||||
|
||||
private TCN configHolder;
|
||||
public TCN configHolder;
|
||||
private String name;
|
||||
|
||||
private RequestCatcherConfig() {}
|
||||
|
@ -23,20 +24,10 @@ public class RequestCatcherConfig {
|
|||
RequestCatcherConfig r = new RequestCatcherConfig();
|
||||
r.name = name;
|
||||
r.configHolder = resp;
|
||||
r.build().err(rej).ok().await();
|
||||
res.call(r);
|
||||
});
|
||||
}
|
||||
|
||||
private Task<RequestCatcherConfig> build() {
|
||||
return t((res, rej) -> {
|
||||
if(this.name == null || this.configHolder == null) {
|
||||
rej.call(new IllegalStateException("RequestCatcherConfig is not correctly initialized but was used"));
|
||||
}
|
||||
res.call(this);
|
||||
});
|
||||
}
|
||||
|
||||
public Task<String> getName() {
|
||||
return t((res, rej) -> {
|
||||
if(name == null)
|
||||
|
@ -45,7 +36,36 @@ public class RequestCatcherConfig {
|
|||
});
|
||||
}
|
||||
|
||||
public Task<IRequestCatcher> load() {
|
||||
return Async
|
||||
.<Class<?>>t((res, rej) -> {
|
||||
try {
|
||||
res.call(Class.forName(configHolder.getString("main class")));
|
||||
} catch (ClassNotFoundException e) {
|
||||
rej.call(new ProjectException("Main class of RequestCatcher does not exist (" + getName().err(rej).ok().await() + ")", e));
|
||||
}
|
||||
})
|
||||
.<Class<? extends IRequestCatcher>>compose((resp, res, rej) -> {
|
||||
try {
|
||||
res.call(resp.asSubclass(IRequestCatcher.class));
|
||||
} catch (ClassCastException e) {
|
||||
rej.call(new ProjectException("Main class of RequestCatcher does not implement RequestCatcher (" + getName().err(rej).ok().await() + ")", e));
|
||||
}
|
||||
})
|
||||
.compose((resp, res, rej) -> {
|
||||
try {
|
||||
res.call(resp.newInstance());
|
||||
} catch (Exception e) {
|
||||
rej.call(new ProjectException("Main class of RequestCatcher is not instantiable (" + getName().err(rej).ok().await() + ")", e));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "RequestCatcherConfig{name=" + name + ",configHolder=" + JSON.write(configHolder) + "}";
|
||||
}
|
||||
|
||||
public Task<Integer> getPort() {
|
||||
return t((res, rej) -> res.call(configHolder.getInteger("port")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,5 +45,11 @@ public class Compose {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ComposeCallback<String, String> cleanString() {
|
||||
return (resp, res, rej) -> {
|
||||
res.call(resp.replace("\\", "\\\\").replace("\"", "\\\"").replace("\'", "\\\'"));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue