diff --git a/build/build.xml b/build/build.xml index cb12e905b..1737c4b54 100644 --- a/build/build.xml +++ b/build/build.xml @@ -28,7 +28,7 @@ - + diff --git a/build/eclipse/settings/org.eclipse.jdt.ui.prefs b/build/eclipse/settings/org.eclipse.jdt.ui.prefs index 5da3ae153..fcdbc532c 100644 --- a/build/eclipse/settings/org.eclipse.jdt.ui.prefs +++ b/build/eclipse/settings/org.eclipse.jdt.ui.prefs @@ -4,7 +4,7 @@ editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_ignite formatter_settings_version=12 org.eclipse.jdt.ui.javadoc=false -org.eclipse.jdt.ui.text.custom_code_templates= +org.eclipse.jdt.ui.text.custom_code_templates= sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_missing_annotations=true diff --git a/build/resources/META-INF/smack-config.xml b/build/resources/META-INF/smack-config.xml index 1c763e0c2..a4df4764c 100644 --- a/build/resources/META-INF/smack-config.xml +++ b/build/resources/META-INF/smack-config.xml @@ -2,21 +2,6 @@ - - - org.jivesoftware.smackx.ServiceDiscoveryManager - org.jivesoftware.smack.PrivacyListManager - org.jivesoftware.smackx.XHTMLManager - org.jivesoftware.smackx.muc.MultiUserChat - org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager - org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager - org.jivesoftware.smackx.filetransfer.FileTransferManager - org.jivesoftware.smackx.LastActivityManager - org.jivesoftware.smack.ReconnectionManager - org.jivesoftware.smackx.commands.AdHocCommandManager - org.jivesoftware.smack.util.dns.JavaxResolver - - 5000 @@ -31,11 +16,25 @@ 10000 - - - 1800 - + false + + + + org.jivesoftware.smackx.ServiceDiscoveryManager + org.jivesoftware.smack.PrivacyListManager + org.jivesoftware.smack.keepalive.KeepAliveManager + org.jivesoftware.smackx.XHTMLManager + org.jivesoftware.smackx.muc.MultiUserChat + org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager + org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager + org.jivesoftware.smackx.filetransfer.FileTransferManager + org.jivesoftware.smackx.LastActivityManager + org.jivesoftware.smack.ReconnectionManager + org.jivesoftware.smackx.commands.AdHocCommandManager + org.jivesoftware.smack.util.dns.JavaxResolver + org.jivesoftware.smackx.ping.PingManager + diff --git a/build/resources/META-INF/smack.providers b/build/resources/META-INF/smack.providers index f1a7c1f91..b1ce64057 100644 --- a/build/resources/META-INF/smack.providers +++ b/build/resources/META-INF/smack.providers @@ -241,7 +241,7 @@ ping urn:xmpp:ping - org.jivesoftware.smackx.ping.provider.PingProvider + org.jivesoftware.smack.ping.provider.PingProvider @@ -641,32 +641,6 @@ org.jivesoftware.smackx.packet.AttentionExtension$Provider - - - forwarded - urn:xmpp:forward:0 - org.jivesoftware.smackx.forward.Forwarded$Provider - - - - - sent - urn:xmpp:carbons:2 - org.jivesoftware.smackx.carbons.Carbon$Provider - - - received - urn:xmpp:carbons:2 - org.jivesoftware.smackx.carbons.Carbon$Provider - - - - - ping - urn:xmpp:ping - org.jivesoftware.smackx.ping.provider.PingProvider - - received diff --git a/build/resources/releasedocs/README.html b/build/resources/releasedocs/README.html index de92dbc8f..f935622c9 100644 --- a/build/resources/releasedocs/README.html +++ b/build/resources/releasedocs/README.html @@ -203,6 +203,36 @@ last release. to use these icons outside of Smack.
  • Third-party source code is licensed as noted in their source files. +
  • Third-party binary code is licensed as follows. +
    + dnsjava (http://dnsjava.org)
    +
    + Copyright (c) 1999-2005, Brian Wellington
    + All rights reserved.
    +	
    + Redistribution and use in source and binary forms, with or without
    + modification, are permitted provided that the following conditions are met:
    +	
    +     * Redistributions of source code must retain the above copyright notice,
    +       this list of conditions and the following disclaimer.
    +     * Redistributions in binary form must reproduce the above copyright notice,
    +       this list of conditions and the following disclaimer in the documentation
    +       and/or other materials provided with the distribution.
    +     * Neither the name of the dnsjava project nor the names of its contributors
    +       may be used to endorse or promote products derived from this software
    +       without specific prior written permission.
    +	
    + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
    + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    +
  • diff --git a/build/resources/releasedocs/changelog.html b/build/resources/releasedocs/changelog.html index 9d75fd6a1..c4f969394 100644 --- a/build/resources/releasedocs/changelog.html +++ b/build/resources/releasedocs/changelog.html @@ -141,9 +141,61 @@ hr {
    +

    3.3.0 -- May 4, 2013

    + +

    Bug Fixes

    +
      +
    • [SMACK-225] - Improper handeling of DNS SRV records
    • +
    • [SMACK-238] - The vCard avatar type always return jpg
    • +
    • [SMACK-270] - Fix for a memory leak in MUC with MUC.finalize()
    • +
    • [SMACK-278] - Deadlock during Smack disconnect
    • +
    • [SMACK-342] - VCards causes ConcurrentModificationException
    • +
    • [SMACK-344] - Bug in SASL authentication mechanism when SRV records are being used.
    • +
    • [SMACK-351] - Rework File Transfer
    • +
    • [SMACK-352] - Update the licensing headers in various files.
    • +
    • [SMACK-355] - IO Error if smack cant use port for local proxy
    • +
    • [SMACK-371] - Some MUC tasks are using stanza's as defined in an older version of the spec. Fails to work on some servers.
    • +
    • [SMACK-375] - Node strings in the discovery info packets are not escaped as in the other packets
    • +
    • [SMACK-382] - Prevent memory leak in AdHocCommandManager
    • +
    • [SMACK-384] - Endless waiting for connection to be established
    • +
    • [SMACK-390] - Smack login will fail if a bad delay packet is received
    • +
    • [SMACK-392] - In ant build, compile-test target doesn't work.
    • +
    • [SMACK-394] - Erroneous cast in IBBInputStream's read() method
    • +
    • [SMACK-395] - Socks5BytestreamManager's establishConnection() should still try to use the local streamhost proxy if the server doesn't provide one
    • +
    • [SMACK-404] - Smack uses the wrong method to decode Base64 Strings
    • +
    • [SMACK-413] - VCardProvider incorrectly parses binary value of avatars
    • +
    • [SMACK-415] - ItemProvider relies on incorrect behavior of MXParser, violating the contract of the XMLPullParser interface
    • +
    • [SMACK-417] - If both PacketReader and PacketWriter fail at the same time, connectionClosedonError() is called two times
    • +
    + +

    New Features

    +
      +
    • [SMACK-331] - Add support for XEP-0184: Message Delivery Receipts
    • +
    • [SMACK-345] - Inproved detection of last activity
    • +
    • [SMACK-361] - Add support for XEP-0115 Entity Capabilities
    • +
    • [SMACK-376] - Setting a custom trust manager to control certificates from outside
    • +
    • [SMACK-388] - XEP-199 XMPP Ping support
    • +
    + +

    Improvements

    +
      +
    • [SMACK-341] - Update the PacketCollector and ConnectionDetachedPacketCollector to use the java concurrent classes.
    • +
    • [SMACK-358] - Support additional properties for account creation in test cases.
    • +
    • [SMACK-363] - Code Cleanup
    • +
    • [SMACK-377] - avoid unnecessary DNS requests in XMPPconnection
    • +
    • [SMACK-379] - Sessions were removed from the specification but Smack still uses them. Should be updated to reflect the spec changes.
    • +
    • [SMACK-385] - Reusing KeyStore in order to reduce memory usage
    • +
    • [SMACK-389] - Add java.util.zip.Deflater(In|Out)putStream as Java7 API native alternative to JZlib
    • +
    • [SMACK-391] - Improve date parsing in StringUtils and make DelayInformationProvider use StringUtils for date parsing.
    • +
    • [SMACK-412] - Replace the whitespace ping with a XEP-0199 ping
    • +
    • [SMACK-419] - PacketWriter: Only flush the BufferedWriter if the packet queue is empty
    • +
    • [SMACK-423] - Investigate whether unhandled packets should still parse the child xml into a string as content
    • +
    • [SMACK-430] - Throw an exception if FileTransferManager.createOutgoingFileTransfer() was used with a bare JID
    • +
    +

    3.2.2 -- Dec. 23, 2011

    -

    Bug

    +

    Bug Fixes

    • [SMACK-263] - Set file info in all send* methods
    • [SMACK-322] - NPE in XMPPConnection
    • @@ -157,15 +209,14 @@ hr {
    • [SMACK-362] - smack throw NoSuchElementException if the muc#roominfo_subject has no values
    -

    Improvement

    +

    Improvements

    • [SMACK-343] - Make Smack jar an OSGi bundle.
    • [SMACK-354] - Provide milliseconds in timestamp colum debugwindow
    -

    3.2.1 -- July 4, 2011

    -

    Bug

    +

    Bug Fixes

    • [SMACK-129] - MultiUserChat will Store Messages in its PacketCollector irregardless of whether or not they are being read
    • [SMACK-230] - Disconnect Can Cause Null Pointer Exception
    • @@ -176,14 +227,14 @@ hr {

    3.2.0 -- May 3, 2011

    -

    New Feature

    +

    New Features

    • [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

    +

    Improvements

    • [SMACK-137] - File Transfer Settings
    • [SMACK-156] - Add the ability to register for roster events before logging in
    • @@ -208,9 +259,9 @@ hr {
    • [SMACK-310] - Add Support for Localized Message Subjects
    -

    Bug

    +

    Bug Fixes

      -
    • [SMACK-163] - Fix NPE in RoomInfo when subject has not value
    • +
    • [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
    • diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java index 72431d5f2..9b68c0095 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/ContentNegotiator.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleActionEnum.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleActionEnum.java index d0ca2b73c..99d13c147 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleActionEnum.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleActionEnum.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java index 965369bc8..db53911a1 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleException.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiatorState.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiatorState.java index caa803419..e00ceb7f2 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiatorState.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleNegotiatorState.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java index d1f7bd27d..9b53c9b55 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionState.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionState.java index 830ec5c7c..ec12c861e 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionState.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionState.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateActive.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateActive.java index f698f4a93..e2244a3e7 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateActive.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateActive.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateEnded.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateEnded.java index a3cefe059..c0b4db229 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateEnded.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateEnded.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStatePending.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStatePending.java index 3221da679..a0bf0f255 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStatePending.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStatePending.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateUnknown.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateUnknown.java index 17fa61d1b..80c2e4b6c 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateUnknown.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionStateUnknown.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java index e4fdd73ff..d67ce3b79 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/JMFInit.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultDecoder.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultDecoder.java index 6fdb17f48..74262eef5 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultDecoder.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultDecoder.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultEncoder.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultEncoder.java index cd77ee888..435695a5c 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultEncoder.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/DefaultEncoder.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageDecoder.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageDecoder.java index 2716f90d8..0e4e702c3 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageDecoder.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageDecoder.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageEncoder.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageEncoder.java index 8d01d210c..fb0ba47e2 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageEncoder.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageEncoder.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java index 169c7ff3e..64a46c4f4 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageReceiver.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageTransmitter.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageTransmitter.java index f346f757a..31ef5330a 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageTransmitter.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/mediaimpl/sshare/api/ImageTransmitter.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/HttpServer.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/HttpServer.java index 5b056b481..4c55893a9 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/HttpServer.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/HttpServer.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java index cf793da07..c9d30a09e 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/ICECandidate.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeClient.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeClient.java index 4a92a091e..ab6055012 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeClient.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeClient.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeServer.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeServer.java index 5a127afd3..61f10e979 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeServer.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TcpUdpBridgeServer.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TestResult.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TestResult.java index 04bf118e3..c0040505d 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TestResult.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TestResult.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java index 843344b3d..bce1737b2 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportCandidate.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java index 67f32107b..db9f19830 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/TransportResolver.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java index c3d18d707..9a7ac2354 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSessionTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSessionTest.java index 0cb7f6ef0..77b40def0 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSessionTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSessionTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSupportTests.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSupportTests.java index c5ef51746..71f2b6071 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSupportTests.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleSupportTests.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java index a4576bf93..95c44ef29 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/PayloadTypeTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BasicResolverTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BasicResolverTest.java index 7cac5d964..bb1b33819 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BasicResolverTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BasicResolverTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java index 5ba2e0a91..6a034b5f7 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/LocalhostTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/LocalhostTest.java index 89640dece..81c271da4 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/LocalhostTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/LocalhostTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java index dcf735bf1..bcd81d503 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportCandidateTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportCandidateTest.java index ee353e735..e1170f969 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportCandidateTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportCandidateTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportResolverTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportResolverTest.java index aefc42a4b..1ae0f5c1f 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportResolverTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/TransportResolverTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/jingle/extension/test/org/jivesoftware/smackx/provider/JingleProviderTest.java b/jingle/extension/test/org/jivesoftware/smackx/provider/JingleProviderTest.java index a4172b758..b02de02cb 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/provider/JingleProviderTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/provider/JingleProviderTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/Connection.java b/source/org/jivesoftware/smack/Connection.java index 9a213dbc8..ced103f22 100644 --- a/source/org/jivesoftware/smack/Connection.java +++ b/source/org/jivesoftware/smack/Connection.java @@ -178,12 +178,12 @@ public abstract class Connection { protected SmackDebugger debugger = null; /** - * The Reader which is used for the {@see debugger}. + * The Reader which is used for the debugger. */ protected Reader reader; /** - * The Writer which is used for the {@see debugger}. + * The Writer which is used for the debugger. */ protected Writer writer; diff --git a/source/org/jivesoftware/smack/PacketWriter.java b/source/org/jivesoftware/smack/PacketWriter.java index f8b5c359f..3fe4db09f 100644 --- a/source/org/jivesoftware/smack/PacketWriter.java +++ b/source/org/jivesoftware/smack/PacketWriter.java @@ -40,18 +40,11 @@ import java.util.concurrent.BlockingQueue; class PacketWriter { private Thread writerThread; - private Thread keepAliveThread; private Writer writer; private XMPPConnection connection; private final BlockingQueue queue; volatile boolean done; - /** - * Timestamp when the last stanza was sent to the server. This information is used - * by the keep alive process to only send heartbeats when the connection has been idle. - */ - private long lastActive = System.currentTimeMillis(); - /** * Creates a new packet writer with the specified connection. * @@ -117,25 +110,6 @@ class PacketWriter { writerThread.start(); } - /** - * Starts the keep alive process. A white space (aka heartbeat) is going to be - * sent to the server every 30 seconds (by default) since the last stanza was sent - * to the server. - */ - void startKeepAliveProcess() { - // Schedule a keep-alive task to run if the feature is enabled. will write - // out a space character each time it runs to keep the TCP/IP connection open. - int keepAliveInterval = SmackConfiguration.getKeepAliveInterval(); - if (keepAliveInterval > 0) { - KeepAliveTask task = new KeepAliveTask(keepAliveInterval); - keepAliveThread = new Thread(task); - task.setThread(keepAliveThread); - keepAliveThread.setDaemon(true); - keepAliveThread.setName("Smack Keep Alive (" + connection.connectionCounterValue + ")"); - keepAliveThread.start(); - } - } - void setWriter(Writer writer) { this.writer = writer; } @@ -149,9 +123,6 @@ class PacketWriter { synchronized (queue) { queue.notifyAll(); } - // Interrupt the keep alive thread if one was created - if (keepAliveThread != null) - keepAliveThread.interrupt(); } /** @@ -191,13 +162,10 @@ class PacketWriter { while (!done && (writerThread == thisThread)) { Packet packet = nextPacket(); if (packet != null) { - synchronized (writer) { - writer.write(packet.toXML()); - if (queue.isEmpty()) { - writer.flush(); - // Keep track of the last time a stanza was sent to the server - lastActive = System.currentTimeMillis(); - } + writer.write(packet.toXML()); + + if (queue.isEmpty()) { + writer.flush(); } } } @@ -205,13 +173,11 @@ class PacketWriter { // we won't have time to entirely flush it before the socket is forced closed // by the shutdown process. try { - synchronized (writer) { - while (!queue.isEmpty()) { - Packet packet = queue.remove(); - writer.write(packet.toXML()); - } - writer.flush(); + while (!queue.isEmpty()) { + Packet packet = queue.remove(); + writer.write(packet.toXML()); } + writer.flush(); } catch (Exception e) { e.printStackTrace(); @@ -268,54 +234,4 @@ class PacketWriter { writer.write(stream.toString()); writer.flush(); } - - /** - * A TimerTask that keeps connections to the server alive by sending a space - * character on an interval. - */ - private class KeepAliveTask implements Runnable { - - private int delay; - private Thread thread; - - public KeepAliveTask(int delay) { - this.delay = delay; - } - - protected void setThread(Thread thread) { - this.thread = thread; - } - - public void run() { - try { - // Sleep a minimum of 15 seconds plus delay before sending first heartbeat. This will give time to - // properly finish TLS negotiation and then start sending heartbeats. - Thread.sleep(15000 + delay); - } - catch (InterruptedException ie) { - // Do nothing - } - while (!done && keepAliveThread == thread) { - synchronized (writer) { - // Send heartbeat if no packet has been sent to the server for a given time - if (System.currentTimeMillis() - lastActive >= delay) { - try { - writer.write(" "); - writer.flush(); - } - catch (Exception e) { - // Do nothing - } - } - } - try { - // Sleep until we should write the next keep-alive. - Thread.sleep(delay); - } - catch (InterruptedException ie) { - // Do nothing - } - } - } - } } diff --git a/source/org/jivesoftware/smack/PrivacyList.java b/source/org/jivesoftware/smack/PrivacyList.java index abb99b742..67d731db7 100644 --- a/source/org/jivesoftware/smack/PrivacyList.java +++ b/source/org/jivesoftware/smack/PrivacyList.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/ReconnectionManager.java b/source/org/jivesoftware/smack/ReconnectionManager.java index 46274520d..cc3e3af19 100644 --- a/source/org/jivesoftware/smack/ReconnectionManager.java +++ b/source/org/jivesoftware/smack/ReconnectionManager.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/SASLAuthentication.java b/source/org/jivesoftware/smack/SASLAuthentication.java index a7e1dcbba..6f8b5bf1e 100644 --- a/source/org/jivesoftware/smack/SASLAuthentication.java +++ b/source/org/jivesoftware/smack/SASLAuthentication.java @@ -315,8 +315,13 @@ public class SASLAuthentication implements UserAuthentication { currentMechanism = constructor.newInstance(this); // Trigger SASL authentication with the selected mechanism. We use // connection.getHost() since GSAPI requires the FQDN of the server, which - // may not match the XMPP domain. - currentMechanism.authenticate(username, connection.getServiceName(), password); + // may not match the XMPP domain. + + //The serviceName is basically the value that XMPP server sends to the client as being the location + //of the XMPP service we are trying to connect to. This should have the format: host [ "/" serv-name ] + //as per RFC-2831 guidelines + String serviceName = connection.getServiceName(); + currentMechanism.authenticate(username, connection.getHost(), serviceName, password); // Wait until SASL negotiation finishes synchronized (this) { @@ -383,7 +388,7 @@ public class SASLAuthentication implements UserAuthentication { public String authenticateAnonymously() throws XMPPException { try { currentMechanism = new SASLAnonymous(this); - currentMechanism.authenticate(null,null,""); + currentMechanism.authenticate(null,null,null,""); // Wait until SASL negotiation finishes synchronized (this) { diff --git a/source/org/jivesoftware/smack/SmackConfiguration.java b/source/org/jivesoftware/smack/SmackConfiguration.java index 80f1906af..3ff84a0ab 100644 --- a/source/org/jivesoftware/smack/SmackConfiguration.java +++ b/source/org/jivesoftware/smack/SmackConfiguration.java @@ -48,7 +48,7 @@ import org.xmlpull.v1.XmlPullParser; */ public final class SmackConfiguration { - private static final String SMACK_VERSION = "3.2.2"; + private static final String SMACK_VERSION = "3.3.0"; private static int packetReplyTimeout = 5000; private static int keepAliveInterval = 30000; @@ -58,11 +58,6 @@ public final class SmackConfiguration { private static int localSocks5ProxyPort = 7777; private static int packetCollectorSize = 5000; - /** - * defaultPingInterval (in seconds) - */ - private static int defaultPingInterval = 1800; // 30 min (30*60) - /** * This automatically enables EntityCaps for new connections if it is set to true */ @@ -117,8 +112,8 @@ public final class SmackConfiguration { else if (parser.getName().equals("packetCollectorSize")) { packetCollectorSize = parseIntProperty(parser, packetCollectorSize); } - else if (parser.getName().equals("defaultPingInterval")) { - defaultPingInterval = parseIntProperty(parser, defaultPingInterval); + else if (parser.getName().equals("autoEnableEntityCaps")) { + autoEnableEntityCaps = Boolean.parseBoolean(parser.nextText()); } else if (parser.getName().equals("autoEnableEntityCaps")) { autoEnableEntityCaps = Boolean.parseBoolean(parser.nextText()); @@ -320,21 +315,12 @@ public final class SmackConfiguration { } /** - * Returns the default ping interval (seconds) + * Set if Entity Caps are enabled or disabled for every new connection * - * @return + * @param true if Entity Caps should be auto enabled, false if not */ - public static int getDefaultPingInterval() { - return defaultPingInterval; - } - - /** - * Sets the default ping interval (seconds). Set it to '-1' to disable the periodic ping - * - * @param defaultPingInterval - */ - public static void setDefaultPingInterval(int defaultPingInterval) { - SmackConfiguration.defaultPingInterval = defaultPingInterval; + public static void setAutoEnableEntityCaps(boolean b) { + autoEnableEntityCaps = b; } /** @@ -345,15 +331,6 @@ public final class SmackConfiguration { return autoEnableEntityCaps; } - /** - * Set if Entity Caps are enabled or disabled for every new connection - * - * @param true if Entity Caps should be auto enabled, false if not - */ - public static void setAutoEnableEntityCaps(boolean b) { - autoEnableEntityCaps = b; - } - private static void parseClassToLoad(XmlPullParser parser) throws Exception { String className = parser.nextText(); // Attempt to load the class so that the class can get initialized diff --git a/source/org/jivesoftware/smack/SmackError.java b/source/org/jivesoftware/smack/SmackError.java new file mode 100644 index 000000000..af22e7c0e --- /dev/null +++ b/source/org/jivesoftware/smack/SmackError.java @@ -0,0 +1,24 @@ +package org.jivesoftware.smack; + +public enum SmackError { + NO_RESPONSE_FROM_SERVER("No response from server."); + + private String message; + + private SmackError(String errMessage) { + message = errMessage; + } + + public String getErrorMessage() { + return message; + } + + public static SmackError getErrorCode(String message) { + for (SmackError code : values()) { + if (code.message.equals(message)) { + return code; + } + } + return null; + } +} diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index 6512aa981..2c75e208a 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -650,10 +650,6 @@ public class XMPPConnection extends Connection { // Make note of the fact that we're now connected. connected = true; - // Start keep alive process (after TLS was negotiated - if available) - packetWriter.startKeepAliveProcess(); - - if (isFirstInitialization) { // Notify listeners that a new connection has been established for (ConnectionCreationListener listener : getConnectionCreationListeners()) { diff --git a/source/org/jivesoftware/smack/XMPPException.java b/source/org/jivesoftware/smack/XMPPException.java index 6da24c2b7..e6da0168c 100644 --- a/source/org/jivesoftware/smack/XMPPException.java +++ b/source/org/jivesoftware/smack/XMPPException.java @@ -41,10 +41,12 @@ import java.io.PrintWriter; * @author Matt Tucker */ public class XMPPException extends Exception { - + private static final long serialVersionUID = 6881651633890968625L; + private StreamError streamError = null; private XMPPError error = null; private Throwable wrappedThrowable = null; + private SmackError smackError = null; /** * Creates a new XMPPException. @@ -62,6 +64,16 @@ public class XMPPException extends Exception { super(message); } + /** + * Creates a new XMPPException with a Smack specific error code. + * + * @param code the root cause of the exception. + */ + public XMPPException(SmackError code) { + super(code.getErrorMessage()); + smackError = code; + } + /** * Creates a new XMPPException with the Throwable that was the root cause of the * exception. @@ -74,7 +86,7 @@ public class XMPPException extends Exception { } /** - * Cretaes a new XMPPException with the stream error that was the root case of the + * Creates a new XMPPException with the stream error that was the root case of the * exception. When a stream error is received from the server then the underlying * TCP connection will be closed by the server. * @@ -144,6 +156,16 @@ public class XMPPException extends Exception { return error; } + /** + * Returns the SmackError asscociated with this exception, or null if there + * isn't one. + * + * @return the SmackError asscociated with this exception. + */ + public SmackError getSmackError() { + return smackError; + } + /** * Returns the StreamError asscociated with this exception, or null if there * isn't one. The underlying TCP connection is closed by the server after sending the diff --git a/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java b/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java index 6ca5d81e8..7e078b407 100644 --- a/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java +++ b/source/org/jivesoftware/smack/debugger/ConsoleDebugger.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/filter/FromContainsFilter.java b/source/org/jivesoftware/smack/filter/FromContainsFilter.java index bc372f927..f8e9e977b 100644 --- a/source/org/jivesoftware/smack/filter/FromContainsFilter.java +++ b/source/org/jivesoftware/smack/filter/FromContainsFilter.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/source/org/jivesoftware/smack/keepalive/KeepAliveManager.java b/source/org/jivesoftware/smack/keepalive/KeepAliveManager.java new file mode 100644 index 000000000..99e1acfba --- /dev/null +++ b/source/org/jivesoftware/smack/keepalive/KeepAliveManager.java @@ -0,0 +1,312 @@ +/** + * Copyright 2012-2013 Florian Schmaus + * + * 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.keepalive; + +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.ConnectionCreationListener; +import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.PacketCollector; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.filter.PacketIDFilter; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.ping.PingFailedListener; +import org.jivesoftware.smack.ping.packet.Ping; + +/** + * Using an implementation of XMPP Ping (XEP-0199). This + * class provides keepalive functionality with the server that will periodically "ping" the server to maintain and/or + * verify that the connection still exists. + *

      + * The ping is done at the application level and is therefore protocol agnostic. It will thus work for both standard TCP + * connections as well as BOSH or any other transport protocol. It will also work regardless of whether the server + * supports the Ping extension, since an error response to the ping serves the same purpose as a pong. + * + * @author Florian Schmaus + */ +public class KeepAliveManager { + private static Map instances = new HashMap(); + private static volatile ScheduledExecutorService periodicPingExecutorService; + + static { + if (SmackConfiguration.getKeepAliveInterval() > 0) { + Connection.addConnectionCreationListener(new ConnectionCreationListener() { + public void connectionCreated(Connection connection) { + new KeepAliveManager(connection); + } + }); + } + } + + private Connection connection; + private long pingInterval = SmackConfiguration.getKeepAliveInterval(); + private Set pingFailedListeners = Collections.synchronizedSet(new HashSet()); + private volatile ScheduledFuture periodicPingTask; + private volatile long lastSuccessfulContact = -1; + + /** + * Retrieves a {@link KeepAliveManager} for the specified {@link Connection}, creating one if it doesn't already + * exist. + * + * @param connection + * The connection the manager is attached to. + * @return The new or existing manager. + */ + public synchronized static KeepAliveManager getInstanceFor(Connection connection) { + KeepAliveManager pingManager = instances.get(connection); + + if (pingManager == null) { + pingManager = new KeepAliveManager(connection); + instances.put(connection, pingManager); + } + return pingManager; + } + + /* + * Start the executor service if it hasn't been started yet. + */ + private synchronized static void enableExecutorService() { + if (periodicPingExecutorService == null) { + periodicPingExecutorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { + @Override + public Thread newThread(Runnable runnable) { + Thread pingThread = new Thread(runnable, "Smack Keepalive"); + pingThread.setDaemon(true); + return pingThread; + } + }); + } + } + + /* + * Stop the executor service if all monitored connections are disconnected. + */ + private synchronized static void handleDisconnect(Connection con) { + if (periodicPingExecutorService != null) { + instances.remove(con); + + if (instances.isEmpty()) { + periodicPingExecutorService.shutdownNow(); + periodicPingExecutorService = null; + } + } + } + + private KeepAliveManager(Connection connection) { + this.connection = connection; + init(); + handleConnect(); + } + + /* + * Call after every connection to add the packet listener. + */ + private void handleConnect() { + // Listen for all incoming packets and reset the scheduled ping whenever + // one arrives. + connection.addPacketListener(new PacketListener() { + + @Override + public void processPacket(Packet packet) { + // reschedule the ping based on this last server contact + lastSuccessfulContact = System.currentTimeMillis(); + schedulePingServerTask(); + } + }, null); + } + + private void init() { + connection.addConnectionListener(new ConnectionListener() { + + @Override + public void connectionClosed() { + stopPingServerTask(); + handleDisconnect(connection); + } + + @Override + public void connectionClosedOnError(Exception arg0) { + stopPingServerTask(); + handleDisconnect(connection); + } + + @Override + public void reconnectionSuccessful() { + handleConnect(); + schedulePingServerTask(); + } + + @Override + public void reconnectingIn(int seconds) { + } + + @Override + public void reconnectionFailed(Exception e) { + } + }); + + instances.put(connection, this); + schedulePingServerTask(); + } + + /** + * Sets the ping interval. + * + * @param pingInterval + * The new ping time interval in milliseconds. + */ + public void setPingInterval(long newPingInterval) { + if (pingInterval == newPingInterval) + return; + + // Enable the executor service + if (newPingInterval > 0) + enableExecutorService(); + + pingInterval = newPingInterval; + + if (pingInterval < 0) { + stopPinging(); + } + else { + schedulePingServerTask(); + } + } + + /** + * Stops pinging the server. This cannot stop a ping that has already started, but will prevent another from being triggered. + *

      + * To restart, call {@link #setPingInterval(long)}. + */ + public void stopPinging() { + pingInterval = -1; + stopPingServerTask(); + } + + /** + * Gets the ping interval. + * + * @return The ping interval in milliseconds. + */ + public long getPingInterval() { + return pingInterval; + } + + /** + * Add listener for notification when a server ping fails. + * + *

      + * Please note that this doesn't necessarily mean that the connection is lost, a slow to respond server could also + * cause a failure due to taking too long to respond and thus causing a reply timeout. + * + * @param listener + * The listener to be called + */ + public void addPingFailedListener(PingFailedListener listener) { + pingFailedListeners.add(listener); + } + + /** + * Remove the listener. + * + * @param listener + * The listener to be removed. + */ + public void removePingFailedListener(PingFailedListener listener) { + pingFailedListeners.remove(listener); + } + + /** + * Returns the elapsed time (in milliseconds) since the last successful contact with the server + * (i.e. the last time any message was received). + *

      + * Note: Result is -1 if no message has been received since manager was created and + * 0 if the elapsed time is negative due to a clock reset. + * + * @return Elapsed time since last message was received. + */ + public long getTimeSinceLastContact() { + if (lastSuccessfulContact == -1) + return lastSuccessfulContact; + long delta = System.currentTimeMillis() - lastSuccessfulContact; + + return (delta < 0) ? 0 : delta; + } + + /** + * Cancels any existing periodic ping task if there is one and schedules a new ping task if pingInterval is greater + * then zero. + * + * This is designed so only one executor is used for scheduling all pings on all connections. This results in only 1 thread used for pinging. + */ + private synchronized void schedulePingServerTask() { + enableExecutorService(); + stopPingServerTask(); + + if (pingInterval > 0) { + periodicPingTask = periodicPingExecutorService.schedule(new Runnable() { + @Override + public void run() { + Ping ping = new Ping(); + PacketFilter responseFilter = new PacketIDFilter(ping.getPacketID()); + final PacketCollector response = connection.createPacketCollector(responseFilter); + connection.sendPacket(ping); + + if (!pingFailedListeners.isEmpty()) { + // Schedule a collector for the ping reply, notify listeners if none is received. + periodicPingExecutorService.schedule(new Runnable() { + @Override + public void run() { + Packet result = response.nextResult(1); + + // Stop queuing results + response.cancel(); + + // The actual result of the reply can be ignored since we only care if we actually got one. + if (result == null) { + for (PingFailedListener listener : pingFailedListeners) { + listener.pingFailed(); + } + } + } + }, SmackConfiguration.getPacketReplyTimeout(), TimeUnit.MILLISECONDS); + } + } + }, getPingInterval(), TimeUnit.MILLISECONDS); + } + } + + private void stopPingServerTask() { + if (periodicPingTask != null) { + periodicPingTask.cancel(true); + periodicPingTask = null; + } + } +} diff --git a/source/org/jivesoftware/smack/packet/PrivacyItem.java b/source/org/jivesoftware/smack/packet/PrivacyItem.java index de7f8fe22..2e144eec6 100644 --- a/source/org/jivesoftware/smack/packet/PrivacyItem.java +++ b/source/org/jivesoftware/smack/packet/PrivacyItem.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smackx/ping/PingFailedListener.java b/source/org/jivesoftware/smack/ping/PingFailedListener.java similarity index 80% rename from source/org/jivesoftware/smackx/ping/PingFailedListener.java rename to source/org/jivesoftware/smack/ping/PingFailedListener.java index 4cda33b0c..450345773 100644 --- a/source/org/jivesoftware/smackx/ping/PingFailedListener.java +++ b/source/org/jivesoftware/smack/ping/PingFailedListener.java @@ -14,8 +14,14 @@ * limitations under the License. */ -package org.jivesoftware.smackx.ping; +package org.jivesoftware.smack.ping; +/** + * Defines the callback used whenever the server ping fails. + */ public interface PingFailedListener { + /** + * Called when the server ping fails. + */ void pingFailed(); } \ No newline at end of file diff --git a/source/org/jivesoftware/smackx/ping/packet/Ping.java b/source/org/jivesoftware/smack/ping/packet/Ping.java similarity index 77% rename from source/org/jivesoftware/smackx/ping/packet/Ping.java rename to source/org/jivesoftware/smack/ping/packet/Ping.java index fc5bbdfdc..e2db68153 100644 --- a/source/org/jivesoftware/smackx/ping/packet/Ping.java +++ b/source/org/jivesoftware/smack/ping/packet/Ping.java @@ -14,25 +14,26 @@ * limitations under the License. */ -package org.jivesoftware.smackx.ping.packet; +package org.jivesoftware.smack.ping.packet; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.ping.PingManager; public class Ping extends IQ { + + public static final String NAMESPACE = "urn:xmpp:ping"; + public static final String ELEMENT = "ping"; public Ping() { } - public Ping(String from, String to) { + public Ping(String to) { setTo(to); - setFrom(from); setType(IQ.Type.GET); - setPacketID(getPacketID()); } + @Override public String getChildElementXML() { - return "<" + PingManager.ELEMENT + " xmlns=\'" + PingManager.NAMESPACE + "\' />"; + return "<" + ELEMENT + " xmlns=\'" + NAMESPACE + "\' />"; } - } diff --git a/source/org/jivesoftware/smackx/ping/provider/PingProvider.java b/source/org/jivesoftware/smack/ping/provider/PingProvider.java similarity index 91% rename from source/org/jivesoftware/smackx/ping/provider/PingProvider.java rename to source/org/jivesoftware/smack/ping/provider/PingProvider.java index ebe766953..a55f1cc04 100644 --- a/source/org/jivesoftware/smackx/ping/provider/PingProvider.java +++ b/source/org/jivesoftware/smack/ping/provider/PingProvider.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package org.jivesoftware.smackx.ping.provider; +package org.jivesoftware.smack.ping.provider; import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.ping.packet.Ping; import org.jivesoftware.smack.provider.IQProvider; -import org.jivesoftware.smackx.ping.packet.Ping; import org.xmlpull.v1.XmlPullParser; public class PingProvider implements IQProvider { diff --git a/source/org/jivesoftware/smack/provider/PrivacyProvider.java b/source/org/jivesoftware/smack/provider/PrivacyProvider.java index 0e0c78a16..62b31205d 100644 --- a/source/org/jivesoftware/smack/provider/PrivacyProvider.java +++ b/source/org/jivesoftware/smack/provider/PrivacyProvider.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/proxy/DirectSocketFactory.java b/source/org/jivesoftware/smack/proxy/DirectSocketFactory.java index ef3da408f..3c5bb3999 100644 --- a/source/org/jivesoftware/smack/proxy/DirectSocketFactory.java +++ b/source/org/jivesoftware/smack/proxy/DirectSocketFactory.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/proxy/HTTPProxySocketFactory.java b/source/org/jivesoftware/smack/proxy/HTTPProxySocketFactory.java index ba1cb1f69..4ee5dd622 100644 --- a/source/org/jivesoftware/smack/proxy/HTTPProxySocketFactory.java +++ b/source/org/jivesoftware/smack/proxy/HTTPProxySocketFactory.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 @@ -92,8 +90,7 @@ class HTTPProxySocketFactory else { String password = proxy.getProxyPassword(); - proxyLine = "\r\nProxy-Authorization: Basic " - + new String(StringUtils.encodeBase64(username + ":" + password)); + proxyLine = "\r\nProxy-Authorization: Basic " + StringUtils.encodeBase64(username + ":" + password); } socket.getOutputStream().write((hostport + " HTTP/1.1\r\nHost: " + hostport + proxyLine + "\r\n\r\n").getBytes("UTF-8")); diff --git a/source/org/jivesoftware/smack/proxy/ProxyException.java b/source/org/jivesoftware/smack/proxy/ProxyException.java index 80d8d52ae..b37910c0c 100644 --- a/source/org/jivesoftware/smack/proxy/ProxyException.java +++ b/source/org/jivesoftware/smack/proxy/ProxyException.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/proxy/ProxyInfo.java b/source/org/jivesoftware/smack/proxy/ProxyInfo.java index 4a00d73bb..5a7d3541e 100644 --- a/source/org/jivesoftware/smack/proxy/ProxyInfo.java +++ b/source/org/jivesoftware/smack/proxy/ProxyInfo.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/proxy/Socks4ProxySocketFactory.java b/source/org/jivesoftware/smack/proxy/Socks4ProxySocketFactory.java index e0cc7c878..6a32c11e9 100644 --- a/source/org/jivesoftware/smack/proxy/Socks4ProxySocketFactory.java +++ b/source/org/jivesoftware/smack/proxy/Socks4ProxySocketFactory.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/proxy/Socks5ProxySocketFactory.java b/source/org/jivesoftware/smack/proxy/Socks5ProxySocketFactory.java index 6746ad1a2..23ef62328 100644 --- a/source/org/jivesoftware/smack/proxy/Socks5ProxySocketFactory.java +++ b/source/org/jivesoftware/smack/proxy/Socks5ProxySocketFactory.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smack/sasl/SASLMechanism.java b/source/org/jivesoftware/smack/sasl/SASLMechanism.java index 4fc139cbd..0d096f2a2 100644 --- a/source/org/jivesoftware/smack/sasl/SASLMechanism.java +++ b/source/org/jivesoftware/smack/sasl/SASLMechanism.java @@ -51,6 +51,30 @@ import javax.security.sasl.SaslException; * using the CallbackHandler method. *

    • {@link #challengeReceived(String)} -- Handle a challenge from the server.
    • *
    + * + * Basic XMPP SASL authentication steps: + * 1. Client authentication initialization, stanza sent to the server (Base64 encoded): + * + * 2. Server sends back to the client the challenge response (Base64 encoded) + * sample: + * realm=,nonce="OA6MG9tEQGm2hh",qop="auth",charset=utf-8,algorithm=md5-sess + * 3. The client responds back to the server (Base 64 encoded): + * sample: + * username=,realm=,nonce="OA6MG9tEQGm2hh", + * cnonce="OA6MHXh6VqTrRk",nc=00000001,qop=auth, + * digest-uri=, + * response=d388dad90d4bbd760a152321f2143af7, + * charset=utf-8, + * authzid= + * 4. The server evaluates if the user is present and contained in the REALM + * if successful it sends: (Base64 encoded) + * if not successful it sends: + * sample: + * + * cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZA== + * + * + * * @author Jay Kline */ @@ -62,37 +86,88 @@ public abstract class SASLMechanism implements CallbackHandler { protected String password; protected String hostname; - public SASLMechanism(SASLAuthentication saslAuthentication) { this.saslAuthentication = saslAuthentication; } /** * Builds and sends the auth stanza to the server. Note that this method of - * authentication is not recommended, since it is very inflexable. Use + * authentication is not recommended, since it is very inflexable. Use * {@link #authenticate(String, String, CallbackHandler)} whenever possible. - * + * + * Explanation of auth stanza: + * + * The client authentication stanza needs to include the digest-uri of the form: xmpp/serverName + * From RFC-2831: + * digest-uri = "digest-uri" "=" digest-uri-value + * digest-uri-value = serv-type "/" host [ "/" serv-name ] + * + * digest-uri: + * Indicates the principal name of the service with which the client + * wishes to connect, formed from the serv-type, host, and serv-name. + * For example, the FTP service + * on "ftp.example.com" would have a "digest-uri" value of "ftp/ftp.example.com"; the SMTP + * server from the example above would have a "digest-uri" value of + * "smtp/mail3.example.com/example.com". + * + * host: + * The DNS host name or IP address for the service requested. The DNS host name + * must be the fully-qualified canonical name of the host. The DNS host name is the + * preferred form; see notes on server processing of the digest-uri. + * + * serv-name: + * Indicates the name of the service if it is replicated. The service is + * considered to be replicated if the client's service-location process involves resolution + * using standard DNS lookup operations, and if these operations involve DNS records (such + * as SRV, or MX) which resolve one DNS name into a set of other DNS names. In this case, + * the initial name used by the client is the "serv-name", and the final name is the "host" + * component. For example, the incoming mail service for "example.com" may be replicated + * through the use of MX records stored in the DNS, one of which points at an SMTP server + * called "mail3.example.com"; it's "serv-name" would be "example.com", it's "host" would be + * "mail3.example.com". If the service is not replicated, or the serv-name is identical to + * the host, then the serv-name component MUST be omitted + * + * digest-uri verification is needed for ejabberd 2.0.3 and higher + * * @param username the username of the user being authenticated. - * @param host the hostname where the user account resides. + * @param host the hostname where the user account resides. + * @param serviceName the xmpp service location - used by the SASL client in digest-uri creation + * serviceName format is: host [ "/" serv-name ] as per RFC-2831 * @param password the password for this account. * @throws IOException If a network error occurs while authenticating. * @throws XMPPException If a protocol error occurs or the user is not authenticated. */ - public void authenticate(String username, String host, String password) throws IOException, XMPPException { + public void authenticate(String username, String host, String serviceName, String password) throws IOException, XMPPException { //Since we were not provided with a CallbackHandler, we will use our own with the given //information //Set the authenticationID as the username, since they must be the same in this case. this.authenticationId = username; this.password = password; - this.hostname = host; + this.hostname = host; String[] mechanisms = { getName() }; - Map props = new HashMap(); - sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this); + Map props = new HashMap(); + sc = Sasl.createSaslClient(mechanisms, username, "xmpp", serviceName, props, this); authenticate(); } + /** + * Same as {@link #authenticate(String, String, String, String)}, but with the hostname used as the serviceName. + *

    + * Kept for backward compatibility only. + * + * @param username the username of the user being authenticated. + * @param host the hostname where the user account resides. + * @param password the password for this account. + * @throws IOException If a network error occurs while authenticating. + * @throws XMPPException If a protocol error occurs or the user is not authenticated. + * @deprecated Please use {@link #authenticate(String, String, String, String)} instead. + */ + public void authenticate(String username, String host, String password) throws IOException, XMPPException { + authenticate(username, host, host, password); + } + /** * Builds and sends the auth stanza to the server. The callback handler will handle * any additional information, such as the authentication ID or realm, if it is needed. @@ -178,7 +253,13 @@ public abstract class SASLMechanism implements CallbackHandler { pcb.setPassword(password.toCharArray()); } else if(callbacks[i] instanceof RealmCallback) { RealmCallback rcb = (RealmCallback)callbacks[i]; - rcb.setText(hostname); + //Retrieve the REALM from the challenge response that the server returned when the client initiated the authentication + //exchange. If this value is not null or empty, *this value* has to be sent back to the server in the client's response + //to the server's challenge + String text = rcb.getDefaultText(); + //The SASL client (sc) created in smack uses rcb.getText when creating the negotiatedRealm to send it back to the server + //Make sure that this value matches the server's realm + rcb.setText(text); } else if(callbacks[i] instanceof RealmChoiceCallback){ //unused //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i]; @@ -319,5 +400,5 @@ public abstract class SASLMechanism implements CallbackHandler { stanza.append(""); return stanza.toString(); } - } + } } diff --git a/source/org/jivesoftware/smack/util/Base32Encoder.java b/source/org/jivesoftware/smack/util/Base32Encoder.java index c7cc1d028..0a4ea21e7 100644 --- a/source/org/jivesoftware/smack/util/Base32Encoder.java +++ b/source/org/jivesoftware/smack/util/Base32Encoder.java @@ -29,7 +29,7 @@ import java.io.IOException; */ public class Base32Encoder implements StringEncoder { - private static Base32Encoder instance; + private static Base32Encoder instance = new Base32Encoder(); private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ2345678"; private Base32Encoder() { @@ -37,9 +37,6 @@ public class Base32Encoder implements StringEncoder { } public static Base32Encoder getInstance() { - if (instance == null) { - instance = new Base32Encoder(); - } return instance; } diff --git a/source/org/jivesoftware/smack/util/Base64.java b/source/org/jivesoftware/smack/util/Base64.java index 940c55118..ba6eb371f 100644 --- a/source/org/jivesoftware/smack/util/Base64.java +++ b/source/org/jivesoftware/smack/util/Base64.java @@ -7,66 +7,9 @@ package org.jivesoftware.smack.util; /** - *

    Encodes and decodes to and from Base64 notation.

    - *

    Homepage: http://iharder.net/base64.

    + *

    Encodes and decodes to and from Base64 notation.

    + * This code was obtained from http://iharder.net/base64

    * - *

    - * Change Log: - *

    - *
      - *
    • v2.2.1 - Fixed bug using URL_SAFE and ORDERED encodings. Fixed bug - * when using very small files (~< 40 bytes).
    • - *
    • v2.2 - Added some helper methods for encoding/decoding directly from - * one file to the next. Also added a main() method to support command line - * encoding/decoding from one file to the next. Also added these Base64 dialects: - *
        - *
      1. The default is RFC3548 format.
      2. - *
      3. Calling Base64.setFormat(Base64.BASE64_FORMAT.URLSAFE_FORMAT) generates - * URL and file name friendly format as described in Section 4 of RFC3548. - * http://www.faqs.org/rfcs/rfc3548.html
      4. - *
      5. Calling Base64.setFormat(Base64.BASE64_FORMAT.ORDERED_FORMAT) generates - * URL and file name friendly format that preserves lexical ordering as described - * in http://www.faqs.org/qa/rfcc-1940.html
      6. - *
      - * Special thanks to Jim Kellerman at http://www.powerset.com/ - * for contributing the new Base64 dialects. - *
    • - * - *
    • v2.1 - Cleaned up javadoc comments and unused variables and methods. Added - * some convenience methods for reading and writing to and from files.
    • - *
    • v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems - * with other encodings (like EBCDIC).
    • - *
    • v2.0.1 - Fixed an error when decoding a single byte, that is, when the - * encoded data was a single byte.
    • - *
    • v2.0 - I got rid of methods that used booleans to set options. - * Now everything is more consolidated and cleaner. The code now detects - * when data that's being decoded is gzip-compressed and will decompress it - * automatically. Generally things are cleaner. You'll probably have to - * change some method calls that you were making to support the new - * options format (ints that you "OR" together).
    • - *
    • v1.5.1 - Fixed bug when decompressing and decoding to a - * byte[] using decode( String s, boolean gzipCompressed ). - * Added the ability to "suspend" encoding in the Output Stream so - * you can turn on and off the encoding if you need to embed base64 - * data in an otherwise "normal" stream (like an XML file).
    • - *
    • v1.5 - Output stream pases on flush() command but doesn't do anything itself. - * This helps when using GZIP streams. - * Added the ability to GZip-compress objects before encoding them.
    • - *
    • v1.4 - Added helper methods to read/write files.
    • - *
    • v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.
    • - *
    • v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream - * where last buffer being read, if not completely full, was not returned.
    • - *
    • v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.
    • - *
    • v1.3.3 - Fixed I/O streams which were totally messed up.
    • - *
    - * - *

    - * I am placing this code in the Public Domain. Do with it as you will. - * This software comes with no guarantees or warranties but with - * plenty of well-wishing instead! - * Please visit http://iharder.net/base64 - * periodically to check for updates or to contribute improvements. - *

    * * @author Robert Harder * @author rob@iharder.net @@ -368,33 +311,6 @@ public class Base64 /** Defeats instantiation. */ private Base64(){} - - /** - * Encodes or decodes two files from the command line; - * feel free to delete this method (in fact you probably should) - * if you're embedding this code into a larger program. - */ - public final static void main( String[] args ) - { - if( args.length < 3 ){ - usage("Not enough arguments."); - } // end if: args.length < 3 - else { - String flag = args[0]; - String infile = args[1]; - String outfile = args[2]; - if( flag.equals( "-e" ) ){ - Base64.encodeFileToFile( infile, outfile ); - } // end if: encode - else if( flag.equals( "-d" ) ) { - Base64.decodeFileToFile( infile, outfile ); - } // end else if: decode - else { - usage( "Unknown flag: " + flag ); - } // end else - } // end else - } // end main - /** * Prints command line usage. * diff --git a/source/org/jivesoftware/smack/util/Base64Encoder.java b/source/org/jivesoftware/smack/util/Base64Encoder.java index 78399b463..d53c0ed08 100644 --- a/source/org/jivesoftware/smack/util/Base64Encoder.java +++ b/source/org/jivesoftware/smack/util/Base64Encoder.java @@ -16,20 +16,18 @@ package org.jivesoftware.smack.util; /** + * A Base 64 encoding implementation. * @author Florian Schmaus */ public class Base64Encoder implements StringEncoder { - private static Base64Encoder instance; + private static Base64Encoder instance = new Base64Encoder(); private Base64Encoder() { // Use getInstance() } public static Base64Encoder getInstance() { - if (instance == null) { - instance = new Base64Encoder(); - } return instance; } diff --git a/source/org/jivesoftware/smack/util/Base64FileUrlEncoder.java b/source/org/jivesoftware/smack/util/Base64FileUrlEncoder.java new file mode 100644 index 000000000..190b37439 --- /dev/null +++ b/source/org/jivesoftware/smack/util/Base64FileUrlEncoder.java @@ -0,0 +1,48 @@ +/** + * 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.util; + + +/** + * A Base 64 encoding implementation that generates filename and Url safe encodings. + * + *

    + * Note: This does NOT produce standard Base 64 encodings, but a variant as defined in + * Section 4 of RFC3548: + * http://www.faqs.org/rfcs/rfc3548.html. + * + * @author Robin Collier + */ +public class Base64FileUrlEncoder implements StringEncoder { + + private static Base64FileUrlEncoder instance = new Base64FileUrlEncoder(); + + private Base64FileUrlEncoder() { + // Use getInstance() + } + + public static Base64FileUrlEncoder getInstance() { + return instance; + } + + public String encode(String s) { + return Base64.encodeBytes(s.getBytes(), Base64.URL_SAFE); + } + + public String decode(String s) { + return new String(Base64.decode(s, Base64.URL_SAFE)); + } + +} diff --git a/source/org/jivesoftware/smack/util/DNSUtil.java b/source/org/jivesoftware/smack/util/DNSUtil.java index 628d8e8f3..20a143faf 100644 --- a/source/org/jivesoftware/smack/util/DNSUtil.java +++ b/source/org/jivesoftware/smack/util/DNSUtil.java @@ -81,7 +81,12 @@ public class DNSUtil { * @return List of HostAddress, which encompasses the hostname and port that the * XMPP server can be reached at for the specified domain. */ - public static List resolveXMPPDomain(String domain) { + public static List resolveXMPPDomain(final String domain) { + if (dnsResolver == null) { + List addresses = new ArrayList(1); + addresses.add(new HostAddress(domain, 5222)); + return addresses; + } return resolveDomain(domain, 'c'); } @@ -102,7 +107,12 @@ public class DNSUtil { * @return List of HostAddress, which encompasses the hostname and port that the * XMPP server can be reached at for the specified domain. */ - public static List resolveXMPPServerDomain(String domain) { + public static List resolveXMPPServerDomain(final String domain) { + if (dnsResolver == null) { + List addresses = new ArrayList(1); + addresses.add(new HostAddress(domain, 5269)); + return addresses; + } return resolveDomain(domain, 's'); } @@ -117,9 +127,6 @@ public class DNSUtil { } } - if (dnsResolver == null) - throw new IllegalStateException("No DNS resolver active."); - List addresses = new ArrayList(); // Step one: Do SRV lookups diff --git a/source/org/jivesoftware/smack/util/DateFormatType.java b/source/org/jivesoftware/smack/util/DateFormatType.java index a9d563da9..9253038d7 100644 --- a/source/org/jivesoftware/smack/util/DateFormatType.java +++ b/source/org/jivesoftware/smack/util/DateFormatType.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2013 Robin Collier. * * 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. @@ -17,48 +17,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack.util; - -import java.text.SimpleDateFormat; - -/** - * Defines the various date and time profiles used in XMPP along with their associated formats. - * @author Robin Collier - * - */ -public enum DateFormatType -{ - XEP_0082_DATE_PROFILE("yyyy-MM-dd"), - XEP_0082_DATETIME_PROFILE("yyyy-MM-dd'T'HH:mm:ssZ"), - XEP_0082_DATETIME_MILLIS_PROFILE("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), - XEP_0082_TIME_PROFILE("hh:mm:ss"), - XEP_0082_TIME_ZONE_PROFILE("hh:mm:ssZ"), - XEP_0082_TIME_MILLIS_PROFILE("hh:mm:ss.SSS"), - XEP_0082_TIME_MILLIS_ZONE_PROFILE("hh:mm:ss.SSSZ"), - XEP_0091_DATETIME("yyyyMMdd'T'HH:mm:ss"); - - private String formatString; - - private DateFormatType(String dateFormat) - { - formatString = dateFormat; - } - - /** - * Get the format string as defined in either XEP-0082 or XEP-0091. - * @return The defined string format for the date. - */ - public String getFormatString() - { - return formatString; - } - - /** - * Create a {@link SimpleDateFormat} object with the format defined by {@link #getFormatString()}. - * @return A new date formatter. - */ - public SimpleDateFormat createFormatter() - { - return new SimpleDateFormat(getFormatString()); - } -} +package org.jivesoftware.smack.util; + +import java.text.SimpleDateFormat; + +/** + * Defines the various date and time profiles used in XMPP along with their associated formats. + * + * @author Robin Collier + * + */ +public enum DateFormatType { + // @formatter:off + XEP_0082_DATE_PROFILE("yyyy-MM-dd"), + XEP_0082_DATETIME_PROFILE("yyyy-MM-dd'T'HH:mm:ssZ"), + XEP_0082_DATETIME_MILLIS_PROFILE("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), + XEP_0082_TIME_PROFILE("hh:mm:ss"), + XEP_0082_TIME_ZONE_PROFILE("hh:mm:ssZ"), + XEP_0082_TIME_MILLIS_PROFILE("hh:mm:ss.SSS"), + XEP_0082_TIME_MILLIS_ZONE_PROFILE("hh:mm:ss.SSSZ"), + XEP_0091_DATETIME("yyyyMMdd'T'HH:mm:ss"); + // @formatter:on + + private String formatString; + + private DateFormatType(String dateFormat) { + formatString = dateFormat; + } + + /** + * Get the format string as defined in either XEP-0082 or XEP-0091. + * + * @return The defined string format for the date. + */ + public String getFormatString() { + return formatString; + } + + /** + * Create a {@link SimpleDateFormat} object with the format defined by {@link #getFormatString()}. + * + * @return A new date formatter. + */ + public SimpleDateFormat createFormatter() { + return new SimpleDateFormat(getFormatString()); + } +} diff --git a/source/org/jivesoftware/smack/util/StringEncoder.java b/source/org/jivesoftware/smack/util/StringEncoder.java index 5a15c9548..4c3d373f3 100644 --- a/source/org/jivesoftware/smack/util/StringEncoder.java +++ b/source/org/jivesoftware/smack/util/StringEncoder.java @@ -17,8 +17,6 @@ */ package org.jivesoftware.smack.util; -// TODO move StringEncoder, Base64Encoder and Base32Encoder to smack.util - public interface StringEncoder { /** * Encodes an string to another representation @@ -26,7 +24,7 @@ public interface StringEncoder { * @param string * @return */ - public String encode(String string); + String encode(String string); /** * Decodes an string back to it's initial representation @@ -34,5 +32,5 @@ public interface StringEncoder { * @param string * @return */ - public String decode(String string); + String decode(String string); } diff --git a/source/org/jivesoftware/smack/util/SyncPacketSend.java b/source/org/jivesoftware/smack/util/SyncPacketSend.java index a1c238aeb..6506cbd88 100644 --- a/source/org/jivesoftware/smack/util/SyncPacketSend.java +++ b/source/org/jivesoftware/smack/util/SyncPacketSend.java @@ -16,6 +16,7 @@ package org.jivesoftware.smack.util; import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.SmackError; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.filter.PacketIDFilter; @@ -47,7 +48,7 @@ final public class SyncPacketSend response.cancel(); if (result == null) { - throw new XMPPException("No response from server."); + throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER); } else if (result.getError() != null) { throw new XMPPException(result.getError()); diff --git a/source/org/jivesoftware/smack/util/dns/DNSJavaResolver.java b/source/org/jivesoftware/smack/util/dns/DNSJavaResolver.java index 91db73b1a..dd93fd3ae 100644 --- a/source/org/jivesoftware/smack/util/dns/DNSJavaResolver.java +++ b/source/org/jivesoftware/smack/util/dns/DNSJavaResolver.java @@ -22,18 +22,19 @@ import org.xbill.DNS.Lookup; import org.xbill.DNS.Record; import org.xbill.DNS.Type; -public class DNSJavaResolver extends DNSResolver { +/** + * This implementation uses the dnsjava implementation for resolving DNS addresses. + * + */ +public class DNSJavaResolver implements DNSResolver { - private static DNSJavaResolver instance; + private static DNSJavaResolver instance = new DNSJavaResolver(); private DNSJavaResolver() { } public static DNSResolver getInstance() { - if (instance == null) { - instance = new DNSJavaResolver(); - } return instance; } diff --git a/source/org/jivesoftware/smack/util/dns/DNSResolver.java b/source/org/jivesoftware/smack/util/dns/DNSResolver.java index 2c5dd296c..86f037b6f 100644 --- a/source/org/jivesoftware/smack/util/dns/DNSResolver.java +++ b/source/org/jivesoftware/smack/util/dns/DNSResolver.java @@ -17,8 +17,17 @@ package org.jivesoftware.smack.util.dns; import java.util.List; -public abstract class DNSResolver { +/** + * Implementations of this interface define a class that is capable of resolving DNS addresses. + * + */ +public interface DNSResolver { - public abstract List lookupSRVRecords(String name); + /** + * Gets a list of service records for the specified service. + * @param name The symbolic name of the service. + * @return The list of SRV records mapped to the service name. + */ + List lookupSRVRecords(String name); } diff --git a/source/org/jivesoftware/smack/util/dns/HostAddress.java b/source/org/jivesoftware/smack/util/dns/HostAddress.java index 978a6de69..eb8b07ad7 100644 --- a/source/org/jivesoftware/smack/util/dns/HostAddress.java +++ b/source/org/jivesoftware/smack/util/dns/HostAddress.java @@ -23,10 +23,10 @@ public class HostAddress { /** * Creates a new HostAddress with the given FQDN. The port will be set to the default XMPP client port: 5222 * - * @param fqdn - * @throws IllegalArgumentException + * @param fqdn Fully qualified domain name. + * @throws IllegalArgumentException If the fqdn is null. */ - public HostAddress(String fqdn) throws IllegalArgumentException { + public HostAddress(String fqdn) { if (fqdn == null) throw new IllegalArgumentException("FQDN is null"); if (fqdn.charAt(fqdn.length() - 1) == '.') { @@ -39,7 +39,14 @@ public class HostAddress { this.port = 5222; } - public HostAddress(String fqdn, int port) throws IllegalArgumentException { + /** + * Creates a new HostAddress with the given FQDN. The port will be set to the default XMPP client port: 5222 + * + * @param fqdn Fully qualified domain name. + * @param port The port to connect on. + * @throws IllegalArgumentException If the fqdn is null or port is out of valid range (0 - 65535). + */ + public HostAddress(String fqdn, int port) { this(fqdn); if (port < 0 || port > 65535) throw new IllegalArgumentException( @@ -60,10 +67,12 @@ public class HostAddress { this.exception = e; } + @Override public String toString() { return fqdn + ":" + port; } + @Override public boolean equals(Object o) { if (this == o) { return true; @@ -80,6 +89,13 @@ public class HostAddress { return port == address.port; } + @Override + public int hashCode() { + int result = 1; + result = 37 * result + fqdn.hashCode(); + return result * 37 + port; + } + public String getErrorMessage() { String error; if (exception == null) { diff --git a/source/org/jivesoftware/smack/util/dns/JavaxResolver.java b/source/org/jivesoftware/smack/util/dns/JavaxResolver.java index 4ea361fdf..ae3dbf6f6 100644 --- a/source/org/jivesoftware/smack/util/dns/JavaxResolver.java +++ b/source/org/jivesoftware/smack/util/dns/JavaxResolver.java @@ -28,12 +28,12 @@ import javax.naming.directory.InitialDirContext; import org.jivesoftware.smack.util.DNSUtil; /** - * A DNS resolver (mostly for SRV records), which makes use of the API provided in the javax.* namepsace. + * A DNS resolver (mostly for SRV records), which makes use of the API provided in the javax.* namespace. * * @author Florian Schmaus * */ -public class JavaxResolver extends DNSResolver { +public class JavaxResolver implements DNSResolver { private static JavaxResolver instance; private static DirContext dirContext; @@ -48,14 +48,14 @@ public class JavaxResolver extends DNSResolver { } // Try to set this DNS resolver as primary one - DNSUtil.setDNSResolver(maybeGetInstance()); + DNSUtil.setDNSResolver(getInstance()); } private JavaxResolver() { } - public static DNSResolver maybeGetInstance() { + public static DNSResolver getInstance() { if (instance == null && isSupported()) { instance = new JavaxResolver(); } diff --git a/source/org/jivesoftware/smack/util/dns/SRVRecord.java b/source/org/jivesoftware/smack/util/dns/SRVRecord.java index 87c6e54fc..457e40eca 100644 --- a/source/org/jivesoftware/smack/util/dns/SRVRecord.java +++ b/source/org/jivesoftware/smack/util/dns/SRVRecord.java @@ -29,13 +29,13 @@ public class SRVRecord extends HostAddress implements Comparable { /** * Create a new SRVRecord * - * @param fqdn - * @param port - * @param priority - * @param weight - * @throws IllegalArgumentException + * @param fqdn Fully qualified domain name + * @param port The connection port + * @param priority Priority of the target host + * @param weight Relative weight for records with same priority + * @throws IllegalArgumentException fqdn is null or any other field is not in valid range (0-65535). */ - public SRVRecord(String fqdn, int port, int priority, int weight) throws IllegalArgumentException { + public SRVRecord(String fqdn, int port, int priority, int weight) { super(fqdn, port); if (weight < 0 || weight > 65535) throw new IllegalArgumentException( @@ -60,6 +60,7 @@ public class SRVRecord extends HostAddress implements Comparable { return weight; } + @Override public int compareTo(SRVRecord other) { // According to RFC2782, // "[a] client MUST attempt to contact the target host with the lowest-numbered priority it can reach". @@ -71,6 +72,7 @@ public class SRVRecord extends HostAddress implements Comparable { return res; } + @Override public String toString() { return super.toString() + " prio:" + priority + ":w:" + weight; } diff --git a/source/org/jivesoftware/smackx/FormField.java b/source/org/jivesoftware/smackx/FormField.java index 44dfa8cec..3d15e921a 100644 --- a/source/org/jivesoftware/smackx/FormField.java +++ b/source/org/jivesoftware/smackx/FormField.java @@ -299,24 +299,23 @@ public class FormField { return buf.toString(); } + @Override public boolean equals(Object obj) { if (obj == null) return false; if (obj == this) return true; - if (obj.getClass() != getClass()) + if (!(obj instanceof FormField)) return false; FormField other = (FormField) obj; - String thisXml = toXML(); - String otherXml = other.toXML(); + return toXML().equals(other.toXML()); + } - if (thisXml.equals(otherXml)) { - return true; - } else { - return false; - } + @Override + public int hashCode() { + return toXML().hashCode(); } /** @@ -356,6 +355,7 @@ public class FormField { return value; } + @Override public String toString() { return getLabel(); } @@ -375,6 +375,7 @@ public class FormField { return buf.toString(); } + @Override public boolean equals(Object obj) { if (obj == null) return false; @@ -396,5 +397,13 @@ public class FormField { return true; } + + @Override + public int hashCode() { + int result = 1; + result = 37 * result + value.hashCode(); + result = 37 * result + (label == null ? 0 : label.hashCode()); + return result; + } } } diff --git a/source/org/jivesoftware/smackx/NodeInformationProvider.java b/source/org/jivesoftware/smackx/NodeInformationProvider.java index 68bb613d3..27ee53a01 100644 --- a/source/org/jivesoftware/smackx/NodeInformationProvider.java +++ b/source/org/jivesoftware/smackx/NodeInformationProvider.java @@ -45,7 +45,7 @@ public interface NodeInformationProvider { * * @return a list of the Items defined in the node. */ - public abstract List getNodeItems(); + List getNodeItems(); /** * Returns a list of the features defined in the node. For @@ -55,7 +55,7 @@ public interface NodeInformationProvider { * * @return a list of the feature strings defined in the node. */ - public abstract List getNodeFeatures(); + List getNodeFeatures(); /** * Returns a list of the indentites defined in the node. For @@ -64,12 +64,12 @@ public interface NodeInformationProvider { * * @return a list of the Identities defined in the node. */ - public abstract List getNodeIdentities(); + List getNodeIdentities(); /** * Returns a list of the packet extensions defined in the node. * * @return a list of the packet extensions defined in the node. */ - public abstract List getNodePacketExtensions(); + List getNodePacketExtensions(); } diff --git a/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java b/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java index f0e7912aa..9e31f6777 100644 --- a/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java +++ b/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java @@ -513,7 +513,7 @@ public class ServiceDiscoveryManager { // If the node version is known, store the new entry. if (nvh != null) { - if (EntityCapsManager.verifyDiscvoerInfoVersion(nvh.getVer(), nvh.getHash(), info)) + if (EntityCapsManager.verifyDiscoverInfoVersion(nvh.getVer(), nvh.getHash(), info)) EntityCapsManager.addDiscoverInfoByNode(nvh.getNodeVer(), info); } diff --git a/source/org/jivesoftware/smackx/SharedGroupManager.java b/source/org/jivesoftware/smackx/SharedGroupManager.java index 8bc39f156..76cd527c5 100644 --- a/source/org/jivesoftware/smackx/SharedGroupManager.java +++ b/source/org/jivesoftware/smackx/SharedGroupManager.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2005 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. diff --git a/source/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java b/source/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java index 47cf92abb..41ab142db 100644 --- a/source/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java +++ b/source/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/source/org/jivesoftware/smackx/carbons/Carbon.java b/source/org/jivesoftware/smackx/carbons/Carbon.java deleted file mode 100644 index 588688aa1..000000000 --- a/source/org/jivesoftware/smackx/carbons/Carbon.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * Copyright 2013 Georg Lukas - * - * 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.smackx.carbons; - -import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smack.packet.PacketExtension; -import org.jivesoftware.smack.provider.PacketExtensionProvider; -import org.jivesoftware.smack.util.PacketParserUtils; -import org.jivesoftware.smackx.forward.Forwarded; -import org.jivesoftware.smackx.packet.DelayInfo; -import org.jivesoftware.smackx.provider.DelayInfoProvider; -import org.xmlpull.v1.XmlPullParser; - -/** - * Packet extension for XEP-0280: Message Carbons. This class implements - * the packet extension and a {@link PacketExtensionProvider} to parse - * message carbon copies from a packet. The extension - * XEP-0280 is - * meant to synchronize a message flow to multiple presences of a user. - * - *

    The {@link Carbon.Provider} must be registered in the - * smack.properties file for the elements sent and - * received with namespace urn:xmpp:carbons:2

    to be used. - * - * @author Georg Lukas - */ -public class Carbon implements PacketExtension { - public static final String NAMESPACE = "urn:xmpp:carbons:2"; - - private Direction dir; - private Forwarded fwd; - - public Carbon(Direction dir, Forwarded fwd) { - this.dir = dir; - this.fwd = fwd; - } - - /** - * get the direction (sent or received) of the carbon. - * - * @return the {@link Direction} of the carbon. - */ - public Direction getDirection() { - return dir; - } - - /** - * get the forwarded packet. - * - * @return the {@link Forwarded} message contained in this Carbon. - */ - public Forwarded getForwarded() { - return fwd; - } - - @Override - public String getElementName() { - return dir.toString(); - } - - @Override - public String getNamespace() { - return NAMESPACE; - } - - @Override - public String toXML() { - StringBuilder buf = new StringBuilder(); - buf.append("<").append(getElementName()).append(" xmlns=\"") - .append(getNamespace()).append("\">"); - - buf.append(fwd.toXML()); - - buf.append(""); - return buf.toString(); - } - - /** - * An enum to display the direction of a {@link Carbon} message. - */ - public static enum Direction { - received, - sent - } - - public static class Provider implements PacketExtensionProvider { - - public PacketExtension parseExtension(XmlPullParser parser) throws Exception { - Direction dir = Direction.valueOf(parser.getName()); - Forwarded fwd = null; - - boolean done = false; - while (!done) { - int eventType = parser.next(); - if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) { - fwd = (Forwarded)new Forwarded.Provider().parseExtension(parser); - } - else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName())) - done = true; - } - if (fwd == null) - throw new Exception("sent/received must contain exactly one tag"); - return new Carbon(dir, fwd); - } - } - - /** - * Packet extension indicating that a message may not be carbon-copied. - */ - public static class Private implements PacketExtension { - public static final String ELEMENT = "private"; - - public String getElementName() { - return ELEMENT; - } - - public String getNamespace() { - return Carbon.NAMESPACE; - } - - public String toXML() { - return "<" + ELEMENT + " xmlns=\"" + Carbon.NAMESPACE + "\"/>"; - } - } -} diff --git a/source/org/jivesoftware/smackx/carbons/CarbonManager.java b/source/org/jivesoftware/smackx/carbons/CarbonManager.java deleted file mode 100644 index f44701afd..000000000 --- a/source/org/jivesoftware/smackx/carbons/CarbonManager.java +++ /dev/null @@ -1,213 +0,0 @@ -/** - * Copyright 2013 Georg Lukas - * - * 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.smackx.carbons; - -import java.util.Collections; -import java.util.Map; -import java.util.WeakHashMap; - -import org.jivesoftware.smack.Connection; -import org.jivesoftware.smack.ConnectionCreationListener; -import org.jivesoftware.smack.PacketCollector; -import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.SmackConfiguration; -import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.filter.PacketIDFilter; -import org.jivesoftware.smack.packet.IQ; -import org.jivesoftware.smack.packet.Message; -import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smackx.ServiceDiscoveryManager; -import org.jivesoftware.smackx.packet.DiscoverInfo; - -/** - * Packet extension for XEP-0280: Message Carbons. This class implements - * the manager for registering {@link Carbon} support, enabling and disabling - * message carbons. - * - * You should call enableCarbons() before sending your first undirected - * presence. - * - * @author Georg Lukas - */ -public class CarbonManager { - - private static Map instances = - Collections.synchronizedMap(new WeakHashMap()); - - static { - Connection.addConnectionCreationListener(new ConnectionCreationListener() { - public void connectionCreated(Connection connection) { - new CarbonManager(connection); - } - }); - } - - private Connection connection; - private volatile boolean enabled_state = false; - - private CarbonManager(Connection connection) { - ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); - sdm.addFeature(Carbon.NAMESPACE); - this.connection = connection; - instances.put(connection, this); - } - - /** - * Obtain the CarbonManager responsible for a connection. - * - * @param connection the connection object. - * - * @return a CarbonManager instance - */ - public static CarbonManager getInstanceFor(Connection connection) { - CarbonManager carbonManager = instances.get(connection); - - if (carbonManager == null) { - carbonManager = new CarbonManager(connection); - } - - return carbonManager; - } - - private IQ carbonsEnabledIQ(final boolean new_state) { - IQ setIQ = new IQ() { - public String getChildElementXML() { - return "<" + (new_state? "enable" : "disable") + " xmlns='" + Carbon.NAMESPACE + "'/>"; - } - }; - setIQ.setType(IQ.Type.SET); - return setIQ; - } - - /** - * Returns true if XMPP Carbons are supported by the server. - * - * @return true if supported - */ - public boolean isSupportedByServer() { - try { - DiscoverInfo result = ServiceDiscoveryManager - .getInstanceFor(connection).discoverInfo(connection.getServiceName()); - return result.containsFeature(Carbon.NAMESPACE); - } - catch (XMPPException e) { - return false; - } - } - - /** - * Notify server to change the carbons state. This method returns - * immediately and changes the variable when the reply arrives. - * - * You should first check for support using isSupportedByServer(). - * - * @param new_state whether carbons should be enabled or disabled - */ - public void sendCarbonsEnabled(final boolean new_state) { - IQ setIQ = carbonsEnabledIQ(new_state); - - connection.addPacketListener(new PacketListener() { - public void processPacket(Packet packet) { - IQ result = (IQ)packet; - if (result.getType() == IQ.Type.RESULT) { - enabled_state = new_state; - } - connection.removePacketListener(this); - } - }, new PacketIDFilter(setIQ.getPacketID())); - - connection.sendPacket(setIQ); - } - - /** - * Notify server to change the carbons state. This method blocks - * some time until the server replies to the IQ and returns true on - * success. - * - * You should first check for support using isSupportedByServer(). - * - * @param new_state whether carbons should be enabled or disabled - * - * @return true if the operation was successful - */ - public boolean setCarbonsEnabled(final boolean new_state) { - if (enabled_state == new_state) - return true; - - IQ setIQ = carbonsEnabledIQ(new_state); - - PacketCollector collector = - connection.createPacketCollector(new PacketIDFilter(setIQ.getPacketID())); - connection.sendPacket(setIQ); - IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); - collector.cancel(); - - if (result != null && result.getType() == IQ.Type.RESULT) { - enabled_state = new_state; - return true; - } - return false; - } - - /** - * Helper method to enable carbons. - * - * @return true if the operation was successful - */ - public boolean enableCarbons() { - return setCarbonsEnabled(true); - } - - /** - * Helper method to disable carbons. - * - * @return true if the operation was successful - */ - public boolean disableCarbons() { - return setCarbonsEnabled(false); - } - - /** - * Check if carbons are enabled on this connection. - */ - public boolean getCarbonsEnabled() { - return this.enabled_state; - } - - /** - * Obtain a Carbon from a message, if available. - * - * @param msg Message object to check for carbons - * - * @return a Carbon if available, null otherwise. - */ - public static Carbon getCarbon(Message msg) { - Carbon cc = (Carbon)msg.getExtension("received", Carbon.NAMESPACE); - if (cc == null) - cc = (Carbon)msg.getExtension("sent", Carbon.NAMESPACE); - return cc; - } - - /** - * Mark a message as "private", so it will not be carbon-copied. - * - * @param msg Message object to mark private - */ - public static void disableCarbons(Message msg) { - msg.addExtension(new Carbon.Private()); - } -} diff --git a/source/org/jivesoftware/smackx/commands/LocalCommandFactory.java b/source/org/jivesoftware/smackx/commands/LocalCommandFactory.java index 8ada9662d..83fc4553a 100644 --- a/source/org/jivesoftware/smackx/commands/LocalCommandFactory.java +++ b/source/org/jivesoftware/smackx/commands/LocalCommandFactory.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2008 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. diff --git a/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java b/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java index d5d6402d2..1da222efd 100644 --- a/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java +++ b/source/org/jivesoftware/smackx/entitycaps/EntityCapsManager.java @@ -506,7 +506,7 @@ public class EntityCapsManager { * @param info * @return true if it's valid and should be cache, false if not */ - public static boolean verifyDiscvoerInfoVersion(String ver, String hash, DiscoverInfo info) { + public static boolean verifyDiscoverInfoVersion(String ver, String hash, DiscoverInfo info) { // step 3.3 check for duplicate identities if (info.containsDuplicateIdentities()) return false; @@ -583,7 +583,7 @@ public class EntityCapsManager { // NAME is not included (in accordance with XEP-0030, the category and // type MUST be included. SortedSet sortedIdentities = new TreeSet(); - ; + for (Iterator it = discoverInfo.getIdentities(); it.hasNext();) sortedIdentities.add(it.next()); @@ -616,7 +616,7 @@ public class EntityCapsManager { // only use the data form for calculation is it has a hidden FORM_TYPE // field // see XEP-0115 5.4 step 3.6 - if (extendedInfo != null && extendedInfo.hasHiddenFromTypeField()) { + if (extendedInfo != null && extendedInfo.hasHiddenFormTypeField()) { synchronized (extendedInfo) { // 6. If the service discovery information response includes // XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e., diff --git a/source/org/jivesoftware/smackx/entitycaps/cache/EntityCapsPersistentCache.java b/source/org/jivesoftware/smackx/entitycaps/cache/EntityCapsPersistentCache.java index 4247e7b1b..044104351 100644 --- a/source/org/jivesoftware/smackx/entitycaps/cache/EntityCapsPersistentCache.java +++ b/source/org/jivesoftware/smackx/entitycaps/cache/EntityCapsPersistentCache.java @@ -24,15 +24,15 @@ public interface EntityCapsPersistentCache { * @param node * @param info */ - abstract void addDiscoverInfoByNodePersistent(String node, DiscoverInfo info); + void addDiscoverInfoByNodePersistent(String node, DiscoverInfo info); /** * Replay the Caches data into EntityCapsManager */ - abstract void replay() throws IOException; + void replay() throws IOException; /** * Empty the Cache */ - abstract void emptyCache(); + void emptyCache(); } diff --git a/source/org/jivesoftware/smackx/entitycaps/cache/SimpleDirectoryPersistentCache.java b/source/org/jivesoftware/smackx/entitycaps/cache/SimpleDirectoryPersistentCache.java index 329e4dce6..5d2365463 100644 --- a/source/org/jivesoftware/smackx/entitycaps/cache/SimpleDirectoryPersistentCache.java +++ b/source/org/jivesoftware/smackx/entitycaps/cache/SimpleDirectoryPersistentCache.java @@ -27,7 +27,7 @@ import java.io.StringReader; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.provider.IQProvider; -import org.jivesoftware.smack.util.Base64Encoder; +import org.jivesoftware.smack.util.Base32Encoder; import org.jivesoftware.smack.util.StringEncoder; import org.jivesoftware.smackx.entitycaps.EntityCapsManager; import org.jivesoftware.smackx.packet.DiscoverInfo; @@ -47,19 +47,20 @@ import org.xmlpull.v1.XmlPullParserException; public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache { private File cacheDir; - private StringEncoder stringEncoder; + private StringEncoder filenameEncoder; /** * Creates a new SimpleDirectoryPersistentCache Object. Make sure that the * cacheDir exists and that it's an directory. - * - * If your cacheDir is case insensitive then make sure to set the - * StringEncoder to Base32. + *

    + * Default filename encoder {@link Base32Encoder}, as this will work on all + * filesystems, both case sensitive and case insensitive. It does however + * produce longer filenames. * * @param cacheDir */ public SimpleDirectoryPersistentCache(File cacheDir) { - this(cacheDir, Base64Encoder.getInstance()); + this(cacheDir, Base32Encoder.getInstance()); } /** @@ -67,26 +68,25 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache * cacheDir exists and that it's an directory. * * If your cacheDir is case insensitive then make sure to set the - * StringEncoder to Base32. + * StringEncoder to {@link Base32Encoder} (which is the default). * - * @param cacheDir - * @param stringEncoder + * @param cacheDir The directory where the cache will be stored. + * @param filenameEncoder Encodes the node string into a filename. */ - public SimpleDirectoryPersistentCache(File cacheDir, StringEncoder stringEncoder) { + public SimpleDirectoryPersistentCache(File cacheDir, StringEncoder filenameEncoder) { if (!cacheDir.exists()) throw new IllegalStateException("Cache directory \"" + cacheDir + "\" does not exist"); if (!cacheDir.isDirectory()) throw new IllegalStateException("Cache directory \"" + cacheDir + "\" is not a directory"); this.cacheDir = cacheDir; - this.stringEncoder = stringEncoder; + this.filenameEncoder = filenameEncoder; } @Override public void addDiscoverInfoByNodePersistent(String node, DiscoverInfo info) { - String filename = stringEncoder.encode(node); + String filename = filenameEncoder.encode(node); File nodeFile = new File(cacheDir, filename); - try { if (nodeFile.createNewFile()) writeInfoToFile(nodeFile, info); @@ -99,7 +99,7 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache public void replay() throws IOException { File[] files = cacheDir.listFiles(); for (File f : files) { - String node = stringEncoder.decode(f.getName()); + String node = filenameEncoder.decode(f.getName()); DiscoverInfo info = restoreInfoFromFile(f); if (info == null) continue; diff --git a/source/org/jivesoftware/smackx/entitycaps/provider/CapsExtensionProvider.java b/source/org/jivesoftware/smackx/entitycaps/provider/CapsExtensionProvider.java index 4328d21b3..a112cd52b 100644 --- a/source/org/jivesoftware/smackx/entitycaps/provider/CapsExtensionProvider.java +++ b/source/org/jivesoftware/smackx/entitycaps/provider/CapsExtensionProvider.java @@ -1,4 +1,4 @@ -/* +/** * Copyright 2009 Jonas Ã…dahl. * Copyright 2011-2013 Florian Schmaus * diff --git a/source/org/jivesoftware/smackx/forward/Forwarded.java b/source/org/jivesoftware/smackx/forward/Forwarded.java deleted file mode 100644 index 817ee27db..000000000 --- a/source/org/jivesoftware/smackx/forward/Forwarded.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright 2013 Georg Lukas - * - * 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.smackx.forward; - -import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smack.packet.PacketExtension; -import org.jivesoftware.smack.provider.PacketExtensionProvider; -import org.jivesoftware.smack.util.PacketParserUtils; -import org.jivesoftware.smackx.packet.DelayInfo; -import org.jivesoftware.smackx.provider.DelayInfoProvider; -import org.xmlpull.v1.XmlPullParser; - -/** - * Packet extension for XEP-0297: Stanza Forwarding. This class implements - * the packet extension and a {@link PacketExtensionProvider} to parse - * forwarded messages from a packet. The extension - * XEP-0297 is - * a prerequisite for XEP-0280 (Message Carbons). - * - *

    The {@link Forwarded.Provider} must be registered in the - * smack.properties file for the element forwarded with - * namespace urn:xmpp:forwarded:0

    to be used. - * - * @author Georg Lukas - */ -public class Forwarded implements PacketExtension { - public static final String NAMESPACE = "urn:xmpp:forward:0"; - public static final String ELEMENT_NAME = "forwarded"; - - private DelayInfo delay; - private Packet forwardedPacket; - - /** - * Creates a new Forwarded packet extension. - * - * @param delay an optional {@link DelayInfo} timestamp of the packet. - * @param fwdPacket the packet that is forwarded (required). - */ - public Forwarded(DelayInfo delay, Packet fwdPacket) { - this.delay = delay; - this.forwardedPacket = fwdPacket; - } - - @Override - public String getElementName() { - return ELEMENT_NAME; - } - - @Override - public String getNamespace() { - return NAMESPACE; - } - - @Override - public String toXML() { - StringBuilder buf = new StringBuilder(); - buf.append("<").append(getElementName()).append(" xmlns=\"") - .append(getNamespace()).append("\">"); - - if (delay != null) - buf.append(delay.toXML()); - buf.append(forwardedPacket.toXML()); - - buf.append(""); - return buf.toString(); - } - - /** - * get the packet forwarded by this stanza. - * - * @return the {@link Packet} instance (typically a message) that was forwarded. - */ - public Packet getForwardedPacket() { - return forwardedPacket; - } - - /** - * get the timestamp of the forwarded packet. - * - * @return the {@link DelayInfo} representing the time when the original packet was sent. May be null. - */ - public DelayInfo getDelayInfo() { - return delay; - } - - public static class Provider implements PacketExtensionProvider { - DelayInfoProvider dip = new DelayInfoProvider(); - - public PacketExtension parseExtension(XmlPullParser parser) throws Exception { - DelayInfo di = null; - Packet packet = null; - - boolean done = false; - while (!done) { - int eventType = parser.next(); - if (eventType == XmlPullParser.START_TAG) { - if (parser.getName().equals("delay")) - di = (DelayInfo)dip.parseExtension(parser); - else if (parser.getName().equals("message")) - packet = PacketParserUtils.parseMessage(parser); - else throw new Exception("Unsupported forwarded packet type: " + parser.getName()); - } - else if (eventType == XmlPullParser.END_TAG && parser.getName().equals(ELEMENT_NAME)) - done = true; - } - if (packet == null) - throw new Exception("forwarded extension must contain a packet"); - return new Forwarded(di, packet); - } - } -} diff --git a/source/org/jivesoftware/smackx/packet/DataForm.java b/source/org/jivesoftware/smackx/packet/DataForm.java index 4bc1f6994..4d12892b5 100644 --- a/source/org/jivesoftware/smackx/packet/DataForm.java +++ b/source/org/jivesoftware/smackx/packet/DataForm.java @@ -202,7 +202,7 @@ public class DataForm implements PacketExtension { * * @return */ - public boolean hasHiddenFromTypeField() { + public boolean hasHiddenFormTypeField() { boolean found = false; for (FormField f : fields) { if (f.getVariable().equals("FORM_TYPE") && f.getType() != null && f.getType().equals("hidden")) diff --git a/source/org/jivesoftware/smackx/packet/DiscoverInfo.java b/source/org/jivesoftware/smackx/packet/DiscoverInfo.java index e2219032d..ba873a96d 100644 --- a/source/org/jivesoftware/smackx/packet/DiscoverInfo.java +++ b/source/org/jivesoftware/smackx/packet/DiscoverInfo.java @@ -257,13 +257,25 @@ public class DiscoverInfo extends IQ { * attributes. * */ - public static class Identity implements Comparable { + public static class Identity implements Comparable { private String category; private String name; private String type; private String lang; // 'xml:lang; + /** + * Creates a new identity for an XMPP entity. + * + * @param category the entity's category. + * @param name the entity's name. + * @deprecated As per the spec, the type field is mandatory and the 3 argument constructor should be used instead. + */ + public Identity(String category, String name) { + this.category = category; + this.name = name; + } + /** * Creates a new identity for an XMPP entity. * 'category' and 'type' are required by @@ -274,6 +286,9 @@ public class DiscoverInfo extends IQ { * @param type the entity's type (required as per XEP-30). */ public Identity(String category, String name, String type) { + if ((category == null) || (type == null)) + throw new IllegalArgumentException("category and type cannot be null"); + this.category = category; this.name = name; this.type = type; @@ -313,6 +328,7 @@ public class DiscoverInfo extends IQ { * 'type' attribute refer to Jabber::Registrar * * @param type the identity's type. + * @deprecated As per the spec, this field is mandatory and the 3 argument constructor should be used instead. */ public void setType(String type) { this.type = type; @@ -374,11 +390,14 @@ public class DiscoverInfo extends IQ { String otherLang = other.lang == null ? "" : other.lang; String thisLang = lang == null ? "" : lang; - - if (!other.type.equals(type)) - return false; if (!otherLang.equals(thisLang)) return false; + + // This safeguard can be removed once the deprecated constructor is removed. + String otherType = other.type == null ? "" : other.type; + String thisType = type == null ? "" : type; + if (!otherType.equals(thisType)) + return false; String otherName = other.name == null ? "" : other.name; String thisName = name == null ? "" : other.name; @@ -387,23 +406,35 @@ public class DiscoverInfo extends IQ { return true; } + + @Override + public int hashCode() { + int result = 1; + result = 37 * result + category.hashCode(); + result = 37 * result + (lang == null ? 0 : lang.hashCode()); + result = 37 * result + (type == null ? 0 : type.hashCode()); + result = 37 * result + (name == null ? 0 : name.hashCode()); + return result; + } /** - * Compares and identity with another object. The comparison order is: + * Compares this identity with another one. The comparison order is: * Category, Type, Lang. If all three are identical the other Identity is considered equal. * Name is not used for comparision, as defined by XEP-0115 * * @param obj * @return */ - public int compareTo(Object obj) { - - DiscoverInfo.Identity other = (DiscoverInfo.Identity) obj; + public int compareTo(DiscoverInfo.Identity other) { String otherLang = other.lang == null ? "" : other.lang; String thisLang = lang == null ? "" : lang; + + // This can be removed once the deprecated constructor is removed. + String otherType = other.type == null ? "" : other.type; + String thisType = type == null ? "" : type; if (category.equals(other.category)) { - if (type.equals(other.type)) { + if (thisType.equals(otherType)) { if (thisLang.equals(otherLang)) { // Don't compare on name, XEP-30 says that name SHOULD // be equals for all identities of an entity @@ -412,7 +443,7 @@ public class DiscoverInfo extends IQ { return thisLang.compareTo(otherLang); } } else { - return type.compareTo(other.type); + return thisType.compareTo(otherType); } } else { return category.compareTo(other.category); @@ -436,6 +467,8 @@ public class DiscoverInfo extends IQ { * @param variable the feature's variable. */ public Feature(String variable) { + if (variable == null) + throw new IllegalArgumentException("variable cannot be null"); this.variable = variable; } @@ -465,5 +498,10 @@ public class DiscoverInfo extends IQ { DiscoverInfo.Feature other = (DiscoverInfo.Feature) obj; return variable.equals(other.variable); } + + @Override + public int hashCode() { + return 37 * variable.hashCode(); + } } } diff --git a/source/org/jivesoftware/smackx/packet/SharedGroupsInfo.java b/source/org/jivesoftware/smackx/packet/SharedGroupsInfo.java index 341811106..59bd98e7c 100644 --- a/source/org/jivesoftware/smackx/packet/SharedGroupsInfo.java +++ b/source/org/jivesoftware/smackx/packet/SharedGroupsInfo.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2005 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. diff --git a/source/org/jivesoftware/smackx/packet/VCard.java b/source/org/jivesoftware/smackx/packet/VCard.java index 9766db824..70d2d59fa 100644 --- a/source/org/jivesoftware/smackx/packet/VCard.java +++ b/source/org/jivesoftware/smackx/packet/VCard.java @@ -85,7 +85,8 @@ import org.jivesoftware.smack.util.StringUtils; * @author Kirill Maximov (kir@maxkir.com) */ public class VCard extends IQ { - + private static final String DEFAULT_MIME_TYPE = "image/jpeg"; + /** * Phone types: * VOICE?, FAX?, PAGER?, MSG?, CELL?, VIDEO?, BBS?, MODEM?, ISDN?, PCS?, PREF? @@ -93,7 +94,6 @@ public class VCard extends IQ { private Map homePhones = new HashMap(); private Map workPhones = new HashMap(); - /** * Address types: * POSTAL?, PARCEL?, (DOM | INTL)?, PREF?, POBOX?, EXTADR?, STREET?, LOCALITY?, @@ -357,7 +357,7 @@ public class VCard extends IQ { * @param bytes the bytes of the avatar, or null to remove the avatar data */ public void setAvatar(byte[] bytes) { - setAvatar(bytes, "image/jpeg"); + setAvatar(bytes, DEFAULT_MIME_TYPE); } /** @@ -390,6 +390,16 @@ public class VCard extends IQ { photoMimeType = mimeType; } + /** + * Set the encoded avatar string. This is used by the provider. + * + * @param encodedAvatar the encoded avatar string. + * @deprecated Use {@link #setAvatar(String, String)} instead. + */ + public void setEncodedImage(String encodedAvatar) { + setAvatar(encodedAvatar, DEFAULT_MIME_TYPE); + } + /** * Return the byte representation of the avatar(if one exists), otherwise returns null if * no avatar could be found. diff --git a/source/org/jivesoftware/smackx/ping/PingManager.java b/source/org/jivesoftware/smackx/ping/PingManager.java index 3ee79a3f5..2da9dcadc 100644 --- a/source/org/jivesoftware/smackx/ping/PingManager.java +++ b/source/org/jivesoftware/smackx/ping/PingManager.java @@ -17,52 +17,47 @@ package org.jivesoftware.smackx.ping; import java.util.Collections; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.ConnectionCreationListener; -import org.jivesoftware.smack.ConnectionListener; -import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.SmackError; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.filter.AndFilter; +import org.jivesoftware.smack.filter.IQTypeFilter; import org.jivesoftware.smack.filter.PacketFilter; -import org.jivesoftware.smack.filter.PacketIDFilter; import org.jivesoftware.smack.filter.PacketTypeFilter; +import org.jivesoftware.smack.keepalive.KeepAliveManager; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.IQ.Type; +import org.jivesoftware.smack.ping.packet.Ping; +import org.jivesoftware.smack.util.SyncPacketSend; import org.jivesoftware.smackx.ServiceDiscoveryManager; import org.jivesoftware.smackx.packet.DiscoverInfo; -import org.jivesoftware.smackx.ping.packet.Ping; -import org.jivesoftware.smackx.ping.packet.Pong; /** - * Implements the XMPP Ping as defined by XEP-0199. This protocol offers an - * alternative to the traditional 'white space ping' approach of determining the - * availability of an entity. The XMPP Ping protocol allows ping messages to be - * send in a more XML-friendly approach, which can be used over more than one - * hop in the communication path. + * Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol + * allows one entity to 'ping' any other entity by simply sending a ping to + * the appropriate JID. + *

    + * NOTE: The {@link KeepAliveManager} already provides a keepalive functionality + * for regularly pinging the server to keep the underlying transport connection + * alive. This class is specifically intended to do manual pings of other + * entities. * * @author Florian Schmaus * @see XEP-0199:XMPP * Ping */ public class PingManager { - - public static final String NAMESPACE = "urn:xmpp:ping"; - public static final String ELEMENT = "ping"; - - - private static Map instances = - Collections.synchronizedMap(new WeakHashMap()); - + private static Map instances = Collections + .synchronizedMap(new WeakHashMap()); + static { Connection.addConnectionCreationListener(new ConnectionCreationListener() { public void connectionCreated(Connection connection) { @@ -71,273 +66,106 @@ public class PingManager { }); } - private ScheduledExecutorService periodicPingExecutorService; private Connection connection; - private int pingInterval = SmackConfiguration.getDefaultPingInterval(); - private Set pingFailedListeners = Collections - .synchronizedSet(new HashSet()); - private ScheduledFuture periodicPingTask; - protected volatile long lastSuccessfulPingByTask = -1; - - // Ping Flood protection - private long pingMinDelta = 100; - private long lastPingStamp = 0; // timestamp of the last received ping - - // Timestamp of the last pong received, either from the server or another entity - // Note, no need to synchronize this value, it will only increase over time - private long lastSuccessfulManualPing = -1; - - private PingManager(Connection connection) { - ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); - sdm.addFeature(NAMESPACE); - this.connection = connection; - init(); - } - - private void init() { - periodicPingExecutorService = new ScheduledThreadPoolExecutor(1); - PacketFilter pingPacketFilter = new PacketTypeFilter(Ping.class); - connection.addPacketListener(new PacketListener() { - /** - * Sends a Pong for every Ping - */ - public void processPacket(Packet packet) { - if (pingMinDelta > 0) { - // Ping flood protection enabled - long currentMillies = System.currentTimeMillis(); - long delta = currentMillies - lastPingStamp; - lastPingStamp = currentMillies; - if (delta < pingMinDelta) { - return; - } - } - Pong pong = new Pong((Ping)packet); - connection.sendPacket(pong); - } - } - , pingPacketFilter); - connection.addConnectionListener(new ConnectionListener() { - - @Override - public void connectionClosed() { - maybeStopPingServerTask(); - } - - @Override - public void connectionClosedOnError(Exception arg0) { - maybeStopPingServerTask(); - } - - @Override - public void reconnectionSuccessful() { - maybeSchedulePingServerTask(); - } - - @Override - public void reconnectingIn(int seconds) { - } - - @Override - public void reconnectionFailed(Exception e) { - } - }); - instances.put(connection, this); - maybeSchedulePingServerTask(); - } - - public static PingManager getInstanceFor(Connection connection) { + /** + * Retrieves a {@link PingManager} for the specified {@link Connection}, creating one if it doesn't already + * exist. + * + * @param connection + * The connection the manager is attached to. + * @return The new or existing manager. + */ + public synchronized static PingManager getInstanceFor(Connection connection) { PingManager pingManager = instances.get(connection); if (pingManager == null) { pingManager = new PingManager(connection); } - return pingManager; } - public void setPingIntervall(int pingIntervall) { - this.pingInterval = pingIntervall; + private PingManager(Connection con) { + this.connection = con; + ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); + + // The ServiceDiscoveryManager was not pre-initialized + if (sdm == null) + sdm = new ServiceDiscoveryManager(connection); + + sdm.addFeature(Ping.NAMESPACE); + + PacketFilter pingPacketFilter = new AndFilter(new PacketTypeFilter(Ping.class), new IQTypeFilter(Type.GET)); + + connection.addPacketListener(new PacketListener() { + /** + * Sends a Pong for every Ping + */ + public void processPacket(Packet packet) { + IQ pong = IQ.createResultIQ((Ping) packet); + connection.sendPacket(pong); + } + }, pingPacketFilter); } - public int getPingIntervall() { - return pingInterval; - } - - public void registerPingFailedListener(PingFailedListener listener) { - pingFailedListeners.add(listener); - } - - public void unregisterPingFailedListener(PingFailedListener listener) { - pingFailedListeners.remove(listener); - } - - public void disablePingFloodProtection() { - setPingMinimumInterval(-1); - } - - public void setPingMinimumInterval(long ms) { - this.pingMinDelta = ms; - } - - public long getPingMinimumInterval() { - return this.pingMinDelta; + /** + * Pings the given jid. This method will return false if an error occurs. The exception + * to this, is a server ping, which will always return true if the server is reachable, + * event if there is an error on the ping itself (i.e. ping not supported). + *

    + * Use {@link #isPingSupported(String)} to determine if XMPP Ping is supported + * by the entity. + * + * @param jid The id of the entity the ping is being sent to + * @param pingTimeout The time to wait for a reply + * @return true if a reply was received from the entity, false otherwise. + */ + public boolean ping(String jid, long pingTimeout) { + Ping ping = new Ping(jid); + + try { + SyncPacketSend.getReply(connection, ping); + } + catch (XMPPException exc) { + + return (jid.equals(connection.getServiceName()) && (exc.getSmackError() != SmackError.NO_RESPONSE_FROM_SERVER)); + } + return true; } /** - * Pings the given jid and returns the IQ response which is either of - * IQ.Type.ERROR or IQ.Type.RESULT. If we are not connected or if there was - * no reply, null is returned. + * Same as calling {@link #ping(String, long)} with the defaultpacket reply + * timeout. * - * You should use isPingSupported(jid) to determine if XMPP Ping is - * supported by the user. - * - * @param jid - * @param pingTimeout - * @return + * @param jid The id of the entity the ping is being sent to + * @return true if a reply was received from the entity, false otherwise. */ - public IQ ping(String jid, long pingTimeout) { - // Make sure we actually connected to the server - if (!connection.isAuthenticated()) - return null; - - Ping ping = new Ping(connection.getUser(), jid); - - PacketCollector collector = - connection.createPacketCollector(new PacketIDFilter(ping.getPacketID())); - - connection.sendPacket(ping); - - IQ result = (IQ) collector.nextResult(pingTimeout); - - collector.cancel(); - return result; - } - - /** - * Pings the given jid and returns the IQ response with the default - * packet reply timeout - * - * @param jid - * @return - */ - public IQ ping(String jid) { + public boolean ping(String jid) { return ping(jid, SmackConfiguration.getPacketReplyTimeout()); } /** - * Pings the given Entity. + * Query the specified entity to see if it supports the Ping protocol (XEP-0199) * - * Note that XEP-199 shows that if we receive a error response - * service-unavailable there is no way to determine if the response was send - * by the entity (e.g. a user JID) or from a server in between. This is - * intended behavior to avoid presence leaks. - * - * Always use isPingSupported(jid) to determine if XMPP Ping is supported - * by the entity. - * - * @param jid - * @return True if a pong was received, otherwise false + * @param jid The id of the entity the query is being sent to + * @return true if it supports ping, false otherwise. + * @throws XMPPException An XMPP related error occurred during the request */ - public boolean pingEntity(String jid, long pingTimeout) { - IQ result = ping(jid, pingTimeout); + public boolean isPingSupported(String jid) throws XMPPException { + DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(jid); + return result.containsFeature(Ping.NAMESPACE); + } - if (result == null || result.getType() == IQ.Type.ERROR) { - return false; - } - pongReceived(); - return true; - } - - public boolean pingEntity(String jid) { - return pingEntity(jid, SmackConfiguration.getPacketReplyTimeout()); - } - /** - * Pings the user's server. Will notify the registered - * pingFailedListeners in case of error. + * Pings the server. This method will return true if the server is reachable. It + * is the equivalent of calling ping with the XMPP domain. + *

    + * Unlike the {@link #ping(String)} case, this method will return true even if + * {@link #isPingSupported(String)} is false. * - * If we receive as response, we can be sure that it came from the server. - * - * @return true if successful, otherwise false - */ - public boolean pingMyServer(long pingTimeout) { - IQ result = ping(connection.getServiceName(), pingTimeout); - - if (result == null) { - for (PingFailedListener l : pingFailedListeners) { - l.pingFailed(); - } - return false; - } - // Maybe not really a pong, but an answer is an answer - pongReceived(); - return true; - } - - /** - * Pings the user's server with the PacketReplyTimeout as defined - * in SmackConfiguration. - * - * @return true if successful, otherwise false + * @return true if a reply was received from the server, false otherwise. */ public boolean pingMyServer() { - return pingMyServer(SmackConfiguration.getPacketReplyTimeout()); - } - - /** - * Returns true if XMPP Ping is supported by a given JID - * - * @param jid - * @return - */ - public boolean isPingSupported(String jid) { - try { - DiscoverInfo result = - ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(jid); - return result.containsFeature(NAMESPACE); - } - catch (XMPPException e) { - return false; - } - } - - /** - * Returns the time of the last successful Ping Pong with the - * users server. If there was no successful Ping (e.g. because this - * feature is disabled) -1 will be returned. - * - * @return - */ - public long getLastSuccessfulPing() { - return Math.max(lastSuccessfulPingByTask, lastSuccessfulManualPing); - } - - protected Set getPingFailedListeners() { - return pingFailedListeners; - } - - /** - * Cancels any existing periodic ping task if there is one and schedules a new ping task if pingInterval is greater - * then zero. - * - */ - protected synchronized void maybeSchedulePingServerTask() { - maybeStopPingServerTask(); - if (pingInterval > 0) { - periodicPingTask = periodicPingExecutorService.schedule(new ServerPingTask(connection), pingInterval, - TimeUnit.SECONDS); - } - } - - private void maybeStopPingServerTask() { - if (periodicPingTask != null) { - periodicPingTask.cancel(true); - periodicPingTask = null; - } - } - - private void pongReceived() { - lastSuccessfulManualPing = System.currentTimeMillis(); + return ping(connection.getServiceName()); } } diff --git a/source/org/jivesoftware/smackx/ping/ServerPingTask.java b/source/org/jivesoftware/smackx/ping/ServerPingTask.java deleted file mode 100644 index 0901b8f15..000000000 --- a/source/org/jivesoftware/smackx/ping/ServerPingTask.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 2012-2013 Florian Schmaus - * - * 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.smackx.ping; - -import java.lang.ref.WeakReference; -import java.util.Set; - -import org.jivesoftware.smack.Connection; - -class ServerPingTask implements Runnable { - - // This has to be a weak reference because IIRC all threads are roots - // for objects and we have a new thread here that should hold a strong - // reference to connection so that it can be GCed. - private WeakReference weakConnection; - - private int delta = 1000; // 1 seconds - private int tries = 3; // 3 tries - - protected ServerPingTask(Connection connection) { - this.weakConnection = new WeakReference(connection); - } - - public void run() { - Connection connection = weakConnection.get(); - if (connection == null) { - // connection has been collected by GC - // which means we can stop the thread by breaking the loop - return; - } - if (connection.isAuthenticated()) { - PingManager pingManager = PingManager.getInstanceFor(connection); - boolean res = false; - - for (int i = 0; i < tries; i++) { - if (i != 0) { - try { - Thread.sleep(delta); - } catch (InterruptedException e) { - // We received an interrupt - // This only happens if we should stop pinging - return; - } - } - res = pingManager.pingMyServer(); - // stop when we receive a pong back - if (res) { - pingManager.lastSuccessfulPingByTask = System.currentTimeMillis(); - break; - } - } - if (!res) { - Set pingFailedListeners = pingManager.getPingFailedListeners(); - for (PingFailedListener l : pingFailedListeners) { - l.pingFailed(); - } - } else { - // Ping was successful, wind-up the periodic task again - pingManager.maybeSchedulePingServerTask(); - } - } - } -} diff --git a/source/org/jivesoftware/smackx/ping/packet/Pong.java b/source/org/jivesoftware/smackx/ping/packet/Pong.java deleted file mode 100644 index 9300db0ce..000000000 --- a/source/org/jivesoftware/smackx/ping/packet/Pong.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2012 Florian Schmaus - * - * 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.smackx.ping.packet; - -import org.jivesoftware.smack.packet.IQ; - -public class Pong extends IQ { - - /** - * Composes a Pong packet from a received ping packet. This basically swaps - * the 'from' and 'to' attributes. And sets the IQ type to result. - * - * @param ping - */ - public Pong(Ping ping) { - setType(IQ.Type.RESULT); - setFrom(ping.getTo()); - setTo(ping.getFrom()); - setPacketID(ping.getPacketID()); - } - - /* - * Returns the child element of the Pong reply, which is non-existent. This - * is why we return 'null' here. See e.g. Example 11 from - * http://xmpp.org/extensions/xep-0199.html#e2e - */ - public String getChildElementXML() { - return null; - } - -} diff --git a/source/org/jivesoftware/smackx/pubsub/CollectionNode.java b/source/org/jivesoftware/smackx/pubsub/CollectionNode.java index 21645afae..dcd1cc4a4 100644 --- a/source/org/jivesoftware/smackx/pubsub/CollectionNode.java +++ b/source/org/jivesoftware/smackx/pubsub/CollectionNode.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier. * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-07-13 - */ package org.jivesoftware.smackx.pubsub; import org.jivesoftware.smack.Connection; diff --git a/source/org/jivesoftware/smackx/pubsub/Node.java b/source/org/jivesoftware/smackx/pubsub/Node.java index a31e778b7..1b0ff5afd 100644 --- a/source/org/jivesoftware/smackx/pubsub/Node.java +++ b/source/org/jivesoftware/smackx/pubsub/Node.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier. * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-07-09 - */ package org.jivesoftware.smackx.pubsub; import java.util.ArrayList; diff --git a/source/org/jivesoftware/smackx/pubsub/NodeEvent.java b/source/org/jivesoftware/smackx/pubsub/NodeEvent.java index 917d3c494..1392e851e 100644 --- a/source/org/jivesoftware/smackx/pubsub/NodeEvent.java +++ b/source/org/jivesoftware/smackx/pubsub/NodeEvent.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier. * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-05-12 - */ package org.jivesoftware.smackx.pubsub; abstract public class NodeEvent diff --git a/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java b/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java index aabd4cb2f..7b06af301 100644 --- a/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java +++ b/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java @@ -24,53 +24,86 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; import org.xmlpull.v1.XmlPullParser; /** - * Parses an item element as is defined in both the {@link PubSubNamespace#BASIC} and {@link PubSubNamespace#EVENT} - * namespaces. To parse the item contents, it will use whatever {@link PacketExtensionProvider} is registered in - * smack.providers for its element name and namespace. If no provider is registered, it will return a {@link SimplePayload}. + * Parses an item element as is defined in both the {@link PubSubNamespace#BASIC} and + * {@link PubSubNamespace#EVENT} namespaces. To parse the item contents, it will use whatever + * {@link PacketExtensionProvider} is registered in smack.providers for its element name and namespace. If no + * provider is registered, it will return a {@link SimplePayload}. * * @author Robin Collier */ -public class ItemProvider implements PacketExtensionProvider +public class ItemProvider implements PacketExtensionProvider { - public PacketExtension parseExtension(XmlPullParser parser) throws Exception - { - String id = parser.getAttributeValue(null, "id"); + 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, node); - } - else - { - String payloadElemName = parser.getName(); - String payloadNS = parser.getNamespace(); - - if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null) - { - boolean done = false; - StringBuilder payloadText = new StringBuilder(); - - while (!done) - { - if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem)) - done = true; - else if (!((tag == XmlPullParser.START_TAG) && parser.isEmptyElementTag())) - payloadText.append(parser.getText()); - - if (!done) - tag = parser.next(); - } - return new PayloadItem(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString())); - } - else - { - return new PayloadItem(id, node, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser)); - } - } - } + String elem = parser.getName(); + + int tag = parser.next(); + + if (tag == XmlPullParser.END_TAG) + { + return new Item(id, node); + } + else + { + String payloadElemName = parser.getName(); + String payloadNS = parser.getNamespace(); + + if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null) + { + boolean done = false; + boolean isEmptyElement = false; + StringBuilder payloadText = new StringBuilder(); + + while (!done) + { + if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem)) + { + done = true; + } + else if (parser.getEventType() == XmlPullParser.START_TAG) + { + payloadText.append("<").append(parser.getName()); + + if (parser.getName().equals(payloadElemName) && (payloadNS.length() > 0)) + payloadText.append(" xmlns=\"").append(payloadNS).append("\""); + int n = parser.getAttributeCount(); + + for (int i = 0; i < n; i++) + payloadText.append(" ").append(parser.getAttributeName(i)).append("=\"") + .append(parser.getAttributeValue(i)).append("\""); + + if (parser.isEmptyElementTag()) + { + payloadText.append("/>"); + isEmptyElement = true; + } + else + { + payloadText.append(">"); + } + } + else if (parser.getEventType() == XmlPullParser.END_TAG) + { + if (isEmptyElement) + isEmptyElement = false; + else + payloadText.append(""); + } + else if (parser.getEventType() == XmlPullParser.TEXT) + { + payloadText.append(parser.getText()); + } + tag = parser.next(); + } + return new PayloadItem(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString())); + } + else { + return new PayloadItem(id, node, PacketParserUtils.parsePacketExtension( + payloadElemName, payloadNS, parser)); + } + } + } } diff --git a/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java b/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java index 14f4456d2..902055671 100644 --- a/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java +++ b/source/org/jivesoftware/smackx/receipts/DeliveryReceipt.java @@ -1,4 +1,4 @@ -/* +/** * 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 @@ -42,16 +42,19 @@ public class DeliveryReceipt implements PacketExtension return id; } + @Override public String getElementName() { return ELEMENT; } + @Override public String getNamespace() { return NAMESPACE; } + @Override public String toXML() { return ""; diff --git a/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index eaac5a4c4..125b87e63 100644 --- a/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -24,20 +24,16 @@ import java.util.WeakHashMap; import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.ConnectionCreationListener; -import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.filter.PacketExtensionFilter; -import org.jivesoftware.smack.filter.PacketIDFilter; -import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smackx.ServiceDiscoveryManager; import org.jivesoftware.smackx.packet.DiscoverInfo; /** - * Packet extension for XEP-0184: Message Delivery Receipts. This class implements + * Manager for XEP-0184: Message Delivery Receipts. This class implements * the manager for {@link DeliveryReceipt} support, enabling and disabling of * automatic DeliveryReceipt transmission. * @@ -167,7 +163,7 @@ public class DeliveryReceiptManager implements PacketListener { * * @param listener the listener to be informed about new receipts */ - public void registerReceiptReceivedListener(ReceiptReceivedListener listener) { + public void addReceiptReceivedListener(ReceiptReceivedListener listener) { receiptReceivedListeners.add(listener); } @@ -176,20 +172,10 @@ public class DeliveryReceiptManager implements PacketListener { * * @param listener the listener to be removed */ - public void unregisterReceiptReceivedListener(ReceiptReceivedListener listener) { + public void removeReceiptReceivedListener(ReceiptReceivedListener listener) { receiptReceivedListeners.remove(listener); } - /** - * Interface for received receipt notifications. - * - * Implement this and add a listener to get notified. - */ - public static interface ReceiptReceivedListener { - void onReceiptReceived(String fromJid, String toJid, String receiptId); - } - - /** * Test if a packet requires a delivery receipt. * diff --git a/source/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java b/source/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java new file mode 100644 index 000000000..318311371 --- /dev/null +++ b/source/org/jivesoftware/smackx/receipts/ReceiptReceivedListener.java @@ -0,0 +1,26 @@ +/** + * Copyright 2013 Georg Lukas + * + * 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.smackx.receipts; + +/** + * Interface for received receipt notifications. + * + * Implement this and add a listener to get notified. + */ +public interface ReceiptReceivedListener { + void onReceiptReceived(String fromJid, String toJid, String receiptId); +} \ No newline at end of file diff --git a/test-unit/org/jivesoftware/smack/DummyConnection.java b/test-unit/org/jivesoftware/smack/DummyConnection.java index 0c4b75c1e..57753a1ba 100644 --- a/test-unit/org/jivesoftware/smack/DummyConnection.java +++ b/test-unit/org/jivesoftware/smack/DummyConnection.java @@ -49,6 +49,7 @@ public class DummyConnection extends Connection { private boolean authenticated = false; private boolean anonymous = false; + private boolean reconnect = false; private String user; private String connectionID; @@ -57,16 +58,26 @@ public class DummyConnection extends Connection { private final BlockingQueue queue = new LinkedBlockingQueue(); public DummyConnection() { - super(new ConnectionConfiguration("example.com")); + this(new ConnectionConfiguration("example.com")); } public DummyConnection(ConnectionConfiguration configuration) { super(configuration); + + for (ConnectionCreationListener listener : getConnectionCreationListeners()) { + listener.connectionCreated(this); + } } @Override public void connect() throws XMPPException { connectionID = "dummy-" + new Random(new Date().getTime()).nextInt(); + + if (reconnect) { + for (ConnectionListener listener : getConnectionListeners()) { + listener.reconnectionSuccessful(); + } + } } @Override @@ -76,6 +87,11 @@ public class DummyConnection extends Connection { roster = null; authenticated = false; anonymous = false; + + for (ConnectionListener listener : getConnectionListeners()) { + listener.connectionClosed(); + } + reconnect = true; } @Override @@ -191,15 +207,27 @@ public class DummyConnection extends Connection { } /** - * Returns the first packet that's sent through {@link #sendPacket(Packet)} and - * that has not been returned by earlier calls to this method. This method - * will block for up to two seconds if no packets have been sent yet. + * Returns the first packet that's sent through {@link #sendPacket(Packet)} + * and that has not been returned by earlier calls to this method. * * @return a sent packet. * @throws InterruptedException */ public Packet getSentPacket() throws InterruptedException { - return queue.poll(2, TimeUnit.SECONDS); + return queue.poll(); + } + + /** + * Returns the first packet that's sent through {@link #sendPacket(Packet)} + * and that has not been returned by earlier calls to this method. This + * method will block for up to the specified number of seconds if no packets + * have been sent yet. + * + * @return a sent packet. + * @throws InterruptedException + */ + public Packet getSentPacket(int wait) throws InterruptedException { + return queue.poll(wait, TimeUnit.SECONDS); } /** diff --git a/test-unit/org/jivesoftware/smack/RosterOfflineTest.java b/test-unit/org/jivesoftware/smack/RosterOfflineTest.java index ff56d8679..3e7f052aa 100644 --- a/test-unit/org/jivesoftware/smack/RosterOfflineTest.java +++ b/test-unit/org/jivesoftware/smack/RosterOfflineTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test-unit/org/jivesoftware/smack/TestUtils.java b/test-unit/org/jivesoftware/smack/TestUtils.java index f9dfcd6a8..0eae51e35 100644 --- a/test-unit/org/jivesoftware/smack/TestUtils.java +++ b/test-unit/org/jivesoftware/smack/TestUtils.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2013 Robin Collier * * 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. @@ -17,61 +17,52 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smack; - -import java.io.IOException; -import java.io.StringReader; - -import org.xmlpull.mxp1.MXParser; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -final public class TestUtils -{ - private TestUtils() {} - - public static XmlPullParser getIQParser(String stanza) - { - return getParser(stanza, "iq"); - } - - public static XmlPullParser getMessageParser(String stanza) - { - return getParser(stanza, "message"); - } - - public static XmlPullParser getPresenceParser(String stanza) - { - return getParser(stanza, "presence"); - } - - public static XmlPullParser getParser(String stanza, String startTag) - { - XmlPullParser parser = new MXParser(); - try - { - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(new StringReader(stanza)); - boolean found = false; - - while (!found) - { - if ((parser.next() == XmlPullParser.START_TAG) && parser.getName().equals(startTag)) - found = true; - } - - if (!found) - throw new IllegalArgumentException("Cannot parse start tag [" + startTag + "] from stanze [" + stanza + "]"); - } - catch (XmlPullParserException e) - { - throw new RuntimeException(e); - } - catch (IOException e) - { - throw new RuntimeException(e); - } - return parser; - } - -} +package org.jivesoftware.smack; + +import java.io.IOException; +import java.io.StringReader; + +import org.xmlpull.mxp1.MXParser; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +final public class TestUtils { + private TestUtils() { + } + + public static XmlPullParser getIQParser(String stanza) { + return getParser(stanza, "iq"); + } + + public static XmlPullParser getMessageParser(String stanza) { + return getParser(stanza, "message"); + } + + public static XmlPullParser getPresenceParser(String stanza) { + return getParser(stanza, "presence"); + } + + public static XmlPullParser getParser(String stanza, String startTag) { + XmlPullParser parser = new MXParser(); + try { + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); + parser.setInput(new StringReader(stanza)); + boolean found = false; + + while (!found) { + if ((parser.next() == XmlPullParser.START_TAG) && parser.getName().equals(startTag)) + found = true; + } + + if (!found) + throw new IllegalArgumentException("Cannot parse start tag [" + startTag + "] from stanza [" + stanza + + "]"); + } catch (XmlPullParserException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + return parser; + } + +} diff --git a/test-unit/org/jivesoftware/smack/ThreadedDummyConnection.java b/test-unit/org/jivesoftware/smack/ThreadedDummyConnection.java index 3375801db..d293dfee2 100644 --- a/test-unit/org/jivesoftware/smack/ThreadedDummyConnection.java +++ b/test-unit/org/jivesoftware/smack/ThreadedDummyConnection.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 @@ -17,80 +15,90 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -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(); - } - } - }; - -} +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; + +/** + * + * @author Robin Collier + * + */ +public class ThreadedDummyConnection extends DummyConnection { + private BlockingQueue replyQ = new ArrayBlockingQueue(1); + private BlockingQueue messageQ = new LinkedBlockingQueue(5); + private volatile boolean timeout = false; + + @Override + public void sendPacket(Packet packet) { + super.sendPacket(packet); + + if (packet instanceof IQ && !timeout) { + timeout = false; + // 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(); + + // If no reply has been set via addIQReply, then we create a simple reply + if (replyPacket == null) { + replyPacket = IQ.createResultIQ((IQ) packet); + replyQ.add(replyPacket); + } + replyPacket.setPacketID(packet.getPacketID()); + replyPacket.setFrom(packet.getTo()); + replyPacket.setTo(packet.getFrom()); + replyPacket.setType(Type.RESULT); + + new ProcessQueue(replyQ).start(); + } + } + + /** + * Calling this method will cause the next sendPacket call with an IQ packet to timeout. + * This is accomplished by simply stopping the auto creating of the reply packet + * or processing one that was entered via {@link #processPacket(Packet)}. + */ + public void setTimeout() { + timeout = true; + } + + 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 index 2e3b57556..56bb93192 100644 --- a/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java +++ b/test-unit/org/jivesoftware/smack/filters/FromMatchesFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2011 Robin Collier * * 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. @@ -25,7 +25,12 @@ import static org.junit.Assert.assertFalse; import org.jivesoftware.smack.filter.FromMatchesFilter; import org.jivesoftware.smack.packet.Packet; import org.junit.Test; - + +/** + * + * @author Robin Collier + * + */ public class FromMatchesFilterTest { private static final String BASE_JID1 = "ss@muc.myserver.com"; private static final String FULL_JID1_R1 = BASE_JID1 + "/resource"; diff --git a/test-unit/org/jivesoftware/smack/keepalive/KeepaliveTest.java b/test-unit/org/jivesoftware/smack/keepalive/KeepaliveTest.java new file mode 100644 index 000000000..937bcebbb --- /dev/null +++ b/test-unit/org/jivesoftware/smack/keepalive/KeepaliveTest.java @@ -0,0 +1,159 @@ +package org.jivesoftware.smack.keepalive; + +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Properties; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.DummyConnection; +import org.jivesoftware.smack.PacketInterceptor; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.TestUtils; +import org.jivesoftware.smack.ThreadedDummyConnection; +import org.jivesoftware.smack.filter.IQTypeFilter; +import org.jivesoftware.smack.filter.PacketTypeFilter; +import org.jivesoftware.smack.keepalive.KeepAliveManager; +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.ping.PingFailedListener; +import org.jivesoftware.smack.ping.packet.Ping; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class KeepaliveTest { + private static final long PING_MINIMUM = 1000; + private static String TO = "juliet@capulet.lit/balcony"; + private static String ID = "s2c1"; + + private static Properties outputProperties = new Properties(); + { + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + } + + private int originalTimeout; + + @Before + public void resetProperties() + { + SmackConfiguration.setKeepAliveInterval(-1); + originalTimeout = SmackConfiguration.getPacketReplyTimeout(); + SmackConfiguration.setPacketReplyTimeout(1000); + } + + @After + public void restoreProperties() + { + SmackConfiguration.setPacketReplyTimeout(originalTimeout); + } + /* + * Stanza copied from spec + */ + @Test + public void validatePingStanzaXML() throws Exception { + // @formatter:off + String control = "" + + ""; + // @formatter:on + + Ping ping = new Ping(TO); + ping.setPacketID(ID); + + assertXMLEqual(control, ping.toXML()); + } + + @Test + public void serverPingFailSingleConnection() throws Exception { + DummyConnection connection = getConnection(); + CountDownLatch latch = new CountDownLatch(2); + addInterceptor(connection, latch); + addPingFailedListener(connection, latch); + + // Time based testing kind of sucks, but this should be reliable on a DummyConnection since there + // is no actual server involved. This will provide enough time to ping and wait for the lack of response. + assertTrue(latch.await(getWaitTime(), TimeUnit.MILLISECONDS)); + } + + @Test + public void serverPingSuccessfulSingleConnection() throws Exception { + ThreadedDummyConnection connection = getThreadedConnection(); + final CountDownLatch latch = new CountDownLatch(1); + + connection.addPacketListener(new PacketListener() { + @Override + public void processPacket(Packet packet) { + latch.countDown(); + } + }, new IQTypeFilter(IQ.Type.RESULT)); + + // Time based testing kind of sucks, but this should be reliable on a DummyConnection since there + // is no actual server involved. This will provide enough time to ping and wait for the lack of response. + assertTrue(latch.await(getWaitTime(), TimeUnit.MILLISECONDS)); + } + + @Test + public void serverPingFailMultipleConnection() throws Exception { + CountDownLatch latch = new CountDownLatch(6); + SmackConfiguration.setPacketReplyTimeout(15000); + + DummyConnection con1 = getConnection(); + addInterceptor(con1, latch); + addPingFailedListener(con1, latch); + + DummyConnection con2 = getConnection(); + addInterceptor(con2, latch); + addPingFailedListener(con2, latch); + + DummyConnection con3 = getConnection(); + addInterceptor(con3, latch); + addPingFailedListener(con2, latch); + + assertTrue(latch.await(getWaitTime(), TimeUnit.MILLISECONDS)); + } + + private void addPingFailedListener(DummyConnection con, final CountDownLatch latch) { + KeepAliveManager manager = KeepAliveManager.getInstanceFor(con); + manager.addPingFailedListener(new PingFailedListener() { + @Override + public void pingFailed() { + latch.countDown(); + } + }); + } + + private DummyConnection getConnection() { + DummyConnection con = new DummyConnection(); + KeepAliveManager mgr = KeepAliveManager.getInstanceFor(con); + mgr.setPingInterval(PING_MINIMUM); + + return con; + } + + private ThreadedDummyConnection getThreadedConnection() { + ThreadedDummyConnection con = new ThreadedDummyConnection(); + KeepAliveManager mgr = KeepAliveManager.getInstanceFor(con); + mgr.setPingInterval(PING_MINIMUM); + + return con; + } + + private void addInterceptor(final Connection con, final CountDownLatch latch) { + con.addPacketInterceptor(new PacketInterceptor() { + @Override + public void interceptPacket(Packet packet) { + con.removePacketInterceptor(this); + latch.countDown(); + } + }, new PacketTypeFilter(Ping.class)); + } + + private long getWaitTime() { + return PING_MINIMUM + SmackConfiguration.getPacketReplyTimeout() + 3000; + } +} diff --git a/test-unit/org/jivesoftware/smack/util/DNSUtilTest.java b/test-unit/org/jivesoftware/smack/util/DNSUtilTest.java index d107f8f0d..2cc7c96c5 100644 --- a/test-unit/org/jivesoftware/smack/util/DNSUtilTest.java +++ b/test-unit/org/jivesoftware/smack/util/DNSUtilTest.java @@ -24,7 +24,7 @@ public class DNSUtilTest { @Test public void xmppClientDomainJavaXTest() { - DNSResolver resolver = JavaxResolver.maybeGetInstance(); + DNSResolver resolver = JavaxResolver.getInstance(); assertNotNull(resolver); DNSUtil.setDNSResolver(resolver); xmppClientDomainTest(); @@ -32,7 +32,7 @@ public class DNSUtilTest { @Test public void xmppServerDomainJavaXTest() { - DNSResolver resolver = JavaxResolver.maybeGetInstance(); + DNSResolver resolver = JavaxResolver.getInstance(); assertNotNull(resolver); DNSUtil.setDNSResolver(resolver); xmppServerDomainTest(); diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java index 295f1f5fb..bec303762 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBPacketUtils.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBTestsSuite.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBTestsSuite.java index f2d11bb14..158459860 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBTestsSuite.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/IBBTestsSuite.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java index 0e1bf792b..92644fcf5 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequestTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java index c43bc1a00..5789bbb25 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionMessageTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java index e7fb76a6b..b715af10a 100644 --- a/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java +++ b/test-unit/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSessionTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test-unit/org/jivesoftware/smackx/carbons/CarbonForwardedTest.java b/test-unit/org/jivesoftware/smackx/carbons/CarbonForwardedTest.java deleted file mode 100644 index b8d3d83a1..000000000 --- a/test-unit/org/jivesoftware/smackx/carbons/CarbonForwardedTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * 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.smackx.carbons; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.StringReader; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Properties; -import java.util.TimeZone; - -import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smackx.packet.DelayInfo; -import org.jivesoftware.smackx.packet.DelayInformation; -import org.jivesoftware.smackx.forward.Forwarded; -import org.junit.Test; -import org.xmlpull.mxp1.MXParser; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import com.jamesmurty.utils.XMLBuilder; - -public class CarbonForwardedTest { - - private static Properties outputProperties = new Properties(); - static { - outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); - } - - @Test - public void forwardedTest() throws Exception { - XmlPullParser parser; - String control; - Forwarded fwd; - - control = XMLBuilder.create("forwarded") - .a("xmlns", "urn:xmpp:forwarded:0") - .e("message") - .a("from", "romeo@montague.com") - .asString(outputProperties); - - parser = getParser(control, "forwarded"); - fwd = (Forwarded) new Forwarded.Provider().parseExtension(parser); - - // no delay in packet - assertEquals(null, fwd.getDelayInfo()); - - // check message - assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom()); - - // check end of tag - assertEquals(XmlPullParser.END_TAG, parser.getEventType()); - assertEquals("forwarded", parser.getName()); - - } - - @Test(expected=Exception.class) - public void forwardedEmptyTest() throws Exception { - XmlPullParser parser; - String control; - - control = XMLBuilder.create("forwarded") - .a("xmlns", "urn:xmpp:forwarded:0") - .asString(outputProperties); - - parser = getParser(control, "forwarded"); - new Forwarded.Provider().parseExtension(parser); - } - - @Test - public void carbonSentTest() throws Exception { - XmlPullParser parser; - String control; - Carbon cc; - Forwarded fwd; - - control = XMLBuilder.create("sent") - .e("forwarded") - .a("xmlns", "urn:xmpp:forwarded:0") - .e("message") - .a("from", "romeo@montague.com") - .asString(outputProperties); - - parser = getParser(control, "sent"); - cc = (Carbon) new Carbon.Provider().parseExtension(parser); - fwd = cc.getForwarded(); - - // meta - assertEquals(Carbon.Direction.sent, cc.getDirection()); - - // no delay in packet - assertEquals(null, fwd.getDelayInfo()); - - // check message - assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom()); - - // check end of tag - assertEquals(XmlPullParser.END_TAG, parser.getEventType()); - assertEquals("sent", parser.getName()); - } - - @Test - public void carbonReceivedTest() throws Exception { - XmlPullParser parser; - String control; - Carbon cc; - - control = XMLBuilder.create("received") - .e("forwarded") - .a("xmlns", "urn:xmpp:forwarded:0") - .e("message") - .a("from", "romeo@montague.com") - .asString(outputProperties); - - parser = getParser(control, "received"); - cc = (Carbon) new Carbon.Provider().parseExtension(parser); - - assertEquals(Carbon.Direction.received, cc.getDirection()); - - // check end of tag - assertEquals(XmlPullParser.END_TAG, parser.getEventType()); - assertEquals("received", parser.getName()); - } - - @Test(expected=Exception.class) - public void carbonEmptyTest() throws Exception { - XmlPullParser parser; - String control; - - control = XMLBuilder.create("sent") - .a("xmlns", "urn:xmpp:forwarded:0") - .asString(outputProperties); - - parser = getParser(control, "sent"); - new Carbon.Provider().parseExtension(parser); - } - - private XmlPullParser getParser(String control, String startTag) - throws XmlPullParserException, IOException { - XmlPullParser parser = new MXParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(new StringReader(control)); - - while (true) { - if (parser.next() == XmlPullParser.START_TAG - && parser.getName().equals(startTag)) { - break; - } - } - return parser; - } - -} diff --git a/test-unit/org/jivesoftware/smackx/entitycaps/EntityCapsManagerTest.java b/test-unit/org/jivesoftware/smackx/entitycaps/EntityCapsManagerTest.java index 754bf6d3c..91057f7d1 100644 --- a/test-unit/org/jivesoftware/smackx/entitycaps/EntityCapsManagerTest.java +++ b/test-unit/org/jivesoftware/smackx/entitycaps/EntityCapsManagerTest.java @@ -1,6 +1,8 @@ package org.jivesoftware.smackx.entitycaps; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; @@ -9,10 +11,9 @@ import java.util.LinkedList; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.util.Base32Encoder; -import org.jivesoftware.smack.util.Base64Encoder; +import org.jivesoftware.smack.util.Base64FileUrlEncoder; import org.jivesoftware.smack.util.StringEncoder; import org.jivesoftware.smackx.FormField; -import org.jivesoftware.smackx.entitycaps.EntityCapsManager; import org.jivesoftware.smackx.entitycaps.cache.EntityCapsPersistentCache; import org.jivesoftware.smackx.entitycaps.cache.SimpleDirectoryPersistentCache; import org.jivesoftware.smackx.packet.DataForm; @@ -37,7 +38,7 @@ public class EntityCapsManagerTest { @Test public void testSimpleDirectoryCacheBase64() throws IOException { EntityCapsManager.persistentCache = null; - testSimpleDirectoryCache(Base64Encoder.getInstance()); + testSimpleDirectoryCache(Base64FileUrlEncoder.getInstance()); } @Test @@ -216,9 +217,7 @@ public class EntityCapsManagerTest { } public static File createTempDirectory() throws IOException { - String tmpdir = System.getProperty("java.io.tmpdir"); - File tmp; - tmp = File.createTempFile(tmpdir, "entityCaps"); + File tmp = File.createTempFile("entity", "caps"); tmp.delete(); tmp.mkdir(); return tmp; diff --git a/test-unit/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java b/test-unit/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java index 3ae1b4e04..f9255241e 100644 --- a/test-unit/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java +++ b/test-unit/org/jivesoftware/smackx/filetransfer/FileTransferNegotiatorTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2011 Robin Collier * * 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. @@ -17,44 +17,42 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -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); - } -} +package org.jivesoftware.smackx.filetransfer; + +import static org.junit.Assert.assertTrue; + +import org.jivesoftware.smack.DummyConnection; +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 index 93ab1eeae..77144869d 100644 --- a/test-unit/org/jivesoftware/smackx/muc/RoomInfoTest.java +++ b/test-unit/org/jivesoftware/smackx/muc/RoomInfoTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2011 Robin Collier * * 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. @@ -17,53 +17,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -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()); - } -} +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/ping/PingPongTest.java b/test-unit/org/jivesoftware/smackx/ping/PingPongTest.java deleted file mode 100644 index 762223ee4..000000000 --- a/test-unit/org/jivesoftware/smackx/ping/PingPongTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2012 Florian Schmaus - * - * 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.smackx.ping; - -import static org.junit.Assert.assertEquals; - -import org.jivesoftware.smackx.ping.packet.Ping; -import org.jivesoftware.smackx.ping.packet.Pong; -import org.junit.Test; - -public class PingPongTest { - - @Test - public void createPongfromPingTest() { - Ping ping = new Ping("from@sender.local/resourceFrom", "to@receiver.local/resourceTo"); - - // create a pong from a ping - Pong pong = new Pong(ping); - - assertEquals(pong.getFrom(), ping.getTo()); - assertEquals(pong.getTo(), ping.getFrom()); - assertEquals(pong.getPacketID(), ping.getPacketID()); - } - -} diff --git a/test-unit/org/jivesoftware/smackx/ping/PingTest.java b/test-unit/org/jivesoftware/smackx/ping/PingTest.java new file mode 100644 index 000000000..c127f18dc --- /dev/null +++ b/test-unit/org/jivesoftware/smackx/ping/PingTest.java @@ -0,0 +1,222 @@ +/** + * Copyright 2012 Florian Schmaus + * + * 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.smackx.ping; + +import org.jivesoftware.smack.DummyConnection; +import org.jivesoftware.smack.TestUtils; +import org.jivesoftware.smack.ThreadedDummyConnection; +import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.ping.packet.Ping; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.packet.DiscoverInfo; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PingTest { + private DummyConnection dummyCon; + private ThreadedDummyConnection threadedCon; + + @Before + public void setup() { + dummyCon = new DummyConnection(); + threadedCon = new ThreadedDummyConnection(); + } + + @Test + public void checkProvider() throws Exception { + // @formatter:off + String control = "" + + "" + + ""; + // @formatter:on + DummyConnection con = new DummyConnection(); + + // Enable ping for this connection + PingManager.getInstanceFor(con); + IQ pingRequest = PacketParserUtils.parseIQ(TestUtils.getIQParser(control), con); + + assertTrue(pingRequest instanceof Ping); + + con.processPacket(pingRequest); + + Packet pongPacket = con.getSentPacket(); + assertTrue(pongPacket instanceof IQ); + + IQ pong = (IQ) pongPacket; + assertEquals("juliet@capulet.lit/balcony", pong.getFrom()); + assertEquals("capulet.lit", pong.getTo()); + assertEquals("s2c1", pong.getPacketID()); + assertEquals(IQ.Type.RESULT, pong.getType()); + } + + @Test + public void checkSendingPing() throws Exception { + dummyCon = new DummyConnection(); + PingManager pinger = PingManager.getInstanceFor(dummyCon); + pinger.ping("test@myserver.com"); + + Packet sentPacket = dummyCon.getSentPacket(); + + assertTrue(sentPacket instanceof Ping); + + } + + @Test + public void checkSuccessfulPing() throws Exception { + threadedCon = new ThreadedDummyConnection(); + + PingManager pinger = PingManager.getInstanceFor(threadedCon); + + boolean pingSuccess = pinger.ping("test@myserver.com"); + + assertTrue(pingSuccess); + + } + + /** + * DummyConnection will not reply so it will timeout. + * @throws Exception + */ + @Test + public void checkFailedPingOnTimeout() throws Exception { + dummyCon = new DummyConnection(); + PingManager pinger = PingManager.getInstanceFor(dummyCon); + + boolean pingSuccess = pinger.ping("test@myserver.com"); + + assertFalse(pingSuccess); + + } + + /** + * Server returns an exception for entity. + * @throws Exception + */ + @Test + public void checkFailedPingToEntityError() throws Exception { + threadedCon = new ThreadedDummyConnection(); + //@formatter:off + String reply = + "" + + "" + + "" + + "" + + "" + + ""; + //@formatter:on + IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), threadedCon); + threadedCon.addIQReply(serviceUnavailable); + + PingManager pinger = PingManager.getInstanceFor(threadedCon); + + boolean pingSuccess = pinger.ping("test@myserver.com"); + + assertFalse(pingSuccess); + } + + @Test + public void checkPingToServerSuccess() throws Exception { + ThreadedDummyConnection con = new ThreadedDummyConnection(); + PingManager pinger = PingManager.getInstanceFor(con); + + boolean pingSuccess = pinger.pingMyServer(); + + assertTrue(pingSuccess); + } + + /** + * Server returns an exception. + * @throws Exception + */ + @Test + public void checkPingToServerError() throws Exception { + ThreadedDummyConnection con = new ThreadedDummyConnection(); + //@formatter:off + String reply = + "" + + "" + + "" + + "" + + "" + + ""; + //@formatter:on + IQ serviceUnavailable = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con); + con.addIQReply(serviceUnavailable); + + PingManager pinger = PingManager.getInstanceFor(con); + + boolean pingSuccess = pinger.pingMyServer(); + + assertTrue(pingSuccess); + } + + @Test + public void checkPingToServerTimeout() throws Exception { + DummyConnection con = new DummyConnection(); + PingManager pinger = PingManager.getInstanceFor(con); + + boolean pingSuccess = pinger.pingMyServer(); + + assertFalse(pingSuccess); + } + + @Test + public void checkSuccessfulDiscoRequest() throws Exception { + ThreadedDummyConnection con = new ThreadedDummyConnection(); + DiscoverInfo info = new DiscoverInfo(); + info.addFeature(Ping.NAMESPACE); + + //@formatter:off + String reply = + "" + + "" + + "" + + ""; + //@formatter:on + IQ discoReply = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con); + con.addIQReply(discoReply); + + PingManager pinger = PingManager.getInstanceFor(con); + boolean pingSupported = pinger.isPingSupported("test@myserver.com"); + + assertTrue(pingSupported); + } + + @Test + public void checkUnuccessfulDiscoRequest() throws Exception { + ThreadedDummyConnection con = new ThreadedDummyConnection(); + DiscoverInfo info = new DiscoverInfo(); + info.addFeature(Ping.NAMESPACE); + + //@formatter:off + String reply = + "" + + "" + + "" + + ""; + //@formatter:on + IQ discoReply = PacketParserUtils.parseIQ(TestUtils.getIQParser(reply), con); + con.addIQReply(discoReply); + + PingManager pinger = PingManager.getInstanceFor(con); + boolean pingSupported = pinger.isPingSupported("test@myserver.com"); + + assertFalse(pingSupported); + } +} diff --git a/test-unit/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java b/test-unit/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java index 4b47aa2ff..784c56f39 100644 --- a/test-unit/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java +++ b/test-unit/org/jivesoftware/smackx/pubsub/ConfigureFormTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2011 Robin Collier * * 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. @@ -33,7 +33,12 @@ import org.jivesoftware.smackx.packet.DiscoverInfo.Identity; import org.jivesoftware.smackx.pubsub.packet.PubSub; import org.junit.Assert; import org.junit.Test; - + +/** + * + * @author Robin Collier + * + */ public class ConfigureFormTest { @Test @@ -83,7 +88,9 @@ public class ConfigureFormTest Node node = mgr.getNode("princely_musings"); - SmackConfiguration.setPacketReplyTimeout(100); + SmackConfiguration.setPacketReplyTimeout(100); + con.setTimeout(); + node.getNodeConfiguration(); } } diff --git a/test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java b/test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java index 9b3d234b1..eb967e5f7 100644 --- a/test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java +++ b/test-unit/org/jivesoftware/smackx/pubsub/ItemValidationTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2011 Robin Collier * * 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. @@ -19,21 +19,31 @@ */ 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; - +import static org.custommonkey.xmlunit.XMLAssert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.Reader; +import java.io.StringReader; + +import org.jivesoftware.smack.TestUtils; +import org.jivesoftware.smack.ThreadedDummyConnection; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; +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; + +/** + * + * @author Robin Collier + * + */ public class ItemValidationTest { private ThreadedDummyConnection connection; @@ -90,37 +100,146 @@ public class ItemValidationTest 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()); -// } + @Test + public void parseBasicItem() throws Exception + { + XmlPullParser parser = TestUtils.getMessageParser( + "" + + "" + + "" + + "" + + "" + + "" + + ""); + + Packet message = PacketParserUtils.parseMessage(parser); + PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns()); + + assertTrue(eventExt instanceof EventElement); + EventElement event = (EventElement) eventExt; + assertEquals(EventElementType.items, event.getEventType()); + assertEquals(1, event.getExtensions().size()); + assertTrue(event.getExtensions().get(0) instanceof ItemsExtension); + assertEquals(1, ((ItemsExtension)event.getExtensions().get(0)).items.size()); + + PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0); + assertTrue(itemExt instanceof Item); + assertEquals("testid1", ((Item)itemExt).getId()); + } + + @Test + public void parseSimplePayloadItem() throws Exception + { + String itemContent = "Some text"; + + XmlPullParser parser = TestUtils.getMessageParser( + "" + + "" + + "" + + "" + + itemContent + + "" + + "" + + "" + + ""); + + Packet message = PacketParserUtils.parseMessage(parser); + PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns()); + EventElement event = (EventElement) eventExt; + PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0); + + assertTrue(itemExt instanceof PayloadItem); + PayloadItem item = (PayloadItem)itemExt; + + assertEquals("testid1", item.getId()); + assertTrue(item.getPayload() instanceof SimplePayload); + + SimplePayload payload = (SimplePayload) item.getPayload(); + assertEquals("foo", payload.getElementName()); + assertEquals("smack:test", payload.getNamespace()); + assertXMLEqual(itemContent, payload.toXML()); + } + + @Test + public void parseComplexItem() throws Exception + { + String itemContent = + "" + + "Soliloquy" + + "

    " + + "To be, or not to be: that is the question:" + + "Whether 'tis nobler in the mind to suffer" + + "The slings and arrows of outrageous fortune," + + "Or to take arms against a sea of troubles," + + "And by opposing end them?" + + "" + + "" + + "tag:denmark.lit,2003:entry-32397" + + "2003-12-13T18:30:02Z" + + "2003-12-13T18:30:02Z" + + ""; + + XmlPullParser parser = TestUtils.getMessageParser( + "" + + "" + + "" + + "" + + itemContent + + "" + + "" + + "" + + ""); + + Packet message = PacketParserUtils.parseMessage(parser); + PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns()); + EventElement event = (EventElement) eventExt; + PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0); + + assertTrue(itemExt instanceof PayloadItem); + PayloadItem item = (PayloadItem)itemExt; + + assertEquals("testid1", item.getId()); + assertTrue(item.getPayload() instanceof SimplePayload); + + SimplePayload payload = (SimplePayload) item.getPayload(); + assertEquals("entry", payload.getElementName()); + assertEquals("http://www.w3.org/2005/Atom", payload.getNamespace()); + assertXMLEqual(itemContent, payload.toXML()); + } + + @Test + public void parseEmptyTag() throws Exception + { + String itemContent = ""; + + XmlPullParser parser = TestUtils.getMessageParser( + "" + + "" + + "" + + "" + + itemContent + + "" + + "" + + "" + + ""); + + Packet message = PacketParserUtils.parseMessage(parser); + PacketExtension eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns()); + + assertTrue(eventExt instanceof EventElement); + EventElement event = (EventElement) eventExt; + assertEquals(EventElementType.items, event.getEventType()); + assertEquals(1, event.getExtensions().size()); + assertTrue(event.getExtensions().get(0) instanceof ItemsExtension); + assertEquals(1, ((ItemsExtension)event.getExtensions().get(0)).items.size()); + + PacketExtension itemExt = ((ItemsExtension)event.getExtensions().get(0)).items.get(0); + assertTrue(itemExt instanceof PayloadItem); + PayloadItem item = (PayloadItem)itemExt; + + assertEquals("testid1", item.getId()); + assertTrue(item.getPayload() instanceof SimplePayload); + + assertXMLEqual(itemContent, ((SimplePayload)item.getPayload()).toXML()); + } } diff --git a/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index d6e51d740..6b0425a60 100644 --- a/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/test-unit/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -13,16 +13,14 @@ */ package org.jivesoftware.smackx.receipts; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringReader; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; import java.util.Properties; -import java.util.TimeZone; import org.jivesoftware.smack.DummyConnection; import org.jivesoftware.smack.packet.Message; @@ -76,7 +74,7 @@ public class DeliveryReceiptTest { DeliveryReceiptManager drm = DeliveryReceiptManager.getInstanceFor(c); TestReceiptReceivedListener rrl = new TestReceiptReceivedListener(); - drm.registerReceiptReceivedListener(rrl); + drm.addReceiptReceivedListener(rrl); Message m = new Message("romeo@montague.com", Message.Type.normal); m.setFrom("julia@capulet.com"); @@ -88,7 +86,7 @@ public class DeliveryReceiptTest { assertEquals("original-test-id", rrl.receiptId); } - private static class TestReceiptReceivedListener implements DeliveryReceiptManager.ReceiptReceivedListener { + private static class TestReceiptReceivedListener implements ReceiptReceivedListener { public String receiptId = null; @Override public void onReceiptReceived(String fromJid, String toJid, String receiptId) { diff --git a/test/org/jivesoftware/smack/ChatTest.java b/test/org/jivesoftware/smack/ChatTest.java index 10de48a48..1d973dd1a 100644 --- a/test/org/jivesoftware/smack/ChatTest.java +++ b/test/org/jivesoftware/smack/ChatTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 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. diff --git a/test/org/jivesoftware/smack/PacketReaderTest.java b/test/org/jivesoftware/smack/PacketReaderTest.java index c3fc35010..5ac670be0 100644 --- a/test/org/jivesoftware/smack/PacketReaderTest.java +++ b/test/org/jivesoftware/smack/PacketReaderTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 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. diff --git a/test/org/jivesoftware/smack/PrivacyClient.java b/test/org/jivesoftware/smack/PrivacyClient.java index 86772d8ea..3dc6cae56 100644 --- a/test/org/jivesoftware/smack/PrivacyClient.java +++ b/test/org/jivesoftware/smack/PrivacyClient.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test/org/jivesoftware/smack/ReconnectionTest.java b/test/org/jivesoftware/smack/ReconnectionTest.java index 35c085813..4f2b080d0 100644 --- a/test/org/jivesoftware/smack/ReconnectionTest.java +++ b/test/org/jivesoftware/smack/ReconnectionTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 @@ -19,7 +17,11 @@ */ package org.jivesoftware.smack; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + import org.jivesoftware.smack.test.SmackTestCase; +import org.jivesoftware.smackx.ping.PingManager; /** * Tests the connection and reconnection mechanism @@ -28,7 +30,9 @@ import org.jivesoftware.smack.test.SmackTestCase; */ public class ReconnectionTest extends SmackTestCase { - + + private static final long MIN_RECONNECT_WAIT = 17; // Seconds + public ReconnectionTest(String arg0) { super(arg0); } @@ -39,20 +43,18 @@ public class ReconnectionTest extends SmackTestCase { */ public void testAutomaticReconnection() throws Exception { - XMPPConnection connection = getConnection(0); - XMPPConnectionTestListener listener = new XMPPConnectionTestListener(); + XMPPConnection connection = getConnection(0); + CountDownLatch latch = new CountDownLatch(1); + XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch); connection.addConnectionListener(listener); // Simulates an error in the connection connection.notifyConnectionError(new Exception("Simulated Error")); - Thread.sleep(12000); + latch.await(MIN_RECONNECT_WAIT, TimeUnit.SECONDS); + // After 10 seconds, the reconnection manager must reestablishes the connection - assertEquals("The ConnectionListener.connectionStablished() notification was not fired", - true, listener.reconnected); - assertEquals("The ConnectionListener.reconnectingIn() notification was not fired", 10, - listener.attemptsNotifications); - assertEquals("The ReconnectionManager algorithm has reconnected without waiting until 0", 0, - listener.remainingSeconds); + assertEquals("The ConnectionListener.connectionStablished() notification was not fired", true, listener.reconnected); + assertTrue("The ReconnectionManager algorithm has reconnected without waiting at least 5 seconds", listener.attemptsNotifications > 0); // Executes some server interaction testing the connection executeSomeServerInteraction(connection); @@ -75,19 +77,17 @@ public class ReconnectionTest extends SmackTestCase { // Executes some server interaction testing the connection executeSomeServerInteraction(connection); - XMPPConnectionTestListener listener = new XMPPConnectionTestListener(); + CountDownLatch latch = new CountDownLatch(1); + XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch); connection.addConnectionListener(listener); // Simulates an error in the connection connection.notifyConnectionError(new Exception("Simulated Error")); - Thread.sleep(12000); + latch.await(MIN_RECONNECT_WAIT, TimeUnit.SECONDS); + // After 10 seconds, the reconnection manager must reestablishes the connection - assertEquals("The ConnectionListener.connectionStablished() notification was not fired", - true, listener.reconnected); - assertEquals("The ConnectionListener.reconnectingIn() notification was not fired", 10, - listener.attemptsNotifications); - assertEquals("The ReconnectionManager algorithm has reconnected without waiting until 0", 0, - listener.remainingSeconds); + assertEquals("The ConnectionListener.connectionEstablished() notification was not fired", true, listener.reconnected); + assertTrue("The ReconnectionManager algorithm has reconnected without waiting at least 5 seconds", listener.attemptsNotifications > 0); // Executes some server interaction testing the connection executeSomeServerInteraction(connection); @@ -99,7 +99,8 @@ public class ReconnectionTest extends SmackTestCase { */ public void testManualReconnectionWithCancelation() throws Exception { XMPPConnection connection = getConnection(0); - XMPPConnectionTestListener listener = new XMPPConnectionTestListener(); + CountDownLatch latch = new CountDownLatch(1); + XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch); connection.addConnectionListener(listener); // Produces a connection error @@ -107,14 +108,14 @@ public class ReconnectionTest extends SmackTestCase { assertEquals( "An error occurs but the ConnectionListener.connectionClosedOnError(e) was not notified", true, listener.connectionClosedOnError); - Thread.sleep(1000); +// Thread.sleep(1000); + // Cancels the automatic reconnection connection.getConfiguration().setReconnectionAllowed(false); // Waits for a reconnection that must not happened. - Thread.sleep(10500); + Thread.sleep(MIN_RECONNECT_WAIT * 1000); // Cancels the automatic reconnection - assertEquals("The connection was stablished but it was not allowed to", false, - listener.reconnected); + assertEquals(false, listener.reconnected); // Makes a manual reconnection from an error terminated connection without reconnection connection.connect(); @@ -139,7 +140,7 @@ public class ReconnectionTest extends SmackTestCase { assertEquals("ConnectionListener.connectionClosed() was not notified", true, listener.connectionClosed); // Waits 10 seconds waiting for a reconnection that must not happened. - Thread.sleep(12200); + Thread.sleep(MIN_RECONNECT_WAIT * 1000); assertEquals("The connection was stablished but it was not allowed to", false, listener.reconnected); @@ -189,8 +190,8 @@ public class ReconnectionTest extends SmackTestCase { * Execute some server interaction in order to test that the regenerated connection works fine. */ private void executeSomeServerInteraction(XMPPConnection connection) throws XMPPException { - PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(connection); - privacyManager.getPrivacyLists(); + PingManager pingManager = PingManager.getInstanceFor(connection); + pingManager.pingMyServer(); } protected int getMaxConnections() { @@ -200,41 +201,59 @@ public class ReconnectionTest extends SmackTestCase { private class XMPPConnectionTestListener implements ConnectionListener { // Variables to support listener notifications verification - private boolean connectionClosed = false; - private boolean connectionClosedOnError = false; - private boolean reconnected = false; - private boolean reconnectionFailed = false; - private int remainingSeconds = 0; - private int attemptsNotifications = 0; - private boolean reconnectionCanceled = false; - + private volatile boolean connectionClosed = false; + private volatile boolean connectionClosedOnError = false; + private volatile boolean reconnected = false; + private volatile boolean reconnectionFailed = false; + private volatile int remainingSeconds = 0; + private volatile int attemptsNotifications = 0; + private volatile boolean reconnectionCanceled = false; + private CountDownLatch countDownLatch; + + private XMPPConnectionTestListener(CountDownLatch latch) { + countDownLatch = latch; + } + + private XMPPConnectionTestListener() { + } /** * Methods to test the listener. */ - public void connectionClosed() { - connectionClosed = true; + public void connectionClosed() { + connectionClosed = true; + + if (countDownLatch != null) + countDownLatch.countDown(); } public void connectionClosedOnError(Exception e) { - connectionClosedOnError = true; + connectionClosedOnError = true; } public void reconnectionCanceled() { reconnectionCanceled = true; + + if (countDownLatch != null) + countDownLatch.countDown(); } public void reconnectingIn(int seconds) { attemptsNotifications = attemptsNotifications + 1; - remainingSeconds = seconds; - + remainingSeconds = seconds; } public void reconnectionSuccessful() { reconnected = true; + + if (countDownLatch != null) + countDownLatch.countDown(); } public void reconnectionFailed(Exception error) { reconnectionFailed = true; + + if (countDownLatch != null) + countDownLatch.countDown(); } } diff --git a/test/org/jivesoftware/smack/RosterInitializedBeforeConnectTest.java b/test/org/jivesoftware/smack/RosterInitializedBeforeConnectTest.java index f031f3031..050e55a2a 100644 --- a/test/org/jivesoftware/smack/RosterInitializedBeforeConnectTest.java +++ b/test/org/jivesoftware/smack/RosterInitializedBeforeConnectTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test/org/jivesoftware/smack/RosterListenerTest.java b/test/org/jivesoftware/smack/RosterListenerTest.java index d0b19d0ed..91ba11de9 100644 --- a/test/org/jivesoftware/smack/RosterListenerTest.java +++ b/test/org/jivesoftware/smack/RosterListenerTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 @@ -22,6 +20,7 @@ package org.jivesoftware.smack; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.concurrent.CountDownLatch; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.test.SmackTestCase; @@ -50,8 +49,6 @@ public class RosterListenerTest extends SmackTestCase { // add user1 to roster to create roster events stored at XMPP server inviterRoster.createEntry(getBareJID(inviteeIndex), getUsername(inviteeIndex), null); - Thread.sleep(500); // wait for XMPP server - XMPPConnection inviteeConnection = getConnection(inviteeIndex); assertFalse("Invitee is already online", inviteeConnection.isConnected()); @@ -82,7 +79,7 @@ public class RosterListenerTest extends SmackTestCase { // connect after adding the listener connectAndLogin(inviteeIndex); - Thread.sleep(500); // wait for packets to be processed + Thread.sleep(5000); // wait for packets to be processed assertNotNull("inviter is not in roster", inviteeRoster.getEntry(getBareJID(inviterIndex))); diff --git a/test/org/jivesoftware/smack/RosterSmackTest.java b/test/org/jivesoftware/smack/RosterSmackTest.java index 8bee8124f..5d2aa97d1 100644 --- a/test/org/jivesoftware/smack/RosterSmackTest.java +++ b/test/org/jivesoftware/smack/RosterSmackTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2005 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. @@ -21,12 +21,16 @@ package org.jivesoftware.smack; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.test.SmackTestCase; import org.jivesoftware.smack.util.StringUtils; +import org.mockito.internal.util.RemoveFirstLine; /** * Tests the Roster functionality by creating and removing roster entries. @@ -43,6 +47,7 @@ public class RosterSmackTest extends SmackTestCase { super(name); } + /** * 1. Create entries in roster groups * 2. Iterate on the groups and remove the entry from each group @@ -52,63 +57,77 @@ public class RosterSmackTest extends SmackTestCase { try { // Add a new roster entry Roster roster = getConnection(0).getRoster(); + + CountDownLatch latch = new CountDownLatch(2); + setupCountdown(latch, roster); + roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends", "Family" }); roster.createEntry(getBareJID(2), "gato12", new String[] { "Family" }); + + waitForCountdown(latch, roster, 2); - // Wait until the server confirms the new entries - long initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && ( - !roster.getPresence(getBareJID(1)).isAvailable() || - !roster.getPresence(getBareJID(2)).isAvailable())) { - Thread.sleep(100); - } + final CountDownLatch removeLatch = new CountDownLatch(3); + RosterListener latchCounter = new RosterListener() { + @Override + public void presenceChanged(Presence presence) {} + + @Override + public void entriesUpdated(Collection addresses) { + removeLatch.countDown(); + } + + @Override + public void entriesDeleted(Collection addresses) {} + + @Override + public void entriesAdded(Collection addresses) {} + }; + + roster.addRosterListener(latchCounter); for (RosterEntry entry : roster.getEntries()) { for (RosterGroup rosterGroup : entry.getGroups()) { rosterGroup.removeEntry(entry); } } - // Wait up to 2 seconds - initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && - (roster.getGroupCount() != 0 && - getConnection(2).getRoster().getEntryCount() != 2)) { - Thread.sleep(100); - } - - assertEquals( - "The number of entries in connection 1 should be 1", - 1, - getConnection(1).getRoster().getEntryCount()); - assertEquals( - "The number of groups in connection 1 should be 0", - 0, - getConnection(1).getRoster().getGroupCount()); - - assertEquals( - "The number of entries in connection 2 should be 1", - 1, - getConnection(2).getRoster().getEntryCount()); - assertEquals( - "The number of groups in connection 2 should be 0", - 0, - getConnection(2).getRoster().getGroupCount()); - - assertEquals( - "The number of entries in connection 0 should be 2", - 2, - roster.getEntryCount()); - assertEquals( - "The number of groups in connection 0 should be 0", - 0, - roster.getGroupCount()); + + removeLatch.await(5, TimeUnit.SECONDS); + roster.removeRosterListener(latchCounter); + + assertEquals("The number of entries in connection 1 should be 1", 1, getConnection(1).getRoster().getEntryCount()); + assertEquals("The number of groups in connection 1 should be 0", 0, getConnection(1).getRoster().getGroupCount()); + assertEquals("The number of entries in connection 2 should be 1", 1, getConnection(2).getRoster().getEntryCount()); + assertEquals("The number of groups in connection 2 should be 0", 0, getConnection(2).getRoster().getGroupCount()); + assertEquals("The number of entries in connection 0 should be 2", 2, roster.getEntryCount()); + assertEquals("The number of groups in connection 0 should be 0", 0, roster.getGroupCount()); } catch (Exception e) { fail(e.getMessage()); } - finally { - cleanUpRoster(); - } + } + + private void setupCountdown(final CountDownLatch latch, Roster roster) { + roster.addRosterListener(new RosterListener() { + + @Override + public void presenceChanged(Presence presence) {} + + @Override + public void entriesUpdated(Collection addresses) { + latch.countDown(); + } + + @Override + public void entriesDeleted(Collection addresses) {} + + @Override + public void entriesAdded(Collection addresses) {} + }); + } + + private void waitForCountdown(CountDownLatch latch, Roster roster, int entryCount) throws InterruptedException { + latch.await(5, TimeUnit.SECONDS); + assertEquals(entryCount, roster.getEntryCount()); } /** @@ -119,50 +138,30 @@ public class RosterSmackTest extends SmackTestCase { public void testDeleteAllRosterEntries() throws Exception { // Add a new roster entry Roster roster = getConnection(0).getRoster(); + + CountDownLatch latch = new CountDownLatch(2); + setupCountdown(latch, roster); + roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends" }); roster.createEntry(getBareJID(2), "gato12", new String[] { "Family" }); - // Wait up to 2 seconds to receive new roster contacts - long initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 2) { - Thread.sleep(100); - } + waitForCountdown(latch, roster, 2); - assertEquals("Wrong number of entries in connection 0", 2, roster.getEntryCount()); - - // Wait up to 2 seconds to receive presences of the new roster contacts - initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 5000 && - (!roster.getPresence(getBareJID(1)).isAvailable() || - !roster.getPresence(getBareJID(2)).isAvailable())) - { - Thread.sleep(100); - } - assertTrue("Presence not received", roster.getPresence(getBareJID(1)).isAvailable()); - assertTrue("Presence not received", roster.getPresence(getBareJID(2)).isAvailable()); + CountDownLatch removeLatch = new CountDownLatch(2); + RosterListener latchCounter = new RemovalListener(removeLatch); + roster.addRosterListener(latchCounter); for (RosterEntry entry : roster.getEntries()) { roster.removeEntry(entry); - Thread.sleep(250); } - // Wait up to 2 seconds to receive roster removal notifications - initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 0) { - Thread.sleep(100); - } + removeLatch.await(5, TimeUnit.SECONDS); + roster.removeRosterListener(latchCounter); assertEquals("Wrong number of entries in connection 0", 0, roster.getEntryCount()); assertEquals("Wrong number of groups in connection 0", 0, roster.getGroupCount()); - - assertEquals( - "Wrong number of entries in connection 1", - 0, - getConnection(1).getRoster().getEntryCount()); - assertEquals( - "Wrong number of groups in connection 1", - 0, - getConnection(1).getRoster().getGroupCount()); + assertEquals("Wrong number of entries in connection 1", 0, getConnection(1).getRoster().getEntryCount()); + assertEquals("Wrong number of groups in connection 1", 0, getConnection(1).getRoster().getGroupCount()); } /** @@ -174,41 +173,29 @@ public class RosterSmackTest extends SmackTestCase { try { // Add a new roster entry Roster roster = getConnection(0).getRoster(); + + CountDownLatch latch = new CountDownLatch(2); + setupCountdown(latch, roster); + roster.createEntry(getBareJID(1), "gato11", null); roster.createEntry(getBareJID(2), "gato12", null); - // Wait up to 2 seconds to let the server process presence subscriptions - long initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && ( - !roster.getPresence(getBareJID(1)).isAvailable() || - !roster.getPresence(getBareJID(2)).isAvailable())) { - Thread.sleep(100); - } - - Thread.sleep(200); + waitForCountdown(latch, roster, 2); + CountDownLatch removeLatch = new CountDownLatch(2); + RosterListener latchCounter = new RemovalListener(removeLatch); + roster.addRosterListener(latchCounter); for (RosterEntry entry : roster.getEntries()) { roster.removeEntry(entry); - Thread.sleep(100); } - // Wait up to 2 seconds to receive roster removal notifications - initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 0) { - Thread.sleep(100); - } + removeLatch.await(5, TimeUnit.SECONDS); + roster.removeRosterListener(latchCounter); assertEquals("Wrong number of entries in connection 0", 0, roster.getEntryCount()); assertEquals("Wrong number of groups in connection 0", 0, roster.getGroupCount()); - - assertEquals( - "Wrong number of entries in connection 1", - 0, - getConnection(1).getRoster().getEntryCount()); - assertEquals( - "Wrong number of groups in connection 1", - 0, - getConnection(1).getRoster().getGroupCount()); + assertEquals("Wrong number of entries in connection 1", 0, getConnection(1).getRoster().getEntryCount()); + assertEquals("Wrong number of groups in connection 1", 0, getConnection(1).getRoster().getGroupCount()); } catch (Exception e) { fail(e.getMessage()); @@ -226,15 +213,30 @@ public class RosterSmackTest extends SmackTestCase { try { // Add a new roster entry Roster roster = getConnection(0).getRoster(); + CountDownLatch latch = new CountDownLatch(1); + setupCountdown(latch, roster); + roster.createEntry(getBareJID(1), null, null); + + waitForCountdown(latch, roster, 1); - // Wait up to 2 seconds to let the server process presence subscriptions - long initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && - !roster.getPresence(getBareJID(1)).isAvailable()) - { - Thread.sleep(100); - } + final CountDownLatch updateLatch = new CountDownLatch(2); + RosterListener latchCounter = new RosterListener() { + @Override + public void entriesAdded(Collection addresses) {} + + @Override + public void entriesUpdated(Collection addresses) { + updateLatch.countDown(); + } + + @Override + public void entriesDeleted(Collection addresses) {} + + @Override + public void presenceChanged(Presence presence) {} + }; + roster.addRosterListener(latchCounter); // Change the roster entry name and check if the change was made for (RosterEntry entry : roster.getEntries()) { @@ -243,7 +245,9 @@ public class RosterSmackTest extends SmackTestCase { } // Reload the roster and check the name again roster.reload(); - Thread.sleep(2000); + + updateLatch.await(5, TimeUnit.SECONDS); + for (RosterEntry entry : roster.getEntries()) { assertEquals("gato11", entry.getName()); } @@ -251,9 +255,6 @@ public class RosterSmackTest extends SmackTestCase { catch (Exception e) { fail(e.getMessage()); } - finally { - cleanUpRoster(); - } } /** @@ -303,9 +304,6 @@ public class RosterSmackTest extends SmackTestCase { } catch (Exception e) { fail(e.getMessage()); } - finally { - cleanUpRoster(); - } } /** @@ -361,9 +359,6 @@ public class RosterSmackTest extends SmackTestCase { catch (Exception e) { fail(e.getMessage()); } - finally { - cleanUpRoster(); - } } /** @@ -426,9 +421,6 @@ public class RosterSmackTest extends SmackTestCase { catch (Exception e) { fail(e.getMessage()); } - finally { - cleanUpRoster(); - } } /** @@ -441,75 +433,67 @@ public class RosterSmackTest extends SmackTestCase { * 5. Check that presence for each connected resource is correct */ public void testRosterPresences() throws Exception { - Thread.sleep(200); - try { - Presence presence; + Presence presence; - // Create another connection for the same user of connection 1 - ConnectionConfiguration connectionConfiguration = - new ConnectionConfiguration(getHost(), getPort(), getServiceName()); - XMPPConnection conn4 = new XMPPConnection(connectionConfiguration); - conn4.connect(); - conn4.login(getUsername(1), getPassword(1), "Home"); + // Create another connection for the same user of connection 1 + ConnectionConfiguration connectionConfiguration = + new ConnectionConfiguration(getHost(), getPort(), getServiceName()); + XMPPConnection conn4 = new XMPPConnection(connectionConfiguration); + conn4.connect(); + conn4.login(getUsername(1), getPassword(1), "Home"); - // Add a new roster entry - Roster roster = getConnection(0).getRoster(); - roster.createEntry(getBareJID(1), "gato11", null); + // Add a new roster entry + Roster roster = getConnection(0).getRoster(); + roster.createEntry(getBareJID(1), "gato11", null); - // Wait up to 2 seconds - long initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 2000 && - (roster.getPresence(getBareJID(1)).getType() == Presence.Type.unavailable)) { - Thread.sleep(100); - } - - // Check that a presence is returned for a user - presence = roster.getPresence(getBareJID(1)); - assertTrue("Returned a null Presence for an existing user", presence.isAvailable()); - - // Check that the right presence is returned for a user+resource - presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getServiceName() + "/Home"); - assertEquals("Returned the wrong Presence", "Home", - StringUtils.parseResource(presence.getFrom())); - - // Check that the right presence is returned for a user+resource - presence = roster.getPresenceResource(getFullJID(1)); - assertTrue("Presence not found for user " + getFullJID(1), presence.isAvailable()); - assertEquals("Returned the wrong Presence", "Smack", - StringUtils.parseResource(presence.getFrom())); - - // Check the returned presence for a non-existent user+resource - presence = roster.getPresenceResource("noname@" + getServiceName() + "/Smack"); - assertFalse("Available presence was returned for a non-existing user", presence.isAvailable()); - assertEquals("Returned Presence for a non-existing user has the incorrect type", - Presence.Type.unavailable, presence.getType()); - - // Check that the returned presences are correct - Iterator presences = roster.getPresences(getBareJID(1)); - int count = 0; - while (presences.hasNext()) { - count++; - presences.next(); - } - assertEquals("Wrong number of returned presences", count, 2); - - // Close the connection so one presence must go - conn4.disconnect(); - - // Check that the returned presences are correct - presences = roster.getPresences(getBareJID(1)); - count = 0; - while (presences.hasNext()) { - count++; - presences.next(); - } - assertEquals("Wrong number of returned presences", count, 1); - - Thread.sleep(200); + // Wait up to 2 seconds + long initial = System.currentTimeMillis(); + while (System.currentTimeMillis() - initial < 2000 && + (roster.getPresence(getBareJID(1)).getType() == Presence.Type.unavailable)) { + Thread.sleep(100); } - finally { - cleanUpRoster(); + + // Check that a presence is returned for a user + presence = roster.getPresence(getBareJID(1)); + assertTrue("Returned a null Presence for an existing user", presence.isAvailable()); + + // Check that the right presence is returned for a user+resource + presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getServiceName() + "/Home"); + assertEquals("Returned the wrong Presence", "Home", + StringUtils.parseResource(presence.getFrom())); + + // Check that the right presence is returned for a user+resource + presence = roster.getPresenceResource(getFullJID(1)); + assertTrue("Presence not found for user " + getFullJID(1), presence.isAvailable()); + assertEquals("Returned the wrong Presence", "Smack", + StringUtils.parseResource(presence.getFrom())); + + // Check the returned presence for a non-existent user+resource + presence = roster.getPresenceResource("noname@" + getServiceName() + "/Smack"); + assertFalse("Available presence was returned for a non-existing user", presence.isAvailable()); + assertEquals("Returned Presence for a non-existing user has the incorrect type", + Presence.Type.unavailable, presence.getType()); + + // Check that the returned presences are correct + Iterator presences = roster.getPresences(getBareJID(1)); + int count = 0; + while (presences.hasNext()) { + count++; + presences.next(); } + assertEquals("Wrong number of returned presences", count, 2); + + // Close the connection so one presence must go + conn4.disconnect(); + + // Check that the returned presences are correct + presences = roster.getPresences(getBareJID(1)); + count = 0; + while (presences.hasNext()) { + count++; + presences.next(); + } + assertEquals("Wrong number of returned presences", count, 1); } /** @@ -605,6 +589,24 @@ public class RosterSmackTest extends SmackTestCase { for (int i=0; i addresses) {} + + @Override + public void entriesDeleted(Collection addresses) { + removalLatch.countDown(); + } + + @Override + public void entriesAdded(Collection addresses) {} + }); + for (RosterEntry entry : roster.getEntries()) { try { roster.removeEntry(entry); @@ -616,49 +618,16 @@ public class RosterSmackTest extends SmackTestCase { } try { - Thread.sleep(700); + removalLatch.await(5, TimeUnit.SECONDS); } catch (InterruptedException e) { fail(e.getMessage()); } } - // Wait up to 6 seconds to receive roster removal notifications - long initial = System.currentTimeMillis(); - while (System.currentTimeMillis() - initial < 6000 && ( - getConnection(0).getRoster().getEntryCount() != 0 || - getConnection(1).getRoster().getEntryCount() != 0 || - getConnection(2).getRoster().getEntryCount() != 0)) { - try { - Thread.sleep(100); - } catch (InterruptedException e) {} - } - assertEquals( - "Wrong number of entries in connection 0", - 0, - getConnection(0).getRoster().getEntryCount()); - assertEquals( - "Wrong number of groups in connection 0", - 0, - getConnection(0).getRoster().getGroupCount()); - - assertEquals( - "Wrong number of entries in connection 1", - 0, - getConnection(1).getRoster().getEntryCount()); - assertEquals( - "Wrong number of groups in connection 1", - 0, - getConnection(1).getRoster().getGroupCount()); - - assertEquals( - "Wrong number of entries in connection 2", - 0, - getConnection(2).getRoster().getEntryCount()); - assertEquals( - "Wrong number of groups in connection 2", - 0, - getConnection(2).getRoster().getGroupCount()); + assertEquals("Wrong number of entries in connection 0", 0, getConnection(0).getRoster().getEntryCount()); + assertEquals("Wrong number of entries in connection 1", 0, getConnection(1).getRoster().getEntryCount()); + assertEquals("Wrong number of entries in connection 2", 0, getConnection(2).getRoster().getEntryCount()); } /** @@ -708,15 +677,37 @@ public class RosterSmackTest extends SmackTestCase { } protected void setUp() throws Exception { - //XMPPConnection.DEBUG_ENABLED = false; - - try { - Thread.sleep(500); - } - catch (InterruptedException e) { - fail(e.getMessage()); - } - super.setUp(); + cleanUpRoster(); } + + + @Override + protected void tearDown() throws Exception { + cleanUpRoster(); + super.tearDown(); + } + + private class RemovalListener implements RosterListener { + private CountDownLatch latch; + + private RemovalListener(CountDownLatch removalLatch) { + latch = removalLatch; + } + + @Override + public void presenceChanged(Presence presence) {} + + @Override + public void entriesUpdated(Collection addresses) {} + + @Override + public void entriesDeleted(Collection addresses) { + latch.countDown(); + } + + @Override + public void entriesAdded(Collection addresses) {} + }; + } \ No newline at end of file diff --git a/test/org/jivesoftware/smack/filter/AndFilterTest.java b/test/org/jivesoftware/smack/filter/AndFilterTest.java index c06096845..bde061e4c 100644 --- a/test/org/jivesoftware/smack/filter/AndFilterTest.java +++ b/test/org/jivesoftware/smack/filter/AndFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/filter/FromContainsFilterTest.java b/test/org/jivesoftware/smack/filter/FromContainsFilterTest.java index c7ea5ebc6..71d3386ca 100644 --- a/test/org/jivesoftware/smack/filter/FromContainsFilterTest.java +++ b/test/org/jivesoftware/smack/filter/FromContainsFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/filter/NotFilterTest.java b/test/org/jivesoftware/smack/filter/NotFilterTest.java index 34f00a7f2..135e27457 100644 --- a/test/org/jivesoftware/smack/filter/NotFilterTest.java +++ b/test/org/jivesoftware/smack/filter/NotFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/filter/OrFilterTest.java b/test/org/jivesoftware/smack/filter/OrFilterTest.java index 716dfc381..7bbae8bc3 100644 --- a/test/org/jivesoftware/smack/filter/OrFilterTest.java +++ b/test/org/jivesoftware/smack/filter/OrFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/filter/PacketIDFilterTest.java b/test/org/jivesoftware/smack/filter/PacketIDFilterTest.java index 9008667d9..febd03897 100644 --- a/test/org/jivesoftware/smack/filter/PacketIDFilterTest.java +++ b/test/org/jivesoftware/smack/filter/PacketIDFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/filter/PacketTypeFilterTest.java b/test/org/jivesoftware/smack/filter/PacketTypeFilterTest.java index b567b6e19..832b2afec 100644 --- a/test/org/jivesoftware/smack/filter/PacketTypeFilterTest.java +++ b/test/org/jivesoftware/smack/filter/PacketTypeFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/filter/ToContainsFilterTest.java b/test/org/jivesoftware/smack/filter/ToContainsFilterTest.java index 26bd3dae9..38438b03e 100644 --- a/test/org/jivesoftware/smack/filter/ToContainsFilterTest.java +++ b/test/org/jivesoftware/smack/filter/ToContainsFilterTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/packet/MockPacket.java b/test/org/jivesoftware/smack/packet/MockPacket.java index e1ae1a1d8..cea2f9060 100644 --- a/test/org/jivesoftware/smack/packet/MockPacket.java +++ b/test/org/jivesoftware/smack/packet/MockPacket.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2003 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. diff --git a/test/org/jivesoftware/smack/packet/PrivacyProviderTest.java b/test/org/jivesoftware/smack/packet/PrivacyProviderTest.java index 06f474c9a..f010c336b 100644 --- a/test/org/jivesoftware/smack/packet/PrivacyProviderTest.java +++ b/test/org/jivesoftware/smack/packet/PrivacyProviderTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test/org/jivesoftware/smack/packet/PrivacyTest.java b/test/org/jivesoftware/smack/packet/PrivacyTest.java index 5ee8dd49f..cead0dc4b 100644 --- a/test/org/jivesoftware/smack/packet/PrivacyTest.java +++ b/test/org/jivesoftware/smack/packet/PrivacyTest.java @@ -3,8 +3,6 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 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 diff --git a/test/org/jivesoftware/smack/util/CacheTest.java b/test/org/jivesoftware/smack/util/CacheTest.java index 371b678d2..ff8eb0233 100644 --- a/test/org/jivesoftware/smack/util/CacheTest.java +++ b/test/org/jivesoftware/smack/util/CacheTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2005 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. diff --git a/test/org/jivesoftware/smack/util/ConnectionUtils.java b/test/org/jivesoftware/smack/util/ConnectionUtils.java index 6d9f49106..74426793e 100644 --- a/test/org/jivesoftware/smack/util/ConnectionUtils.java +++ b/test/org/jivesoftware/smack/util/ConnectionUtils.java @@ -6,6 +6,8 @@ import org.jivesoftware.smack.XMPPException; public class ConnectionUtils { + private ConnectionUtils() {} + public static void becomeFriends(Connection con0, Connection con1) throws XMPPException { Roster r0 = con0.getRoster(); Roster r1 = con1.getRoster(); diff --git a/test/org/jivesoftware/smack/util/XMPPErrorTest.java b/test/org/jivesoftware/smack/util/XMPPErrorTest.java index a91d577e0..d7936ad76 100644 --- a/test/org/jivesoftware/smack/util/XMPPErrorTest.java +++ b/test/org/jivesoftware/smack/util/XMPPErrorTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2006 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. diff --git a/test/org/jivesoftware/smackx/FileTransferTest.java b/test/org/jivesoftware/smackx/FileTransferTest.java index 3d9bab3c3..13aac53ee 100644 --- a/test/org/jivesoftware/smackx/FileTransferTest.java +++ b/test/org/jivesoftware/smackx/FileTransferTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2006 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. diff --git a/test/org/jivesoftware/smackx/FormTest.java b/test/org/jivesoftware/smackx/FormTest.java index f63743e92..b189cbaf2 100644 --- a/test/org/jivesoftware/smackx/FormTest.java +++ b/test/org/jivesoftware/smackx/FormTest.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 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. diff --git a/test/org/jivesoftware/smackx/VCardTest.java b/test/org/jivesoftware/smackx/VCardTest.java index ac32a2494..e38e183b2 100644 --- a/test/org/jivesoftware/smackx/VCardTest.java +++ b/test/org/jivesoftware/smackx/VCardTest.java @@ -66,10 +66,8 @@ public class VCardTest extends SmackTestCase { fail(e.getMessage()); } - //assertEquals("Should load own VCard successfully", origVCard.toString(), loaded.toString()); assertEquals("Should load own VCard successfully", origVCard, loaded); - loaded = new VCard(); try { loaded.load(getConnection(1), getBareJID(0)); @@ -78,7 +76,6 @@ public class VCardTest extends SmackTestCase { fail(e.getMessage()); } - //assertEquals("Should load another user's VCard successfully", origVCard.toString(), loaded.toString()); assertEquals("Should load another user's VCard successfully", origVCard, loaded); } @@ -167,20 +164,6 @@ public class VCardTest extends SmackTestCase { "CgADtrKoqPLpKaXPVXUdPtnXTNUBLlTQR4xHlj+gHT/7pjw8oTsf/9k="; } - /* - public void testFullName() throws Throwable { - VCard card = new VCard(); - card.setFirstName("kir"); - // assertEquals("kir", card.getFullName()); - - card.setLastName("maximov"); - // assertEquals("kir maximov", card.getFullName()); - - card.setField("FN", "some name"); - // assertEquals("some name", card.getFullName()); - } - */ - protected int getMaxConnections() { return 2; } diff --git a/test/org/jivesoftware/smackx/entitycaps/EntityCapsTest.java b/test/org/jivesoftware/smackx/entitycaps/EntityCapsTest.java index 49a81f3e4..0725a6abf 100644 --- a/test/org/jivesoftware/smackx/entitycaps/EntityCapsTest.java +++ b/test/org/jivesoftware/smackx/entitycaps/EntityCapsTest.java @@ -35,10 +35,10 @@ public class EntityCapsTest extends SmackTestCase { return 2; } + @Override protected void setUp() throws Exception { super.setUp(); SmackConfiguration.setAutoEnableEntityCaps(true); - SmackConfiguration.setPacketReplyTimeout(1000 * 60 * 5); con0 = getConnection(0); con1 = getConnection(1); ecm0 = EntityCapsManager.getInstanceFor(getConnection(0)); @@ -47,7 +47,7 @@ public class EntityCapsTest extends SmackTestCase { sdm1 = ServiceDiscoveryManager.getInstanceFor(con1); letsAllBeFriends(); } - + public void testLocalEntityCaps() throws InterruptedException { DiscoverInfo info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecm1.getLocalNodeVer()); assertFalse(info.containsFeature(DISCOVER_TEST_FEATURE)); diff --git a/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java b/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java index 91b3d0366..dbd0e55ba 100644 --- a/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java +++ b/test/org/jivesoftware/smackx/packet/RosterExchangeTest.java @@ -17,10 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 01/08/2003 - * - */ package org.jivesoftware.smackx.packet; import java.util.Iterator; diff --git a/test/org/jivesoftware/smackx/pubsub/CarExtension.java b/test/org/jivesoftware/smackx/pubsub/CarExtension.java index 6fe8ea8b3..3af9848c2 100644 --- a/test/org/jivesoftware/smackx/pubsub/CarExtension.java +++ b/test/org/jivesoftware/smackx/pubsub/CarExtension.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier. * * 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. @@ -17,13 +17,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-05-05 - */ package org.jivesoftware.smackx.pubsub; import org.jivesoftware.smack.packet.PacketExtension; - + +/** + * + * @author Robin Collier + * + */ class CarExtension implements PacketExtension { private String color; diff --git a/test/org/jivesoftware/smackx/pubsub/CarExtensionProvider.java b/test/org/jivesoftware/smackx/pubsub/CarExtensionProvider.java index 555aeea5d..fe3095920 100644 --- a/test/org/jivesoftware/smackx/pubsub/CarExtensionProvider.java +++ b/test/org/jivesoftware/smackx/pubsub/CarExtensionProvider.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,15 +17,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-05-05 - */ package org.jivesoftware.smackx.pubsub; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.xmlpull.v1.XmlPullParser; - + +/** + * + * @author Robin Collier + * + */ public class CarExtensionProvider implements PacketExtensionProvider { diff --git a/test/org/jivesoftware/smackx/pubsub/EntityUseCases.java b/test/org/jivesoftware/smackx/pubsub/EntityUseCases.java index 1d7633c3e..12c251c4b 100644 --- a/test/org/jivesoftware/smackx/pubsub/EntityUseCases.java +++ b/test/org/jivesoftware/smackx/pubsub/EntityUseCases.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier. * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-04-09 - */ package org.jivesoftware.smackx.pubsub; import java.util.Iterator; @@ -29,7 +26,12 @@ import org.jivesoftware.smackx.packet.DiscoverInfo; import org.jivesoftware.smackx.packet.DiscoverItems; import org.jivesoftware.smackx.packet.DiscoverInfo.Identity; import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase; - + +/** + * + * @author Robin Collier + * + */ public class EntityUseCases extends SingleUserTestCase { public void testDiscoverPubsubInfo() throws Exception diff --git a/test/org/jivesoftware/smackx/pubsub/MultiUserSubscriptionUseCases.java b/test/org/jivesoftware/smackx/pubsub/MultiUserSubscriptionUseCases.java index 47cc37c1a..031472ed5 100644 --- a/test/org/jivesoftware/smackx/pubsub/MultiUserSubscriptionUseCases.java +++ b/test/org/jivesoftware/smackx/pubsub/MultiUserSubscriptionUseCases.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier. * * 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. @@ -25,7 +25,12 @@ import java.util.List; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smackx.pubsub.test.PubSubTestCase; - + +/** + * + * @author Robin Collier + * + */ public class MultiUserSubscriptionUseCases extends PubSubTestCase { diff --git a/test/org/jivesoftware/smackx/pubsub/OwnerUseCases.java b/test/org/jivesoftware/smackx/pubsub/OwnerUseCases.java index 98c2a8692..23e9529f9 100644 --- a/test/org/jivesoftware/smackx/pubsub/OwnerUseCases.java +++ b/test/org/jivesoftware/smackx/pubsub/OwnerUseCases.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,16 +17,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-04-09 - */ package org.jivesoftware.smackx.pubsub; import java.util.Collection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase; - + +/** + * + * @author Robin Collier + * + */ public class OwnerUseCases extends SingleUserTestCase { public void testCreateInstantNode() throws Exception diff --git a/test/org/jivesoftware/smackx/pubsub/PublisherUseCases.java b/test/org/jivesoftware/smackx/pubsub/PublisherUseCases.java index d54e0c381..4e69c1327 100644 --- a/test/org/jivesoftware/smackx/pubsub/PublisherUseCases.java +++ b/test/org/jivesoftware/smackx/pubsub/PublisherUseCases.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-04-09 - */ package org.jivesoftware.smackx.pubsub; import java.util.Collection; @@ -30,7 +27,12 @@ import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError.Condition; import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace; import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase; - + +/** + * + * @author Robin Collier + * + */ public class PublisherUseCases extends SingleUserTestCase { public void testSendNodeTrNot() throws Exception diff --git a/test/org/jivesoftware/smackx/pubsub/SubscriberUseCases.java b/test/org/jivesoftware/smackx/pubsub/SubscriberUseCases.java index 9a39ce91b..bb1cf3a70 100644 --- a/test/org/jivesoftware/smackx/pubsub/SubscriberUseCases.java +++ b/test/org/jivesoftware/smackx/pubsub/SubscriberUseCases.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-04-09 - */ package org.jivesoftware.smackx.pubsub; import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; @@ -34,7 +31,12 @@ import java.util.Map; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.FormField; import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase; - + +/** + * + * @author Robin Collier + * + */ public class SubscriberUseCases extends SingleUserTestCase { public void testSubscribe() throws Exception diff --git a/test/org/jivesoftware/smackx/pubsub/TestAPI.java b/test/org/jivesoftware/smackx/pubsub/TestAPI.java index e11cb8f3a..d6ca512dc 100644 --- a/test/org/jivesoftware/smackx/pubsub/TestAPI.java +++ b/test/org/jivesoftware/smackx/pubsub/TestAPI.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,14 +17,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-04-09 - */ package org.jivesoftware.smackx.pubsub; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase; - + +/** + * + * @author Robin Collier + * + */ public class TestAPI extends SingleUserTestCase { public void testGetNonexistentNode() diff --git a/test/org/jivesoftware/smackx/pubsub/TestEvents.java b/test/org/jivesoftware/smackx/pubsub/TestEvents.java index 53ea3a2fe..9e07a93cc 100644 --- a/test/org/jivesoftware/smackx/pubsub/TestEvents.java +++ b/test/org/jivesoftware/smackx/pubsub/TestEvents.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-04-22 - */ package org.jivesoftware.smackx.pubsub; import java.util.ArrayList; @@ -36,7 +33,12 @@ import org.jivesoftware.smack.test.SmackTestCase; import org.jivesoftware.smackx.pubsub.listener.ItemDeleteListener; import org.jivesoftware.smackx.pubsub.listener.ItemEventListener; import org.jivesoftware.smackx.pubsub.listener.NodeConfigListener; - + +/** + * + * @author Robin Collier + * + */ public class TestEvents extends SmackTestCase { diff --git a/test/org/jivesoftware/smackx/pubsub/TestMessageContent.java b/test/org/jivesoftware/smackx/pubsub/TestMessageContent.java index af0d4094b..a1ce54285 100644 --- a/test/org/jivesoftware/smackx/pubsub/TestMessageContent.java +++ b/test/org/jivesoftware/smackx/pubsub/TestMessageContent.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,13 +17,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-08-05 - */ package org.jivesoftware.smackx.pubsub; import junit.framework.TestCase; - + +/** + * + * @author Robin Collier + * + */ public class TestMessageContent extends TestCase { String payloadXmlWithNS = ""; diff --git a/test/org/jivesoftware/smackx/pubsub/test/PubSubTestCase.java b/test/org/jivesoftware/smackx/pubsub/test/PubSubTestCase.java index 6da93c79d..f4b599fc7 100644 --- a/test/org/jivesoftware/smackx/pubsub/test/PubSubTestCase.java +++ b/test/org/jivesoftware/smackx/pubsub/test/PubSubTestCase.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-05-05 - */ package org.jivesoftware.smackx.pubsub.test; import org.jivesoftware.smack.XMPPException; @@ -29,7 +26,12 @@ import org.jivesoftware.smackx.pubsub.ConfigureForm; import org.jivesoftware.smackx.pubsub.FormType; import org.jivesoftware.smackx.pubsub.LeafNode; import org.jivesoftware.smackx.pubsub.PubSubManager; - + +/** + * + * @author Robin Collier + * + */ abstract public class PubSubTestCase extends SmackTestCase { private PubSubManager[] manager; diff --git a/test/org/jivesoftware/smackx/pubsub/test/SingleUserTestCase.java b/test/org/jivesoftware/smackx/pubsub/test/SingleUserTestCase.java index 8a017807e..38d5f73f8 100644 --- a/test/org/jivesoftware/smackx/pubsub/test/SingleUserTestCase.java +++ b/test/org/jivesoftware/smackx/pubsub/test/SingleUserTestCase.java @@ -3,7 +3,7 @@ * $Revision$ * $Date$ * - * Copyright 2003-2007 Jive Software. + * Copyright 2009 Robin Collier * * 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. @@ -17,15 +17,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Created on 2009-05-05 - */ package org.jivesoftware.smackx.pubsub.test; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.pubsub.LeafNode; import org.jivesoftware.smackx.pubsub.PubSubManager; - + +/** + * + * @author Robin Collier + * + */ public class SingleUserTestCase extends PubSubTestCase { protected PubSubManager getManager()