本文整理汇总了Java中org.xmpp.packet.Packet.setTo方法的典型用法代码示例。如果您正苦于以下问题:Java Packet.setTo方法的具体用法?Java Packet.setTo怎么用?Java Packet.setTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Packet
的用法示例。
在下文中一共展示了Packet.setTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
@Override
public void process(Packet packet) throws UnauthorizedException, PacketException {
boolean handled = false;
String host = packet.getTo().getDomain();
for (Channel<Packet> channel : transports.values()) {
if (channel.getName().equalsIgnoreCase(host)) {
channel.add(packet);
handled = true;
}
}
if (!handled) {
JID recipient = packet.getTo();
JID sender = packet.getFrom();
packet.setError(PacketError.Condition.remote_server_timeout);
packet.setFrom(recipient);
packet.setTo(sender);
try {
deliverer.deliver(packet);
}
catch (PacketException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
示例2: presencePush
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Just pushes a available presence, we need this for GAJIM Client as it does not push available presence after
* registering We also wait a little so after register transport is on users roster. Really didnt wanted this here
* but doesnt really belong anywhere else
*
* @param to
* @param from
* @param delay MS until the job should be done
*/
private void presencePush(final JID to, final JID from, int delay) {
TimerTask pushPresenceTask = new TimerTask() {
@Override
public void run() {
PacketRouter router = server.getPacketRouter();
Packet presence = new Presence();
presence.setTo(to);
presence.setFrom(from);
router.route(presence);
}
};
Timer timer = new Timer();
timer.schedule(pushPresenceTask, delay);
}
示例3: process
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public void process(Packet packet) throws UnauthorizedException, PacketException {
boolean handled = false;
String host = packet.getTo().getDomain();
for (Channel channel : transports.values()) {
if (channel.getName().equalsIgnoreCase(host)) {
channel.add(packet);
handled = true;
}
}
if (!handled) {
JID recipient = packet.getTo();
JID sender = packet.getFrom();
packet.setError(PacketError.Condition.remote_server_timeout);
packet.setFrom(recipient);
packet.setTo(sender);
try {
deliverer.deliver(packet);
}
catch (PacketException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
示例4: presencePush
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Just pushes a available presence, we need this for GAJIM Client as it does not push available presence after
* registering We also wait a little so after register transport is on users roster. Really didnt wanted this here
* but doesnt really belong anywhere else
*
* @param to
* @param from
* @param delay MS until the job should be done
*/
private void presencePush(final JID to, final JID from, int delay) {
TimerTask pushPresenceTask = new TimerTask() {
@Override
public void run() {
PacketRouter router = server.getPacketRouter();
Packet presence = new Presence();
presence.setTo(to);
presence.setFrom(from);
router.route(presence);
}
};
Timer timer = new Timer();
timer.schedule(pushPresenceTask, delay);
}
示例5: main
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
List<Packet> list = new ArrayList<Packet>();
Packet message = new Message();
message.setTo("[email protected]/android");
message.setFrom("[email protected]/iphone");
list.add(message);
testSerializer(message, PacketConstant.CONTENT_TYPE_BSON);
testSerializer(message, PacketConstant.CONTENT_TYPE_JSON);
Packet iq = new IQ();
iq.setTo("[email protected]/android");
iq.setFrom("[email protected]/iphone");
list.add(iq);
testSerializer(iq, PacketConstant.CONTENT_TYPE_BSON);
testSerializer(iq, PacketConstant.CONTENT_TYPE_JSON);
Packet presence = new Presence();
presence.setTo("[email protected]/android");
presence.setFrom("[email protected]/iphone");
list.add(presence);
testSerializer(presence, PacketConstant.CONTENT_TYPE_BSON);
testSerializer(presence, PacketConstant.CONTENT_TYPE_JSON);
testSerializerElement(presence.getElement(), PacketConstant.CONTENT_TYPE_BSON);
testSerializerElement(presence.getElement(), PacketConstant.CONTENT_TYPE_JSON);
}
示例6: testPacketSendMalformedFailure
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Test the simple case of packet send/receive by sending a malformed request.
*/
public void testPacketSendMalformedFailure() {
Packet packet = new IQ();
packet.setFrom(server1.jid);
packet.setID("irrelevant");
packet.setTo(server2.jid);
PacketCallback callback = mock(PacketCallback.class);
// Send an outgoing packet from server1 -> server2
server1.manager.send(packet, callback, PACKET_TIMEOUT);
assertEquals("First transport should have a single packet pending",
1, server1.transport.packets.size());
assertEquals("First transport should have unmodified outgoing packet",
packet, server1.transport.packets.peek());
// Confirm that server2 sent back an error
assertEquals("Second transport should have a single packet pending",
1, server2.transport.packets.size());
assertNotNull("Second transport should be an error packet",
server2.transport.packets.peek().getError());
// Ensure the error is interpreted correctly and returned to the callback
ArgumentCaptor<FederationError> errorCaptor = ArgumentCaptor.forClass(FederationError.class);
verify(callback).error(errorCaptor.capture());
verify(callback, never()).run(any(Packet.class));
assertEquals("Invalid packet was sent, error should be BAD_REQUEST",
FederationError.Code.BAD_REQUEST, errorCaptor.getValue().getErrorCode());
}
示例7: send
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
@Override
public void send(Packet packet) {
if (packet == null) {
return;
}
packet.setTo(user.getAddress());
if (session != null && session.getStatus() == Session.STATUS_AUTHENTICATED) {
// Send the packet directly to the local user session
session.process(packet);
}
else {
router.route(packet);
}
}
示例8: send
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public void send(Packet packet) {
if (packet == null) {
return;
}
packet.setTo(user.getAddress());
if (session != null && session.getStatus() == Session.STATUS_AUTHENTICATED) {
// Send the packet directly to the local user session
session.process(packet);
}
else {
router.route(packet);
}
}
示例9: processIncoming
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
@Override
public void processIncoming(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
JID fromJID = packet.getFrom();
JID toJID = packet.getTo();
packet.setTo(fromJID);
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element meta = mmx.element(Constants.MMX_META);
if (meta == null) {
LOGGER.info("No meta in the message with id:{}", message.getID());
return;
}
//Simulate SDK ack
String originalMessageId = packet.getID();
String from = fromJID.toString();
String to = toJID.toString();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Attempting to deliver ack");
}
IQ ackIQ = BotRegistrationImpl.buildAckIQ(from, to, originalMessageId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ack IQ:{}", ackIQ.toXML());
}
connection.sendPacket(ackIQ);
String metaJSON = meta.getText();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Meta JSON:{}", metaJSON);
}
RPSLSGameInfo gameInfo = GsonData.getGson().fromJson(metaJSON, RPSLSGameInfo.class);
if (gameInfo.getType() == RPSLSMessageType.INVITATION) {
//process an invitation
//step 1. Send an acceptance
//step 2. Send a choice after 2 seconds.
processRPSLSInvitationMessage(fromJID, toJID, gameInfo);
} else {
//ignore the other types
LOGGER.info("Ignoring a message with type:{} message:{}", gameInfo.getType(), message);
}
}
}
示例10: userBroadcast
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Broadcasts the given data to all connected sessions for a particular
* user. Excellent for updating all connected resources for users such as
* roster pushes.
*
* @param username the user to send the boradcast to.
* @param packet the packet to be broadcast.
* @throws PacketException if a packet exception occurs.
*/
public void userBroadcast(String username, Packet packet) throws PacketException {
// TODO broadcast to ALL sessions of the user and not only available
for (JID address : routingTable.getRoutes(new JID(username, serverName, null), null)) {
packet.setTo(address);
routingTable.routePacket(address, packet, true);
}
}