mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 18:29:45 +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
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
package org.jivesoftware.smack.tcp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -28,6 +28,8 @@ import org.jivesoftware.smack.sasl.SASLMechanism.Challenge;
|
|||
import org.jivesoftware.smack.sasl.SASLMechanism.SASLFailure;
|
||||
import org.jivesoftware.smack.sasl.SASLMechanism.Success;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
|
||||
import org.jivesoftware.smack.XMPPException.StreamErrorException;
|
||||
|
@ -80,7 +82,7 @@ class PacketReader {
|
|||
parsePackets(this);
|
||||
}
|
||||
};
|
||||
readerThread.setName("Smack Packet Reader (" + connection.connectionCounterValue + ")");
|
||||
readerThread.setName("Smack Packet Reader (" + connection.getConnectionCounter() + ")");
|
||||
readerThread.setDaemon(true);
|
||||
|
||||
resetParser();
|
||||
|
@ -131,7 +133,7 @@ class PacketReader {
|
|||
try {
|
||||
parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(connection.reader);
|
||||
parser.setInput(connection.getReader());
|
||||
}
|
||||
catch (XmlPullParserException e) {
|
||||
throw new SmackException(e);
|
||||
|
@ -205,7 +207,7 @@ class PacketReader {
|
|||
}
|
||||
else if (parser.getAttributeName(i).equals("from")) {
|
||||
// Use the server name that the server says that it is.
|
||||
connection.config.setServiceName(parser.getAttributeValue(i));
|
||||
connection.setServiceName(parser.getAttributeValue(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +344,7 @@ class PacketReader {
|
|||
connection.setAvailableCompressionMethods(PacketParserUtils.parseCompressionMethods(parser));
|
||||
}
|
||||
else if (parser.getName().equals("register")) {
|
||||
AccountManager.getInstance(connection).setSupportsAccountCreation(true);
|
||||
connection.serverSupportsAccountCreation();
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
package org.jivesoftware.smack.tcp;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
|
@ -67,7 +67,7 @@ class PacketWriter {
|
|||
* is invoked if the connection is disconnected by an error.
|
||||
*/
|
||||
protected void init() {
|
||||
this.writer = connection.writer;
|
||||
writer = connection.getWriter();
|
||||
done = false;
|
||||
shutdownDone.set(false);
|
||||
|
||||
|
@ -77,7 +77,7 @@ class PacketWriter {
|
|||
writePackets(this);
|
||||
}
|
||||
};
|
||||
writerThread.setName("Smack Packet Writer (" + connection.connectionCounterValue + ")");
|
||||
writerThread.setName("Smack Packet Writer (" + connection.getConnectionCounter() + ")");
|
||||
writerThread.setDaemon(true);
|
||||
}
|
||||
|
|
@ -14,11 +14,20 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack;
|
||||
package org.jivesoftware.smack.tcp;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.ConnectionListener;
|
||||
import org.jivesoftware.smack.SASLAuthentication;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.SmackException.ConnectionException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
|
@ -44,7 +53,9 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.Socket;
|
||||
import java.security.KeyStore;
|
||||
|
@ -248,7 +259,7 @@ public class XMPPTCPConnection extends XMPPConnection {
|
|||
if (response != null) {
|
||||
this.user = response;
|
||||
// Update the serviceName with the one returned by the server
|
||||
config.setServiceName(StringUtils.parseServer(response));
|
||||
setServiceName(StringUtils.parseServer(response));
|
||||
}
|
||||
else {
|
||||
this.user = username + "@" + getServiceName();
|
||||
|
@ -267,7 +278,7 @@ public class XMPPTCPConnection extends XMPPConnection {
|
|||
}
|
||||
|
||||
// Stores the authentication for future reconnection
|
||||
config.setLoginInfo(username, password, resource);
|
||||
setLoginInfo(username, password, resource);
|
||||
|
||||
// If debugging is enabled, change the the debug window title to include the
|
||||
// name we are now logged-in as.
|
||||
|
@ -299,7 +310,7 @@ public class XMPPTCPConnection extends XMPPConnection {
|
|||
// Set the user value.
|
||||
this.user = response;
|
||||
// Update the serviceName with the one returned by the server
|
||||
config.setServiceName(StringUtils.parseServer(response));
|
||||
setServiceName(StringUtils.parseServer(response));
|
||||
|
||||
// If compression is enabled then request the server to use stream compression
|
||||
if (config.isCompressionEnabled()) {
|
||||
|
@ -375,14 +386,15 @@ public class XMPPTCPConnection extends XMPPConnection {
|
|||
writer = null;
|
||||
}
|
||||
|
||||
void sendPacketInternal(Packet packet) throws NotConnectedException {
|
||||
@Override
|
||||
protected void sendPacketInternal(Packet packet) throws NotConnectedException {
|
||||
packetWriter.sendPacket(packet);
|
||||
}
|
||||
|
||||
private void connectUsingConfiguration(ConnectionConfiguration config) throws SmackException, IOException {
|
||||
Exception exception = null;
|
||||
try {
|
||||
config.maybeResolveDns();
|
||||
maybeResolveDns();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new SmackException(e);
|
||||
|
@ -782,7 +794,7 @@ public class XMPPTCPConnection extends XMPPConnection {
|
|||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
void connectInternal() throws SmackException, IOException, XMPPException {
|
||||
protected void connectInternal() throws SmackException, IOException, XMPPException {
|
||||
// Establishes the connection, readers and writers
|
||||
connectUsingConfiguration(config);
|
||||
// TODO is there a case where connectUsing.. does not throw an exception but connected is
|
||||
|
@ -823,10 +835,70 @@ public class XMPPTCPConnection extends XMPPConnection {
|
|||
callConnectionClosedOnErrorListener(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processPacket(Packet packet) {
|
||||
super.processPacket(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Reader getReader() {
|
||||
return super.getReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Writer getWriter() {
|
||||
return super.getWriter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void throwConnectionExceptionOrNoResponse() throws IOException, NoResponseException {
|
||||
super.throwConnectionExceptionOrNoResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setServiceName(String serviceName) {
|
||||
super.setServiceName(serviceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serverRequiresBinding() {
|
||||
super.serverRequiresBinding();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setServiceCapsNode(String node) {
|
||||
super.setServiceCapsNode(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serverSupportsSession() {
|
||||
super.serverSupportsSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setRosterVersioningSupported() {
|
||||
super.setRosterVersioningSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serverSupportsAccountCreation() {
|
||||
super.serverSupportsAccountCreation();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SASLAuthentication getSASLAuthentication() {
|
||||
return super.getSASLAuthentication();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionConfiguration getConfiguration() {
|
||||
return super.getConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a notification indicating that the connection was reconnected successfully.
|
||||
*/
|
||||
protected void notifyReconnection() {
|
||||
private void notifyReconnection() {
|
||||
// Notify connection listeners of the reconnection.
|
||||
for (ConnectionListener listener : getConnectionListeners()) {
|
||||
try {
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack;
|
||||
package org.jivesoftware.smack.tcp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
@ -34,7 +34,7 @@ public class PacketWriterTest {
|
|||
/**
|
||||
* Make sure that packet writer does block once the queue reaches
|
||||
* {@link PacketWriter#QUEUE_SIZE} and that
|
||||
* {@link PacketWriter#sendPacket(org.jivesoftware.smack.packet.Packet)} does unblock after the
|
||||
* {@link PacketWriter#sendPacket(org.jivesoftware.smack.tcp.packet.Packet)} does unblock after the
|
||||
* interrupt.
|
||||
*
|
||||
* @throws InterruptedException
|
|
@ -14,10 +14,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack;
|
||||
package org.jivesoftware.smack.tcp;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.jivesoftware.smack.Roster;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue