in framework/src/main/java/org/apache/felix/framework/URLHandlers.java [167:353]
private URLHandlers()
{
m_sm = new SecurityManagerEx();
synchronized (URL.class)
{
URLStreamHandlerFactory currentFactory = null;
try
{
currentFactory = (URLStreamHandlerFactory) m_secureAction.swapStaticFieldIfNotClass(URL.class,
URLStreamHandlerFactory.class, URLHANDLERS_CLASS, "streamHandlerLock");
}
catch (Throwable ex)
{
// Ignore, this is a best effort (maybe log it or something)
}
init("file", currentFactory);
init("ftp", currentFactory);
init("http", currentFactory);
init("https", currentFactory);
// Try to preload the jrt handler as we need it from the jvm on java > 8
if (getFromCache(m_builtIn, "jrt") == null)
{
try
{
// Try to get it directly from the URL class to if possible
Method getURLStreamHandler = m_secureAction.getDeclaredMethod(URL.class,"getURLStreamHandler", new Class[]{String.class});
URLStreamHandler handler = (URLStreamHandler) m_secureAction.invoke(getURLStreamHandler, null, new Object[]{"jrt"});
addToCache(m_builtIn, "jrt", handler);
}
catch (Throwable ex)
{
// Ignore, this is a best effort and try to load the normal way
try
{
getBuiltInStreamHandler("jrt", currentFactory);
}
catch (Throwable ex2)
{
// Ignore, this is a best efforts
}
}
}
// Try to preload the jar handler as we need it from the jvm on java > 8
if (getFromCache(m_builtIn, "jar") == null)
{
try
{
// Try to get it directly from the URL class to if possible
Method getURLStreamHandler = m_secureAction.getDeclaredMethod(URL.class,"getURLStreamHandler", new Class[]{String.class});
URLStreamHandler handler = (URLStreamHandler) m_secureAction.invoke(getURLStreamHandler, null, new Object[]{"jar"});
addToCache(m_builtIn, "jar", handler);
}
catch (Throwable ex)
{
// Ignore, this is a best effort
try
{
getBuiltInStreamHandler("jar", currentFactory);
}
catch (Throwable ex2)
{
// Ignore, this is a best effort (maybe log it or something)
}
}
}
if (currentFactory != null)
{
try
{
URL.setURLStreamHandlerFactory(currentFactory);
}
catch (Throwable ex)
{
// Ignore, this is a best effort (maybe log it or something)
}
}
try
{
URL.setURLStreamHandlerFactory(this);
m_streamHandlerFactory = this;
m_rootURLHandlers = this;
// try to flush the cache (gnu/classpath doesn't do it itself)
try
{
m_secureAction.flush(URL.class, URL.class);
}
catch (Throwable t)
{
// Not much we can do
}
}
catch (Error err)
{
try
{
// there already is a factory set so try to swap it with ours.
m_streamHandlerFactory = (URLStreamHandlerFactory)
m_secureAction.swapStaticFieldIfNotClass(URL.class,
URLStreamHandlerFactory.class, URLHANDLERS_CLASS, "streamHandlerLock");
if (m_streamHandlerFactory == null)
{
throw err;
}
if (!m_streamHandlerFactory.getClass().getName().equals(URLHANDLERS_CLASS.getName()))
{
URL.setURLStreamHandlerFactory(this);
m_rootURLHandlers = this;
}
else if (URLHANDLERS_CLASS != m_streamHandlerFactory.getClass())
{
try
{
m_secureAction.invoke(
m_secureAction.getDeclaredMethod(m_streamHandlerFactory.getClass(),
"registerFrameworkListsForContextSearch",
new Class[]{ClassLoader.class, List.class}),
m_streamHandlerFactory, new Object[]{ URLHANDLERS_CLASS.getClassLoader(),
m_frameworks });
m_rootURLHandlers = m_streamHandlerFactory;
}
catch (Exception ex)
{
throw new RuntimeException(ex.getMessage());
}
}
}
catch (Exception e)
{
throw err;
}
}
try
{
URLConnection.setContentHandlerFactory(this);
m_contentHandlerFactory = this;
// try to flush the cache (gnu/classpath doesn't do it itself)
try
{
m_secureAction.flush(URLConnection.class, URLConnection.class);
}
catch (Throwable t)
{
// Not much we can do
}
}
catch (Error err)
{
// there already is a factory set so try to swap it with ours.
try
{
m_contentHandlerFactory = (ContentHandlerFactory)
m_secureAction.swapStaticFieldIfNotClass(
URLConnection.class, ContentHandlerFactory.class,
URLHANDLERS_CLASS, null);
if (m_contentHandlerFactory == null)
{
throw err;
}
if (!m_contentHandlerFactory.getClass().getName().equals(
URLHANDLERS_CLASS.getName()))
{
URLConnection.setContentHandlerFactory(this);
}
}
catch (Exception ex)
{
throw err;
}
}
}
// are we not the new root?
if (!((m_streamHandlerFactory == this) || !URLHANDLERS_CLASS.getName().equals(
m_streamHandlerFactory.getClass().getName())))
{
m_sm = null;
m_protocolToURL.clear();
m_builtIn.clear();
}
}