Newer
Older
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import com.sun.net.httpserver.HttpServer;
import db.DBC;
Alfredo Chissotti
committed
public static void main(String[] args) throws IOException, JSONException {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor)Executors.newCachedThreadPool();
HttpServer server=HttpServer.create(new InetSocketAddress(port),0);
Alfredo Chissotti
committed
Alfredo Chissotti
committed
URL url = new URL("https://gitlab.di.unipmn.it/alfredo/iotlabgw.edu-al.unipmn.it/-/raw/main/index.json");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
Alfredo Chissotti
committed
Helper.setConnectionSettings(con,"GET");
Alfredo Chissotti
committed
// leggo risposta
int status = con.getResponseCode();
Alfredo Chissotti
committed
String content = Helper.getResponseFromConnection(con);
Alfredo Chissotti
committed
Alfredo Chissotti
committed
Alfredo Chissotti
committed
server.createContext("/install/", new InstallHandler());
server.createContext("/start/", new StartHandler());
server.createContext("/stop/", new StopHandler());
server.createContext("/delete/", new DeleteHandler());
server.createContext("/secured/domains/", new TokenHandler());
server.createContext("/secured/services", new ServicesHandler());
server.createContext("/secured/priviledges", new PriviledgesHandler());
Alfredo Chissotti
committed
server.start();
System.out.println("Domain in ascolto su "+Helper.getSelfURL());
}
private static void riempiModuli(String content) throws JSONException {
JSONObject obj=new JSONObject(content);
JSONArray jr = obj.getJSONArray("response");
for(int i=0;i<jr.length();i++) {
s1[i]=jr.getString(i);
}
for(int i=0;i<s1.length;i++) {
String remZip=s1[i].substring(0, s1[i].length()-4);
String[] curr=remZip.split("-");
for(int j=0;j<curr.length;j++) {
Alfredo Chissotti
committed
String b=curr[1];
DBC.fillModules(a, b, s1[i]);
} catch (SQLException | JSONException e) {
e.printStackTrace();
}
}
else {
String a=curr[0];
try {
DBC.fillModules(a,"Arduino1", s1[i]);
} catch (SQLException | JSONException e) {
e.printStackTrace();
}
Alfredo Chissotti
committed