1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Add XMPPConnection.sendStanza(Stanza)

and deprecate sendPacket().
This commit is contained in:
Florian Schmaus 2015-03-04 21:44:43 +01:00
parent 183af99ffb
commit ed4fa3390f
58 changed files with 183 additions and 167 deletions

View file

@ -61,7 +61,7 @@ public class CompressionTest extends SmackTestCase {
// Create a packet collector to listen for a response.
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(version.getStanzaId()));
connection.sendPacket(version);
connection.sendStanza(version);
// Wait up to 5 seconds for a result.
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

View file

@ -123,7 +123,7 @@ public class FormTest extends SmackTestCase {
// Add the completed form to the message
msg2.addExtension(completedForm.getDataFormToSend());
// Send the message with the completed form
getConnection(1).sendPacket(msg2);
getConnection(1).sendStanza(msg2);
// Get the message with the completed form
Message msg3 = (Message) collector.nextResult(2000);

View file

@ -46,7 +46,7 @@ public class GroupChatInvitationTest extends SmackTestCase {
Message message = new Message(getBareJID(1));
message.setBody("Group chat invitation!");
message.addExtension(invitation);
getConnection(0).sendPacket(message);
getConnection(0).sendStanza(message);
Thread.sleep(250);

View file

@ -35,7 +35,7 @@ public class LastActivityManagerTest extends SmackTestCase {
// Send a message as the last activity action from connection 1 to
// connection 0
conn1.sendPacket(new Message(getBareJID(0)));
conn1.sendStanza(new Message(getBareJID(0)));
// Wait 1 seconds to have some idle time
try {
@ -70,7 +70,7 @@ public class LastActivityManagerTest extends SmackTestCase {
// Send a message as the last activity action from connection 2 to
// connection 0
conn2.sendPacket(new Message(getBareJID(0)));
conn2.sendStanza(new Message(getBareJID(0)));
// Wait 1 seconds to have some idle time
try {

View file

@ -55,7 +55,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
*/
public void testReadAndDelete() {
// Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
try {
Thread.sleep(500);
@ -100,7 +100,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
// User2 becomes available again
PacketCollector collector = getConnection(1).createPacketCollector(
new MessageTypeFilter(Message.Type.chat));
getConnection(1).sendPacket(new Presence(Presence.Type.available));
getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Check that no offline messages was sent to the user
Message message = (Message) collector.nextResult(2500);
@ -124,7 +124,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
*/
public void testFetchAndPurge() {
// Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
try {
Thread.sleep(500);
@ -158,7 +158,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
// User2 becomes available again
PacketCollector collector = getConnection(1).createPacketCollector(
new MessageTypeFilter(Message.Type.chat));
getConnection(1).sendPacket(new Presence(Presence.Type.available));
getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Check that no offline messages was sent to the user
Message message = (Message) collector.nextResult(2500);

View file

@ -47,7 +47,7 @@ public class VersionTest extends SmackTestCase {
// Create a packet collector to listen for a response.
PacketCollector collector = getConnection(0).createPacketCollector(new PacketIDFilter(version.getStanzaId()));
getConnection(0).sendPacket(version);
getConnection(0).sendStanza(version);
// Wait up to 5 seconds for a result.
IQ result = (IQ)collector.nextResult(5000);

View file

@ -63,7 +63,7 @@ public class InBandBytestreamTest extends SmackTestCase {
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
open.getStanzaId()));
initiatorConnection.sendPacket(open);
initiatorConnection.sendStanza(open);
Packet result = collector.nextResult();
assertNotNull(result.getError());

View file

@ -84,7 +84,7 @@ public class Socks5ByteStreamTest extends SmackTestCase {
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
bytestreamInitiation.getStanzaId()));
initiatorConnection.sendPacket(bytestreamInitiation);
initiatorConnection.sendStanza(bytestreamInitiation);
Packet result = collector.nextResult();
assertNotNull(result.getError());

View file

@ -102,7 +102,7 @@ public class MultipleRecipientManager {
&& StringUtils.isNullOrEmpty(replyTo) && StringUtils.isNullOrEmpty(replyRoom)) {
String toJid = to.iterator().next();
packet.setTo(toJid);
connection.sendPacket(packet);
connection.sendStanza(packet);
return;
}
String serviceAddress = getMultipleRecipienServiceAddress(connection);
@ -155,7 +155,7 @@ public class MultipleRecipientManager {
if (replyAddress != null && replyAddress.getJid() != null) {
// Send reply to the reply_to address
reply.setTo(replyAddress.getJid());
connection.sendPacket(reply);
connection.sendStanza(reply);
}
else {
// Send reply to multiple recipients
@ -203,19 +203,19 @@ public class MultipleRecipientManager {
if (to != null) {
for (String jid : to) {
packet.setTo(jid);
connection.sendPacket(new PacketCopy(packet.toXML()));
connection.sendStanza(new PacketCopy(packet.toXML()));
}
}
if (cc != null) {
for (String jid : cc) {
packet.setTo(jid);
connection.sendPacket(new PacketCopy(packet.toXML()));
connection.sendStanza(new PacketCopy(packet.toXML()));
}
}
if (bcc != null) {
for (String jid : bcc) {
packet.setTo(jid);
connection.sendPacket(new PacketCopy(packet.toXML()));
connection.sendStanza(new PacketCopy(packet.toXML()));
}
}
}
@ -258,7 +258,7 @@ public class MultipleRecipientManager {
// Add extension to packet
packet.addExtension(multipleAddresses);
// Send the packet
connection.sendPacket(packet);
connection.sendStanza(packet);
}
/**

View file

@ -442,7 +442,7 @@ public class InBandBytestreamManager implements BytestreamManager {
protected void replyRejectPacket(IQ request) throws NotConnectedException {
XMPPError xmppError = new XMPPError(XMPPError.Condition.not_acceptable);
IQ error = IQ.createErrorResponse(request, xmppError);
this.connection.sendPacket(error);
this.connection.sendStanza(error);
}
/**
@ -455,7 +455,7 @@ public class InBandBytestreamManager implements BytestreamManager {
protected void replyResourceConstraintPacket(IQ request) throws NotConnectedException {
XMPPError xmppError = new XMPPError(XMPPError.Condition.resource_constraint);
IQ error = IQ.createErrorResponse(request, xmppError);
this.connection.sendPacket(error);
this.connection.sendStanza(error);
}
/**
@ -468,7 +468,7 @@ public class InBandBytestreamManager implements BytestreamManager {
protected void replyItemNotFoundPacket(IQ request) throws NotConnectedException {
XMPPError xmppError = new XMPPError(XMPPError.Condition.item_not_found);
IQ error = IQ.createErrorResponse(request, xmppError);
this.connection.sendPacket(error);
this.connection.sendStanza(error);
}
/**

View file

@ -79,7 +79,7 @@ public class InBandBytestreamRequest implements BytestreamRequest {
// acknowledge request
IQ resultIQ = IQ.createResultIQ(this.byteStreamRequest);
connection.sendPacket(resultIQ);
connection.sendStanza(resultIQ);
return ibbSession;
}

View file

@ -173,7 +173,7 @@ public class InBandBytestreamSession implements BytestreamSession {
// acknowledge close request
IQ confirmClose = IQ.createResultIQ(closeRequest);
this.connection.sendPacket(confirmClose);
this.connection.sendStanza(confirmClose);
}
@ -457,7 +457,7 @@ public class InBandBytestreamSession implements BytestreamSession {
if (data.getSeq() <= this.lastSequence) {
IQ unexpectedRequest = IQ.createErrorResponse((IQ) packet, new XMPPError(
XMPPError.Condition.unexpected_request));
connection.sendPacket(unexpectedRequest);
connection.sendStanza(unexpectedRequest);
return;
}
@ -467,7 +467,7 @@ public class InBandBytestreamSession implements BytestreamSession {
// data is invalid; respond with bad-request error
IQ badRequest = IQ.createErrorResponse((IQ) packet, new XMPPError(
XMPPError.Condition.bad_request));
connection.sendPacket(badRequest);
connection.sendStanza(badRequest);
return;
}
@ -476,7 +476,7 @@ public class InBandBytestreamSession implements BytestreamSession {
// confirm IQ
IQ confirmData = IQ.createResultIQ((IQ) packet);
connection.sendPacket(confirmData);
connection.sendStanza(confirmData);
// set last seen sequence
this.lastSequence = data.getSeq();
@ -808,7 +808,7 @@ public class InBandBytestreamSession implements BytestreamSession {
Message message = new Message(remoteJID);
message.addExtension(data);
connection.sendPacket(message);
connection.sendStanza(message);
}

View file

@ -704,7 +704,7 @@ public final class Socks5BytestreamManager implements BytestreamManager {
protected void replyRejectPacket(IQ packet) throws NotConnectedException {
XMPPError xmppError = new XMPPError(XMPPError.Condition.not_acceptable);
IQ errorIQ = IQ.createErrorResponse(packet, xmppError);
this.connection.sendPacket(errorIQ);
this.connection.sendStanza(errorIQ);
}
/**

View file

@ -257,7 +257,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
// send used-host confirmation
Bytestream response = createUsedHostResponse(selectedHost);
this.manager.getConnection().sendPacket(response);
this.manager.getConnection().sendStanza(response);
return new Socks5BytestreamSession(socket, selectedHost.getJID().equals(
this.bytestreamRequest.getFrom()));
@ -282,7 +282,7 @@ public class Socks5BytestreamRequest implements BytestreamRequest {
String errorMessage = "Could not establish socket with any provided host";
XMPPError error = XMPPError.from(XMPPError.Condition.item_not_found, errorMessage);
IQ errorIQ = IQ.createErrorResponse(this.bytestreamRequest, error);
this.manager.getConnection().sendPacket(errorIQ);
this.manager.getConnection().sendStanza(errorIQ);
throw new XMPPErrorException(errorMessage, error);
}

View file

@ -505,7 +505,7 @@ public class EntityCapsManager extends Manager {
if (connection != null && connection.isAuthenticated() && presenceSend) {
Presence presence = new Presence(Presence.Type.available);
try {
connection.sendPacket(presence);
connection.sendStanza(presence);
}
catch (NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could could not update presence with caps info", e);

View file

@ -173,6 +173,6 @@ public class FileTransferManager extends Manager {
// Socks5BytestreamManager.replyRejectPacket(IQ).
IQ rejection = IQ.createErrorResponse(initiation, new XMPPError(
XMPPError.Condition.forbidden));
connection().sendPacket(rejection);
connection().sendStanza(rejection);
}
}

View file

@ -192,7 +192,7 @@ public class FileTransferNegotiator extends Manager {
String errorMessage = "No stream methods contained in stanza.";
XMPPError error = XMPPError.from(XMPPError.Condition.bad_request, errorMessage);
IQ iqPacket = IQ.createErrorResponse(si, error);
connection().sendPacket(iqPacket);
connection().sendStanza(iqPacket);
throw new FileTransferException.NoStreamMethodsOfferedException();
}
@ -203,7 +203,7 @@ public class FileTransferNegotiator extends Manager {
}
catch (NoAcceptableTransferMechanisms e) {
IQ iqPacket = IQ.createErrorResponse(si, XMPPError.from(XMPPError.Condition.bad_request, "No acceptable transfer mechanism"));
connection().sendPacket(iqPacket);
connection().sendStanza(iqPacket);
throw e;
}

View file

@ -98,7 +98,7 @@ public abstract class StreamNegotiator {
streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getPacketReplyTimeout(), new Callback<NotConnectedException>() {
@Override
public void action() throws NotConnectedException {
connection.sendPacket(response);
connection.sendStanza(response);
}
});
}

View file

@ -518,7 +518,7 @@ public class MultiUserChat {
// field is in the form "roomName@service/nickname"
Presence leavePresence = new Presence(Presence.Type.unavailable);
leavePresence.setTo(room + "/" + nickname);
connection.sendPacket(leavePresence);
connection.sendStanza(leavePresence);
// Reset occupant information.
occupantsMap.clear();
nickname = null;
@ -689,7 +689,7 @@ public class MultiUserChat {
// Add the MUCUser packet that includes the invitation to the message
message.addExtension(mucUser);
connection.sendPacket(message);
connection.sendStanza(message);
}
/**
@ -892,7 +892,7 @@ public class MultiUserChat {
joinPresence.setTo(room + "/" + nickname);
// Send join packet.
connection.sendPacket(joinPresence);
connection.sendStanza(joinPresence);
}
/**
@ -939,7 +939,7 @@ public class MultiUserChat {
form.addField(requestVoiceField);
Message message = new Message(room);
message.addExtension(form);
connection.sendPacket(message);
connection.sendStanza(message);
}
/**
@ -1575,7 +1575,7 @@ public class MultiUserChat {
public void sendMessage(String text) throws XMPPException, NotConnectedException {
Message message = createMessage();
message.setBody(text);
connection.sendPacket(message);
connection.sendStanza(message);
}
/**
@ -1612,7 +1612,7 @@ public class MultiUserChat {
public void sendMessage(Message message) throws XMPPException, NotConnectedException {
message.setTo(room);
message.setType(Message.Type.groupchat);
connection.sendPacket(message);
connection.sendStanza(message);
}
/**

View file

@ -284,7 +284,7 @@ public class MultiUserChatManager extends Manager {
// Add the MUCUser packet that includes the rejection
message.addExtension(mucUser);
connection().sendPacket(message);
connection().sendStanza(message);
}
/**

View file

@ -36,7 +36,7 @@ import org.xmlpull.v1.XmlPullParserException;
* Message message = new Message("user@chat.example.com");
* message.setBody("Join me for a group chat!");
* message.addExtension(new GroupChatInvitation("room@chat.example.com"););
* con.sendPacket(message);
* con.sendStanza(message);
* </pre>
*
* To listen for group chat invitations, use a StanzaExtensionFilter for the

View file

@ -115,7 +115,7 @@ public class PEPManager {
//pubSub.setFrom(connection.getUser());
// Send the message that contains the roster
connection.sendPacket(pubSub);
connection.sendStanza(pubSub);
}
/**

View file

@ -211,7 +211,7 @@ public class LeafNode extends Node
{
PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
con.sendPacket(packet);
con.sendStanza(packet);
}
/**
@ -256,7 +256,7 @@ public class LeafNode extends Node
{
PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
con.sendPacket(packet);
con.sendStanza(packet);
}
/**

View file

@ -56,7 +56,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
* });
* Message message =
* DeliveryReceiptRequest.addTo(message);
* connection.sendPacket(message);
* connection.sendStanza(message);
* </pre>
*
* DeliveryReceiptManager can be configured to automatically add delivery receipt requests to every
@ -158,7 +158,7 @@ public class DeliveryReceiptManager extends Manager {
final Message messageWithReceiptRequest = (Message) packet;
Message ack = receiptMessageFor(messageWithReceiptRequest);
connection.sendPacket(ack);
connection.sendStanza(ack);
}
}, MESSAGES_WITH_DEVLIERY_RECEIPT_REQUEST);
}

View file

@ -68,7 +68,7 @@ public class CloseListenerTest {
// capture reply to the In-Band Bytestream close request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());

View file

@ -70,7 +70,7 @@ public class DataListenerTest {
// capture reply to the In-Band Bytestream close request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());

View file

@ -78,7 +78,7 @@ public class InBandBytestreamRequestTest {
// capture reply to the In-Band Bytestream open request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());
@ -103,7 +103,7 @@ public class InBandBytestreamRequestTest {
// capture reply to the In-Band Bytestream open request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct acknowledgment packet
assertEquals(initiatorJID, argument.getValue().getTo());

View file

@ -86,7 +86,7 @@ public class InitiationListenerTest {
// capture reply to the In-Band Bytestream open request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());
@ -114,7 +114,7 @@ public class InitiationListenerTest {
// capture reply to the In-Band Bytestream open request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());
@ -204,7 +204,7 @@ public class InitiationListenerTest {
// capture reply to the In-Band Bytestream open request
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());

View file

@ -93,7 +93,7 @@ public class InitiationListenerTest {
// capture reply to the SOCKS5 Bytestream initiation
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());
@ -183,7 +183,7 @@ public class InitiationListenerTest {
// capture reply to the SOCKS5 Bytestream initiation
ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
verify(connection).sendPacket(argument.capture());
verify(connection).sendStanza(argument.capture());
// assert that reply is the correct error packet
assertEquals(initiatorJID, argument.getValue().getTo());

View file

@ -53,7 +53,7 @@ public class ConnectionUtils {
* <pre>
* <code>
* PacketCollector collector = connection.createPacketCollector(new PacketFilter());
* connection.sendPacket(packet);
* connection.sendStanza(packet);
* Packet reply = collector.nextResult();
* </code>
* </pre>
@ -95,7 +95,7 @@ public class ConnectionUtils {
return null;
}
};
doAnswer(addIncoming).when(connection).sendPacket(isA(Stanza.class));
doAnswer(addIncoming).when(connection).sendStanza(isA(Stanza.class));
// mock receive methods
Answer<Stanza> answer = new Answer<Stanza>() {

View file

@ -52,7 +52,7 @@ import org.jivesoftware.smack.packet.Stanza;
* public void methodToTest() {
* Packet packet = new Packet(); // create an XMPP packet
* PacketCollector collector = connection.createPacketCollector(new StanzaIdFilter());
* connection.sendPacket(packet);
* connection.sendStanza(packet);
* Packet reply = collector.nextResult();
* }
*