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