Skip to content
Snippets Groups Projects
Commit 561c90be authored by Alfredo Chissotti's avatar Alfredo Chissotti
Browse files

non mi piaceva il conf.json

parent 3f79d977
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,6 @@ import java.io.OutputStream;
import org.json.JSONException;
import org.json.JSONObject;
// import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpsExchange;
public class Helper {
......
{
"base-self-url": "http://localhost:3001",
"keycloak": {
"realm": "test00",
"base-server-url": "http://localhost:8080/"
},
"cloudapp": {
"base-server-url": "http://localhost:3002/"
}
}
\ No newline at end of file
......@@ -130,7 +130,6 @@ public class Domain {
server.createContext("/secured/priviledges", new PriviledgesHandler());
server.start();
Helper.getInstance();//to let the helper load the configuration
System.out.println("Domain in ascolto su "+Helper.getSelfURL());
}
......
......@@ -2,8 +2,6 @@ package code;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
......@@ -19,89 +17,16 @@ import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
public class Helper {
private static Helper instance = null;
private static JSONObject keycloak = null;
private static JSONObject cloudapp = null;
private static String selfURL = null;
private Helper(){
// read config file
try {
JSONObject conf = new JSONObject(leggiFile("../res/conf.json"));
Helper.keycloak = conf.getJSONObject("keycloak");
Helper.cloudapp = conf.getJSONObject("cloudapp");
Helper.selfURL = conf.getString("base-self-url");
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
public static Helper getInstance(){
if(instance==null){
instance=new Helper();
}
return instance;
}
private static String leggiFile(String path) throws IOException {
String line;
StringBuffer answer = new StringBuffer();
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader(path));
while((line = bufferedReader.readLine()) != null) {
answer.append(line).append("\n");
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} finally {
if(bufferedReader != null)
bufferedReader.close();
}
return answer.toString();
}
// public static JSONObject getKeycloak() {
// return keycloak;
// }
public static String getKeycloakRealm(){
try {
return keycloak.getString("realm");
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
public static String getKeycloakURL(){
try {
return keycloak.getString("base-server-url");
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
public static String getCloudappURL(){
try {
return cloudapp.getString("base-server-url");
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
public static String getSelfURL(){
return selfURL;
}
private static String keycloakRealm = "test00";
private static String keycloakURL = "http://localhost:8080/";
private static String cloudappURL = "http://localhost:3002/";
private static String selfURL = "http://localhost:3001";
public static void sendCors(HttpExchange exchange, int stato, String response) throws IOException {
Headers headers = exchange.getResponseHeaders();
......@@ -217,5 +142,21 @@ public class Helper {
reader.close();
return content.toString();
}
public static String getKeycloakRealm(){
return keycloakRealm;
}
public static String getKeycloakURL(){
return keycloakURL;
}
public static String getCloudappURL(){
return cloudappURL;
}
public static String getSelfURL(){
return selfURL;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment