本文整理汇总了Java中org.xmpp.packet.JID.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java JID.getResource方法的具体用法?Java JID.getResource怎么用?Java JID.getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.JID
的用法示例。
在下文中一共展示了JID.getResource方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSession
import org.xmpp.packet.JID; //导入方法依赖的package包/类
/**
* 根据JID返回与之关联的会话
*
* @param from
* @return
*/
public ClientSession getSession(JID from) {
if (from == null || serverName == null
|| !serverName.equals(from.getDomain())) {
return null;
}
// 检查预认证会话
if (from.getResource() != null) {
ClientSession session = preAuthSessions.get(from.getResource());
if (session != null) {
return session;
}
}
if (from.getResource() == null || from.getNode() == null) {
return null;
}
return clientSessions.get(from.toString());
}
示例2: build
import org.xmpp.packet.JID; //导入方法依赖的package包/类
/**
* Build a DeliveryConfirmationMessage using the source Message
* @param source
* @return DeliveryConfirmationMessage if the source message represents a DeliveryConfirmation
* null other wise.
*/
public static DeliveryConfirmationMessage build (Message source) {
DeliveryConfirmationMessage dc = null;
if (source != null) {
PacketExtension confirmation = source.getExtension(Constants.XMPP_RECEIVED, Constants.XMPP_NS_RECEIPTS);
if (confirmation != null) {
//make sure we have the id attribute which identifies the id of the message
//for which this message represents a delivery confirmation
Element extensionElement = confirmation.getElement();
String idVal = extensionElement.attributeValue(Constants.XMPP_ATTR_ID);
if (idVal != null || !idVal.isEmpty()) {
dc = new DeliveryConfirmationMessage();
dc.messageId = idVal;
dc.wrapped = source;
JID from = source.getFrom();
if (from != null && from.getResource() != null) {
dc.confirmingDeviceId = from.getResource();
}
}
}
}
return dc;
}
示例3: build
import org.xmpp.packet.JID; //导入方法依赖的package包/类
/**
* Build the ServerAckMessage
* @return Message
*/
public Message build() {
JID sender = originalMessage.getFrom();
String senderUserId = JIDUtil.getUserId(sender);
String senderDeviceId = sender.getResource();
Message ackMessage = new Message();
ackMessage.setType(Message.Type.normal); // unreliable signal message; don't need an ack
ackMessage.setFrom(appId + "%" + appId + "@" + XMPPServer.getInstance().getServerInfo().getXMPPDomain());
ackMessage.setTo(sender);
ackMessage.setID(new MessageIdGeneratorImpl().generate(sender.toString(), appId, senderDeviceId));
Element mmxElement = ackMessage.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_SIGNAL);
Element mmxMetaElement = mmxElement.addElement(Constants.MMX_MMXMETA);
Map<String, ServerAckMmxMeta> mmxMetaMap = new HashMap<String, ServerAckMmxMeta>();
ServerAckMmxMeta meta = new ServerAckMmxMeta();
meta.setAckForMsgId(originalMessage.getID());
if (type != Type.BATCH_BEGIN) {
if (badReceivers == null) {
// Don't allow null; use an empty list
badReceivers = new ArrayList<MetaToEntry>(0);
}
meta.setBadReceivers(badReceivers);
}
meta.setErrorCode(errorCode);
meta.setSender(senderUserId, senderDeviceId);
mmxMetaMap.put(type.getValue(), meta);
String mmxMetaJSON = GsonData.getGson().toJson(mmxMetaMap);
mmxMetaElement.setText(mmxMetaJSON);
// Element payloadElement = mmxElement.addElement(Constants.MMX_PAYLOAD);
//
// DateFormat fmt = Utils.buildISO8601DateFormat();
// String formattedDateTime = fmt.format(new Date());
// payloadElement.addAttribute(Constants.MMX_ATTR_STAMP, formattedDateTime);
// payloadElement.addAttribute(Constants.MMX_ATTR_CHUNK, MessageBuilder.buildChunkAttributeValue(text));
// ackMessage.setBody(MMXServerConstants.MESSAGE_BODY_DOT);
return ackMessage;
}
示例4: build
import org.xmpp.packet.JID; //导入方法依赖的package包/类
/**
* Build a topicName subscription object using the node subscription information.
* @param nodeSubscription
* @return
*/
public static ChannelSubscription build (NodeSubscription nodeSubscription) {
JID subscriberJID = nodeSubscription.getJID();
String subscriberJIDNode = subscriberJID.getNode();
String userId = JIDUtil.getUserId(subscriberJIDNode);
String resource = subscriberJID.getResource();
AppTopic topic = TopicHelper.parseTopic(nodeSubscription.getNode().getNodeID());
String topicName = topic.getName();
ChannelSubscription subscription = new ChannelSubscription();
subscription.subscriptionId = nodeSubscription.getID();
subscription.channelName = topicName;
subscription.userId = userId;
subscription.deviceId = resource;
return subscription;
}
示例5: build
import org.xmpp.packet.JID; //导入方法依赖的package包/类
/**
* Build a topicName subscription object using the node subscription information.
* @param nodeSubscription
* @return
*/
public static TopicSubscription build (NodeSubscription nodeSubscription) {
JID subscriberJID = nodeSubscription.getJID();
String subscriberJIDNode = subscriberJID.getNode();
String username = JIDUtil.getUserId(subscriberJIDNode);
String resource = subscriberJID.getResource();
AppTopic topic = TopicHelper.parseTopic(nodeSubscription.getNode().getNodeID());
String topicName = topic.getName();
TopicSubscription subscription = new TopicSubscription();
subscription.subscriptionId = nodeSubscription.getID();
subscription.topicName = topicName;
subscription.username = username;
subscription.deviceId = resource;
return subscription;
}
示例6: MMXItemPublisher
import org.xmpp.packet.JID; //导入方法依赖的package包/类
public MMXItemPublisher(JID publisher) {
userId = JIDUtil.getUserId(publisher);
deviceId = publisher.getResource();
}
示例7: processIncoming
import org.xmpp.packet.JID; //导入方法依赖的package包/类
@Override
public void processIncoming(Packet packet) {
if (packet instanceof Message) {
LOGGER.debug("Sending the same message back");
Message message = (Message) packet;
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
boolean receiptRequested = message.getChildElement(Constants.XMPP_REQUEST, Constants.XMPP_NS_RECEIPTS) != null;
JID fromJID = message.getFrom();
JID toJID = message.getTo();
message.setTo(fromJID);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String userId = JIDUtil.getUserId(fromJID);
String devId = fromJID.getResource();
String mmxMetaJSON = MMXMetaBuilder.build(userId, devId);
if (internalMeta != null) {
mmx.remove(internalMeta);
}
Element revisedMeta = mmx.addElement(Constants.MMX_MMXMETA);
revisedMeta.setText(mmxMetaJSON);
if (receiptRequested) {
//remove the receipt requested element to ensure we don't have a loop
message.deleteExtension(Constants.XMPP_REQUEST, Constants.XMPP_NS_RECEIPTS);
}
try {
//add a little sleep to differentiate between the send and recvd time.
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
}
autoRespondingConnection.sendPacket(message);
/*
* Acknowledge the receipt by sending an IQ
*/
String originalMessageId = message.getID();
String from = fromJID.toString();
String to = toJID.toString();
LOGGER.debug("Attempting to deliver ack");
IQ ackIQ = buildAckIQ(from, to, originalMessageId);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ack IQ:{}", ackIQ.toXML());
}
autoRespondingConnection.sendPacket(ackIQ);
if (receiptRequested) {
LOGGER.debug("Sending delivery receipt for message with id:{}", originalMessageId);
String appId = JIDUtil.getAppId(to);
Message receipt = buildDeliveryReceipt(appId, from, to, originalMessageId);
autoRespondingConnection.sendPacket(receipt);
} else {
LOGGER.debug("Not sending delivery receipt for message with id:{}", originalMessageId);
}
}
}
示例8: buildAcceptanceMessage
import org.xmpp.packet.JID; //导入方法依赖的package包/类
/**
* Build the acceptance message.
* @param sourceFrom
* @param sourceTo
* @param gameInfo
* @return
*/
protected Message buildAcceptanceMessage(JID sourceFrom, JID sourceTo, RPSLSGameInfo gameInfo) {
JID fromJID = sourceTo;
JID toJID = sourceFrom;
String appId = JIDUtil.getAppId(toJID);
Message message = new Message();
message.setTo(toJID);
message.setFrom(fromJID);
MessageIdGenerator generator = new MessageIdGeneratorImpl();
String id = generator.generate(toJID.getNode(), appId, null);
message.setID(id);
message.setType(Message.Type.chat);
Element mmx = message.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
//mmx meta
Element internalMeta = mmx.addElement(Constants.MMX_MMXMETA);
String userId = JIDUtil.getUserId(toJID);
String devId = toJID.getResource();
String senderId = JIDUtil.getUserId(fromJID);
String senderDevId = fromJID.getResource();
MmxHeaders mmxMeta = new MmxHeaders();
mmxMeta.setTo(new MMXid[] {new MMXid(userId, devId, null)});
mmxMeta.setFrom(new MMXid(senderId, senderDevId, null));
internalMeta.setText(GsonData.getGson().toJson(mmxMeta));
Element meta = mmx.addElement(Constants.MMX_META);
AcceptanceRPSLSGameInfo acceptance = new AcceptanceRPSLSGameInfo();
acceptance.setGameId(gameInfo.gameId);
acceptance.setLosses(0);
acceptance.setWins(0);
acceptance.setTies(0);
Date current = new Date();
acceptance.setTimestamp(current.getTime());
acceptance.setType(RPSLSMessageType.ACCEPTANCE);
String myUserId = JIDUtil.getUserId(sourceTo);
acceptance.setUsername(myUserId); // user id of the bot user.
String acceptanceJSON = acceptance.toJson();
meta.setText(acceptanceJSON);
Element payloadElement = mmx.addElement(Constants.MMX_PAYLOAD);
DateFormat fmt = Utils.buildISO8601DateFormat();
String formattedDateTime = fmt.format(new Date());
payloadElement.addAttribute(Constants.MMX_ATTR_STAMP, formattedDateTime);
String text = INVITE_REPLY_MESSAGE;
payloadElement.setText(text);
payloadElement.addAttribute(Constants.MMX_ATTR_CHUNK, MessageBuilder.buildChunkAttributeValue(text));
return message;
}
示例9: buildChoiceMessage
import org.xmpp.packet.JID; //导入方法依赖的package包/类
/**
* Build a message by randomly choosing from the possible choices.
* @param sourceFrom
* @param sourceTo
* @param gameInfo
* @return
*/
protected Message buildChoiceMessage(JID sourceFrom, JID sourceTo, RPSLSGameInfo gameInfo) {
JID fromJID = sourceTo;
JID toJID = sourceFrom;
String appId = JIDUtil.getAppId(toJID);
Message choiceMessage = new Message();
MessageIdGenerator generator = new MessageIdGeneratorImpl();
String id = generator.generate(toJID.getNode(), appId, null);
choiceMessage.setID(id);
choiceMessage.setType(Message.Type.chat);
choiceMessage.setTo(toJID);
choiceMessage.setFrom(fromJID);
Element mmx = choiceMessage.addChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
//mmx meta
Element internalMeta = mmx.addElement(Constants.MMX_MMXMETA);
String userId = JIDUtil.getUserId(toJID);
String devId = toJID.getResource();
String senderId = JIDUtil.getUserId(fromJID);
String senderDevId = fromJID.getResource();
MmxHeaders mmxMeta = new MmxHeaders();
mmxMeta.setTo(new MMXid[] {new MMXid(userId, devId, null)});
mmxMeta.setFrom(new MMXid(senderId, senderDevId, null));
internalMeta.setText(GsonData.getGson().toJson(mmxMeta));
Element meta = mmx.addElement(Constants.MMX_META);
ChoiceRPSLSGameInfo choice = new ChoiceRPSLSGameInfo();
choice.setGameId(gameInfo.getGameId());
choice.setLosses(0);
choice.setWins(0);
choice.setTies(0);
Date current = new Date();
choice.setTimestamp(current.getTime());
choice.setType(RPSLSMessageType.CHOICE);
String myUserId = JIDUtil.getUserId(sourceTo);
choice.setUsername(myUserId); // user id of the bot user.
String choiceValue = getRandomChoice();
choice.setChoice(choiceValue);
String choiceJSON = choice.toJson();
meta.setText(choiceJSON);
Element payloadElement = mmx.addElement(Constants.MMX_PAYLOAD);
DateFormat fmt = Utils.buildISO8601DateFormat();
String formattedDateTime = fmt.format(new Date());
payloadElement.addAttribute(Constants.MMX_ATTR_STAMP, formattedDateTime);
String text = String.format(CHOICE_TEMPLATE, choiceValue);
payloadElement.setText(text);
payloadElement.addAttribute(Constants.MMX_ATTR_CHUNK, MessageBuilder.buildChunkAttributeValue(text));
return choiceMessage;
}