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 Loader { private ExternalUrls externalUrls; // public static void main(String [] args) { // Loader l = new Loader("file:///home/nikolas/git/OpenAIRE-EUDAT-DMP/dmp-backend/src/main/resources/ExternalUrls.xml"); // } public Loader(String fileUrl) { System.out.println("LOADING FILE: "+fileUrl); 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)); } 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); } } } }