本文整理汇总了Java中org.xmpp.packet.Packet.getTo方法的典型用法代码示例。如果您正苦于以下问题:Java Packet.getTo方法的具体用法?Java Packet.getTo怎么用?Java Packet.getTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Packet
的用法示例。
在下文中一共展示了Packet.getTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deliver
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* 将数据包传递给数据包收件人
*
* @param packet
* 要被投递的数据包
* @throws PacketException
* 如果数据包为空,或收件人未找到
*/
public static void deliver(Packet packet) throws PacketException {
if (packet == null) {
throw new PacketException("数据包为null");
}
try {
JID recipient = packet.getTo();
if (recipient != null) {
ClientSession clientSession = SessionManager.getInstance()
.getSession(recipient);
if (clientSession != null) {
clientSession.deliver(packet);
}
}
} catch (Exception e) {
log.error("不能提供数据包: " + packet.toString(), e);
}
}
示例2: 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);
}
}
}
示例3: processPacket
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public void processPacket(Packet packet) {
if (!isServiceEnabled()) {
return;
}
// The MUC service will receive all the packets whose domain matches the domain of the MUC
// service. This means that, for instance, a disco request should be responded by the
// service itself instead of relying on the server to handle the request.
try {
// Check if the packet is a disco request or a packet with namespace iq:register
if (packet instanceof IQ) {
if (process((IQ)packet)) {
return;
}
}
// The packet is a normal packet that should possibly be sent to the room
JID receipient = packet.getTo();
String roomName = receipient != null ? receipient.getNode() : null;
getChatUser(packet.getFrom(), roomName).process(packet);
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
示例4: deliver
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Delivers the packet to the packet recipient.
*
* @param packet the packet to deliver
* @throws PacketException if the packet is null or the recipient was not found.
*/
public static void deliver(Packet packet) throws PacketException {
if (packet == null) {
throw new PacketException("Packet was null");
}
try {
JID recipient = packet.getTo();
if (recipient != null) {
ClientSession clientSession = SessionManager.getInstance()
.getSession(recipient);
if (clientSession != null) {
clientSession.deliver(packet);
}
}
} catch (Exception e) {
log.error("Could not deliver packet: " + packet.toString(), e);
}
}
示例5: deliver
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public static void deliver(Packet packet) throws PacketException {
if (packet == null) {
throw new PacketException("Packet was null");
}
try {
JID recipient = packet.getTo();
if (recipient != null) {
ClientSession clientSession = SessionManager.getInstance()
.getSession(recipient);
if (clientSession != null) {
clientSession.deliver(packet);
}
}
} catch (Exception e) {
log.error("Could not deliver packet\n" + packet.toString(), e);
}
}
示例6: 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);
}
}
}
示例7: send
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Sends the given XMPP packet over the backing transport. This accepts a
* callback which is guaranteed to be invoked at a later point, either through
* a normal response, error response, or timeout.
*
* @param packet packet to be sent
* @param callback callback to be invoked on response or timeout
* @param timeout timeout, in seconds, for this callback
*/
public void send(Packet packet, final PacketCallback callback, int timeout) {
final String key = packet.getID() + "#" + packet.getTo() + "#" + packet.getFrom();
final OutgoingCall call = new OutgoingCall(packet.getClass(), callback);
if (callbacks.putIfAbsent(key, call) == null) {
// Timeout runnable to be invoked on packet expiry.
Runnable timeoutTask = new Runnable() {
@Override
public void run() {
if (callbacks.remove(key, call)) {
callback.error(
FederationErrors.newFederationError(FederationError.Code.REMOTE_SERVER_TIMEOUT));
} else {
// Likely race condition where success has actually occurred. Ignore.
}
}
};
call.start(timeoutExecutor.schedule(timeoutTask, timeout, TimeUnit.SECONDS));
transport.sendPacket(packet);
} else {
String msg = "Could not send packet, ID already in-flight: " + key;
LOG.warning(msg);
// Invoke the callback with an internal error.
callback.error(
FederationErrors.newFederationError(FederationError.Code.UNDEFINED_CONDITION, msg));
}
}
示例8: causeImmediateTimeout
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Cause an immediate timeout for the given packet, which is presumed to have
* already been sent via {@link #send}.
*/
@VisibleForTesting
void causeImmediateTimeout(Packet packet) {
String key = packet.getID() + "#" + packet.getTo() + "#" + packet.getFrom();
OutgoingCall call = callbacks.remove(key);
if (call != null) {
call.callback.error(FederationErrors.newFederationError(
FederationError.Code.REMOTE_SERVER_TIMEOUT, "Forced immediate timeout"));
}
}
示例9: response
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
/**
* Invoke the callback for a packet already identified as a response. This may
* either invoke the error or normal callback as necessary.
*/
private void response(Packet packet) {
String key = packet.getID() + "#" + packet.getFrom() + "#" + packet.getTo();
OutgoingCall call = callbacks.remove(key);
if (call == null) {
LOG.warning("Received response packet without paired request: " + packet.getID());
} else {
// Cancel the outstanding timeout.
call.timeout.cancel(false);
// Look for error condition and invoke the relevant callback.
Element element = packet.getElement().element("error");
if (element != null) {
LOG.fine("Invoking error callback for: " + packet.getID());
call.callback.error(toFederationError(new PacketError(element)));
} else {
if (call.responseType.equals(packet.getClass())) {
LOG.fine("Invoking normal callback for: " + packet.getID());
call.callback.run(packet);
} else {
String msg =
"Received mismatched response packet type: expected " + call.responseType
+ ", given " + packet.getClass();
LOG.warning(msg);
call.callback.error(FederationErrors.newFederationError(
FederationError.Code.UNDEFINED_CONDITION, msg));
}
}
// Clear call's reference to callback, otherwise callback only
// becomes eligible for GC once the timeout expires, because
// timeoutExecutor holds on to the call object till then, even
// though we cancelled the timeout.
call.callback = null;
}
}
示例10: accept
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public boolean accept(Packet packet) {
if (packet.getTo() == null) {
return false;
} else {
return packet.getTo().toFullJID().toLowerCase().indexOf(to) != -1;
}
}
示例11: process
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
@Override
public void process(Packet packet) throws UnauthorizedException, PacketException {
try {
JID recipient = packet.getTo();
// Check if the target domain belongs to a remote server or a component
if (server.matchesComponent(recipient) || server.isRemote(recipient)) {
routingTable.routePacket(recipient, packet, false);
}
// The target domain belongs to the local server
else if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) {
// no TO was found so send back the packet to the sender
routingTable.routePacket(packet.getFrom(), packet, false);
}
else if (recipient.getResource() != null || !(packet instanceof Presence)) {
// JID is of the form <[email protected]/resource>
routingTable.routePacket(recipient, packet, false);
}
else {
// JID is of the form <[email protected]>
for (JID route : routingTable.getRoutes(recipient, null)) {
routingTable.routePacket(route, packet, false);
}
}
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.deliver") + "\n" + packet.toString(), e);
}
}
示例12: findMatch
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public Rule findMatch(Packet packet) {
if (packet.getTo() == null || packet.getFrom() == null)
return null;
// TODO Would it be better to keep a local copy of the rules?
for (Rule rule : ruleManager.getRules()) {
if (!rule.isDisabled() && typeMatch(rule.getPackeType(), packet)
&& sourceDestMatch(rule.getDestType(), rule.getDestination(), packet.getTo())
&& sourceDestMatch(rule.getSourceType(), rule.getSource(), packet.getFrom())) {
return rule;
}
}
return null;
}
示例13: interceptPacket
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) {
if (!processed) {
// Ignore packets sent or received by users that are present in the ignore list
JID from = packet.getFrom();
JID to = packet.getTo();
if ((from == null || !ignoreList.contains(from.getNode())) &&
(to == null || !ignoreList.contains(to.getNode()))) {
auditor.audit(packet, session);
}
}
}
示例14: process
import org.xmpp.packet.Packet; //导入方法依赖的package包/类
public void process(Packet packet) throws UnauthorizedException, PacketException {
try {
JID recipient = packet.getTo();
// Check if the target domain belongs to a remote server or a component
if (server.matchesComponent(recipient) || server.isRemote(recipient)) {
routingTable.routePacket(recipient, packet, false);
}
// The target domain belongs to the local server
else if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) {
// no TO was found so send back the packet to the sender
routingTable.routePacket(packet.getFrom(), packet, false);
}
else if (recipient.getResource() != null || !(packet instanceof Presence)) {
// JID is of the form <[email protected]/resource>
routingTable.routePacket(recipient, packet, false);
}
else {
// JID is of the form <[email protected]>
for (JID route : routingTable.getRoutes(recipient, null)) {
routingTable.routePacket(route, packet, false);
}
}
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.deliver") + "\n" + packet.toString(), e);
}
}
示例15: 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);
}
}
}