Adds "if file exists" check functionality on setting configurable providers and fixes bug not closing input stream when error occures. (Issue #183)
This commit is contained in:
parent
b6b2c93096
commit
290aa5260c
|
@ -96,15 +96,20 @@ public class DevelConfigLoader implements ConfigLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfigurableProviders() {
|
private void setConfigurableProviders() {
|
||||||
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
||||||
String current = null;
|
String current;
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
current = new java.io.File(".").getCanonicalPath();
|
current = new java.io.File(".").getCanonicalPath();
|
||||||
is = new URL("file:///" + current + filePath).openStream();
|
File tempFile = new File(current + filePath);
|
||||||
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
if (tempFile.exists()) {
|
||||||
this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class);
|
is = new URL("file:///" + current + filePath).openStream();
|
||||||
|
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
this.configurableProviders = mapper.readValue(is, ConfigurableProviders.class);
|
||||||
|
} else {
|
||||||
|
this.configurableProviders = new ConfigurableProviders();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -11,10 +11,7 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -88,16 +85,26 @@ public class ProductionConfigLoader implements ConfigLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfigurableProviders() {
|
private void setConfigurableProviders() {
|
||||||
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
String filePath = environment.getProperty("configuration.configurable_login_providers");
|
||||||
String current = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
current = new java.io.File(".").getCanonicalPath();
|
File tempFile = new File(filePath);
|
||||||
InputStream is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
if (tempFile.exists()) {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
is = new URL(Paths.get(filePath).toUri().toURL().toString()).openStream();
|
||||||
this.configurableProviders = objectMapper.readValue(is, ConfigurableProviders.class);
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
this.configurableProviders = objectMapper.readValue(is, ConfigurableProviders.class);
|
||||||
|
} else {
|
||||||
|
this.configurableProviders = new ConfigurableProviders();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (is != null) is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Warning: Could not close a stream after reading from file: " + filePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue