refactor config
This commit is contained in:
parent
41a78b282f
commit
742e848040
@ -32,6 +32,8 @@ public abstract class AbstractProcess {
|
||||
|
||||
protected Gson gson;
|
||||
|
||||
protected ConfigManager config = ConfigManager.getInstance();
|
||||
|
||||
protected AbstractProcess() {
|
||||
|
||||
gson = new GsonBuilder().create();
|
||||
@ -45,18 +47,21 @@ public abstract class AbstractProcess {
|
||||
});
|
||||
}
|
||||
|
||||
protected static String getTrustStorePath() {
|
||||
String path = System.getProperty("user.dir") + File.separatorChar
|
||||
+ ConfigManager.getInstance().getTruststorePath();
|
||||
if (!new File(path).canRead())
|
||||
return null;
|
||||
protected String getTrustStorePath() {
|
||||
String path = config.getTruststorePath();
|
||||
if (!new File(path).canRead()) {
|
||||
path = System.getProperty("user.dir") + File.separatorChar + config.getTruststorePath();
|
||||
if (!new File(path).canRead()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
protected static void setTrustStoreCredentials() {
|
||||
protected void setTrustStoreCredentials() {
|
||||
log.info(getTrustStorePath());
|
||||
System.setProperty("javax.net.ssl.trustStore", getTrustStorePath());
|
||||
System.setProperty("javax.net.ssl.trustStorePassword", ConfigManager.getInstance().getTruststorePassword());
|
||||
System.setProperty("javax.net.ssl.trustStorePassword", config.getTruststorePassword());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +269,7 @@ public abstract class AbstractProcess {
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the list of APIs by name.
|
||||
*
|
||||
|
||||
@ -74,12 +74,16 @@ public final class ConfigManager {
|
||||
|
||||
private final int maxThreads;
|
||||
|
||||
private static volatile ConfigManager INSTANCE;
|
||||
|
||||
/** Všechny načtené hodnoty. */
|
||||
private final Properties props = new Properties();
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* SINGLETON – lazy‑initialization‑on-demand holder */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
private ConfigManager() {
|
||||
Properties props = new Properties();
|
||||
|
||||
log.info("Loading property file '{}'", PROPERTY_FILENAME);
|
||||
|
||||
@ -121,37 +125,47 @@ public final class ConfigManager {
|
||||
log.error("Cannot load property file.", e);
|
||||
}
|
||||
|
||||
sourceRegistrationApiUrl = props.getProperty(PROP_SOURCE_REGISTRATION_API_URL);
|
||||
sourcePublisherApiUrl = props.getProperty(PROP_SOURCE_PUBLISHER_API_URL);
|
||||
sourceDevportalApiUrl = props.getProperty(PROP_SOURCE_DEVPORTAL_API_URL);
|
||||
sourcePublisherTokenUrl = props.getProperty(PROP_SOURCE_PUBLISHER_TOKEN_URL);
|
||||
sourceWso2User = props.getProperty(PROP_SOURCE_WSO2_USER);
|
||||
sourceRegistrationApiUrl = getRequired(PROP_SOURCE_REGISTRATION_API_URL);
|
||||
sourcePublisherApiUrl = getRequired(PROP_SOURCE_PUBLISHER_API_URL);
|
||||
sourceDevportalApiUrl = getRequired(PROP_SOURCE_DEVPORTAL_API_URL);
|
||||
sourcePublisherTokenUrl = getRequired(PROP_SOURCE_PUBLISHER_TOKEN_URL);
|
||||
sourceWso2User = getRequired(PROP_SOURCE_WSO2_USER);
|
||||
|
||||
targetRegistrationApiUrl = props.getProperty(PROP_TARGET_REGISTRATION_API_URL);
|
||||
targetPublisherApiUrl = props.getProperty(PROP_TARGET_PUBLISHER_API_URL);
|
||||
targetDevportalApiUrl = props.getProperty(PROP_TARGET_DEVPORTAL_API_URL);
|
||||
targetPublisherTokenUrl = props.getProperty(PROP_TARGET_PUBLISHER_TOKEN_URL);
|
||||
targetWso2User = props.getProperty(PROP_TARGET_WSO2_USER);
|
||||
targetRegistrationApiUrl = getRequired(PROP_TARGET_REGISTRATION_API_URL);
|
||||
targetPublisherApiUrl = getRequired(PROP_TARGET_PUBLISHER_API_URL);
|
||||
targetDevportalApiUrl = getRequired(PROP_TARGET_DEVPORTAL_API_URL);
|
||||
targetPublisherTokenUrl = getRequired(PROP_TARGET_PUBLISHER_TOKEN_URL);
|
||||
targetWso2User = getRequired(PROP_TARGET_WSO2_USER);
|
||||
|
||||
truststorePath = props.getProperty(PROP_TRUSTSTORE_PATH);
|
||||
truststorePassword = props.getProperty(PROP_TRUSTSTORE_PASSWORD);
|
||||
truststorePath = getRequired(PROP_TRUSTSTORE_PATH);
|
||||
truststorePassword = getRequired(PROP_TRUSTSTORE_PASSWORD);
|
||||
|
||||
publisherUrlPattern = props.getProperty(PROP_PUBLISHER_URL_PATTERN);
|
||||
devportalUrlPattern = props.getProperty(PROP_DEVPORTAL_URL_PATTERN);
|
||||
publisherUrlPattern = getRequired(PROP_PUBLISHER_URL_PATTERN);
|
||||
devportalUrlPattern = getRequired(PROP_DEVPORTAL_URL_PATTERN);
|
||||
|
||||
apicurioApiUrl = props.getProperty(PROP_APICURIO_API_URL);
|
||||
defaultApiGroup = props.getProperty(PROP_DEFAULT_API_GROUP);
|
||||
apicurioApiUrl = getRequired(PROP_APICURIO_API_URL);
|
||||
defaultApiGroup = getRequired(PROP_DEFAULT_API_GROUP);
|
||||
|
||||
maxThreads = Integer.parseInt(props.getProperty(PROP_MAX_THREADS, "10"));
|
||||
}
|
||||
|
||||
/** Lazily‑initialized singleton instance. */
|
||||
private static final class Holder {
|
||||
static final ConfigManager INSTANCE = new ConfigManager();
|
||||
public static ConfigManager getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (ConfigManager.class) {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ConfigManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static ConfigManager getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
private String getRequired(String key) {
|
||||
String value = props.getProperty(key);
|
||||
if (value == null) {
|
||||
throw new IllegalStateException("Missing required property: " + key);
|
||||
}
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
@ -17,7 +17,6 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import cz.trask.apioperator.AbstractProcess;
|
||||
import cz.trask.apioperator.config.ConfigManager;
|
||||
import cz.trask.apioperator.model.APIInfo;
|
||||
import cz.trask.apioperator.model.APIList;
|
||||
import cz.trask.apioperator.model.HttpResponse;
|
||||
@ -44,11 +43,9 @@ public class Import extends AbstractProcess {
|
||||
StartParameters sp;
|
||||
RegistryClient client;
|
||||
static int i = 1;
|
||||
private ConfigManager config;
|
||||
|
||||
public Import(StartParameters sp) throws Exception {
|
||||
this.sp = sp;
|
||||
this.config = ConfigManager.getInstance();
|
||||
client = RegistryClientFactory.create(config.getApicurioApiUrl());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user