2017-11-20 18:01:19 +01:00
|
|
|
package proxy.config;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
2017-11-21 17:29:16 +01:00
|
|
|
public class ConfigLoader {
|
2017-11-20 18:01:19 +01:00
|
|
|
|
|
|
|
private ExternalUrls externalUrls;
|
|
|
|
|
|
|
|
|
|
|
|
// public static void main(String [] args) {
|
2017-11-21 17:29:16 +01:00
|
|
|
// ConfigLoader l = new ConfigLoader("file:///home/nikolas/git/OpenAIRE-EUDAT-DMP/dmp-backend/src/main/resources/ExternalUrls.xml");
|
2017-11-20 18:01:19 +01:00
|
|
|
// }
|
|
|
|
|
|
|
|
|
2017-11-21 17:29:16 +01:00
|
|
|
public ConfigLoader(String fileUrl) {
|
|
|
|
System.out.println("Loaded also config file: "+fileUrl);
|
2017-11-20 18:01:19 +01:00
|
|
|
InputStream is = null;
|
|
|
|
try {
|
|
|
|
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
|
|
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
|
|
|
is = new URL(fileUrl).openStream();
|
|
|
|
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
|
2017-11-21 17:29:16 +01:00
|
|
|
// System.out.println(new ObjectMapper().writeValueAsString(externalUrls));
|
2017-11-20 18:01:19 +01:00
|
|
|
}
|
|
|
|
catch(Exception ex) {
|
|
|
|
//log the error and shutdown the system (that's a critical error)
|
|
|
|
ex.printStackTrace();
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
try {
|
|
|
|
if(is !=null) is.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Warning: Could not close a stream after reading from file: "+fileUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 17:29:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
public ExternalUrls getExternalUrls() {
|
|
|
|
return externalUrls;
|
|
|
|
}
|
2017-11-20 18:01:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|