diff --git a/.idea/libraries/google_code_gson.xml b/.idea/libraries/google_code_gson.xml
new file mode 100644
index 0000000..f62abb1
--- /dev/null
+++ b/.idea/libraries/google_code_gson.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ProtegeToAASMini.iml b/ProtegeToAASMini.iml
index deb8228..237d7ef 100644
--- a/ProtegeToAASMini.iml
+++ b/ProtegeToAASMini.iml
@@ -20,5 +20,6 @@
+
\ No newline at end of file
diff --git a/src/Main.java b/src/Main.java
index fe2c1f0..7ea6ea8 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,19 +1,65 @@
import AASMini.AASMini;
+import ProtegeGX.ProtegeGX;
+import Web.WebResponse;
+import Web.WebServer;
+import org.pmw.tinylog.Logger;
public class Main {
private static AASMini aas;
+ private static ProtegeGX protegeGX;
+ private static WebServer web;
private static String aasIP = "192.168.10.10";
- private static int aasPort = 8080;
+ private static int aasPort = 5000;
+ private static int webPort = 8080;
public static void main(String[] args) {
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- System.out.println("Shutting down...");
- if (aas!=null) aas.Disconnect();
+ GetArguments(args);
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ System.out.println("Shutting down...");
+ if (aas!=null) aas.Disconnect();
+ if (protegeGX!=null) protegeGX.Disconnect();
+ if (web!=null) web.Stop();
+ }));
+
+ System.out.println("Protege to AAS Mini Connector");
+
+ protegeGX = new ProtegeGX();
+ protegeGX.setOnCardRead(data -> {
+ Logger.info(data);
+ if (aas!=null && aas.IsConnected()){
+ // send something to AAS
}
});
- System.out.println("Protege to AAS Mini Connector");
aas = new AASMini(aasIP, aasPort);
aas.Connect();
+
+ web = new WebServer();
+ web.Start(webPort);
+ web.setAasAPI(data -> {
+ Logger.info(data);
+ // Do something with AAS
+ WebResponse wr = new WebResponse();
+ return wr;
+ });
+ web.setProtegeGXAPI(data -> {
+ Logger.info(data);
+ // Do something with ProtegeGX
+ WebResponse wr = new WebResponse();
+ return wr;
+ });
+ }
+
+ private static void GetArguments(String[] args){
+ for(String arg: args){
+ if (arg.startsWith("-aasip=")){
+ aasIP = arg.substring(7);
+ }
+ if (arg.startsWith("-aasport=")){
+ aasPort = Integer.parseInt(arg.substring(9));
+ }
+ if (arg.startsWith("-webport=")){
+ webPort = Integer.parseInt(arg.substring(9));
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Web/WebRequest.java b/src/Web/WebRequest.java
new file mode 100644
index 0000000..72ec61e
--- /dev/null
+++ b/src/Web/WebRequest.java
@@ -0,0 +1,12 @@
+package Web;
+
+public class WebRequest {
+ public String command;
+ public String data;
+ public String additional;
+ public WebRequest(){
+ command = "";
+ data = "";
+ additional = "";
+ }
+}
diff --git a/src/Web/WebResponse.java b/src/Web/WebResponse.java
new file mode 100644
index 0000000..37f8049
--- /dev/null
+++ b/src/Web/WebResponse.java
@@ -0,0 +1,12 @@
+package Web;
+
+public class WebResponse {
+ public String reply;
+ public String data;
+ public String additional;
+ public WebResponse(){
+ reply = "";
+ data = "";
+ additional = "";
+ }
+}
diff --git a/src/Web/WebServer.java b/src/Web/WebServer.java
index 9a47437..c94616a 100644
--- a/src/Web/WebServer.java
+++ b/src/Web/WebServer.java
@@ -1,24 +1,31 @@
package Web;
+import com.google.gson.Gson;
import io.javalin.Javalin;
import lombok.Setter;
-import java.util.function.Consumer;
+import java.util.function.Function;
-import static io.javalin.apibuilder.ApiBuilder.get;
-import static io.javalin.apibuilder.ApiBuilder.path;
+import static io.javalin.apibuilder.ApiBuilder.*;
@SuppressWarnings("unused")
public class WebServer {
- @Setter private Consumer aasAPI;
- @Setter private Consumer protegeGXAPI;
+ @Setter private Function aasAPI;
+ @Setter private Function protegeGXAPI;
+ private final Gson gson = new Gson();
- private void updateAASAPI(String data){
- if (aasAPI!=null) aasAPI.accept(data);
+ private WebResponse ProcessAAS(WebRequest request){
+ if (aasAPI!=null){
+ return aasAPI.apply(request);
+ }
+ return null;
}
- private void updateProtegeGXAPI(String data){
- if (protegeGXAPI!=null) protegeGXAPI.accept(data);
+ private WebResponse ProcessProtegeGX(WebRequest request){
+ if (protegeGXAPI!=null){
+ return protegeGXAPI.apply(request);
+ }
+ return null;
}
Javalin app;
@@ -31,11 +38,41 @@ public class WebServer {
path("aasmini", ()->{
//TODO implement API for AAS Mini
get(ctx -> ctx.result("AAS Mini API"));
+ post(ctx -> {
+ try{
+ WebRequest request = gson.fromJson(ctx.body(), WebRequest.class);
+ WebResponse response = ProcessAAS(request);
+ if (response!=null){
+ ctx.result(gson.toJson(response));
+ } else {
+ ctx.status(400);
+ ctx.result("No response from AAS Mini");
+ }
+ } catch(Exception e){
+ ctx.status(400);
+ ctx.result("Exception: "+e.getMessage());
+ }
+ });
});
// API for ProtegeGX
path("protegegx", ()->{
//TODO implement API for ProtegeGX
get(ctx -> ctx.result("ProtegeGX API"));
+ post(ctx -> {
+ try{
+ WebRequest request = gson.fromJson(ctx.body(), WebRequest.class);
+ WebResponse response = ProcessProtegeGX(request);
+ if (response!=null){
+ ctx.result(gson.toJson(response));
+ } else {
+ ctx.status(400);
+ ctx.result("No response from ProtegeGX");
+ }
+ } catch(Exception e){
+ ctx.status(400);
+ ctx.result("Exception: "+e.getMessage());
+ }
+ });
});
});
});