mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-23 02:58:00 +01:00
Additional refactoring work.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4539 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
f57ff10ad9
commit
9895123ff3
11 changed files with 138 additions and 374 deletions
|
@ -28,10 +28,7 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Registration;
|
import org.jivesoftware.smack.packet.Registration;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows creation and management of accounts on an XMPP server.
|
* Allows creation and management of accounts on an XMPP server.
|
||||||
|
@ -73,8 +70,8 @@ public class AccountManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for the (String) names of the required account attributes.
|
* Returns an unmodifiable collection of the names of the required account attributes.
|
||||||
* All attributes must be set when creating new accounts. The standard
|
* All attributes must be set when creating new accounts. The standard set of possible
|
||||||
* attributes are as follows: <ul>
|
* attributes are as follows: <ul>
|
||||||
* <li>name -- the user's name.
|
* <li>name -- the user's name.
|
||||||
* <li>first -- the user's first name.
|
* <li>first -- the user's first name.
|
||||||
|
@ -96,20 +93,20 @@ public class AccountManager {
|
||||||
*
|
*
|
||||||
* @return the required account attributes.
|
* @return the required account attributes.
|
||||||
*/
|
*/
|
||||||
public Iterator<String> getAccountAttributes() {
|
public Collection<String> getAccountAttributes() {
|
||||||
try {
|
try {
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
getRegistrationInfo();
|
getRegistrationInfo();
|
||||||
}
|
}
|
||||||
Map<String, String> attributes = info.getAttributes();
|
Map<String, String> attributes = info.getAttributes();
|
||||||
if (attributes != null) {
|
if (attributes != null) {
|
||||||
return attributes.keySet().iterator();
|
return Collections.unmodifiableSet(attributes.keySet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (XMPPException xe) {
|
catch (XMPPException xe) {
|
||||||
xe.printStackTrace();
|
xe.printStackTrace();
|
||||||
}
|
}
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,8 +167,7 @@ public class AccountManager {
|
||||||
}
|
}
|
||||||
// Create a map for all the required attributes, but give them blank values.
|
// Create a map for all the required attributes, but give them blank values.
|
||||||
Map<String, String> attributes = new HashMap<String, String>();
|
Map<String, String> attributes = new HashMap<String, String>();
|
||||||
for (Iterator<String> i=getAccountAttributes(); i.hasNext(); ) {
|
for (String attributeName : getAccountAttributes()) {
|
||||||
String attributeName = i.next();
|
|
||||||
attributes.put(attributeName, "");
|
attributes.put(attributeName, "");
|
||||||
}
|
}
|
||||||
createAccount(username, password, attributes);
|
createAccount(username, password, attributes);
|
||||||
|
|
|
@ -362,13 +362,7 @@ class PacketWriter {
|
||||||
stream.append(" to=\"").append(connection.serviceName).append("\"");
|
stream.append(" to=\"").append(connection.serviceName).append("\"");
|
||||||
stream.append(" xmlns=\"jabber:client\"");
|
stream.append(" xmlns=\"jabber:client\"");
|
||||||
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\"");
|
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\"");
|
||||||
if (connection instanceof SSLXMPPConnection) {
|
stream.append(" version=\"1.0\">");
|
||||||
// Old SSL connections should not include indicate XMPP 1.0 compliance
|
|
||||||
stream.append(">");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stream.append(" version=\"1.0\">");
|
|
||||||
}
|
|
||||||
writer.write(stream.toString());
|
writer.write(stream.toString());
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,40 +38,21 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
*
|
*
|
||||||
* Others users may attempt to subscribe to this user using a subscription request. Three
|
* Others users may attempt to subscribe to this user using a subscription request. Three
|
||||||
* modes are supported for handling these requests: <ul>
|
* modes are supported for handling these requests: <ul>
|
||||||
* <li> SUBSCRIPTION_ACCEPT_ALL -- accept all subscription requests.
|
* <li>{@link SubscriptionMode#accept_all accept_all} -- accept all subscription requests.</li>
|
||||||
* <li> SUBSCRIPTION_REJECT_ALL -- reject all subscription requests.
|
* <li>{@link SubscriptionMode#reject_all reject_all} -- reject all subscription requests.</li>
|
||||||
* <li> SUBSCRIPTION_MANUAL -- manually process all subscription requests. </ul>
|
* <li>{@link SubscriptionMode#manual manual} -- manually process all subscription requests.</li>
|
||||||
|
* </ul>
|
||||||
*
|
*
|
||||||
* @see XMPPConnection#getRoster()
|
* @see XMPPConnection#getRoster()
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public class Roster {
|
public class Roster {
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatically accept all subscription and unsubscription requests. This is
|
|
||||||
* the default mode and is suitable for simple client. More complex client will
|
|
||||||
* likely wish to handle subscription requests manually.
|
|
||||||
*/
|
|
||||||
public static final int SUBSCRIPTION_ACCEPT_ALL = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatically reject all subscription requests.
|
|
||||||
*/
|
|
||||||
public static final int SUBSCRIPTION_REJECT_ALL = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subscription requests are ignored, which means they must be manually
|
|
||||||
* processed by registering a listener for presence packets and then looking
|
|
||||||
* for any presence requests that have the type Presence.Type.SUBSCRIBE or
|
|
||||||
* Presence.Type.UNSUBSCRIBE.
|
|
||||||
*/
|
|
||||||
public static final int SUBSCRIPTION_MANUAL = 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default subscription processing mode to use when a Roster is created. By default
|
* The default subscription processing mode to use when a Roster is created. By default
|
||||||
* all subscription requests are automatically accepted.
|
* all subscription requests are automatically accepted.
|
||||||
*/
|
*/
|
||||||
private static int defaultSubscriptionMode = SUBSCRIPTION_ACCEPT_ALL;
|
private static SubscriptionMode defaultSubscriptionMode = SubscriptionMode.accept_all;
|
||||||
|
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
private final Map<String, RosterGroup> groups;
|
private final Map<String, RosterGroup> groups;
|
||||||
|
@ -83,17 +64,17 @@ public class Roster {
|
||||||
// has been recieved and processed.
|
// has been recieved and processed.
|
||||||
boolean rosterInitialized = false;
|
boolean rosterInitialized = false;
|
||||||
|
|
||||||
private int subscriptionMode = getDefaultSubscriptionMode();
|
private SubscriptionMode subscriptionMode = getDefaultSubscriptionMode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default subscription processing mode to use when a new Roster is created. The
|
* Returns the default subscription processing mode to use when a new Roster is created. The
|
||||||
* subscription processing mode dictates what action Smack will take when subscription
|
* subscription processing mode dictates what action Smack will take when subscription
|
||||||
* requests from other users are made. The default subscription mode
|
* requests from other users are made. The default subscription mode
|
||||||
* is {@link #SUBSCRIPTION_ACCEPT_ALL}.
|
* is {@link SubscriptionMode#accept_all}.
|
||||||
*
|
*
|
||||||
* @return the default subscription mode to use for new Rosters
|
* @return the default subscription mode to use for new Rosters
|
||||||
*/
|
*/
|
||||||
public static int getDefaultSubscriptionMode() {
|
public static SubscriptionMode getDefaultSubscriptionMode() {
|
||||||
return defaultSubscriptionMode;
|
return defaultSubscriptionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +82,11 @@ public class Roster {
|
||||||
* Sets the default subscription processing mode to use when a new Roster is created. The
|
* Sets the default subscription processing mode to use when a new Roster is created. The
|
||||||
* subscription processing mode dictates what action Smack will take when subscription
|
* subscription processing mode dictates what action Smack will take when subscription
|
||||||
* requests from other users are made. The default subscription mode
|
* requests from other users are made. The default subscription mode
|
||||||
* is {@link #SUBSCRIPTION_ACCEPT_ALL}.
|
* is {@link SubscriptionMode#accept_all}.
|
||||||
*
|
*
|
||||||
* @param subscriptionMode the default subscription mode to use for new Rosters.
|
* @param subscriptionMode the default subscription mode to use for new Rosters.
|
||||||
*/
|
*/
|
||||||
public static void setDefaultSubscriptionMode(int subscriptionMode) {
|
public static void setDefaultSubscriptionMode(SubscriptionMode subscriptionMode) {
|
||||||
defaultSubscriptionMode = subscriptionMode;
|
defaultSubscriptionMode = subscriptionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +113,7 @@ public class Roster {
|
||||||
/**
|
/**
|
||||||
* Returns the subscription processing mode, which dictates what action
|
* Returns the subscription processing mode, which dictates what action
|
||||||
* Smack will take when subscription requests from other users are made.
|
* Smack will take when subscription requests from other users are made.
|
||||||
* The default subscription mode is {@link #SUBSCRIPTION_ACCEPT_ALL}.<p>
|
* The default subscription mode is {@link SubscriptionMode#accept_all}.<p>
|
||||||
*
|
*
|
||||||
* If using the manual mode, a PacketListener should be registered that
|
* If using the manual mode, a PacketListener should be registered that
|
||||||
* listens for Presence packets that have a type of
|
* listens for Presence packets that have a type of
|
||||||
|
@ -140,14 +121,14 @@ public class Roster {
|
||||||
*
|
*
|
||||||
* @return the subscription mode.
|
* @return the subscription mode.
|
||||||
*/
|
*/
|
||||||
public int getSubscriptionMode() {
|
public SubscriptionMode getSubscriptionMode() {
|
||||||
return subscriptionMode;
|
return subscriptionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the subscription processing mode, which dictates what action
|
* Sets the subscription processing mode, which dictates what action
|
||||||
* Smack will take when subscription requests from other users are made.
|
* Smack will take when subscription requests from other users are made.
|
||||||
* The default subscription mode is {@link #SUBSCRIPTION_ACCEPT_ALL}.<p>
|
* The default subscription mode is {@link SubscriptionMode#accept_all}.<p>
|
||||||
*
|
*
|
||||||
* If using the manual mode, a PacketListener should be registered that
|
* If using the manual mode, a PacketListener should be registered that
|
||||||
* listens for Presence packets that have a type of
|
* listens for Presence packets that have a type of
|
||||||
|
@ -155,13 +136,7 @@ public class Roster {
|
||||||
*
|
*
|
||||||
* @param subscriptionMode the subscription mode.
|
* @param subscriptionMode the subscription mode.
|
||||||
*/
|
*/
|
||||||
public void setSubscriptionMode(int subscriptionMode) {
|
public void setSubscriptionMode(SubscriptionMode subscriptionMode) {
|
||||||
if (subscriptionMode != SUBSCRIPTION_ACCEPT_ALL &&
|
|
||||||
subscriptionMode != SUBSCRIPTION_REJECT_ALL &&
|
|
||||||
subscriptionMode != SUBSCRIPTION_MANUAL)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Invalid mode.");
|
|
||||||
}
|
|
||||||
this.subscriptionMode = subscriptionMode;
|
this.subscriptionMode = subscriptionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,15 +317,14 @@ public class Roster {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for the unfiled roster entries. An unfiled entry is
|
* Returns an unmodifiable collection for the unfiled roster entries. An unfiled entry is
|
||||||
* an entry that doesn't belong to any groups.
|
* an entry that doesn't belong to any groups.
|
||||||
*
|
*
|
||||||
* @return an iterator the unfiled roster entries.
|
* @return the unfiled roster entries.
|
||||||
*/
|
*/
|
||||||
public Iterator<RosterEntry> getUnfiledEntries() {
|
public Collection<RosterEntry> getUnfiledEntries() {
|
||||||
synchronized (unfiledEntries) {
|
synchronized (unfiledEntries) {
|
||||||
return Collections.unmodifiableList(new ArrayList<RosterEntry>(unfiledEntries))
|
return Collections.unmodifiableList(new ArrayList<RosterEntry>(unfiledEntries));
|
||||||
.iterator();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,6 +549,32 @@ public class Roster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enumeration for the subscription mode options.
|
||||||
|
*/
|
||||||
|
public enum SubscriptionMode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically accept all subscription and unsubscription requests. This is
|
||||||
|
* the default mode and is suitable for simple client. More complex client will
|
||||||
|
* likely wish to handle subscription requests manually.
|
||||||
|
*/
|
||||||
|
accept_all,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically reject all subscription requests.
|
||||||
|
*/
|
||||||
|
reject_all,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscription requests are ignored, which means they must be manually
|
||||||
|
* processed by registering a listener for presence packets and then looking
|
||||||
|
* for any presence requests that have the type Presence.Type.SUBSCRIBE or
|
||||||
|
* Presence.Type.UNSUBSCRIBE.
|
||||||
|
*/
|
||||||
|
manual
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for all presence packets and processes them.
|
* Listens for all presence packets and processes them.
|
||||||
*/
|
*/
|
||||||
|
@ -630,13 +630,13 @@ public class Roster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (presence.getType() == Presence.Type.subscribe) {
|
else if (presence.getType() == Presence.Type.subscribe) {
|
||||||
if (subscriptionMode == SUBSCRIPTION_ACCEPT_ALL) {
|
if (subscriptionMode == SubscriptionMode.accept_all) {
|
||||||
// Accept all subscription requests.
|
// Accept all subscription requests.
|
||||||
Presence response = new Presence(Presence.Type.subscribed);
|
Presence response = new Presence(Presence.Type.subscribed);
|
||||||
response.setTo(presence.getFrom());
|
response.setTo(presence.getFrom());
|
||||||
connection.sendPacket(response);
|
connection.sendPacket(response);
|
||||||
}
|
}
|
||||||
else if (subscriptionMode == SUBSCRIPTION_REJECT_ALL) {
|
else if (subscriptionMode == SubscriptionMode.reject_all) {
|
||||||
// Reject all subscription requests.
|
// Reject all subscription requests.
|
||||||
Presence response = new Presence(Presence.Type.unsubscribed);
|
Presence response = new Presence(Presence.Type.unsubscribed);
|
||||||
response.setTo(presence.getFrom());
|
response.setTo(presence.getFrom());
|
||||||
|
@ -645,7 +645,7 @@ public class Roster {
|
||||||
// Otherwise, in manual mode so ignore.
|
// Otherwise, in manual mode so ignore.
|
||||||
}
|
}
|
||||||
else if (presence.getType() == Presence.Type.unsubscribe) {
|
else if (presence.getType() == Presence.Type.unsubscribe) {
|
||||||
if (subscriptionMode != SUBSCRIPTION_MANUAL) {
|
if (subscriptionMode != SubscriptionMode.manual) {
|
||||||
// Acknowledge and accept unsubscription notification so that the
|
// Acknowledge and accept unsubscription notification so that the
|
||||||
// server will stop sending notifications saying that the contact
|
// server will stop sending notifications saying that the contact
|
||||||
// has unsubscribed to our presence.
|
// has unsubscribed to our presence.
|
||||||
|
|
|
@ -1,160 +0,0 @@
|
||||||
/**
|
|
||||||
* $RCSfile$
|
|
||||||
* $Revision$
|
|
||||||
* $Date$
|
|
||||||
*
|
|
||||||
* Copyright 2003-2004 Jive Software.
|
|
||||||
*
|
|
||||||
* All rights reserved. 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;
|
|
||||||
|
|
||||||
import javax.net.SocketFactory;
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
import javax.net.ssl.TrustManager;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.security.KeyManagementException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an SSL connection to a XMPP server using the legacy dedicated SSL port
|
|
||||||
* mechanism. Fully compliant XMPP 1.0 servers (e.g. Wildfire 2.4.0) do not
|
|
||||||
* require using a dedicated SSL port. Instead, TLS (a standardized version of SSL 3.0)
|
|
||||||
* is dynamically negotiated over the standard XMPP port. Therefore, only use this
|
|
||||||
* class to connect to an XMPP server if you know that the server does not support
|
|
||||||
* XMPP 1.0 TLS connections.
|
|
||||||
*
|
|
||||||
* @author Matt Tucker
|
|
||||||
*/
|
|
||||||
public class SSLXMPPConnection extends XMPPConnection {
|
|
||||||
|
|
||||||
private static SocketFactory socketFactory = new DummySSLSocketFactory();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new SSL connection to the specified host on the default
|
|
||||||
* SSL port (5223). The IP address of the server is assumed to match the
|
|
||||||
* service name.
|
|
||||||
*
|
|
||||||
* @param host the XMPP host.
|
|
||||||
* @throws XMPPException if an error occurs while trying to establish the connection.
|
|
||||||
* Two possible errors can occur which will be wrapped by an XMPPException --
|
|
||||||
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
|
|
||||||
* 502). The error codes and wrapped exceptions can be used to present more
|
|
||||||
* appropiate error messages to end-users.
|
|
||||||
*/
|
|
||||||
public SSLXMPPConnection(String host) throws XMPPException {
|
|
||||||
this(host, 5223);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new SSL connection to the specified host on the specified port. The IP address
|
|
||||||
* of the server is assumed to match the service name.
|
|
||||||
*
|
|
||||||
* @param host the XMPP host.
|
|
||||||
* @param port the port to use for the connection (default XMPP SSL port is 5223).
|
|
||||||
* @throws XMPPException if an error occurs while trying to establish the connection.
|
|
||||||
* Two possible errors can occur which will be wrapped by an XMPPException --
|
|
||||||
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
|
|
||||||
* 502). The error codes and wrapped exceptions can be used to present more
|
|
||||||
* appropiate error messages to end-users.
|
|
||||||
*/
|
|
||||||
public SSLXMPPConnection(String host, int port) throws XMPPException {
|
|
||||||
this(host, port, host);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new SSL connection to the specified XMPP server on the given host and port.
|
|
||||||
*
|
|
||||||
* @param host the host name, or null for the loopback address.
|
|
||||||
* @param port the port on the server that should be used (default XMPP SSL port is 5223).
|
|
||||||
* @param serviceName the name of the XMPP server to connect to; e.g. <tt>jivesoftware.com</tt>.
|
|
||||||
* @throws XMPPException if an error occurs while trying to establish the connection.
|
|
||||||
* Two possible errors can occur which will be wrapped by an XMPPException --
|
|
||||||
* UnknownHostException (XMPP error code 504), and IOException (XMPP error code
|
|
||||||
* 502). The error codes and wrapped exceptions can be used to present more
|
|
||||||
* appropiate error messages to end-users.
|
|
||||||
*/
|
|
||||||
public SSLXMPPConnection(String host, int port, String serviceName) throws XMPPException {
|
|
||||||
super(host, port, serviceName, socketFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSecureConnection() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An SSL socket factory that will let any certifacte past, even if it's expired or
|
|
||||||
* not singed by a root CA.
|
|
||||||
*/
|
|
||||||
private static class DummySSLSocketFactory extends SSLSocketFactory {
|
|
||||||
|
|
||||||
private SSLSocketFactory factory;
|
|
||||||
|
|
||||||
public DummySSLSocketFactory() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
SSLContext sslcontent = SSLContext.getInstance("TLS");
|
|
||||||
sslcontent.init(null, // KeyManager not required
|
|
||||||
new TrustManager[] { new OpenTrustManager() },
|
|
||||||
new java.security.SecureRandom());
|
|
||||||
factory = sslcontent.getSocketFactory();
|
|
||||||
}
|
|
||||||
catch (NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
catch (KeyManagementException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SocketFactory getDefault() {
|
|
||||||
return new DummySSLSocketFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket createSocket(Socket socket, String s, int i, boolean flag)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
return factory.createSocket(socket, s, i, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket createSocket(InetAddress inaddr, int i, InetAddress inaddr2, int j)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
return factory.createSocket(inaddr, i, inaddr2, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket createSocket(InetAddress inaddr, int i) throws IOException {
|
|
||||||
return factory.createSocket(inaddr, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket createSocket(String s, int i, InetAddress inaddr, int j) throws IOException {
|
|
||||||
return factory.createSocket(s, i, inaddr, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket createSocket(String s, int i) throws IOException {
|
|
||||||
return factory.createSocket(s, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getDefaultCipherSuites() {
|
|
||||||
return factory.getSupportedCipherSuites();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getSupportedCipherSuites() {
|
|
||||||
return factory.getSupportedCipherSuites();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -44,7 +44,7 @@ import java.util.Enumeration;
|
||||||
*/
|
*/
|
||||||
public final class SmackConfiguration {
|
public final class SmackConfiguration {
|
||||||
|
|
||||||
private static final String SMACK_VERSION = "2.2.1";
|
private static final String SMACK_VERSION = "3.0.0";
|
||||||
|
|
||||||
private static int packetReplyTimeout = 5000;
|
private static int packetReplyTimeout = 5000;
|
||||||
private static int keepAliveInterval = 30000;
|
private static int keepAliveInterval = 30000;
|
||||||
|
@ -100,6 +100,7 @@ public final class SmackConfiguration {
|
||||||
systemStream.close();
|
systemStream.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
// Ignore.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -941,20 +941,20 @@ public class XMPPConnection {
|
||||||
Class<?> zoClass = Class.forName("com.jcraft.jzlib.ZOutputStream");
|
Class<?> zoClass = Class.forName("com.jcraft.jzlib.ZOutputStream");
|
||||||
//ZOutputStream out = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_COMPRESSION);
|
//ZOutputStream out = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_COMPRESSION);
|
||||||
Constructor<?> constructor =
|
Constructor<?> constructor =
|
||||||
zoClass.getConstructor(new Class[]{OutputStream.class, Integer.TYPE});
|
zoClass.getConstructor(OutputStream.class, Integer.TYPE);
|
||||||
Object out = constructor.newInstance(new Object[] {socket.getOutputStream(), new Integer(9)});
|
Object out = constructor.newInstance(socket.getOutputStream(), 9);
|
||||||
//out.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
|
//out.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
|
||||||
Method method = zoClass.getMethod("setFlushMode", new Class[] {Integer.TYPE});
|
Method method = zoClass.getMethod("setFlushMode", Integer.TYPE);
|
||||||
method.invoke(out, new Object[] {new Integer(1)});
|
method.invoke(out, 1);
|
||||||
writer = new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8"));
|
writer = new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8"));
|
||||||
|
|
||||||
Class<?> ziClass = Class.forName("com.jcraft.jzlib.ZInputStream");
|
Class<?> ziClass = Class.forName("com.jcraft.jzlib.ZInputStream");
|
||||||
//ZInputStream in = new ZInputStream(socket.getInputStream());
|
//ZInputStream in = new ZInputStream(socket.getInputStream());
|
||||||
constructor = ziClass.getConstructor(new Class[]{InputStream.class});
|
constructor = ziClass.getConstructor(InputStream.class);
|
||||||
Object in = constructor.newInstance(new Object[] {socket.getInputStream()});
|
Object in = constructor.newInstance(socket.getInputStream());
|
||||||
//in.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
|
//in.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
|
||||||
method = ziClass.getMethod("setFlushMode", new Class[] {Integer.TYPE});
|
method = ziClass.getMethod("setFlushMode", Integer.TYPE);
|
||||||
method.invoke(in, new Object[] {new Integer(1)});
|
method.invoke(in, 1);
|
||||||
reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8"));
|
reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8"));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
@ -982,6 +982,7 @@ public class XMPPConnection {
|
||||||
className = System.getProperty("smack.debuggerClass");
|
className = System.getProperty("smack.debuggerClass");
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
|
// Ignore.
|
||||||
}
|
}
|
||||||
Class<?> debuggerClass = null;
|
Class<?> debuggerClass = null;
|
||||||
if (className != null) {
|
if (className != null) {
|
||||||
|
@ -1010,10 +1011,8 @@ public class XMPPConnection {
|
||||||
// option
|
// option
|
||||||
try {
|
try {
|
||||||
Constructor<?> constructor =
|
Constructor<?> constructor =
|
||||||
debuggerClass.getConstructor(
|
debuggerClass.getConstructor(XMPPConnection.class, Writer.class, Reader.class);
|
||||||
new Class[] { XMPPConnection.class, Writer.class, Reader.class });
|
debugger = (SmackDebugger) constructor.newInstance(this, writer, reader);
|
||||||
debugger = (SmackDebugger) constructor
|
|
||||||
.newInstance(new Object[]{this, writer, reader});
|
|
||||||
reader = debugger.getReader();
|
reader = debugger.getReader();
|
||||||
writer = debugger.getWriter();
|
writer = debugger.getWriter();
|
||||||
}
|
}
|
||||||
|
@ -1143,7 +1142,7 @@ public class XMPPConnection {
|
||||||
* speed network connection. However, the server will need to use more CPU time in order to
|
* speed network connection. However, the server will need to use more CPU time in order to
|
||||||
* un/compress network data so under high load the server performance might be affected.<p>
|
* un/compress network data so under high load the server performance might be affected.<p>
|
||||||
*
|
*
|
||||||
* Note: To use stream compression the smackx.jar file has to be present in the classpath.
|
* Note: to use stream compression the smackx.jar file has to be present in the classpath.
|
||||||
*
|
*
|
||||||
* @return true if network traffic is being compressed.
|
* @return true if network traffic is being compressed.
|
||||||
*/
|
*/
|
||||||
|
@ -1161,7 +1160,7 @@ public class XMPPConnection {
|
||||||
* zlib method is supported by the client. Stream compression negotiation has to be done
|
* zlib method is supported by the client. Stream compression negotiation has to be done
|
||||||
* before authentication took place.<p>
|
* before authentication took place.<p>
|
||||||
*
|
*
|
||||||
* Note: To use stream compression the smackx.jar file has to be present in the classpath.
|
* Note: to use stream compression the smackx.jar file has to be present in the classpath.
|
||||||
*
|
*
|
||||||
* @return true if stream compression negotiation was successful.
|
* @return true if stream compression negotiation was successful.
|
||||||
*/
|
*/
|
||||||
|
@ -1184,7 +1183,9 @@ public class XMPPConnection {
|
||||||
try {
|
try {
|
||||||
this.wait(SmackConfiguration.getPacketReplyTimeout() * 5);
|
this.wait(SmackConfiguration.getPacketReplyTimeout() * 5);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {}
|
catch (InterruptedException e) {
|
||||||
|
// Ignore.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return usingCompression;
|
return usingCompression;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,7 @@
|
||||||
|
|
||||||
package org.jivesoftware.smack.packet;
|
package org.jivesoftware.smack.packet;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of the PacketExtension interface. Unless a PacketExtensionProvider
|
* Default implementation of the PacketExtension interface. Unless a PacketExtensionProvider
|
||||||
|
@ -51,7 +48,7 @@ public class DefaultPacketExtension implements PacketExtension {
|
||||||
|
|
||||||
private String elementName;
|
private String elementName;
|
||||||
private String namespace;
|
private String namespace;
|
||||||
private Map map;
|
private Map<String,String> map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new generic packet extension.
|
* Creates a new generic packet extension.
|
||||||
|
@ -85,8 +82,7 @@ public class DefaultPacketExtension implements PacketExtension {
|
||||||
public String toXML() {
|
public String toXML() {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\">");
|
buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\">");
|
||||||
for (Iterator i=getNames(); i.hasNext(); ) {
|
for (String name : getNames()) {
|
||||||
String name = (String)i.next();
|
|
||||||
String value = getValue(name);
|
String value = getValue(name);
|
||||||
buf.append("<").append(name).append(">");
|
buf.append("<").append(name).append(">");
|
||||||
buf.append(value);
|
buf.append(value);
|
||||||
|
@ -97,16 +93,16 @@ public class DefaultPacketExtension implements PacketExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for the names that can be used to get
|
* Returns an unmodifiable collection of the names that can be used to get
|
||||||
* values of the packet extension.
|
* values of the packet extension.
|
||||||
*
|
*
|
||||||
* @return an Iterator for the names.
|
* @return the names.
|
||||||
*/
|
*/
|
||||||
public synchronized Iterator getNames() {
|
public synchronized Collection<String> getNames() {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(new HashMap(map)).keySet().iterator();
|
return Collections.unmodifiableSet(new HashMap<String,String>(map).keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +115,7 @@ public class DefaultPacketExtension implements PacketExtension {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (String)map.get(name);
|
return map.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,7 +126,7 @@ public class DefaultPacketExtension implements PacketExtension {
|
||||||
*/
|
*/
|
||||||
public synchronized void setValue(String name, String value) {
|
public synchronized void setValue(String name, String value) {
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
map = new HashMap();
|
map = new HashMap<String,String>();
|
||||||
}
|
}
|
||||||
map.put(name, value);
|
map.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,8 @@ public abstract class Packet {
|
||||||
private String packetID = null;
|
private String packetID = null;
|
||||||
private String to = null;
|
private String to = null;
|
||||||
private String from = null;
|
private String from = null;
|
||||||
private List packetExtensions = null;
|
private List<PacketExtension> packetExtensions = null;
|
||||||
private Map properties = null;
|
private Map<String,Object> properties = null;
|
||||||
private XMPPError error = null;
|
private XMPPError error = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,15 +168,15 @@ public abstract class Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for the packet extensions attached to the packet.
|
* Returns an unmodifiable collection of the packet extensions attached to the packet.
|
||||||
*
|
*
|
||||||
* @return an Iterator for the packet extensions.
|
* @return the packet extensions.
|
||||||
*/
|
*/
|
||||||
public synchronized Iterator getExtensions() {
|
public synchronized Collection<PacketExtension> getExtensions() {
|
||||||
if (packetExtensions == null) {
|
if (packetExtensions == null) {
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(new ArrayList(packetExtensions)).iterator();
|
return Collections.unmodifiableList(new ArrayList<PacketExtension>(packetExtensions));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,8 +197,7 @@ public abstract class Packet {
|
||||||
if (packetExtensions == null || elementName == null || namespace == null) {
|
if (packetExtensions == null || elementName == null || namespace == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Iterator i=packetExtensions.iterator(); i.hasNext(); ) {
|
for (PacketExtension ext : packetExtensions) {
|
||||||
PacketExtension ext = (PacketExtension)i.next();
|
|
||||||
if (elementName.equals(ext.getElementName()) && namespace.equals(ext.getNamespace())) {
|
if (elementName.equals(ext.getElementName()) && namespace.equals(ext.getNamespace())) {
|
||||||
return ext;
|
return ext;
|
||||||
}
|
}
|
||||||
|
@ -213,7 +212,7 @@ public abstract class Packet {
|
||||||
*/
|
*/
|
||||||
public synchronized void addExtension(PacketExtension extension) {
|
public synchronized void addExtension(PacketExtension extension) {
|
||||||
if (packetExtensions == null) {
|
if (packetExtensions == null) {
|
||||||
packetExtensions = new ArrayList();
|
packetExtensions = new ArrayList<PacketExtension>();
|
||||||
}
|
}
|
||||||
packetExtensions.add(extension);
|
packetExtensions.add(extension);
|
||||||
}
|
}
|
||||||
|
@ -245,56 +244,6 @@ public abstract class Packet {
|
||||||
return properties.get(name);
|
return properties.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a packet property with an int value.
|
|
||||||
*
|
|
||||||
* @param name the name of the property.
|
|
||||||
* @param value the value of the property.
|
|
||||||
*/
|
|
||||||
public void setProperty(String name, int value) {
|
|
||||||
setProperty(name, new Integer(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a packet property with a long value.
|
|
||||||
*
|
|
||||||
* @param name the name of the property.
|
|
||||||
* @param value the value of the property.
|
|
||||||
*/
|
|
||||||
public void setProperty(String name, long value) {
|
|
||||||
setProperty(name, new Long(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a packet property with a float value.
|
|
||||||
*
|
|
||||||
* @param name the name of the property.
|
|
||||||
* @param value the value of the property.
|
|
||||||
*/
|
|
||||||
public void setProperty(String name, float value) {
|
|
||||||
setProperty(name, new Float(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a packet property with a double value.
|
|
||||||
*
|
|
||||||
* @param name the name of the property.
|
|
||||||
* @param value the value of the property.
|
|
||||||
*/
|
|
||||||
public void setProperty(String name, double value) {
|
|
||||||
setProperty(name, new Double(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a packet property with a bboolean value.
|
|
||||||
*
|
|
||||||
* @param name the name of the property.
|
|
||||||
* @param value the value of the property.
|
|
||||||
*/
|
|
||||||
public void setProperty(String name, boolean value) {
|
|
||||||
setProperty(name, new Boolean(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a property with an Object as the value. The value must be Serializable
|
* Sets a property with an Object as the value. The value must be Serializable
|
||||||
* or an IllegalArgumentException will be thrown.
|
* or an IllegalArgumentException will be thrown.
|
||||||
|
@ -307,7 +256,7 @@ public abstract class Packet {
|
||||||
throw new IllegalArgumentException("Value must be serialiazble");
|
throw new IllegalArgumentException("Value must be serialiazble");
|
||||||
}
|
}
|
||||||
if (properties == null) {
|
if (properties == null) {
|
||||||
properties = new HashMap();
|
properties = new HashMap<String, Object>();
|
||||||
}
|
}
|
||||||
properties.put(name, value);
|
properties.put(name, value);
|
||||||
}
|
}
|
||||||
|
@ -325,15 +274,15 @@ public abstract class Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for all the property names that are set.
|
* Returns an unmodifiable collection of all the property names that are set.
|
||||||
*
|
*
|
||||||
* @return an Iterator for all property names.
|
* @return all property names.
|
||||||
*/
|
*/
|
||||||
public synchronized Iterator getPropertyNames() {
|
public synchronized Collection<String> getPropertyNames() {
|
||||||
if (properties == null) {
|
if (properties == null) {
|
||||||
return Collections.EMPTY_LIST.iterator();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
return properties.keySet().iterator();
|
return Collections.unmodifiableSet(new HashSet<String>(properties.keySet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -355,17 +304,14 @@ public abstract class Packet {
|
||||||
protected synchronized String getExtensionsXML() {
|
protected synchronized String getExtensionsXML() {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
// Add in all standard extension sub-packets.
|
// Add in all standard extension sub-packets.
|
||||||
Iterator extensions = getExtensions();
|
for (PacketExtension extension : getExtensions()) {
|
||||||
while (extensions.hasNext()) {
|
|
||||||
PacketExtension extension = (PacketExtension)extensions.next();
|
|
||||||
buf.append(extension.toXML());
|
buf.append(extension.toXML());
|
||||||
}
|
}
|
||||||
// Add in packet properties.
|
// Add in packet properties.
|
||||||
if (properties != null && !properties.isEmpty()) {
|
if (properties != null && !properties.isEmpty()) {
|
||||||
buf.append("<properties xmlns=\"http://www.jivesoftware.com/xmlns/xmpp/properties\">");
|
buf.append("<properties xmlns=\"http://www.jivesoftware.com/xmlns/xmpp/properties\">");
|
||||||
// Loop through all properties and write them out.
|
// Loop through all properties and write them out.
|
||||||
for (Iterator i=getPropertyNames(); i.hasNext(); ) {
|
for (String name : getPropertyNames()) {
|
||||||
String name = (String)i.next();
|
|
||||||
Object value = getProperty(name);
|
Object value = getProperty(name);
|
||||||
buf.append("<property>");
|
buf.append("<property>");
|
||||||
buf.append("<name>").append(StringUtils.escapeForXML(name)).append("</name>");
|
buf.append("<name>").append(StringUtils.escapeForXML(name)).append("</name>");
|
||||||
|
@ -409,10 +355,20 @@ public abstract class Packet {
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (out != null) {
|
if (out != null) {
|
||||||
try { out.close(); } catch (Exception e) { }
|
try {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// Ignore.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (byteStream != null) {
|
if (byteStream != null) {
|
||||||
try { byteStream.close(); } catch (Exception e) { }
|
try {
|
||||||
|
byteStream.close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// Ignore.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages providers for parsing custom XML sub-documents of XMPP packets. Two types of
|
* Manages providers for parsing custom XML sub-documents of XMPP packets. Two types of
|
||||||
|
@ -110,8 +111,8 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public class ProviderManager {
|
public class ProviderManager {
|
||||||
|
|
||||||
private static Map extensionProviders = new Hashtable();
|
private static Map<String, Object> extensionProviders = new ConcurrentHashMap<String, Object>();
|
||||||
private static Map iqProviders = new Hashtable();
|
private static Map<String, Object> iqProviders = new ConcurrentHashMap<String, Object>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Load IQ processing providers.
|
// Load IQ processing providers.
|
||||||
|
@ -154,7 +155,7 @@ public class ProviderManager {
|
||||||
// Add the provider to the map.
|
// Add the provider to the map.
|
||||||
Class provider = Class.forName(className);
|
Class provider = Class.forName(className);
|
||||||
if (IQProvider.class.isAssignableFrom(provider)) {
|
if (IQProvider.class.isAssignableFrom(provider)) {
|
||||||
iqProviders.put(key, provider.newInstance());
|
iqProviders.put(key, (IQProvider)provider.newInstance());
|
||||||
}
|
}
|
||||||
else if (IQ.class.isAssignableFrom(provider)) {
|
else if (IQ.class.isAssignableFrom(provider)) {
|
||||||
iqProviders.put(key, provider);
|
iqProviders.put(key, provider);
|
||||||
|
@ -211,6 +212,7 @@ public class ProviderManager {
|
||||||
providerStream.close();
|
providerStream.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
// Ignore.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,12 +249,14 @@ public class ProviderManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for all IQProvider instances.
|
* Returns an unmodifiable collection of all IQProvider instances. Each object
|
||||||
|
* in the collection will either be an IQProvider instance, or a Class object
|
||||||
|
* that implements the IQProvider interface.
|
||||||
*
|
*
|
||||||
* @return an Iterator for all IQProvider instances.
|
* @return all IQProvider instances.
|
||||||
*/
|
*/
|
||||||
public static Iterator getIQProviders() {
|
public static Collection<Object> getIQProviders() {
|
||||||
return Collections.unmodifiableCollection(new HashMap(iqProviders).values()).iterator();
|
return Collections.unmodifiableCollection(iqProviders.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -348,13 +352,14 @@ public class ProviderManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for all PacketExtensionProvider instances.
|
* Returns an unmodifiable collection of all PacketExtensionProvider instances. Each object
|
||||||
|
* in the collection will either be a PacketExtensionProvider instance, or a Class object
|
||||||
|
* that implements the PacketExtensionProvider interface.
|
||||||
*
|
*
|
||||||
* @return an Iterator for all PacketExtensionProvider instances.
|
* @return all PacketExtensionProvider instances.
|
||||||
*/
|
*/
|
||||||
public static Iterator getExtensionProviders() {
|
public static Collection<Object> getExtensionProviders() {
|
||||||
return Collections.unmodifiableCollection(
|
return Collections.unmodifiableCollection(extensionProviders.values());
|
||||||
new HashMap(extensionProviders).values()).iterator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -377,7 +382,7 @@ public class ProviderManager {
|
||||||
*/
|
*/
|
||||||
private static ClassLoader[] getClassLoaders() {
|
private static ClassLoader[] getClassLoaders() {
|
||||||
ClassLoader[] classLoaders = new ClassLoader[2];
|
ClassLoader[] classLoaders = new ClassLoader[2];
|
||||||
classLoaders[0] = new ProviderManager().getClass().getClassLoader();
|
classLoaders[0] = ProviderManager.class.getClassLoader();
|
||||||
classLoaders[1] = Thread.currentThread().getContextClassLoader();
|
classLoaders[1] = Thread.currentThread().getContextClassLoader();
|
||||||
return classLoaders;
|
return classLoaders;
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,9 +218,8 @@ public class EnhancedDebuggerWindow {
|
||||||
JPanel iqProvidersPanel = new JPanel();
|
JPanel iqProvidersPanel = new JPanel();
|
||||||
iqProvidersPanel.setLayout(new GridLayout(1, 1));
|
iqProvidersPanel.setLayout(new GridLayout(1, 1));
|
||||||
iqProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed IQ Providers"));
|
iqProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed IQ Providers"));
|
||||||
Vector providers = new Vector();
|
Vector<String> providers = new Vector<String>();
|
||||||
for (Iterator it = ProviderManager.getIQProviders(); it.hasNext();) {
|
for (Object provider : ProviderManager.getIQProviders()) {
|
||||||
Object provider = it.next();
|
|
||||||
if (provider.getClass() == Class.class) {
|
if (provider.getClass() == Class.class) {
|
||||||
providers.add(((Class) provider).getName());
|
providers.add(((Class) provider).getName());
|
||||||
}
|
}
|
||||||
|
@ -238,9 +237,8 @@ public class EnhancedDebuggerWindow {
|
||||||
JPanel extensionProvidersPanel = new JPanel();
|
JPanel extensionProvidersPanel = new JPanel();
|
||||||
extensionProvidersPanel.setLayout(new GridLayout(1, 1));
|
extensionProvidersPanel.setLayout(new GridLayout(1, 1));
|
||||||
extensionProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed Extension Providers"));
|
extensionProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed Extension Providers"));
|
||||||
providers = new Vector();
|
providers = new Vector<String>();
|
||||||
for (Iterator it = ProviderManager.getExtensionProviders(); it.hasNext();) {
|
for (Object provider : ProviderManager.getExtensionProviders()) {
|
||||||
Object provider = it.next();
|
|
||||||
if (provider.getClass() == Class.class) {
|
if (provider.getClass() == Class.class) {
|
||||||
providers.add(((Class) provider).getName());
|
providers.add(((Class) provider).getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,29 +103,6 @@ public class MessageTest extends SmackTestCase {
|
||||||
// Check that the second message was received
|
// Check that the second message was received
|
||||||
rcv = (Message) collector.nextResult(1000);
|
rcv = (Message) collector.nextResult(1000);
|
||||||
assertNotNull("No Message was received", rcv);
|
assertNotNull("No Message was received", rcv);
|
||||||
|
|
||||||
// Try now sending huge messages over an SSL connection
|
|
||||||
XMPPConnection conn = null;
|
|
||||||
try {
|
|
||||||
conn = new SSLXMPPConnection(getServiceName());
|
|
||||||
conn.login(getUsername(0), getUsername(0), "Other resource");
|
|
||||||
|
|
||||||
// Send the first message
|
|
||||||
conn.sendPacket(msg);
|
|
||||||
// Check that the connection that sent the message is still connected
|
|
||||||
assertTrue("Connection was closed", conn.isConnected());
|
|
||||||
// Check that the message was received
|
|
||||||
rcv = (Message) collector.nextResult(1000);
|
|
||||||
assertNotNull("No Message was received", rcv);
|
|
||||||
} catch (XMPPException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (conn != null) {
|
|
||||||
conn.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getMaxConnections() {
|
protected int getMaxConnections() {
|
||||||
|
|
Loading…
Reference in a new issue