mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Reworked OSGi support of Smack (SMACK-343)
Because of OSGi, no subproject of Smack (which is the same as a OSGi bundle) must export a package that is already exported by another subproject. Therefore it was necessary to move the TCP and BOSH code into their own packages: org.jivesoftware.smack.(tcp|bosh). OSGi classloader restrictions also made it necessary to create a Declarative Service for smack-extensions, smack-experimental and smack-lagacy (i.e. smack subprojects which should be initialized), in order to initialize them accordingly, as smack-core is, when used in a OSGi environment, unable to load and initialize classes from other smack bundles. OSGi's "Service Component Runtime" (SCR) will now take care of running the initialization code of the particular Smack bundle by activating its Declarative Service. That is also the reason why most initialization related method now have an additional classloader argument. Note that due the refactoring, some ugly changes in XMPPTCPConnection and its PacketReader and PacketWriter where necessary.
This commit is contained in:
parent
541b8b3798
commit
4c76f2652d
39 changed files with 413 additions and 446 deletions
|
@ -406,7 +406,7 @@ public class SASLAuthentication {
|
|||
* @param mechanisms collection of strings with the available SASL mechanism reported
|
||||
* by the server.
|
||||
*/
|
||||
void setAvailableSASLMethods(Collection<String> mechanisms) {
|
||||
public void setAvailableSASLMethods(Collection<String> mechanisms) {
|
||||
this.serverMechanisms = mechanisms;
|
||||
}
|
||||
|
||||
|
@ -429,7 +429,7 @@ public class SASLAuthentication {
|
|||
* @throws IOException If a network error occures while authenticating.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
void challengeReceived(String challenge) throws IOException, NotConnectedException {
|
||||
public void challengeReceived(String challenge) throws IOException, NotConnectedException {
|
||||
currentMechanism.challengeReceived(challenge);
|
||||
}
|
||||
|
||||
|
@ -437,7 +437,7 @@ public class SASLAuthentication {
|
|||
* Notification message saying that SASL authentication was successful. The next step
|
||||
* would be to bind the resource.
|
||||
*/
|
||||
void authenticated() {
|
||||
public void authenticated() {
|
||||
saslNegotiated = true;
|
||||
// Wake up the thread that is waiting in the #authenticate method
|
||||
synchronized (this) {
|
||||
|
@ -452,7 +452,7 @@ public class SASLAuthentication {
|
|||
* @param saslFailure the SASL failure as reported by the server
|
||||
* @see <a href="https://tools.ietf.org/html/rfc6120#section-6.5">RFC6120 6.5</a>
|
||||
*/
|
||||
void authenticationFailed(SASLFailure saslFailure) {
|
||||
public void authenticationFailed(SASLFailure saslFailure) {
|
||||
this.saslFailure = saslFailure;
|
||||
// Wake up the thread that is waiting in the #authenticate method
|
||||
synchronized (this) {
|
||||
|
|
|
@ -311,7 +311,13 @@ public final class SmackConfiguration {
|
|||
return res;
|
||||
}
|
||||
|
||||
public static void processConfigFile(InputStream cfgFileStream, Collection<Exception> exceptions) throws Exception {
|
||||
public static void processConfigFile(InputStream cfgFileStream,
|
||||
Collection<Exception> exceptions) throws Exception {
|
||||
processConfigFile(cfgFileStream, exceptions, SmackConfiguration.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static void processConfigFile(InputStream cfgFileStream,
|
||||
Collection<Exception> exceptions, ClassLoader classLoader) throws Exception {
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(cfgFileStream, "UTF-8");
|
||||
|
@ -319,10 +325,10 @@ public final class SmackConfiguration {
|
|||
do {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (parser.getName().equals("startupClasses")) {
|
||||
parseClassesToLoad(parser, false, exceptions);
|
||||
parseClassesToLoad(parser, false, exceptions, classLoader);
|
||||
}
|
||||
else if (parser.getName().equals("optionalStartupClasses")) {
|
||||
parseClassesToLoad(parser, true, exceptions);
|
||||
parseClassesToLoad(parser, true, exceptions, classLoader);
|
||||
}
|
||||
}
|
||||
eventType = parser.next();
|
||||
|
@ -336,7 +342,9 @@ public final class SmackConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
private static void parseClassesToLoad(XmlPullParser parser, boolean optional, Collection<Exception> exceptions) throws XmlPullParserException, IOException, Exception {
|
||||
private static void parseClassesToLoad(XmlPullParser parser, boolean optional,
|
||||
Collection<Exception> exceptions, ClassLoader classLoader)
|
||||
throws XmlPullParserException, IOException, Exception {
|
||||
final String startName = parser.getName();
|
||||
int eventType;
|
||||
String name;
|
||||
|
@ -350,26 +358,30 @@ public final class SmackConfiguration {
|
|||
}
|
||||
else {
|
||||
try {
|
||||
loadSmackClass(classToLoad, optional);
|
||||
} catch (Exception e) {
|
||||
loadSmackClass(classToLoad, optional, classLoader);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Don't throw the exception if an exceptions collection is given, instead
|
||||
// record it there. This is used for unit testing purposes.
|
||||
if (exceptions != null) {
|
||||
exceptions.add(e);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (! (eventType == XmlPullParser.END_TAG && startName.equals(name)));
|
||||
}
|
||||
while (!(eventType == XmlPullParser.END_TAG && startName.equals(name)));
|
||||
}
|
||||
|
||||
private static void loadSmackClass(String className, boolean optional) throws Exception {
|
||||
private static void loadSmackClass(String className, boolean optional, ClassLoader classLoader) throws Exception {
|
||||
Class<?> initClass;
|
||||
try {
|
||||
// Attempt to load the class so that the class can get initialized
|
||||
initClass = Class.forName(className);
|
||||
// Attempt to load and initialize the class so that all static initializer blocks of
|
||||
// class are executed
|
||||
initClass = Class.forName(className, true, classLoader);
|
||||
}
|
||||
catch (ClassNotFoundException cnfe) {
|
||||
Level logLevel;
|
||||
|
@ -388,8 +400,7 @@ public final class SmackConfiguration {
|
|||
}
|
||||
if (SmackInitializer.class.isAssignableFrom(initClass)) {
|
||||
SmackInitializer initializer = (SmackInitializer) initClass.newInstance();
|
||||
initializer.initialize();
|
||||
List<Exception> exceptions = initializer.getExceptions();
|
||||
List<Exception> exceptions = initializer.initialize();
|
||||
if (exceptions.size() == 0) {
|
||||
LOGGER.log(Level.FINE, "Loaded SmackInitializer " + className);
|
||||
} else {
|
||||
|
|
|
@ -352,7 +352,7 @@ public abstract class XMPPConnection {
|
|||
*/
|
||||
public abstract boolean isSecureConnection();
|
||||
|
||||
abstract void sendPacketInternal(Packet packet) throws NotConnectedException;
|
||||
protected abstract void sendPacketInternal(Packet packet) throws NotConnectedException;
|
||||
|
||||
/**
|
||||
* Returns true if network traffic is being compressed. When using stream compression network
|
||||
|
@ -398,7 +398,7 @@ public abstract class XMPPConnection {
|
|||
* @throws IOException
|
||||
* @throws XMPPException
|
||||
*/
|
||||
abstract void connectInternal() throws SmackException, IOException, XMPPException;
|
||||
protected abstract void connectInternal() throws SmackException, IOException, XMPPException;
|
||||
|
||||
/**
|
||||
* Logs in to the server using the strongest authentication mode supported by
|
||||
|
@ -476,7 +476,7 @@ public abstract class XMPPConnection {
|
|||
* Notification message saying that the server requires the client to bind a
|
||||
* resource to the stream.
|
||||
*/
|
||||
void serverRequiresBinding() {
|
||||
protected void serverRequiresBinding() {
|
||||
synchronized (bindingRequired) {
|
||||
bindingRequired.set(true);
|
||||
bindingRequired.notify();
|
||||
|
@ -488,11 +488,11 @@ public abstract class XMPPConnection {
|
|||
* sessions the client needs to send a Session packet after successfully binding a resource
|
||||
* for the session.
|
||||
*/
|
||||
void serverSupportsSession() {
|
||||
protected void serverSupportsSession() {
|
||||
sessionSupported = true;
|
||||
}
|
||||
|
||||
String bindResourceAndEstablishSession(String resource) throws XMPPErrorException,
|
||||
protected String bindResourceAndEstablishSession(String resource) throws XMPPErrorException,
|
||||
ResourceBindingNotOfferedException, NoResponseException, NotConnectedException {
|
||||
|
||||
synchronized (bindingRequired) {
|
||||
|
@ -537,6 +537,30 @@ public abstract class XMPPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
protected Reader getReader() {
|
||||
return reader;
|
||||
}
|
||||
|
||||
protected Writer getWriter() {
|
||||
return writer;
|
||||
}
|
||||
|
||||
protected void setServiceName(String serviceName) {
|
||||
config.setServiceName(serviceName);
|
||||
}
|
||||
|
||||
protected void setLoginInfo(String username, String password, String resource) {
|
||||
config.setLoginInfo(username, password, resource);
|
||||
}
|
||||
|
||||
protected void serverSupportsAccountCreation() {
|
||||
AccountManager.getInstance(this).setSupportsAccountCreation(true);
|
||||
}
|
||||
|
||||
protected void maybeResolveDns() throws Exception {
|
||||
config.maybeResolveDns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the specified packet to the server.
|
||||
*
|
||||
|
@ -627,6 +651,7 @@ public abstract class XMPPConnection {
|
|||
}
|
||||
return roster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SASLAuthentication manager that is responsible for authenticating with
|
||||
* the server.
|
||||
|
@ -634,7 +659,7 @@ public abstract class XMPPConnection {
|
|||
* @return the SASLAuthentication manager that is responsible for authenticating with
|
||||
* the server.
|
||||
*/
|
||||
public SASLAuthentication getSASLAuthentication() {
|
||||
protected SASLAuthentication getSASLAuthentication() {
|
||||
return saslAuthentication;
|
||||
}
|
||||
|
||||
|
@ -1127,13 +1152,13 @@ public abstract class XMPPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
void callConnectionConnectedListener() {
|
||||
protected void callConnectionConnectedListener() {
|
||||
for (ConnectionListener listener : getConnectionListeners()) {
|
||||
listener.connected(this);
|
||||
}
|
||||
}
|
||||
|
||||
void callConnectionAuthenticatedListener() {
|
||||
protected void callConnectionAuthenticatedListener() {
|
||||
for (ConnectionListener listener : getConnectionListeners()) {
|
||||
listener.authenticated(this);
|
||||
}
|
||||
|
@ -1152,7 +1177,7 @@ public abstract class XMPPConnection {
|
|||
}
|
||||
}
|
||||
|
||||
void callConnectionClosedOnErrorListener(Exception e) {
|
||||
protected void callConnectionClosedOnErrorListener(Exception e) {
|
||||
LOGGER.log(Level.WARNING, "Connection closed with error", e);
|
||||
for (ConnectionListener listener : getConnectionListeners()) {
|
||||
try {
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright the original author or authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.initializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
|
||||
/**
|
||||
* Initializes the Java logging system.
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class LoggingInitializer implements SmackInitializer {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(LoggingInitializer.class.getName());
|
||||
|
||||
private List<Exception> exceptions = new LinkedList<Exception>();
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
try {
|
||||
LogManager.getLogManager().readConfiguration(FileUtils.getStreamForUrl("classpath:org.jivesofware.smack/jul.properties", null));
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.log(Level.WARNING, "Could not initialize Java Logging from default file.", e);
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> getExceptions() {
|
||||
return Collections.unmodifiableList(exceptions);
|
||||
}
|
||||
}
|
|
@ -30,6 +30,6 @@ import org.jivesoftware.smack.SmackConfiguration;
|
|||
*
|
||||
*/
|
||||
public interface SmackInitializer {
|
||||
void initialize();
|
||||
List<Exception> getExceptions();
|
||||
public List<Exception> initialize();
|
||||
public List<Exception> initialize(ClassLoader classLoader);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.initializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.provider.ProviderFileLoader;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
|
||||
/**
|
||||
* Loads the provider file defined by the URL returned by {@link #getProvidersUrl()} and the generic
|
||||
* smack configuration file returned {@link #getConfigUrl()}.
|
||||
*
|
||||
* @author Florian Schmaus
|
||||
*/
|
||||
public abstract class UrlInitializer implements SmackInitializer {
|
||||
private static final Logger LOGGER = Logger.getLogger(UrlInitializer.class.getName());
|
||||
|
||||
/**
|
||||
* A simple wrapper around {@link #initialize} for OSGi, as the activate method of a component
|
||||
* must have a void return type.
|
||||
*/
|
||||
public final void activate() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> initialize() {
|
||||
return initialize(this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> initialize(ClassLoader classLoader) {
|
||||
InputStream is;
|
||||
final List<Exception> exceptions = new LinkedList<Exception>();
|
||||
final String providerUrl = getProvidersUrl();
|
||||
if (providerUrl != null) {
|
||||
try {
|
||||
is = FileUtils.getStreamForUrl(providerUrl, classLoader);
|
||||
|
||||
if (is != null) {
|
||||
LOGGER.log(Level.FINE, "Loading providers for providerUrl [" + providerUrl
|
||||
+ "]");
|
||||
ProviderFileLoader pfl = new ProviderFileLoader(is, classLoader);
|
||||
ProviderManager.addLoader(pfl);
|
||||
exceptions.addAll(pfl.getLoadingExceptions());
|
||||
}
|
||||
else {
|
||||
LOGGER.log(Level.WARNING, "No input stream created for " + providerUrl);
|
||||
exceptions.add(new IOException("No input stream created for " + providerUrl));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Error trying to load provider file " + providerUrl, e);
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
final String configUrl = getConfigUrl();
|
||||
if (configUrl != null) {
|
||||
try {
|
||||
is = FileUtils.getStreamForUrl(configUrl, classLoader);
|
||||
SmackConfiguration.processConfigFile(is, exceptions, classLoader);
|
||||
}
|
||||
catch (Exception e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
protected String getProvidersUrl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getConfigUrl() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright the original author or authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.initializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.provider.ProviderFileLoader;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
|
||||
/**
|
||||
* Loads the provider file defined by the URL returned by {@link #getFilePath()}. This file will be loaded on Smack initialization.
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public abstract class UrlProviderFileInitializer implements SmackInitializer {
|
||||
private static final Logger LOGGER = Logger.getLogger(UrlProviderFileInitializer.class.getName());
|
||||
|
||||
private List<Exception> exceptions = new LinkedList<Exception>();
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
String filePath = getFilePath();
|
||||
|
||||
try {
|
||||
InputStream is = FileUtils.getStreamForUrl(filePath, getClassLoader());
|
||||
|
||||
if (is != null) {
|
||||
LOGGER.log(Level.INFO, "Loading providers for file [" + filePath + "]");
|
||||
ProviderFileLoader pfl = new ProviderFileLoader(is);
|
||||
ProviderManager.addLoader(pfl);
|
||||
exceptions.addAll(pfl.getLoadingExceptions());
|
||||
}
|
||||
else {
|
||||
LOGGER.log(Level.WARNING, "No input stream created for " + filePath);
|
||||
exceptions.add(new IOException("No input stream created for " + filePath));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Error trying to load provider file " + filePath, e);
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> getExceptions() {
|
||||
return Collections.unmodifiableList(exceptions);
|
||||
}
|
||||
|
||||
protected abstract String getFilePath();
|
||||
|
||||
/**
|
||||
* Returns an array of class loaders to load resources from.
|
||||
*
|
||||
* @return an array of ClassLoader instances.
|
||||
*/
|
||||
protected ClassLoader getClassLoader() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.initializer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
|
||||
|
||||
|
@ -26,16 +29,17 @@ import org.jivesoftware.smack.provider.ProviderManager;
|
|||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class VmArgInitializer extends UrlProviderFileInitializer {
|
||||
public class VmArgInitializer extends UrlInitializer {
|
||||
|
||||
protected String getFilePath() {
|
||||
return System.getProperty("smack.provider.file");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
public List<Exception> initialize() {
|
||||
if (getFilePath() != null) {
|
||||
super.initialize();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,8 +45,12 @@ public class ProviderFileLoader implements ProviderLoader {
|
|||
|
||||
private List<Exception> exceptions = new LinkedList<Exception>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ProviderFileLoader(InputStream providerStream) {
|
||||
this(providerStream, ProviderFileLoader.class.getClassLoader());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ProviderFileLoader(InputStream providerStream, ClassLoader classLoader) {
|
||||
iqProviders = new ArrayList<IQProviderInfo>();
|
||||
extProviders = new ArrayList<ExtensionProviderInfo>();
|
||||
|
||||
|
@ -73,13 +77,13 @@ public class ProviderFileLoader implements ProviderLoader {
|
|||
String className = parser.nextText();
|
||||
|
||||
try {
|
||||
final Class<?> provider = classLoader.loadClass(className);
|
||||
// Attempt to load the provider class and then create
|
||||
// a new instance if it's an IQProvider. Otherwise, if it's
|
||||
// an IQ class, add the class object itself, then we'll use
|
||||
// reflection later to create instances of the class.
|
||||
if ("iqProvider".equals(typeName)) {
|
||||
// Add the provider to the map.
|
||||
Class<?> provider = Class.forName(className);
|
||||
|
||||
if (IQProvider.class.isAssignableFrom(provider)) {
|
||||
iqProviders.add(new IQProviderInfo(elementName, namespace, (IQProvider) provider.newInstance()));
|
||||
|
@ -94,7 +98,6 @@ public class ProviderFileLoader implements ProviderLoader {
|
|||
// a PacketExtension, add the class object itself and
|
||||
// then we'll use reflection later to create instances
|
||||
// of the class.
|
||||
Class<?> provider = Class.forName(className);
|
||||
if (PacketExtensionProvider.class.isAssignableFrom(provider)) {
|
||||
extProviders.add(new ExtensionProviderInfo(elementName, namespace, (PacketExtensionProvider) provider.newInstance()));
|
||||
}
|
||||
|
|
|
@ -46,7 +46,10 @@ public final class FileUtils {
|
|||
|
||||
if (fileUri.getScheme().equals("classpath")) {
|
||||
// Get an array of class loaders to try loading the providers files from.
|
||||
ClassLoader[] classLoaders = getClassLoaders();
|
||||
List<ClassLoader> classLoaders = getClassLoaders();
|
||||
if (loader != null) {
|
||||
classLoaders.add(0, loader);
|
||||
}
|
||||
for (ClassLoader classLoader : classLoaders) {
|
||||
InputStream is = classLoader.getResourceAsStream(fileUri.getSchemeSpecificPart());
|
||||
|
||||
|
@ -64,21 +67,21 @@ public final class FileUtils {
|
|||
/**
|
||||
* Returns default classloaders.
|
||||
*
|
||||
* @return an array of ClassLoader instances.
|
||||
* @return a List of ClassLoader instances.
|
||||
*/
|
||||
public static ClassLoader[] getClassLoaders() {
|
||||
public static List<ClassLoader> getClassLoaders() {
|
||||
ClassLoader[] classLoaders = new ClassLoader[2];
|
||||
classLoaders[0] = FileUtils.class.getClassLoader();
|
||||
classLoaders[1] = Thread.currentThread().getContextClassLoader();
|
||||
// Clean up possible null values. Note that #getClassLoader may return a null value.
|
||||
List<ClassLoader> loaders = new ArrayList<ClassLoader>();
|
||||
|
||||
// Clean up possible null values. Note that #getClassLoader may return a null value.
|
||||
List<ClassLoader> loaders = new ArrayList<ClassLoader>(classLoaders.length);
|
||||
for (ClassLoader classLoader : classLoaders) {
|
||||
if (classLoader != null) {
|
||||
loaders.add(classLoader);
|
||||
}
|
||||
}
|
||||
return loaders.toArray(new ClassLoader[loaders.size()]);
|
||||
return loaders;
|
||||
}
|
||||
|
||||
public static boolean addLines(String url, Set<String> set) throws MalformedURLException, IOException {
|
||||
|
|
|
@ -8,12 +8,9 @@
|
|||
</startupClasses>
|
||||
|
||||
<optionalStartupClasses>
|
||||
<className>org.jivesoftware.smack.util.dns.JavaxResolver</className>
|
||||
<className>org.jivesoftware.smackx.ExtensionsProviderInitializer</className>
|
||||
<className>org.jivesoftware.smackx.ExtensionsStartupClasses</className>
|
||||
<className>org.jivesoftware.smackx.ExperimentalProviderInitializer</className>
|
||||
<className>org.jivesoftware.smackx.ExperimentalStartupClasses</className>
|
||||
<className>org.jivesoftware.smackx.WorkgroupProviderInitializer</className>
|
||||
<className>org.jivesoftware.smackx.LegacyProviderInitializer</className>
|
||||
<className>org.jivesoftware.smack.util.dns.javax.JavaxResolver</className>
|
||||
<className>org.jivesoftware.smack.initializer.extensions.ExtensionsInitializer</className>
|
||||
<className>org.jivesoftware.smack.initializer.experimental.ExperimentalInitializer</className>
|
||||
<className>org.jivesoftware.smack.initializer.legacy.LegacyInitializer</className>
|
||||
</optionalStartupClasses>
|
||||
</smack>
|
||||
|
|
|
@ -74,7 +74,7 @@ public class DummyConnection extends XMPPConnection {
|
|||
}
|
||||
|
||||
@Override
|
||||
void connectInternal() {
|
||||
protected void connectInternal() {
|
||||
connectionID = "dummy-" + new Random(new Date().getTime()).nextInt();
|
||||
|
||||
if (reconnect) {
|
||||
|
@ -185,7 +185,7 @@ public class DummyConnection extends XMPPConnection {
|
|||
}
|
||||
|
||||
@Override
|
||||
void sendPacketInternal(Packet packet) {
|
||||
protected void sendPacketInternal(Packet packet) {
|
||||
if (SmackConfiguration.DEBUG_ENABLED) {
|
||||
System.out.println("[SEND]: " + packet.toXML());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue