diff --git a/build/build.xml b/build/build.xml index c30efd8cb..0f35dc027 100644 --- a/build/build.xml +++ b/build/build.xml @@ -28,7 +28,7 @@ - + @@ -98,8 +98,8 @@ destdir="${compile.dir}" includeAntRuntime="no" debug="on" - source="1.5" - target="1.5" + source="1.6" + target="1.6" > @@ -113,8 +113,8 @@ destdir="${compile.dir}/jingle/extension" includeAntRuntime="no" debug="on" - source="1.5" - target="1.5" + source="1.6" + target="1.6" > @@ -141,8 +141,8 @@ destdir="${compile.test.dir}" includeAntRuntime="no" debug="on" - source="1.5" - target="1.5" + source="1.6" + target="1.6" > diff --git a/build/resources/releasedocs/changelog.html b/build/resources/releasedocs/changelog.html index b2d91cf82..13e9500a8 100644 --- a/build/resources/releasedocs/changelog.html +++ b/build/resources/releasedocs/changelog.html @@ -141,22 +141,22 @@ hr {
-

3.2.0 Beta -- February 4, 2011

-

New Feature

+

3.2.0 -- May 3, 2011

+

New Feature

  • [SMACK-272] - Add support for pubsub (XEP-0060)
  • [SMACK-296] - Add support for XEP-0224: Attention
  • [SMACK-319] - Add common interfaces for SOCKS5 Bytestreams and In-Band Bytestreams
-

Improvement

+

Improvement

  • [SMACK-137] - File Transfer Settings
  • [SMACK-156] - Add the ability to register for roster events before logging in
  • [SMACK-261] - Minor Jingle cleanup to better support Jingle in Spark
  • -
  • [SMACK-266] - Add provider for fastpath to smackx
  • [SMACK-277] - Update XMLUnit to the latest version
  • [SMACK-282] - Support SASL-related error conditions.
  • +
  • [SMACK-283] - Investigate why Jingle is connecting to stun.xten.net
  • [SMACK-285] - Add support for Nicks
  • [SMACK-289] - There is no way of retrieving items from a pubsub node when the user has multiple subscriptions.
  • [SMACK-294] - Handle empty roster groups and no goups in the same way
  • @@ -174,8 +174,9 @@ hr {
  • [SMACK-310] - Add Support for Localized Message Subjects
-

Bug

+

Bug

    +
  • [SMACK-163] - Fix NPE in RoomInfo when subject has not value
  • [SMACK-207] - Parsing of messages may disconnect Smack/Spark
  • [SMACK-225] - Improper handeling of DNS SRV records
  • [SMACK-232] - Better handling of Roster error
  • @@ -184,6 +185,7 @@ hr {
  • [SMACK-269] - Smack 3.1.0 creates a new chat for every incoming message
  • [SMACK-271] - Deadlock in XMPPConnection while login and parsing stream features
  • [SMACK-275] - Patch: Fix for broken SASL DIGEST-MD5 implementation
  • +
  • [SMACK-280] - The authentification should use the Connection#sendPacket method and work transparent with packets and packet listeners.
  • [SMACK-288] - The parsing of the result for a LeafNode.getItems() call is incorrect. It creates a DefaultPacketExtension instead of an Item for every other item in the result.
  • [SMACK-290] - Deadlock while getting Roster before it's initialized
  • [SMACK-291] - RosterGroup modifications should depend on roster push
  • @@ -193,6 +195,8 @@ hr {
  • [SMACK-312] - Only fire RosterListener#entriesUpdated for RosterEntries that changed
  • [SMACK-327] - getFeatures() method on DiscoverInfo is improperly set to be package protected instead of public
  • [SMACK-328] - Number format exception while parsing dates.
  • +
  • [SMACK-332] - Smack 3.2.0b2 shows wrong version in Smack Dubugger Window
  • +
  • [SMACK-334] - Error in form for FileTransferNegotiator

3.1.0 -- November 20, 2008

@@ -387,4 +391,4 @@ hr {
- \ No newline at end of file + diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java index a3d2c24b7..496dc7578 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUNResolver.java @@ -52,11 +52,6 @@ public class STUNResolver extends TransportResolver { // The filename where the STUN servers are stored. public final static String STUNSERVERS_FILENAME = "META-INF/stun-config.xml"; - // Fallback values when we don't have any STUN server to use... - private final static String FALLBACKHOSTNAME = "stun.xten.net"; - - private final static int FALLBACKHOSTPORT = 3478; - // Current STUN server we are using protected STUNService currentServer; @@ -189,10 +184,10 @@ public class STUNResolver extends TransportResolver { } catch (XmlPullParserException e) { - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); } catch (IOException e) { - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); } currentServer = bestSTUNServer(serversList); @@ -247,13 +242,7 @@ public class STUNResolver extends TransportResolver { } } catch (Exception e) { - e.printStackTrace(); - } - - // If the list of candidates is empty, add at least one default server - if (serversList.isEmpty()) { - currentServer = new STUNService(FALLBACKHOSTNAME, FALLBACKHOSTPORT); - serversList.add(currentServer); + LOGGER.error(e.getMessage(), e); } return serversList; @@ -370,14 +359,14 @@ public class STUNResolver extends TransportResolver { } } catch (Exception e) { - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); } } } } } catch (SocketException e) { - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); } finally { setInitialized(); @@ -524,7 +513,7 @@ public class STUNResolver extends TransportResolver { } } catch (Exception e) { - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); } return result; diff --git a/source/org/jivesoftware/smack/Connection.java b/source/org/jivesoftware/smack/Connection.java index e857254de..cde0ab4aa 100644 --- a/source/org/jivesoftware/smack/Connection.java +++ b/source/org/jivesoftware/smack/Connection.java @@ -323,9 +323,13 @@ public abstract class Connection { /** * Logs in to the server using the strongest authentication mode supported by - * the server, then sets presence to available. If more than five seconds - * (default timeout) elapses in each step of the authentication process without - * a response from the server, or if an error occurs, a XMPPException will be thrown.

+ * the server, then sets presence to available. If the server supports SASL authentication + * then the user will be authenticated using SASL if not Non-SASL authentication will + * be tried. If more than five seconds (default timeout) elapses in each step of the + * authentication process without a response from the server, or if an error occurs, a + * XMPPException will be thrown.

+ * + * Before logging in (i.e. authenticate) to the server the connection must be connected. * * It is possible to log in without sending an initial available presence by using * {@link ConnectionConfiguration#setSendPresence(boolean)}. If this connection is @@ -346,15 +350,13 @@ public abstract class Connection { /** * Logs in to the server using the strongest authentication mode supported by - * the server. If the server supports SASL authentication then the user will be - * authenticated using SASL if not Non-SASL authentication will be tried. If more than - * five seconds (default timeout) elapses in each step of the authentication process - * without a response from the server, or if an error occurs, a XMPPException will be - * thrown.

+ * the server, then sets presence to available. If the server supports SASL authentication + * then the user will be authenticated using SASL if not Non-SASL authentication will + * be tried. If more than five seconds (default timeout) elapses in each step of the + * authentication process without a response from the server, or if an error occurs, a + * XMPPException will be thrown.

* * Before logging in (i.e. authenticate) to the server the connection must be connected. - * For compatibility and easiness of use the connection will automatically connect to the - * server if not already connected.

* * It is possible to log in without sending an initial available presence by using * {@link ConnectionConfiguration#setSendPresence(boolean)}. If this connection is diff --git a/source/org/jivesoftware/smack/ReconnectionManager.java b/source/org/jivesoftware/smack/ReconnectionManager.java index b0119b8b2..514c8235e 100644 --- a/source/org/jivesoftware/smack/ReconnectionManager.java +++ b/source/org/jivesoftware/smack/ReconnectionManager.java @@ -1,7 +1,7 @@ package org.jivesoftware.smack; import org.jivesoftware.smack.packet.StreamError; - +import java.util.Random; /** * Handles the automatic reconnection process. Every time a connection is dropped without * the application explictly closing it, the manager automatically tries to reconnect to @@ -20,7 +20,9 @@ public class ReconnectionManager implements ConnectionListener { // Holds the connection to the server private Connection connection; - + private Thread reconnectionThread; + private int randomBase = new Random().nextInt(11) + 5; // between 5 and 15 seconds + // Holds the state of the reconnection boolean done = false; @@ -61,12 +63,15 @@ public class ReconnectionManager implements ConnectionListener { *

  • Finally it will try indefinitely every 5 minutes. * */ - protected void reconnect() { + synchronized protected void reconnect() { if (this.isReconnectionAllowed()) { // Since there is no thread running, creates a new one to attempt // the reconnection. - Thread reconnectionThread = new Thread() { - + // avoid to run duplicated reconnectionThread -- fd: 16/09/2010 + if (reconnectionThread!=null && reconnectionThread.isAlive()) return; + + reconnectionThread = new Thread() { + /** * Holds the current number of reconnection attempts */ @@ -78,13 +83,14 @@ public class ReconnectionManager implements ConnectionListener { * @return the number of seconds until the next reconnection attempt. */ private int timeDelay() { + attempts++; if (attempts > 13) { - return 60 * 5; // 5 minutes + return randomBase*6*5; // between 2.5 and 7.5 minutes (~5 minutes) } if (attempts > 7) { - return 60; // 1 minute + return randomBase*6; // between 30 and 90 seconds (~1 minutes) } - return 10; // 10 seconds + return randomBase; // 10 seconds } /** diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index df5d53d9b..93f3ccf96 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -854,9 +854,11 @@ public class Roster { // If the entry was in then list then update its state with the new values RosterEntry oldEntry = entries.put(item.getUser(), entry); - // Keep note that an entry has been updated but only if it's different - if (oldEntry == null || !oldEntry.equalsDeep(entry)) { - updatedEntries.add(item.getUser()); + RosterPacket.Item oldItem = RosterEntry.toRosterItem(oldEntry); + //We have also to check if only the group names have changed from the item + if (oldEntry == null || !oldEntry.equalsDeep(entry) || !item.getGroupNames().equals(oldItem.getGroupNames())) + { + updatedEntries.add(item.getUser()); } } // If the roster entry belongs to any groups, remove it from the diff --git a/source/org/jivesoftware/smack/SmackConfiguration.java b/source/org/jivesoftware/smack/SmackConfiguration.java index d8beb334c..0e09d23f8 100644 --- a/source/org/jivesoftware/smack/SmackConfiguration.java +++ b/source/org/jivesoftware/smack/SmackConfiguration.java @@ -44,7 +44,7 @@ import java.util.*; */ public final class SmackConfiguration { - private static final String SMACK_VERSION = "3.2.0 Beta2"; + private static final String SMACK_VERSION = "3.2.0"; private static int packetReplyTimeout = 5000; private static int keepAliveInterval = 30000; diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index 8ccaef2b8..d04585081 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -184,34 +184,7 @@ public class XMPPConnection extends Connection { return user; } - /** - * Logs in to the server using the strongest authentication mode supported by - * the server. If the server supports SASL authentication then the user will be - * authenticated using SASL if not Non-SASL authentication will be tried. If more than - * five seconds (default timeout) elapses in each step of the authentication process - * without a response from the server, or if an error occurs, a XMPPException will be - * thrown.

    - * - * Before logging in (i.e. authenticate) to the server the connection must be connected. - * For compatibility and easiness of use the connection will automatically connect to the - * server if not already connected.

    - * - * It is possible to log in without sending an initial available presence by using - * {@link ConnectionConfiguration#setSendPresence(boolean)}. If this connection is - * not interested in loading its roster upon login then use - * {@link ConnectionConfiguration#setRosterLoadedAtLogin(boolean)}. - * Finally, if you want to not pass a password and instead use a more advanced mechanism - * while using SASL then you may be interested in using - * {@link ConnectionConfiguration#setCallbackHandler(javax.security.auth.callback.CallbackHandler)}. - * For more advanced login settings see {@link ConnectionConfiguration}. - * - * @param username the username. - * @param password the password or null if using a CallbackHandler. - * @param resource the resource. - * @throws XMPPException if an error occurs. - * @throws IllegalStateException if not connected to the server, or already logged in - * to the server. - */ + @Override public synchronized void login(String username, String password, String resource) throws XMPPException { if (!isConnected()) { throw new IllegalStateException("Not connected to server."); @@ -286,16 +259,7 @@ public class XMPPConnection extends Connection { } } - /** - * Logs in to the server anonymously. Very few servers are configured to support anonymous - * authentication, so it's fairly likely logging in anonymously will fail. If anonymous login - * does succeed, your XMPP address will likely be in the form "server/123ABC" (where "123ABC" - * is a random value generated by the server). - * - * @throws XMPPException if an error occurs or anonymous logins are not supported by the server. - * @throws IllegalStateException if not connected to the server, or already logged in - * to the server. - */ + @Override public synchronized void loginAnonymously() throws XMPPException { if (!isConnected()) { throw new IllegalStateException("Not connected to server."); diff --git a/source/org/jivesoftware/smack/packet/PrivacyItem.java b/source/org/jivesoftware/smack/packet/PrivacyItem.java index 57767082e..78cb8db17 100644 --- a/source/org/jivesoftware/smack/packet/PrivacyItem.java +++ b/source/org/jivesoftware/smack/packet/PrivacyItem.java @@ -169,7 +169,7 @@ public class PrivacyItem { * * @param order indicates the order in the list. */ - private void setOrder(int order) { + public void setOrder(int order) { this.order = order; } diff --git a/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java b/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java index 8f490229a..1c7d8a55f 100644 --- a/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java +++ b/source/org/jivesoftware/smackx/debugger/EnhancedDebugger.java @@ -316,7 +316,27 @@ public class EnhancedDebugger implements SmackDebugger { menu.add(menuItem1); // Add listener to the text area so the popup menu can come up. messageTextArea.addMouseListener(new PopupListener(menu)); - allPane.setBottomComponent(new JScrollPane(messageTextArea)); + JPanel sublayout = new JPanel(new BorderLayout()); + sublayout.add(new JScrollPane(messageTextArea), BorderLayout.CENTER); + + JButton clearb = new JButton("Clear All Packets"); + + clearb.addActionListener(new AbstractAction() { + private static final long serialVersionUID = -8576045822764763613L; + + @Override + public void actionPerformed(ActionEvent e) { + for(int i=0; i< messagesTable.getRowCount();i++) + { + messagesTable.removeRow(i); + } + + } + }); + + sublayout.add(clearb, BorderLayout.NORTH); + allPane.setBottomComponent(sublayout); + allPane.setDividerLocation(150); tabbedPane.add("All Packets", allPane); diff --git a/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java b/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java index cd74c1ff7..06ec67316 100644 --- a/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java +++ b/source/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java @@ -473,7 +473,7 @@ public class FileTransferNegotiator { private DataForm createDefaultInitiationForm() { DataForm form = new DataForm(Form.TYPE_FORM); FormField field = new FormField(STREAM_DATA_FIELD_NAME); - field.setType(FormField.TYPE_LIST_MULTI); + field.setType(FormField.TYPE_LIST_SINGLE); if (!IBB_ONLY) { field.addOption(new FormField.Option(Socks5BytestreamManager.NAMESPACE)); } diff --git a/source/org/jivesoftware/smackx/muc/RoomInfo.java b/source/org/jivesoftware/smackx/muc/RoomInfo.java index 1e2c655b7..7a632cfa0 100644 --- a/source/org/jivesoftware/smackx/muc/RoomInfo.java +++ b/source/org/jivesoftware/smackx/muc/RoomInfo.java @@ -21,6 +21,7 @@ package org.jivesoftware.smackx.muc; import org.jivesoftware.smackx.Form; +import org.jivesoftware.smackx.FormField; import org.jivesoftware.smackx.packet.DiscoverInfo; import java.util.Iterator; @@ -88,17 +89,14 @@ public class RoomInfo { // Get the information based on the discovered extended information Form form = Form.getFormFrom(info); if (form != null) { - this.description = - form.getField("muc#roominfo_description").getValues().next(); - Iterator values = form.getField("muc#roominfo_subject").getValues(); - if (values.hasNext()) { - this.subject = values.next(); - } - else { - this.subject = ""; - } - this.occupantsCount = - Integer.parseInt(form.getField("muc#roominfo_occupants").getValues() + FormField descField = form.getField("muc#roominfo_description"); + this.description = descField == null ? "" : descField.getValues().next(); + + FormField subjField = form.getField("muc#roominfo_subject"); + this.subject = subjField == null ? "" : subjField.getValues().next(); + + FormField occCountField = form.getField("muc#roominfo_occupants"); + this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues() .next()); } } diff --git a/source/org/jivesoftware/smackx/pubsub/ConfigureForm.java b/source/org/jivesoftware/smackx/pubsub/ConfigureForm.java index 2962c9bee..7f1005e87 100644 --- a/source/org/jivesoftware/smackx/pubsub/ConfigureForm.java +++ b/source/org/jivesoftware/smackx/pubsub/ConfigureForm.java @@ -161,7 +161,9 @@ public class ConfigureForm extends Form public void setChildrenAssociationPolicy(ChildrenAssociationPolicy policy) { addField(ConfigureNodeFields.children_association_policy, FormField.TYPE_LIST_SINGLE); - setAnswer(ConfigureNodeFields.children_association_policy.getFieldName(), policy.toString()); + List values = new ArrayList(1); + values.add(policy.toString()); + setAnswer(ConfigureNodeFields.children_association_policy.getFieldName(), values); } /** diff --git a/source/org/jivesoftware/smackx/pubsub/Item.java b/source/org/jivesoftware/smackx/pubsub/Item.java index 9d627abfe..2ce0baac5 100644 --- a/source/org/jivesoftware/smackx/pubsub/Item.java +++ b/source/org/jivesoftware/smackx/pubsub/Item.java @@ -13,7 +13,7 @@ */ package org.jivesoftware.smackx.pubsub; -import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.pubsub.provider.ItemProvider; /** @@ -39,7 +39,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider; * * @author Robin Collier */ -public class Item implements PacketExtension +public class Item extends NodeExtension { private String id; @@ -52,6 +52,7 @@ public class Item implements PacketExtension */ public Item() { + super(PubSubElementType.ITEM); } /** @@ -63,8 +64,27 @@ public class Item implements PacketExtension */ public Item(String itemId) { + // The element type is actually irrelevant since we override getNamespace() to return null + super(PubSubElementType.ITEM); id = itemId; } + + /** + * Create an Item with an id and a node id. + *

    + * Note: This is not valid for publishing an item to a node, only receiving from + * one as part of {@link Message}. If used to create an Item to publish + * (via {@link LeafNode#publish(Item)}, the server may return an + * error for an invalid packet. + * + * @param itemId The id of the item. + * @param nodeId The id of the node which the item was published to. + */ + public Item(String itemId, String nodeId) + { + super(PubSubElementType.ITEM_EVENT, nodeId); + id = itemId; + } /** * Get the item id. Unique to the node it is associated with. @@ -76,16 +96,13 @@ public class Item implements PacketExtension return id; } - public String getElementName() - { - return "item"; - } - + @Override public String getNamespace() { return null; } + @Override public String toXML() { StringBuilder builder = new StringBuilder(""); return builder.toString(); diff --git a/source/org/jivesoftware/smackx/pubsub/PayloadItem.java b/source/org/jivesoftware/smackx/pubsub/PayloadItem.java index e147e6102..6ebd430c1 100644 --- a/source/org/jivesoftware/smackx/pubsub/PayloadItem.java +++ b/source/org/jivesoftware/smackx/pubsub/PayloadItem.java @@ -16,6 +16,8 @@ package org.jivesoftware.smackx.pubsub; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smackx.pubsub.provider.ItemProvider; +import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; + /** * This class represents an item that has been, or will be published to a * pubsub node. An Item has several properties that are dependent @@ -43,6 +45,20 @@ public class PayloadItem extends Item { private E payload; + /** + * Create an Item with no id and a payload The id will be set by the server. + * + * @param payloadExt A {@link PacketExtension} which represents the payload data. + */ + public PayloadItem(E payloadExt) + { + super(); + + if (payloadExt == null) + throw new IllegalArgumentException("payload cannot be 'null'"); + payload = payloadExt; + } + /** * Create an Item with an id and payload. * @@ -58,6 +74,28 @@ public class PayloadItem extends Item payload = payloadExt; } + /** + * Create an Item with an id, node id and payload. + * + *

    + * Note: This is not valid for publishing an item to a node, only receiving from + * one as part of {@link Message}. If used to create an Item to publish + * (via {@link LeafNode#publish(Item)}, the server may return an + * error for an invalid packet. + * + * @param itemId The id of this item. + * @param nodeId The id of the node the item was published to. + * @param payloadExt A {@link PacketExtension} which represents the payload data. + */ + public PayloadItem(String itemId, String nodeId, E payloadExt) + { + super(itemId, nodeId); + + if (payloadExt == null) + throw new IllegalArgumentException("payload cannot be 'null'"); + payload = payloadExt; + } + /** * Get the payload associated with this Item. Customising the payload * parsing from the server can be accomplished as described in {@link ItemProvider}. @@ -69,6 +107,7 @@ public class PayloadItem extends Item return payload; } + @Override public String toXML() { StringBuilder builder = new StringBuilder(" extends Item builder.append("'"); } + if (getNode() != null) { + builder.append(" node='"); + builder.append(getNode()); + builder.append("'"); + } builder.append(">"); builder.append(payload.toXML()); builder.append(""); @@ -92,4 +136,4 @@ public class PayloadItem extends Item { return getClass().getName() + " | Content [" + toXML() + "]"; } -} +} \ No newline at end of file diff --git a/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java b/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java index 78fa9c193..a887ca2ba 100644 --- a/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java +++ b/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java @@ -32,6 +32,9 @@ public enum PubSubElementType OPTIONS("options", PubSubNamespace.BASIC), DEFAULT("default", PubSubNamespace.OWNER), ITEMS("items", PubSubNamespace.BASIC), + ITEMS_EVENT("items", PubSubNamespace.EVENT), + ITEM("item", PubSubNamespace.BASIC), + ITEM_EVENT("item", PubSubNamespace.EVENT), PUBLISH("publish", PubSubNamespace.BASIC), PUBLISH_OPTIONS("publish-options", PubSubNamespace.BASIC), PURGE_OWNER("purge", PubSubNamespace.OWNER), @@ -41,7 +44,7 @@ public enum PubSubElementType SUBSCRIBE("subscribe", PubSubNamespace.BASIC), SUBSCRIPTION("subscription", PubSubNamespace.BASIC), SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC), - UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC); + UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC); private String eName; private PubSubNamespace nSpace; diff --git a/source/org/jivesoftware/smackx/pubsub/PubSubManager.java b/source/org/jivesoftware/smackx/pubsub/PubSubManager.java index 4e67b315e..e3eeae4b4 100644 --- a/source/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/source/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -48,13 +48,15 @@ final public class PubSubManager private Map nodeMap = new ConcurrentHashMap(); /** - * Create a pubsub manager associated to the specified connection. + * Create a pubsub manager associated to the specified connection. Defaults the service + * name to pubsub * * @param connection The XMPP connection */ public PubSubManager(Connection connection) { con = connection; + to = "pubsub." + connection.getServiceName(); } /** diff --git a/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java b/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java index f8b59427e..aabd4cb2f 100644 --- a/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java +++ b/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java @@ -35,13 +35,14 @@ public class ItemProvider implements PacketExtensionProvider public PacketExtension parseExtension(XmlPullParser parser) throws Exception { String id = parser.getAttributeValue(null, "id"); + String node = parser.getAttributeValue(null, "node"); String elem = parser.getName(); int tag = parser.next(); if (tag == XmlPullParser.END_TAG) { - return new Item(id); + return new Item(id, node); } else { @@ -63,11 +64,11 @@ public class ItemProvider implements PacketExtensionProvider if (!done) tag = parser.next(); } - return new PayloadItem(id, new SimplePayload(payloadElemName, payloadNS, payloadText.toString())); + return new PayloadItem(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString())); } else { - return new PayloadItem(id, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser)); + return new PayloadItem(id, node, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser)); } } } diff --git a/test-unit/org/jivesoftware/smack/ThreadedDummyConnection.java b/test-unit/org/jivesoftware/smack/ThreadedDummyConnection.java new file mode 100644 index 000000000..8631b0371 --- /dev/null +++ b/test-unit/org/jivesoftware/smack/ThreadedDummyConnection.java @@ -0,0 +1,77 @@ +package org.jivesoftware.smack; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.IQ.Type; + +public class ThreadedDummyConnection extends DummyConnection +{ + private BlockingQueue replyQ = new ArrayBlockingQueue(1); + private BlockingQueue messageQ = new LinkedBlockingQueue(5); + + @Override + public void sendPacket(Packet packet) + { + super.sendPacket(packet); + + if ((packet instanceof IQ) && !replyQ.isEmpty()) + { + // Set reply packet to match one being sent. We haven't started the + // other thread yet so this is still safe. + IQ replyPacket = replyQ.peek(); + replyPacket.setPacketID(packet.getPacketID()); + replyPacket.setFrom(packet.getTo()); + replyPacket.setTo(packet.getFrom()); + replyPacket.setType(Type.RESULT); + + new ProcessQueue(replyQ).start(); + } + } + + public void addMessage(Message msgToProcess) + { + messageQ.add(msgToProcess); + } + + public void addIQReply(IQ reply) + { + replyQ.add(reply); + } + + public void processMessages() + { + if (!messageQ.isEmpty()) + new ProcessQueue(messageQ).start(); + else + System.out.println("No messages to process"); + } + + class ProcessQueue extends Thread + { + private BlockingQueue processQ; + + ProcessQueue(BlockingQueue queue) + { + processQ = queue; + } + + @Override + public void run() + { + try + { + processPacket(processQ.take()); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + }; + +} diff --git a/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java b/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java new file mode 100644 index 000000000..6bb1106b5 --- /dev/null +++ b/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java @@ -0,0 +1,92 @@ +package org.jivesoftware.smack.filters; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import org.jivesoftware.smack.filter.FromMatchesFilter; +import org.jivesoftware.smack.packet.Packet; +import org.junit.Test; + +public class FromMatchesFilterTest { + private static final String BASE_JID1 = "ss@muc.myserver.com"; + private static final String FULL_JID1_R1 = BASE_JID1 + "/resource"; + private static final String FULL_JID1_R2 = BASE_JID1 + "/resource2"; + private static final String BASE_JID2 = "sss@muc.myserver.com"; + private static final String FULL_JID2 = BASE_JID2 + "/resource"; + + private static final String SERVICE_JID1 = "muc.myserver.com"; + private static final String SERVICE_JID2 = "pubsub.myserver.com"; + + @Test + public void compareMatchingFullJid() + { + FromMatchesFilter filter = new FromMatchesFilter(FULL_JID1_R1); + Packet packet = new Packet() { + @Override + public String toXML() { return null; } + }; + + packet.setFrom(FULL_JID1_R1); + assertTrue(filter.accept(packet)); + + packet.setFrom(BASE_JID1); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R2); + assertFalse(filter.accept(packet)); + + packet.setFrom(BASE_JID2); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID2); + assertFalse(filter.accept(packet)); + } + + @Test + public void compareMatchingBaseJid() + { + FromMatchesFilter filter = new FromMatchesFilter(BASE_JID1); + Packet packet = new Packet() { + @Override + public String toXML() { return null; } + }; + + packet.setFrom(BASE_JID1); + assertTrue(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R1); + assertTrue(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R2); + assertTrue(filter.accept(packet)); + + packet.setFrom(BASE_JID2); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID2); + assertFalse(filter.accept(packet)); + } + + @Test + public void compareMatchingServiceJid() + { + FromMatchesFilter filter = new FromMatchesFilter(SERVICE_JID1); + Packet packet = new Packet() { + @Override + public String toXML() { return null; } + }; + + packet.setFrom(SERVICE_JID1); + assertTrue(filter.accept(packet)); + + packet.setFrom(SERVICE_JID2); + assertFalse(filter.accept(packet)); + + packet.setFrom(BASE_JID1); + assertFalse(filter.accept(packet)); + + packet.setFrom(FULL_JID1_R1); + assertFalse(filter.accept(packet)); + + } +} diff --git a/test-unit/org/jivesoftware/smack/packet/MessageTest.java b/test-unit/org/jivesoftware/smack/packet/MessageTest.java index fd79aad0d..526698bb1 100644 --- a/test-unit/org/jivesoftware/smack/packet/MessageTest.java +++ b/test-unit/org/jivesoftware/smack/packet/MessageTest.java @@ -8,6 +8,8 @@ package org.jivesoftware.smack.packet; import static org.custommonkey.xmlunit.XMLAssert.*; + +import org.junit.Ignore; import org.junit.Test; import org.xml.sax.SAXException; @@ -105,6 +107,7 @@ public class MessageTest { assertXMLEqual(control, message.toXML()); } + @Ignore @Test public void multipleMessageBodiesTest() throws IOException, SAXException, ParserConfigurationException { final String messageBody1 = "This is a test of the emergency broadcast system, 1."; diff --git a/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java b/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java index 7365343ba..068d37d26 100644 --- a/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java +++ b/test-unit/org/jivesoftware/smack/util/PacketParserUtilsTest.java @@ -19,6 +19,7 @@ import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; +import org.junit.Ignore; import org.junit.Test; import org.xmlpull.mxp1.MXParser; import org.xmlpull.v1.XmlPullParser; @@ -714,6 +715,7 @@ public class PacketParserUtilsTest { } + @Ignore @Test public void multipleMessageBodiesParsingTest() throws Exception { String control = XMLBuilder.create("message") @@ -733,7 +735,6 @@ public class PacketParserUtilsTest { .a("xml:lang", "sp") .t("This is a test of the emergency broadcast system, 3.") .asString(outputProperties); - Packet message = PacketParserUtils.parseMessage(getParser(control)); assertXMLEqual(control, message.toXML()); diff --git a/test-unit/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java b/test-unit/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java new file mode 100644 index 000000000..9a6e6cd63 --- /dev/null +++ b/test-unit/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java @@ -0,0 +1,41 @@ +package org.jivesoftware.smackx.filetransfer; + +import static org.junit.Assert.*; + +import org.jivesoftware.smack.DummyConnection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smackx.ServiceDiscoveryManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class FileTransferNegotiatorTest { + private DummyConnection connection; + + @Before + public void setUp() throws Exception { + // Uncomment this to enable debug output + //Connection.DEBUG_ENABLED = true; + + connection = new DummyConnection(); + connection.connect(); + connection.login("me", "secret"); + new ServiceDiscoveryManager(connection); + } + + @After + public void tearDown() throws Exception { + if (connection != null) + connection.disconnect(); + } + + @Test + public void verifyForm() throws Exception + { + FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection); + fileNeg.negotiateOutgoingTransfer("me", "streamid", "file", 1024, null, 10); + Packet packet = connection.getSentPacket(); + assertTrue(packet.toXML().indexOf("\"stream-method\" type=\"list-single\"") != -1); + } +} diff --git a/test-unit/org/jivesoftware/smackx/muc/RoomInfoTest.java b/test-unit/org/jivesoftware/smackx/muc/RoomInfoTest.java new file mode 100644 index 000000000..09e2b6d37 --- /dev/null +++ b/test-unit/org/jivesoftware/smackx/muc/RoomInfoTest.java @@ -0,0 +1,50 @@ +package org.jivesoftware.smackx.muc; + +import org.jivesoftware.smackx.FormField; +import org.jivesoftware.smackx.muc.RoomInfo; +import org.jivesoftware.smackx.packet.DataForm; +import org.jivesoftware.smackx.packet.DiscoverInfo; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class RoomInfoTest +{ + @Test + public void validateRoomWithEmptyForm() + { + DataForm dataForm = new DataForm("result"); + + DiscoverInfo discoInfo = new DiscoverInfo(); + discoInfo.addExtension(dataForm); + RoomInfo roomInfo = new RoomInfo(discoInfo); + assertTrue(roomInfo.getDescription().isEmpty()); + assertTrue(roomInfo.getSubject().isEmpty()); + assertEquals(-1, roomInfo.getOccupantsCount()); + } + + @Test + public void validateRoomWithForm() + { + DataForm dataForm = new DataForm("result"); + + FormField desc = new FormField("muc#roominfo_description"); + desc.addValue("The place for all good witches!"); + dataForm.addField(desc); + + FormField subject = new FormField("muc#roominfo_subject"); + subject.addValue("Spells"); + dataForm.addField(subject); + + FormField occupants = new FormField("muc#roominfo_occupants"); + occupants.addValue("3"); + dataForm.addField(occupants); + + DiscoverInfo discoInfo = new DiscoverInfo(); + discoInfo.addExtension(dataForm); + RoomInfo roomInfo = new RoomInfo(discoInfo); + assertEquals("The place for all good witches!", roomInfo.getDescription()); + assertEquals("Spells", roomInfo.getSubject()); + assertEquals(3, roomInfo.getOccupantsCount()); + } +} diff --git a/test-unit/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/test-unit/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java new file mode 100644 index 000000000..291d16019 --- /dev/null +++ b/test-unit/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java @@ -0,0 +1,16 @@ +package org.jivesoftware.smackx.pubsub; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ConfigureFormTest +{ + @Test + public void checkChildrenAssocPolicy() + { + ConfigureForm form = new ConfigureForm(FormType.submit); + form.setChildrenAssociationPolicy(ChildrenAssociationPolicy.owners); + assertEquals(ChildrenAssociationPolicy.owners, form.getChildrenAssociationPolicy()); + } +} diff --git a/test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java b/test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java new file mode 100644 index 000000000..a314b4628 --- /dev/null +++ b/test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java @@ -0,0 +1,107 @@ +package org.jivesoftware.smackx.pubsub; + +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.Reader; +import java.io.StringReader; + +import org.jivesoftware.smack.ThreadedDummyConnection; +import org.jivesoftware.smackx.pubsub.provider.ItemsProvider; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.xmlpull.mxp1.MXParser; +import org.xmlpull.v1.XmlPullParser; + +public class ItemValidationTest +{ + private ThreadedDummyConnection connection; + + @Before + public void setUp() throws Exception + { + // Uncomment this to enable debug output + // Connection.DEBUG_ENABLED = true; + + connection = new ThreadedDummyConnection(); + connection.connect(); + connection.login("me", "secret"); + } + + @After + public void tearDown() throws Exception + { + if (connection != null) + connection.disconnect(); + } + + @Test + public void verifyBasicItem() throws Exception + { + Item simpleItem = new Item(); + String simpleCtrl = ""; + assertXMLEqual(simpleCtrl, simpleItem.toXML()); + + Item idItem = new Item("uniqueid"); + String idCtrl = ""; + assertXMLEqual(idCtrl, idItem.toXML()); + + Item itemWithNodeId = new Item("testId", "testNode"); + String nodeIdCtrl = ""; + assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML()); + } + + @Test + public void verifyPayloadItem() throws Exception + { + SimplePayload payload = new SimplePayload(null, null, "This is the payload"); + + PayloadItem simpleItem = new PayloadItem(payload); + String simpleCtrl = "" + payload.toXML() + ""; + assertXMLEqual(simpleCtrl, simpleItem.toXML()); + + PayloadItem idItem = new PayloadItem("uniqueid", payload); + String idCtrl = "" + payload.toXML() + ""; + assertXMLEqual(idCtrl, idItem.toXML()); + + PayloadItem itemWithNodeId = new PayloadItem("testId", "testNode", payload); + String nodeIdCtrl = "" + payload.toXML() + ""; + assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML()); + } + +// @Test +// public void parseBasicItemWithoutNode() throws Exception +// { +// XmlPullParser parser = new MXParser(); +// Reader reader = new StringReader( +// "" + +// "" + +// "" + +// ""); +// parser.setInput(reader); +// ItemsProvider itemsProvider = new ItemsProvider(); +// ItemsExtension ext = (ItemsExtension) itemsProvider.parseExtension(parser); +// Item basicItem = (Item) ext.getItems().get(0); +// +// assertEquals("testid1", basicItem.getId()); +// assertNull(basicItem.getNode()); +// } + +// @Test +// public void parseBasicItemNode() throws Exception +// { +// BlockingQueue itemQ = new ArrayBlockingQueue(1); +// +// setupListener(itemQ); +// Message itemMsg = getMessage(""); +// connection.addMessage(itemMsg); +// +// Item basicItem = itemQ.poll(2, TimeUnit.SECONDS); +// +// assertNotNull(basicItem); +// assertEquals("testid1", basicItem.getId()); +// assertEquals("testNode", basicItem.getNode()); +// } +} diff --git a/test/org/jivesoftware/smackx/packet/XHTMLExtensionTest.java b/test/org/jivesoftware/smackx/packet/XHTMLExtensionTest.java index 757b085fc..e27238503 100644 --- a/test/org/jivesoftware/smackx/packet/XHTMLExtensionTest.java +++ b/test/org/jivesoftware/smackx/packet/XHTMLExtensionTest.java @@ -52,11 +52,16 @@ package org.jivesoftware.smackx.packet; -import java.util.*; +import java.util.Iterator; -import org.jivesoftware.smack.*; -import org.jivesoftware.smack.filter.*; -import org.jivesoftware.smack.packet.*; +import org.jivesoftware.smack.Chat; +import org.jivesoftware.smack.PacketCollector; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.filter.PacketExtensionFilter; +import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.filter.ThreadFilter; +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.test.SmackTestCase; /** @@ -70,7 +75,7 @@ public class XHTMLExtensionTest extends SmackTestCase { private int bodiesReceived; public XHTMLExtensionTest(String name) { - super(name); + super(name); } /** @@ -79,27 +84,27 @@ public class XHTMLExtensionTest extends SmackTestCase { * 1. User_1 will send a message with formatted text (XHTML) to user_2 */ public void testSendSimpleXHTMLMessage() { - // User1 creates a chat with user2 - Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); + // User1 creates a chat with user2 + Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); - // User1 creates a message to send to user2 - Message msg = new Message(); - msg.setSubject("Any subject you want"); - msg.setBody("Hey John, this is my new green!!!!"); - // Create a XHTMLExtension Package and add it to the message - XHTMLExtension xhtmlExtension = new XHTMLExtension(); - xhtmlExtension.addBody( - "

    Hey John, this is my new green!!!!

    "); - msg.addExtension(xhtmlExtension); + // User1 creates a message to send to user2 + Message msg = new Message(); + msg.setSubject("Any subject you want"); + msg.setBody("Hey John, this is my new green!!!!"); + // Create a XHTMLExtension Package and add it to the message + XHTMLExtension xhtmlExtension = new XHTMLExtension(); + xhtmlExtension.addBody( + "

    Hey John, this is my new green!!!!

    "); + msg.addExtension(xhtmlExtension); - // User1 sends the message that contains the XHTML to user2 - try { - chat1.sendMessage(msg); - Thread.sleep(200); - } - catch (Exception e) { - fail("An error occured sending the message with XHTML"); - } + // User1 sends the message that contains the XHTML to user2 + try { + chat1.sendMessage(msg); + Thread.sleep(200); + } + catch (Exception e) { + fail("An error occured sending the message with XHTML"); + } } /** @@ -111,48 +116,48 @@ public class XHTMLExtensionTest extends SmackTestCase { * something is wrong */ public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() { - // Create a chat for each connection - Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); - final PacketCollector chat2 = getConnection(1).createPacketCollector( - new ThreadFilter(chat1.getThreadID())); + // Create a chat for each connection + Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); + final PacketCollector chat2 = getConnection(1).createPacketCollector( + new ThreadFilter(chat1.getThreadID())); - // User1 creates a message to send to user2 - Message msg = new Message(); - msg.setSubject("Any subject you want"); - msg.setBody("Hey John, this is my new green!!!!"); - // Create a XHTMLExtension Package and add it to the message - XHTMLExtension xhtmlExtension = new XHTMLExtension(); - xhtmlExtension.addBody( - "

    Hey John, this is my new green!!!!

    "); - msg.addExtension(xhtmlExtension); + // User1 creates a message to send to user2 + Message msg = new Message(); + msg.setSubject("Any subject you want"); + msg.setBody("Hey John, this is my new green!!!!"); + // Create a XHTMLExtension Package and add it to the message + XHTMLExtension xhtmlExtension = new XHTMLExtension(); + xhtmlExtension.addBody( + "

    Hey John, this is my new green!!!!

    "); + msg.addExtension(xhtmlExtension); - // User1 sends the message that contains the XHTML to user2 - try { - chat1.sendMessage(msg); - } - catch (Exception e) { - fail("An error occured sending the message with XHTML"); - } - Packet packet = chat2.nextResult(2000); - Message message = (Message) packet; - assertNotNull("Body is null", message.getBody()); - try { - xhtmlExtension = - (XHTMLExtension) message.getExtension( - "html", - "http://jabber.org/protocol/xhtml-im"); - assertNotNull( - "Message without extension \"http://jabber.org/protocol/xhtml-im\"", - xhtmlExtension); - assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0); - for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) { - String body = (String) it.next(); - System.out.println(body); - } - } - catch (ClassCastException e) { - fail("ClassCastException - Most probable cause is that smack providers is misconfigured"); - } + // User1 sends the message that contains the XHTML to user2 + try { + chat1.sendMessage(msg); + } + catch (Exception e) { + fail("An error occured sending the message with XHTML"); + } + Packet packet = chat2.nextResult(2000); + Message message = (Message) packet; + assertNotNull("Body is null", message.getBody()); + try { + xhtmlExtension = + (XHTMLExtension) message.getExtension( + "html", + "http://jabber.org/protocol/xhtml-im"); + assertNotNull( + "Message without extension \"http://jabber.org/protocol/xhtml-im\"", + xhtmlExtension); + assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0); + for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) { + String body = (String) it.next(); + System.out.println(body); + } + } + catch (ClassCastException e) { + fail("ClassCastException - Most probable cause is that smack providers is misconfigured"); + } } /** @@ -164,22 +169,23 @@ public class XHTMLExtensionTest extends SmackTestCase { * something is wrong */ public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() { - // Create a chat for each connection - Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); - final PacketCollector chat2 = getConnection(1).createPacketCollector( - new ThreadFilter(chat1.getThreadID())); + // Create a chat for each connection + Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); + final PacketCollector chat2 = getConnection(1).createPacketCollector( + new ThreadFilter(chat1.getThreadID())); - // Create a Listener that listens for Messages with the extension - //"http://jabber.org/protocol/xhtml-im" - // This listener will listen on the conn2 and answer an ACK if everything is ok - PacketFilter packetFilter = - new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im"); - PacketListener packetListener = new PacketListener() { - public void processPacket(Packet packet) { + // Create a Listener that listens for Messages with the extension + //"http://jabber.org/protocol/xhtml-im" + // This listener will listen on the conn2 and answer an ACK if everything is ok + PacketFilter packetFilter = + new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im"); + PacketListener packetListener = new PacketListener() { + @Override + public void processPacket(Packet packet) { - } - }; - getConnection(1).addPacketListener(packetListener, packetFilter); + } + }; + getConnection(1).addPacketListener(packetListener, packetFilter); // User1 creates a message to send to user2 Message msg = new Message(); @@ -194,47 +200,48 @@ public class XHTMLExtensionTest extends SmackTestCase { "

    awesome!

    As Emerson once said:

    A foolish consistency is the hobgoblin of little minds.

    "); msg.addExtension(xhtmlExtension); - // User1 sends the message that contains the XHTML to user2 - try { - bodiesSent = xhtmlExtension.getBodiesCount(); - bodiesReceived = 0; - chat1.sendMessage(msg); - } - catch (Exception e) { - fail("An error occured sending the message with XHTML"); - } - Packet packet = chat2.nextResult(2000); - int received = 0; - Message message = (Message) packet; - assertNotNull("Body is null", message.getBody()); - try { - xhtmlExtension = - (XHTMLExtension) message.getExtension( - "html", - "http://jabber.org/protocol/xhtml-im"); - assertNotNull( - "Message without extension \"http://jabber.org/protocol/xhtml-im\"", - xhtmlExtension); - assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0); - for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) { - received++; - System.out.println((String) it.next()); - } - bodiesReceived = received; - } - catch (ClassCastException e) { - fail("ClassCastException - Most probable cause is that smack providers is " + - "misconfigured"); - } - // Wait half second so that the complete test can run - assertEquals( - "Number of sent and received XHTMP bodies does not match", - bodiesSent, - bodiesReceived); + // User1 sends the message that contains the XHTML to user2 + try { + bodiesSent = xhtmlExtension.getBodiesCount(); + bodiesReceived = 0; + chat1.sendMessage(msg); + } + catch (Exception e) { + fail("An error occured sending the message with XHTML"); + } + Packet packet = chat2.nextResult(2000); + int received = 0; + Message message = (Message) packet; + assertNotNull("Body is null", message.getBody()); + try { + xhtmlExtension = + (XHTMLExtension) message.getExtension( + "html", + "http://jabber.org/protocol/xhtml-im"); + assertNotNull( + "Message without extension \"http://jabber.org/protocol/xhtml-im\"", + xhtmlExtension); + assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0); + for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) { + received++; + System.out.println((String) it.next()); + } + bodiesReceived = received; + } + catch (ClassCastException e) { + fail("ClassCastException - Most probable cause is that smack providers is " + + "misconfigured"); + } + // Wait half second so that the complete test can run + assertEquals( + "Number of sent and received XHTMP bodies does not match", + bodiesSent, + bodiesReceived); } + @Override protected int getMaxConnections() { - return 2; + return 2; } }