|
@@ -2,12 +2,13 @@ package at.acdp.urweb.web;
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
-import at.acdp.urweb.ScReadThread;
|
|
|
+import at.acdp.urweb.URBot;
|
|
|
import at.acdp.urweb.sclient.URLog;
|
|
|
import io.undertow.Handlers;
|
|
|
import io.undertow.Undertow;
|
|
|
import io.undertow.server.HttpHandler;
|
|
|
import io.undertow.server.HttpServerExchange;
|
|
|
+import io.undertow.server.handlers.HttpTraceHandler;
|
|
|
import io.undertow.server.handlers.resource.PathResourceManager;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -16,11 +17,11 @@ import static io.undertow.Handlers.resource;
|
|
|
public class WebServer {
|
|
|
private final static org.slf4j.Logger logger = LoggerFactory.getLogger(WebServer.class);
|
|
|
private final int port;
|
|
|
- private final ScReadThread sc;
|
|
|
+ private final URBot urbot;
|
|
|
private Undertow server;
|
|
|
|
|
|
- public WebServer(int port, boolean debug, ScReadThread sc) {
|
|
|
- this.sc = sc;
|
|
|
+ public WebServer(int port, boolean debug, URBot urbot) {
|
|
|
+ this.urbot = urbot;
|
|
|
this.port = port;
|
|
|
}
|
|
|
|
|
@@ -31,29 +32,18 @@ public class WebServer {
|
|
|
.post("/cmd", new HttpHandler() {
|
|
|
@Override
|
|
|
public void handleRequest(HttpServerExchange ex) throws Exception {
|
|
|
- if (ex.isInIoThread()) {
|
|
|
- ex.dispatch(this);
|
|
|
- return;
|
|
|
- }
|
|
|
+ dispatch(ex, this);
|
|
|
ex.startBlocking();
|
|
|
byte[] bytes = ex.getInputStream().readAllBytes();
|
|
|
String cmd=new String(bytes);
|
|
|
- String[] lines=cmd.split("[\\r\\n]+");
|
|
|
- String res="";
|
|
|
- for(String line:lines) {
|
|
|
- line=line.trim();
|
|
|
- if(line.startsWith("//"))
|
|
|
- continue;
|
|
|
- if(line.startsWith("#"))
|
|
|
- continue;
|
|
|
- if(!line.endsWith("\n"))
|
|
|
- line+="\n";
|
|
|
-
|
|
|
- res+=line;
|
|
|
- }
|
|
|
- if(!cmd.endsWith("\n"))
|
|
|
- cmd+="\n";
|
|
|
- sc.writeCmd(cmd);
|
|
|
+ urbot.sendProgram(cmd);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .post("/freedrive", new HttpHandler() {
|
|
|
+ @Override
|
|
|
+ public void handleRequest(HttpServerExchange ex) throws Exception {
|
|
|
+ dispatch(ex, this);
|
|
|
+ urbot.sendFreedrive(1);
|
|
|
}
|
|
|
})
|
|
|
.get("/log/{from}", ex -> {
|
|
@@ -72,4 +62,11 @@ public class WebServer {
|
|
|
server = builder.build();
|
|
|
server.start();
|
|
|
}
|
|
|
+
|
|
|
+ private void dispatch(HttpServerExchange ex, HttpHandler handler) {
|
|
|
+ if (ex.isInIoThread()) {
|
|
|
+ ex.dispatch(handler);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|