import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
protected Integer httpReadTimeout;
protected HashMap<String, PartnerDetails> partnerStore;
+ private static final Pattern retryPattern = Pattern.compile(".*,(http|https):.*");
public RestapiCallNode() {
String configDir = System.getProperty(PROPERTIES_DIR_KEY, DEFAULT_PROPERTIES_DIR);
loadPartners(partners);
log.info("Partners support enabled");
} catch (Exception e) {
- log.warn("Partners file could not be read, Partner support will not be enabled.", e);
+ log.warn("Partners file could not be read, Partner support will not be enabled. " + e.getMessage());
}
try (FileInputStream in = new FileInputStream(configDir + "/" + UEB_PROPERTIES_FILE_NAME)) {
uebServers = props.getProperty("servers");
log.info("UEB support enabled");
} catch (Exception e) {
- log.warn("UEB properties could not be read, UEB support will not be enabled.", e);
+ log.warn("UEB properties could not be read, UEB support will not be enabled. " + e.getMessage());
}
httpConnectTimeout = readOptionalInteger("HTTP_CONNECT_TIMEOUT_MS",DEFAULT_HTTP_CONNECT_TIMEOUT_MS);
httpReadTimeout = readOptionalInteger("HTTP_READ_TIMEOUT_MS",DEFAULT_HTTP_READ_TIMEOUT_MS);
String skipSendingStr = paramMap.get(skipSendingMessage);
p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
p.convertResponse = valueOf(parseParam(paramMap, "convertResponse", false, "true"));
- p.trustStoreFileName = parseParam(paramMap, "trustStoreFileName", false, null);
- p.trustStorePassword = parseParam(paramMap, "trustStorePassword", false, null);
p.keyStoreFileName = parseParam(paramMap, "keyStoreFileName", false, null);
p.keyStorePassword = parseParam(paramMap, "keyStorePassword", false, null);
- p.ssl = p.trustStoreFileName != null && p.trustStorePassword != null && p.keyStoreFileName != null
- && p.keyStorePassword != null;
+ p.ssl = p.keyStoreFileName != null && p.keyStorePassword != null;
p.customHttpHeaders = parseParam(paramMap, "customHttpHeaders", false, null);
p.partner = parseParam(paramMap, "partner", false, null);
p.dumpHeaders = valueOf(parseParam(paramMap, "dumpHeaders", false, null));
* @throws SvcLogicException when URL validation fails
*/
private static void validateUrl(String restapiUrl) throws SvcLogicException {
- if (restapiUrl.contains(",")) {
- String[] urls = restapiUrl.split(",");
+ if (containsMultipleUrls(restapiUrl)) {
+ String[] urls = getMultipleUrls(restapiUrl);
for (String url : urls) {
validateUrl(url);
}
if(p.targetEntity != null && !p.targetEntity.isEmpty()) {
MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, p.targetEntity);
}
- if (p.restapiUrl.contains(",") && retryPolicy == null) {
- String[] urls = p.restapiUrl.split(",");
+ if (containsMultipleUrls(p.restapiUrl) && retryPolicy == null) {
+ String[] urls = getMultipleUrls(p.restapiUrl);
retryPolicy = new RetryPolicy(urls, urls.length * 2);
p.restapiUrl = urls[0];
}
ssl = createSSLContext(p);
}
Client client;
-
if (ssl != null) {
HttpsURLConnection.setDefaultSSLSocketFactory(ssl.getSocketFactory());
client = ClientBuilder.newBuilder().sslContext(ssl).hostnameVerifier((s, sslSession) -> true).build();
} else {
client = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true).build();
}
+
setClientTimeouts(client);
// Needed to support additional HTTP methods such as PATCH
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
protected SSLContext createSSLContext(Parameters p) {
try (FileInputStream in = new FileInputStream(p.keyStoreFileName)) {
- System.setProperty("jsse.enableSNIExtension", "false");
- System.setProperty("javax.net.ssl.trustStore", p.trustStoreFileName);
- System.setProperty("javax.net.ssl.trustStorePassword", p.trustStorePassword);
-
HttpsURLConnection.setDefaultHostnameVerifier((string, ssls) -> true);
-
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance("PKCS12");
char[] pwd = p.keyStorePassword.toCharArray();
ks.load(in, pwd);
kmf.init(ks, pwd);
-
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), null, null);
return ctx;
return defaultValue;
}
+ protected static String[] getMultipleUrls(String restapiUrl) {
+ List<String> urls = new ArrayList<>();
+ int start = 0;
+ for (int i = 0; i < restapiUrl.length(); i++) {
+ if (restapiUrl.charAt(i) == ',') {
+ if (i + 9 < restapiUrl.length()) {
+ String part = restapiUrl.substring(i + 1, i + 9);
+ if (part.equals("https://") || part.startsWith("http://")) {
+ urls.add(restapiUrl.substring(start, i));
+ start = i + 1;
+ }
+ }
+ } else if (i == restapiUrl.length() - 1) {
+ urls.add(restapiUrl.substring(start, i + 1));
+ }
+ }
+ String[] arr = new String[urls.size()];
+ return urls.toArray(arr);
+ }
+
+ protected static boolean containsMultipleUrls(String restapiUrl) {
+ Matcher m = retryPattern.matcher(restapiUrl);
+ return m.matches();
+ }
private static class FileParam {