Skip to content

Commit

Permalink
Merge pull request #76 from Evolveum/url-to-uri
Browse files Browse the repository at this point in the history
Use URI instead of URL to avoid domain name resolution for maps
  • Loading branch information
semancik committed Apr 9, 2018
2 parents 2b4660c + 6772472 commit 594e8e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.security.Key;
import java.util.Arrays;
Expand Down Expand Up @@ -172,7 +173,7 @@ public class ConnectorFactoryConnIdImpl implements ConnectorFactory {

private ConnectorInfoManagerFactory connectorInfoManagerFactory;
private ConnectorInfoManager localConnectorInfoManager;
private Set<URL> bundleURLs;
private Set<URI> bundleURLs;
private Set<ConnectorType> localConnectorTypes = null;

@Autowired(required = true)
Expand Down Expand Up @@ -213,7 +214,7 @@ public void initialize() {
bundleURLs.addAll(scanDirectory(dir));
}

for (URL u : bundleURLs) {
for (URI u : bundleURLs) {
LOGGER.debug("ICF bundle URL : {}", u);
}

Expand Down Expand Up @@ -543,8 +544,8 @@ private ConnectorInfoManager getRemoteConnectorInfoManager(ConnectorHostType hos
*
* @return Set of all bundle URL
*/
private Set<URL> scanClassPathForBundles() {
Set<URL> bundle = new HashSet<>();
private Set<URI> scanClassPathForBundles() {
Set<URI> bundle = new HashSet<>();

// scan class path for bundles
Enumeration<URL> en = null;
Expand Down Expand Up @@ -595,7 +596,11 @@ private Set<URL> scanClassPathForBundles() {

URL tmp = new URL(toUrl(upath.substring(0, upath.lastIndexOf("!"))));
if (isThisBundleCompatible(tmp)) {
bundle.add(tmp);
try {
bundle.add(tmp.toURI());
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
} else {
LOGGER.warn("Skip loading ICF bundle {} due error occured", tmp);
}
Expand Down Expand Up @@ -623,23 +628,24 @@ private String toUrl(String string) {
* @param path
* @return
*/
private Set<URL> scanDirectory(String path) {
private Set<URI> scanDirectory(String path) {

// Prepare return object
Set<URL> bundle = new HashSet<>();
// COnvert path to object File
Set<URI> bundle = new HashSet<>();
// Convert path to object File
File dir = new File(path);

// Test if this path is single jar or need to do deep examination
if (isThisJarFileBundle(dir)) {
try {
if (isThisBundleCompatible(dir.toURI().toURL())) {
bundle.add(dir.toURI().toURL());
final URI uri = dir.toURI();
if (isThisBundleCompatible(uri.toURL())) {
bundle.add(uri);
} else {
LOGGER.warn("Skip loading budle {} due error occured", dir.toURI().toURL());
LOGGER.warn("Skip loading bundle {} due error occurred", uri.toURL());
}
} catch (MalformedURLException e) {
LOGGER.error("This never happend we hope.", e);
LOGGER.error("This never happened we hope.", e);
throw new SystemException(e);
}
return bundle;
Expand All @@ -657,17 +663,18 @@ private Set<URL> scanDirectory(String path) {
return bundle;
}

// test all entires for bundle
// test all entries for bundle
for (int i = 0; i < dirEntries.length; i++) {
if (isThisJarFileBundle(dirEntries[i])) {
try {
if (isThisBundleCompatible(dirEntries[i].toURI().toURL())) {
bundle.add(dirEntries[i].toURI().toURL());
final URI uri = dirEntries[i].toURI();
if (isThisBundleCompatible(uri.toURL())) {
bundle.add(uri);
} else {
LOGGER.warn("Skip loading budle {} due error occured", dirEntries[i].toURI().toURL());
LOGGER.warn("Skip loading bundle {} due error occurred", uri.toURL());
}
} catch (MalformedURLException e) {
LOGGER.error("This never happend we hope.", e);
LOGGER.error("This never happened we hope.", e);
throw new SystemException(e);
}
}
Expand Down
Expand Up @@ -148,7 +148,7 @@ private void updateConfigurationBooleanProperty(Configuration configuration, Pro
if (value == null) {
return;
}
boolean val = new Boolean(value).booleanValue();
boolean val = Boolean.valueOf(value);
LOGGER.info("Overriding loaded configuration with value read from system properties: {}={}", propertyName, val);
configuration.setProperty(propertyName, val);
}
Expand Down

0 comments on commit 594e8e2

Please sign in to comment.