diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java index ee5dc2244..eab3ddbde 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java @@ -47,7 +47,6 @@ import org.jivesoftware.smack.filter.PacketTypeFilter; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.ping.packet.Ping; -import org.jivesoftware.smackx.ping.packet.Pong; /** * Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol allows one entity to @@ -59,8 +58,6 @@ import org.jivesoftware.smackx.ping.packet.Pong; * @see XEP-0199:XMPP Ping */ public class PingManager extends Manager { - public static final String NAMESPACE = "urn:xmpp:ping"; - private static final Logger LOGGER = Logger.getLogger(PingManager.class.getName()); private static final Map INSTANCES = Collections @@ -137,15 +134,15 @@ public class PingManager extends Manager { executorService = new ScheduledThreadPoolExecutor(1, new PingExecutorThreadFactory(connection.getConnectionCounter())); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); - sdm.addFeature(PingManager.NAMESPACE); + sdm.addFeature(Ping.NAMESPACE); INSTANCES.put(connection, this); connection.addPacketListener(new PacketListener() { // Send a Pong for every Ping @Override public void processPacket(Packet packet) throws NotConnectedException { - Pong pong = new Pong(packet); - connection().sendPacket(pong); + Ping ping = (Ping) packet; + connection().sendPacket(ping.getPong()); } }, PING_PACKET_FILTER); connection.addConnectionListener(new AbstractConnectionListener() { @@ -213,7 +210,7 @@ public class PingManager extends Manager { * @throws NotConnectedException */ public boolean isPingSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException { - return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, PingManager.NAMESPACE); + return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Ping.NAMESPACE); } /** diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java index de9e9227f..596b4c278 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Ping.java @@ -17,22 +17,31 @@ package org.jivesoftware.smackx.ping.packet; import org.jivesoftware.smack.packet.IQ; -import org.jivesoftware.smackx.ping.PingManager; public class Ping extends IQ { public static final String ELEMENT = "ping"; - + public static final String NAMESPACE = "urn:xmpp:ping"; + public Ping() { } - + public Ping(String to) { setTo(to); setType(IQ.Type.get); } - + @Override public String getChildElementXML() { - return "<" + ELEMENT + " xmlns=\'" + PingManager.NAMESPACE + "\' />"; + return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>"; + } + + /** + * Create a XMPP Pong for this Ping + * + * @return the Pong + */ + public IQ getPong() { + return createResultIQ(this); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Pong.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Pong.java deleted file mode 100644 index 706a18f00..000000000 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/packet/Pong.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright 2012-2014 Florian Schmaus - * - * 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; -import org.jivesoftware.smack.packet.Packet; - -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(Packet 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/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java index f3a47a2e5..526db9845 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java @@ -191,7 +191,7 @@ public class PingTest extends InitExtensions { public void checkSuccessfulDiscoRequest() throws Exception { ThreadedDummyConnection con = new ThreadedDummyConnection(); DiscoverInfo info = new DiscoverInfo(); - info.addFeature(PingManager.NAMESPACE); + info.addFeature(Ping.NAMESPACE); //@formatter:off String reply = @@ -213,7 +213,7 @@ public class PingTest extends InitExtensions { public void checkUnuccessfulDiscoRequest() throws Exception { ThreadedDummyConnection con = new ThreadedDummyConnection(); DiscoverInfo info = new DiscoverInfo(); - info.addFeature(PingManager.NAMESPACE); + info.addFeature(Ping.NAMESPACE); //@formatter:off String reply =