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.util.StringUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* All attributes must be set when creating new accounts. The standard
|
||||
* Returns an unmodifiable collection of the names of the required account attributes.
|
||||
* All attributes must be set when creating new accounts. The standard set of possible
|
||||
* attributes are as follows: <ul>
|
||||
* <li>name -- the user's name.
|
||||
* <li>first -- the user's first name.
|
||||
|
@ -96,20 +93,20 @@ public class AccountManager {
|
|||
*
|
||||
* @return the required account attributes.
|
||||
*/
|
||||
public Iterator<String> getAccountAttributes() {
|
||||
public Collection<String> getAccountAttributes() {
|
||||
try {
|
||||
if (info == null) {
|
||||
getRegistrationInfo();
|
||||
}
|
||||
Map<String, String> attributes = info.getAttributes();
|
||||
if (attributes != null) {
|
||||
return attributes.keySet().iterator();
|
||||
return Collections.unmodifiableSet(attributes.keySet());
|
||||
}
|
||||
}
|
||||
catch (XMPPException xe) {
|
||||
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.
|
||||
Map<String, String> attributes = new HashMap<String, String>();
|
||||
for (Iterator<String> i=getAccountAttributes(); i.hasNext(); ) {
|
||||
String attributeName = i.next();
|
||||
for (String attributeName : getAccountAttributes()) {
|
||||
attributes.put(attributeName, "");
|
||||
}
|
||||
createAccount(username, password, attributes);
|
||||
|
|
|
@ -362,13 +362,7 @@ class PacketWriter {
|
|||
stream.append(" to=\"").append(connection.serviceName).append("\"");
|
||||
stream.append(" xmlns=\"jabber:client\"");
|
||||
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\"");
|
||||
if (connection instanceof SSLXMPPConnection) {
|
||||
// Old SSL connections should not include indicate XMPP 1.0 compliance
|
||||
stream.append(">");
|
||||
}
|
||||
else {
|
||||
stream.append(" version=\"1.0\">");
|
||||
}
|
||||
stream.append(" version=\"1.0\">");
|
||||
writer.write(stream.toString());
|
||||
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
|
||||
* modes are supported for handling these requests: <ul>
|
||||
* <li> SUBSCRIPTION_ACCEPT_ALL -- accept all subscription requests.
|
||||
* <li> SUBSCRIPTION_REJECT_ALL -- reject all subscription requests.
|
||||
* <li> SUBSCRIPTION_MANUAL -- manually process all subscription requests. </ul>
|
||||
* <li>{@link SubscriptionMode#accept_all accept_all} -- accept all subscription requests.</li>
|
||||
* <li>{@link SubscriptionMode#reject_all reject_all} -- reject all subscription requests.</li>
|
||||
* <li>{@link SubscriptionMode#manual manual} -- manually process all subscription requests.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see XMPPConnection#getRoster()
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
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
|
||||
* all subscription requests are automatically accepted.
|
||||
*/
|
||||
private static int defaultSubscriptionMode = SUBSCRIPTION_ACCEPT_ALL;
|
||||
private static SubscriptionMode defaultSubscriptionMode = SubscriptionMode.accept_all;
|
||||
|
||||
private XMPPConnection connection;
|
||||
private final Map<String, RosterGroup> groups;
|
||||
|
@ -83,17 +64,17 @@ public class Roster {
|
|||
// has been recieved and processed.
|
||||
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
|
||||
* subscription processing mode dictates what action Smack will take when subscription
|
||||
* 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
|
||||
*/
|
||||
public static int getDefaultSubscriptionMode() {
|
||||
public static SubscriptionMode getDefaultSubscriptionMode() {
|
||||
return defaultSubscriptionMode;
|
||||
}
|
||||
|
||||
|
@ -101,11 +82,11 @@ public class Roster {
|
|||
* 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
|
||||
* 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.
|
||||
*/
|
||||
public static void setDefaultSubscriptionMode(int subscriptionMode) {
|
||||
public static void setDefaultSubscriptionMode(SubscriptionMode subscriptionMode) {
|
||||
defaultSubscriptionMode = subscriptionMode;
|
||||
}
|
||||
|
||||
|
@ -132,7 +113,7 @@ public class Roster {
|
|||
/**
|
||||
* Returns the subscription processing mode, which dictates what action
|
||||
* 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
|
||||
* listens for Presence packets that have a type of
|
||||
|
@ -140,14 +121,14 @@ public class Roster {
|
|||
*
|
||||
* @return the subscription mode.
|
||||
*/
|
||||
public int getSubscriptionMode() {
|
||||
public SubscriptionMode getSubscriptionMode() {
|
||||
return subscriptionMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subscription processing mode, which dictates what action
|
||||
* 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
|
||||
* listens for Presence packets that have a type of
|
||||
|
@ -155,13 +136,7 @@ public class Roster {
|
|||
*
|
||||
* @param subscriptionMode the subscription mode.
|
||||
*/
|
||||
public void setSubscriptionMode(int subscriptionMode) {
|
||||
if (subscriptionMode != SUBSCRIPTION_ACCEPT_ALL &&
|
||||
subscriptionMode != SUBSCRIPTION_REJECT_ALL &&
|
||||
subscriptionMode != SUBSCRIPTION_MANUAL)
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid mode.");
|
||||
}
|
||||
public void setSubscriptionMode(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.
|
||||
*
|
||||
* @return an iterator the unfiled roster entries.
|
||||
* @return the unfiled roster entries.
|
||||
*/
|
||||
public Iterator<RosterEntry> getUnfiledEntries() {
|
||||
public Collection<RosterEntry> getUnfiledEntries() {
|
||||
synchronized (unfiledEntries) {
|
||||
return Collections.unmodifiableList(new ArrayList<RosterEntry>(unfiledEntries))
|
||||
.iterator();
|
||||
return Collections.unmodifiableList(new ArrayList<RosterEntry>(unfiledEntries));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,7 +395,7 @@ public class Roster {
|
|||
* Returns the presence info for a particular user, or <tt>null</tt> if the user
|
||||
* is unavailable (offline) or if no presence information is available, such as
|
||||
* when you are not subscribed to the user's presence updates.<p>
|
||||
*
|
||||
*
|
||||
* If the user has several presences (one for each resource) then answer the presence
|
||||
* with the highest priority.<p>
|
||||
*
|
||||
|
@ -472,7 +446,7 @@ public class Roster {
|
|||
* when you are not subscribed to the user's presence updates.
|
||||
*
|
||||
* @param userResource a fully qualified xmpp ID including a resource.
|
||||
* @return the user's current presence, or <tt>null</tt> if the user is unavailable
|
||||
* @return the user's current presence, or <tt>null</tt> if the user is unavailable
|
||||
* or if no presence information is available.
|
||||
*/
|
||||
public Presence getPresenceResource(String userResource) {
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -630,13 +630,13 @@ public class Roster {
|
|||
}
|
||||
}
|
||||
else if (presence.getType() == Presence.Type.subscribe) {
|
||||
if (subscriptionMode == SUBSCRIPTION_ACCEPT_ALL) {
|
||||
if (subscriptionMode == SubscriptionMode.accept_all) {
|
||||
// Accept all subscription requests.
|
||||
Presence response = new Presence(Presence.Type.subscribed);
|
||||
response.setTo(presence.getFrom());
|
||||
connection.sendPacket(response);
|
||||
}
|
||||
else if (subscriptionMode == SUBSCRIPTION_REJECT_ALL) {
|
||||
else if (subscriptionMode == SubscriptionMode.reject_all) {
|
||||
// Reject all subscription requests.
|
||||
Presence response = new Presence(Presence.Type.unsubscribed);
|
||||
response.setTo(presence.getFrom());
|
||||
|
@ -645,9 +645,9 @@ public class Roster {
|
|||
// Otherwise, in manual mode so ignore.
|
||||
}
|
||||
else if (presence.getType() == Presence.Type.unsubscribe) {
|
||||
if (subscriptionMode != SUBSCRIPTION_MANUAL) {
|
||||
if (subscriptionMode != SubscriptionMode.manual) {
|
||||
// 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.
|
||||
Presence response = new Presence(Presence.Type.unsubscribed);
|
||||
response.setTo(presence.getFrom());
|
||||
|
|
|
@ -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 {
|
||||
|
||||
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 keepAliveInterval = 30000;
|
||||
|
@ -100,6 +100,7 @@ public final class SmackConfiguration {
|
|||
systemStream.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ public class XMPPConnection {
|
|||
|
||||
/**
|
||||
* Creates a new connection to the XMPP server at the specifiec host and port.
|
||||
*
|
||||
*
|
||||
* @param host the name of the XMPP server to connect to; e.g. <tt>jivesoftware.com</tt>.
|
||||
* @param port the port on the server that should be used; e.g. <tt>5222</tt>.
|
||||
* @throws XMPPException if an error occurs while trying to establish the connection.
|
||||
|
@ -941,20 +941,20 @@ public class XMPPConnection {
|
|||
Class<?> zoClass = Class.forName("com.jcraft.jzlib.ZOutputStream");
|
||||
//ZOutputStream out = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_COMPRESSION);
|
||||
Constructor<?> constructor =
|
||||
zoClass.getConstructor(new Class[]{OutputStream.class, Integer.TYPE});
|
||||
Object out = constructor.newInstance(new Object[] {socket.getOutputStream(), new Integer(9)});
|
||||
zoClass.getConstructor(OutputStream.class, Integer.TYPE);
|
||||
Object out = constructor.newInstance(socket.getOutputStream(), 9);
|
||||
//out.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
|
||||
Method method = zoClass.getMethod("setFlushMode", new Class[] {Integer.TYPE});
|
||||
method.invoke(out, new Object[] {new Integer(1)});
|
||||
Method method = zoClass.getMethod("setFlushMode", Integer.TYPE);
|
||||
method.invoke(out, 1);
|
||||
writer = new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8"));
|
||||
|
||||
Class<?> ziClass = Class.forName("com.jcraft.jzlib.ZInputStream");
|
||||
//ZInputStream in = new ZInputStream(socket.getInputStream());
|
||||
constructor = ziClass.getConstructor(new Class[]{InputStream.class});
|
||||
Object in = constructor.newInstance(new Object[] {socket.getInputStream()});
|
||||
constructor = ziClass.getConstructor(InputStream.class);
|
||||
Object in = constructor.newInstance(socket.getInputStream());
|
||||
//in.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
|
||||
method = ziClass.getMethod("setFlushMode", new Class[] {Integer.TYPE});
|
||||
method.invoke(in, new Object[] {new Integer(1)});
|
||||
method = ziClass.getMethod("setFlushMode", Integer.TYPE);
|
||||
method.invoke(in, 1);
|
||||
reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -982,6 +982,7 @@ public class XMPPConnection {
|
|||
className = System.getProperty("smack.debuggerClass");
|
||||
}
|
||||
catch (Throwable t) {
|
||||
// Ignore.
|
||||
}
|
||||
Class<?> debuggerClass = null;
|
||||
if (className != null) {
|
||||
|
@ -1010,10 +1011,8 @@ public class XMPPConnection {
|
|||
// option
|
||||
try {
|
||||
Constructor<?> constructor =
|
||||
debuggerClass.getConstructor(
|
||||
new Class[] { XMPPConnection.class, Writer.class, Reader.class });
|
||||
debugger = (SmackDebugger) constructor
|
||||
.newInstance(new Object[]{this, writer, reader});
|
||||
debuggerClass.getConstructor(XMPPConnection.class, Writer.class, Reader.class);
|
||||
debugger = (SmackDebugger) constructor.newInstance(this, writer, reader);
|
||||
reader = debugger.getReader();
|
||||
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
|
||||
* 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.
|
||||
*/
|
||||
|
@ -1161,7 +1160,7 @@ public class XMPPConnection {
|
|||
* zlib method is supported by the client. Stream compression negotiation has to be done
|
||||
* 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.
|
||||
*/
|
||||
|
@ -1184,7 +1183,9 @@ public class XMPPConnection {
|
|||
try {
|
||||
this.wait(SmackConfiguration.getPacketReplyTimeout() * 5);
|
||||
}
|
||||
catch (InterruptedException e) {}
|
||||
catch (InterruptedException e) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
return usingCompression;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,7 @@
|
|||
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Default implementation of the PacketExtension interface. Unless a PacketExtensionProvider
|
||||
|
@ -51,7 +48,7 @@ public class DefaultPacketExtension implements PacketExtension {
|
|||
|
||||
private String elementName;
|
||||
private String namespace;
|
||||
private Map map;
|
||||
private Map<String,String> map;
|
||||
|
||||
/**
|
||||
* Creates a new generic packet extension.
|
||||
|
@ -85,8 +82,7 @@ public class DefaultPacketExtension implements PacketExtension {
|
|||
public String toXML() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\">");
|
||||
for (Iterator i=getNames(); i.hasNext(); ) {
|
||||
String name = (String)i.next();
|
||||
for (String name : getNames()) {
|
||||
String value = getValue(name);
|
||||
buf.append("<").append(name).append(">");
|
||||
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.
|
||||
*
|
||||
* @return an Iterator for the names.
|
||||
* @return the names.
|
||||
*/
|
||||
public synchronized Iterator getNames() {
|
||||
public synchronized Collection<String> getNames() {
|
||||
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) {
|
||||
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) {
|
||||
if (map == null) {
|
||||
map = new HashMap();
|
||||
map = new HashMap<String,String>();
|
||||
}
|
||||
map.put(name, value);
|
||||
}
|
||||
|
|
|
@ -72,8 +72,8 @@ public abstract class Packet {
|
|||
private String packetID = null;
|
||||
private String to = null;
|
||||
private String from = null;
|
||||
private List packetExtensions = null;
|
||||
private Map properties = null;
|
||||
private List<PacketExtension> packetExtensions = null;
|
||||
private Map<String,Object> properties = 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) {
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
for (Iterator i=packetExtensions.iterator(); i.hasNext(); ) {
|
||||
PacketExtension ext = (PacketExtension)i.next();
|
||||
for (PacketExtension ext : packetExtensions) {
|
||||
if (elementName.equals(ext.getElementName()) && namespace.equals(ext.getNamespace())) {
|
||||
return ext;
|
||||
}
|
||||
|
@ -213,7 +212,7 @@ public abstract class Packet {
|
|||
*/
|
||||
public synchronized void addExtension(PacketExtension extension) {
|
||||
if (packetExtensions == null) {
|
||||
packetExtensions = new ArrayList();
|
||||
packetExtensions = new ArrayList<PacketExtension>();
|
||||
}
|
||||
packetExtensions.add(extension);
|
||||
}
|
||||
|
@ -245,56 +244,6 @@ public abstract class Packet {
|
|||
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
|
||||
* or an IllegalArgumentException will be thrown.
|
||||
|
@ -307,7 +256,7 @@ public abstract class Packet {
|
|||
throw new IllegalArgumentException("Value must be serialiazble");
|
||||
}
|
||||
if (properties == null) {
|
||||
properties = new HashMap();
|
||||
properties = new HashMap<String, Object>();
|
||||
}
|
||||
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) {
|
||||
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() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
// Add in all standard extension sub-packets.
|
||||
Iterator extensions = getExtensions();
|
||||
while (extensions.hasNext()) {
|
||||
PacketExtension extension = (PacketExtension)extensions.next();
|
||||
for (PacketExtension extension : getExtensions()) {
|
||||
buf.append(extension.toXML());
|
||||
}
|
||||
// Add in packet properties.
|
||||
if (properties != null && !properties.isEmpty()) {
|
||||
buf.append("<properties xmlns=\"http://www.jivesoftware.com/xmlns/xmpp/properties\">");
|
||||
// Loop through all properties and write them out.
|
||||
for (Iterator i=getPropertyNames(); i.hasNext(); ) {
|
||||
String name = (String)i.next();
|
||||
for (String name : getPropertyNames()) {
|
||||
Object value = getProperty(name);
|
||||
buf.append("<property>");
|
||||
buf.append("<name>").append(StringUtils.escapeForXML(name)).append("</name>");
|
||||
|
@ -409,10 +355,20 @@ public abstract class Packet {
|
|||
}
|
||||
finally {
|
||||
if (out != null) {
|
||||
try { out.close(); } catch (Exception e) { }
|
||||
try {
|
||||
out.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
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.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Manages providers for parsing custom XML sub-documents of XMPP packets. Two types of
|
||||
|
@ -110,8 +111,8 @@ import java.util.*;
|
|||
*/
|
||||
public class ProviderManager {
|
||||
|
||||
private static Map extensionProviders = new Hashtable();
|
||||
private static Map iqProviders = new Hashtable();
|
||||
private static Map<String, Object> extensionProviders = new ConcurrentHashMap<String, Object>();
|
||||
private static Map<String, Object> iqProviders = new ConcurrentHashMap<String, Object>();
|
||||
|
||||
static {
|
||||
// Load IQ processing providers.
|
||||
|
@ -154,7 +155,7 @@ public class ProviderManager {
|
|||
// Add the provider to the map.
|
||||
Class provider = Class.forName(className);
|
||||
if (IQProvider.class.isAssignableFrom(provider)) {
|
||||
iqProviders.put(key, provider.newInstance());
|
||||
iqProviders.put(key, (IQProvider)provider.newInstance());
|
||||
}
|
||||
else if (IQ.class.isAssignableFrom(provider)) {
|
||||
iqProviders.put(key, provider);
|
||||
|
@ -211,6 +212,7 @@ public class ProviderManager {
|
|||
providerStream.close();
|
||||
}
|
||||
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() {
|
||||
return Collections.unmodifiableCollection(new HashMap(iqProviders).values()).iterator();
|
||||
public static Collection<Object> getIQProviders() {
|
||||
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() {
|
||||
return Collections.unmodifiableCollection(
|
||||
new HashMap(extensionProviders).values()).iterator();
|
||||
public static Collection<Object> getExtensionProviders() {
|
||||
return Collections.unmodifiableCollection(extensionProviders.values());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -377,7 +382,7 @@ public class ProviderManager {
|
|||
*/
|
||||
private static ClassLoader[] getClassLoaders() {
|
||||
ClassLoader[] classLoaders = new ClassLoader[2];
|
||||
classLoaders[0] = new ProviderManager().getClass().getClassLoader();
|
||||
classLoaders[0] = ProviderManager.class.getClassLoader();
|
||||
classLoaders[1] = Thread.currentThread().getContextClassLoader();
|
||||
return classLoaders;
|
||||
}
|
||||
|
|
|
@ -218,9 +218,8 @@ public class EnhancedDebuggerWindow {
|
|||
JPanel iqProvidersPanel = new JPanel();
|
||||
iqProvidersPanel.setLayout(new GridLayout(1, 1));
|
||||
iqProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed IQ Providers"));
|
||||
Vector providers = new Vector();
|
||||
for (Iterator it = ProviderManager.getIQProviders(); it.hasNext();) {
|
||||
Object provider = it.next();
|
||||
Vector<String> providers = new Vector<String>();
|
||||
for (Object provider : ProviderManager.getIQProviders()) {
|
||||
if (provider.getClass() == Class.class) {
|
||||
providers.add(((Class) provider).getName());
|
||||
}
|
||||
|
@ -238,9 +237,8 @@ public class EnhancedDebuggerWindow {
|
|||
JPanel extensionProvidersPanel = new JPanel();
|
||||
extensionProvidersPanel.setLayout(new GridLayout(1, 1));
|
||||
extensionProvidersPanel.setBorder(BorderFactory.createTitledBorder("Installed Extension Providers"));
|
||||
providers = new Vector();
|
||||
for (Iterator it = ProviderManager.getExtensionProviders(); it.hasNext();) {
|
||||
Object provider = it.next();
|
||||
providers = new Vector<String>();
|
||||
for (Object provider : ProviderManager.getExtensionProviders()) {
|
||||
if (provider.getClass() == Class.class) {
|
||||
providers.add(((Class) provider).getName());
|
||||
}
|
||||
|
|
|
@ -103,29 +103,6 @@ public class MessageTest extends SmackTestCase {
|
|||
// Check that the second message was received
|
||||
rcv = (Message) collector.nextResult(1000);
|
||||
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() {
|
||||
|
|
Loading…
Reference in a new issue