use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class HttpSessionDeliverable method testNamespaceOnStanza.
/**
* Verifies that the default namespace is set on (non-empty) stanzas.
*
* @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
*/
@Test
public void testNamespaceOnStanza() throws Exception {
// Setup fixture
final Message message = new Message();
message.setTo("unittest@example.org/test");
message.addChildElement("unittest", "unit:test:namespace");
final List<Packet> packets = new ArrayList<>();
packets.add(message);
// Execute system under test
final HttpSession.Deliverable deliverable = new HttpSession.Deliverable(packets);
final String result = deliverable.getDeliverable();
// verify results
// Note that this assertion depends on the Openfire XML parser-specific ordering of attributes.
assertEquals("<message to=\"unittest@example.org/test\" xmlns=\"jabber:client\"><unittest xmlns=\"unit:test:namespace\"/></message>", result);
}
use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class HttpSessionDeliverable method testNamespaceOnStanzaWithNamespace.
/**
* Verifies that the default namespace is not set on stanzas that already have defined a default namespace.
*
* @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
*/
@Test
public void testNamespaceOnStanzaWithNamespace() throws Exception {
// Setup fixture
final Message message = new Message();
message.getElement().setQName(QName.get("message", "unit:test:preexisting:namespace"));
message.setTo("unittest@example.org/test");
message.addChildElement("unittest", "unit:test:namespace");
final List<Packet> packets = new ArrayList<>();
packets.add(message);
// Execute system under test
final HttpSession.Deliverable deliverable = new HttpSession.Deliverable(packets);
final String result = deliverable.getDeliverable();
// verify results
// Note that this assertion depends on the Openfire XML parser-specific ordering of attributes.
assertEquals("<message xmlns=\"unit:test:preexisting:namespace\" to=\"unittest@example.org/test\"><unittest xmlns=\"unit:test:namespace\"/></message>", result);
}
use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class MultiUserChatServiceImpl method sendErrorPacket.
/**
* Generate and send an error packet to indicate that something went wrong.
*
* @param packet the packet to be responded to with an error.
* @param error the reason why the operation failed.
* @param message an optional human-readable error message.
*/
private void sendErrorPacket(Packet packet, PacketError.Condition error, String message) {
if (packet.getError() != null) {
Log.debug("Avoid generating an error in response to a stanza that itself has an error (to avoid the chance of entering an endless back-and-forth of exchanging errors). Suppress sending an {} error (with message '{}') in response to: {}", error, message, packet);
return;
}
if (packet instanceof IQ) {
IQ reply = IQ.createResultIQ((IQ) packet);
reply.setChildElement(((IQ) packet).getChildElement().createCopy());
reply.setError(error);
if (message != null) {
reply.getError().setText(message);
}
XMPPServer.getInstance().getPacketRouter().route(reply);
} else {
Packet reply = packet.createCopy();
reply.setError(error);
if (message != null) {
reply.getError().setText(message);
}
reply.setFrom(packet.getTo());
reply.setTo(packet.getFrom());
XMPPServer.getInstance().getPacketRouter().route(reply);
}
}
Aggregations