argos/dmp-backend/src/main/java/proxy/config/ConfigLoader.java

54 lines
1.3 KiB
Java
Raw Normal View History

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;
public class ConfigLoader {
2017-11-20 18:01:19 +01:00
private ExternalUrls externalUrls;
// public static void main(String [] args) {
// 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
// }
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);
// 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);
}
}
}
public ExternalUrls getExternalUrls() {
return externalUrls;
}
2017-11-20 18:01:19 +01:00
}