本文整理汇总了Java中org.xmpp.packet.Message.getTo方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getTo方法的具体用法?Java Message.getTo怎么用?Java Message.getTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Message
的用法示例。
在下文中一共展示了Message.getTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSendWithDeviceIdSpecifiedButNotRecipientId
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Test
public void testSendWithDeviceIdSpecifiedButNotRecipientId() throws Exception {
SendMessageRequest request = new SendMessageRequest();
request.setDeviceId("12345678987654322");
String message = "Simple Message";
request.setReceipt(true);
request.setReplyTo("login3");
Map<String, String> content = new HashMap<String, String>();
content.put("textContent", message);
request.setContent(content);
String appId = "AAABSNIBKOstQST7";
MessageSenderImpl sender = new MessageReturningStubMessageSenderImpl();
SendMessageResult result = sender.send("bogus-sender-user-id", appId, request);
assertNotNull("message result is null", result);
assertNotNull("Message Id is expected to be not null", result.getSentList().get(0).getMessageId());
/**
* validate the message contents
*/
Message builtMessage = ((MessageReturningStubMessageSenderImpl) sender).messageList.get(0);
JID to = builtMessage.getTo();
String expectedUserId = "magnet.way";
String expectedTo = expectedUserId + JIDUtil.APP_ID_DELIMITER + appId.toLowerCase() + "@" + sender.getDomain() + "/" + request.getDeviceId(); //importantuser%[email protected]/12345678987654322
String builtMessageXML = builtMessage.toXML();
assertNotNull(builtMessageXML);
assertEquals("Non matching to", expectedTo, to.toString());
Element receipt = builtMessage.getChildElement(Constants.XMPP_REQUEST, Constants.XMPP_NS_RECEIPTS);
assertNotNull("Receipt element is missing", receipt);
}
示例2: interceptPacket
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException
{
// Ignore any packets that haven't already been processed by interceptors.
if (!processed) {
return;
}
if (packet instanceof Message) {
// Ignore any outgoing messages (we'll catch them when they're incoming).
if (!incoming) {
return;
}
Message message = (Message) packet;
// Ignore any messages that don't have a body so that we skip events.
// Note: XHTML messages should always include a body so we should be ok. It's
// possible that we may need special XHTML filtering in the future, however.
if (message.getBody() != null) {
// Only process messages that are between two users, group chat rooms, or gateways.
if (conversationManager.isConversation(message)) {
// Process this event in the senior cluster member or local JVM when not in a cluster
if (ClusterManager.isSeniorClusterMember()) {
conversationManager.processMessage(message.getFrom(), message.getTo(), message.getBody(), message.toXML(), new Date());
}
else {
JID sender = message.getFrom();
JID receiver = message.getTo();
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
ConversationEvent.chatMessageReceived(sender, receiver,
conversationManager.isMessageArchivingEnabled() ? message.getBody() : null,
new Date()));
}
}
}
}
}
示例3: interceptPacket
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException
{
// Ignore any packets that haven't already been processed by interceptors.
if (!processed) {
return;
}
if (packet instanceof Message) {
// Ignore any outgoing messages (we'll catch them when they're incoming).
if (!incoming) {
return;
}
Message message = (Message) packet;
// Ignore any messages that don't have a body so that we skip events.
// Note: XHTML messages should always include a body so we should be ok. It's
// possible that we may need special XHTML filtering in the future, however.
if (message.getBody() != null) {
// Only process messages that are between two users, group chat rooms, or gateways.
if (conversationManager.isConversation(message)) {
// Process this event in the senior cluster member or local JVM when not in a cluster
if (ClusterManager.isSeniorClusterMember()) {
conversationManager.processMessage(message.getFrom(), message.getTo(), message.getBody(), new Date());
}
else {
JID sender = message.getFrom();
JID receiver = message.getTo();
ConversationEventsQueue eventsQueue = conversationManager.getConversationEventsQueue();
eventsQueue.addChatEvent(conversationManager.getConversationKey(sender, receiver),
ConversationEvent.chatMessageReceived(sender, receiver,
conversationManager.isMessageArchivingEnabled() ? message.getBody() : null,
new Date()));
}
}
}
}
}
示例4: handleMMXMulticast
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void handleMMXMulticast(MMXMsgRuleInput input)
throws PacketRejectedException {
Message message = input.getMessage();
JID mcastJid = message.getTo();
String appId = JIDUtil.getAppId(mcastJid);
PacketExtension payload = message.getExtension(Constants.MMX,
Constants.MMX_NS_MSG_PAYLOAD);
if (payload == null) {
LOGGER.warn("Dropping a malformed MMX multicast message.");
if (!(Boolean) getMmxMeta(payload, MmxHeaders.NO_ACK, Boolean.FALSE)) {
sendBeginAckMessageOnce(message, appId, 0, ErrorCode.SEND_MESSAGE_MALFORMED);
}
throw new PacketRejectedException(
"Stop processing for malformed multicast message");
}
MMXid[] recipients = getRecipients(payload);
if (recipients == null || recipients.length == 0) {
LOGGER.warn("No recipients found in MMX multicast message");
if (!(Boolean) getMmxMeta(payload, MmxHeaders.NO_ACK, Boolean.FALSE)) {
sendBeginAckMessageOnce(message, appId, 0, ErrorCode.SEND_MESSAGE_NO_TARGET);
}
} else {
// Save a recipient counter for the multicast message and send a begin
// ack. The count will be decremented when each routed message is handled
// later. When the count reaches zero, the end ack will be sent. Note,
// the packet routing in the for-loop is done asynchronously.
if (!(Boolean) getMmxMeta(payload, MmxHeaders.NO_ACK, Boolean.FALSE)) {
sendBeginAckMessageOnce(message, appId, recipients.length, ErrorCode.NO_ERROR);
}
PacketRouter pktRouter = XMPPServer.getInstance().getPacketRouter();
for (MMXid recipient : recipients) {
JID jid = new JID(JIDUtil.makeNode(recipient.getUserId(), appId),
mcastJid.getDomain(), recipient.getDeviceId(), true);
// TODO: need a deep copy because payload cannot be shared with
// multiple messages; it has a DOM parent.
Message unicastMsg = message.createCopy();
unicastMsg.setTo(jid);
pktRouter.route(unicastMsg);
}
}
throw new PacketRejectedException("MMX multicast message is processed");
}
示例5: isValidDistributableMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public static boolean isValidDistributableMessage(Packet packet) {
if(!(packet instanceof Message)) {
LOGGER.debug("isValidDistributableMessage : false packet is not a XMPP Message stanza");
return false;
}
Message mmxMessage = (Message) packet;
if (isMulticastMessage(mmxMessage)) {
LOGGER.debug("isValidDistributableMessage :false packet is a Multicast message");
return false;
}
if (isGeoEventMessage(mmxMessage)) {
LOGGER.debug("isValidDistributableMessage :false packet is a GeoEvent message");
return false;
}
if (isPubSubMessage(mmxMessage)) {
LOGGER.debug("isValidDistributableMessage :false packet is a PubSub message");
return false;
}
if(Strings.isNullOrEmpty(mmxMessage.getID())){
LOGGER.debug("isValidDistributableMessage : false bad messageId={}", mmxMessage.getID());
return false;
}
if(mmxMessage.getType() == Message.Type.error) {
LOGGER.debug("isValidDistributableMessage : false message is an error message={}", mmxMessage.getID());
return false;
}
if(mmxMessage.getTo() == null) {
LOGGER.trace("isValidDistributableMessage : false toJID=null");
return false;
}
if (isSignalMessage(mmxMessage)) {
LOGGER.debug("isValidDistributableMessage :false packet is a signal message");
return false;
}
return true;
}
示例6: processIncoming
import org.xmpp.packet.Message; //导入方法依赖的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);
}
}
}
示例7: addMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Adds a message to this message store. Messages will be stored and made
* available for later delivery.
*
* @param message the message to store.
*/
public void addMessage(Message message) {
if (message == null) {
return;
}
if(!shouldStoreMessage(message)) {
return;
}
JID recipient = message.getTo();
String username = recipient.getNode();
// If the username is null (such as when an anonymous user), don't store.
if (username == null || !UserManager.getInstance().isRegisteredUser(recipient)) {
return;
}
else
if (!XMPPServer.getInstance().getServerInfo().getXMPPDomain().equals(recipient.getDomain())) {
// Do not store messages sent to users of remote servers
return;
}
long messageID = SequenceManager.nextID(JiveConstants.OFFLINE);
// Get the message in XML format.
String msgXML = message.getElement().asXML();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_OFFLINE);
pstmt.setString(1, username);
pstmt.setLong(2, messageID);
pstmt.setString(3, StringUtils.dateToMillis(new java.util.Date()));
pstmt.setInt(4, msgXML.length());
pstmt.setString(5, msgXML);
pstmt.executeUpdate();
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
// Update the cached size if it exists.
if (sizeCache.containsKey(username)) {
int size = sizeCache.get(username);
size += msgXML.length();
sizeCache.put(username, size);
}
}
示例8: archiveMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void archiveMessage(Session session, Message message, boolean incoming)
{
final XMPPServer server = XMPPServer.getInstance();
final ArchivedMessage.Direction direction;
final ArchivedMessage archivedMessage;
final Conversation conversation;
final JID ownerJid;
final JID withJid;
// TODO support groupchat
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.normal)
{
return;
}
if (server.isLocal(message.getFrom()) && incoming)
{
ownerJid = message.getFrom();
withJid = message.getTo();
// sent by the owner => to
direction = ArchivedMessage.Direction.to;
}
else if (server.isLocal(message.getTo()) && ! incoming)
{
ownerJid = message.getTo();
withJid = message.getFrom();
// received by the owner => from
direction = ArchivedMessage.Direction.from;
}
else
{
return;
}
archivedMessage = ArchiveFactory.createArchivedMessage(session, message, direction, withJid);
if (archivedMessage.isEmpty())
{
return;
}
conversation = determineConversation(ownerJid, withJid, message.getSubject(), message.getThread(), archivedMessage);
archivedMessage.setConversation(conversation);
persistenceManager.createMessage(archivedMessage);
if (indexManager != null)
{
indexManager.indexObject(archivedMessage);
}
}
示例9: sendViolationNotification
import org.xmpp.packet.Message; //导入方法依赖的package包/类
private void sendViolationNotification(Packet originalPacket) {
String subject = "Content filter notification! ("
+ originalPacket.getFrom().getNode() + ")";
String body;
if (originalPacket instanceof Message) {
Message originalMsg = (Message) originalPacket;
body = "Disallowed content detected in message from:"
+ originalMsg.getFrom()
+ " to:"
+ originalMsg.getTo()
+ ", message was "
+ (allowOnMatch ? "allowed" + (contentFilter.isMaskingContent() ? " and masked." : " but not masked.") : "rejected.")
+ (violationIncludeOriginalPacketEnabled ? "\nOriginal subject:"
+ (originalMsg.getSubject() != null ? originalMsg
.getSubject() : "")
+ "\nOriginal content:"
+ (originalMsg.getBody() != null ? originalMsg
.getBody() : "")
: "");
} else {
// presence
Presence originalPresence = (Presence) originalPacket;
body = "Disallowed status detected in presence from:"
+ originalPresence.getFrom()
+ ", status was "
+ (allowOnMatch ? "allowed" + (contentFilter.isMaskingContent() ? " and masked." : " but not masked.") : "rejected.")
+ (violationIncludeOriginalPacketEnabled ? "\nOriginal status:"
+ originalPresence.getStatus()
: "");
}
if (violationNotificationByIMEnabled) {
if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending IM notification");
}
sendViolationNotificationIM(subject, body);
}
if (violationNotificationByEmailEnabled) {
if (Log.isDebugEnabled()) {
Log.debug("Content filter: sending email notification");
}
sendViolationNotificationEmail(subject, body);
}
}
示例10: addMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Adds a message to this message store. Messages will be stored and made
* available for later delivery.
*
* @param message the message to store.
*/
public void addMessage(Message message) {
if (message == null) {
return;
}
if (message.getBody() == null || message.getBody().length() == 0) {
// ignore empty bodied message (typically chat-state notifications).
return;
}
JID recipient = message.getTo();
String username = recipient.getNode();
// If the username is null (such as when an anonymous user), don't store.
if (username == null || !UserManager.getInstance().isRegisteredUser(recipient)) {
return;
}
else
if (!XMPPServer.getInstance().getServerInfo().getXMPPDomain().equals(recipient.getDomain())) {
// Do not store messages sent to users of remote servers
return;
}
long messageID = SequenceManager.nextID(JiveConstants.OFFLINE);
// Get the message in XML format.
String msgXML = message.getElement().asXML();
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_OFFLINE);
pstmt.setString(1, username);
pstmt.setLong(2, messageID);
pstmt.setString(3, StringUtils.dateToMillis(new java.util.Date()));
pstmt.setInt(4, msgXML.length());
pstmt.setString(5, msgXML);
pstmt.executeUpdate();
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
// Update the cached size if it exists.
if (sizeCache.containsKey(username)) {
int size = sizeCache.get(username);
size += msgXML.length();
sizeCache.put(username, size);
}
}
示例11: storeOffline
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void storeOffline(Message message) {
if (message != null) {
// Do nothing if the message was sent to the server itself, an anonymous user or a non-existent user
JID recipientJID = message.getTo();
if (recipientJID == null || serverAddress.equals(recipientJID) ||
recipientJID.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
return;
}
// Do not store messages of type groupchat, error or headline as specified in JEP-160
if (Message.Type.groupchat == message.getType() ||
Message.Type.error == message.getType() ||
Message.Type.headline == message.getType()) {
return;
}
// Do not store messages if communication is blocked
PrivacyList list =
PrivacyListManager.getInstance().getDefaultPrivacyList(recipientJID.getNode());
if (list != null && list.shouldBlockPacket(message)) {
return;
}
if (type == Type.bounce) {
bounce(message);
}
else if (type == Type.store) {
store(message);
}
else if (type == Type.store_and_bounce) {
if (underQuota(message)) {
store(message);
}
else {
bounce(message);
}
}
else if (type == Type.store_and_drop) {
if (underQuota(message)) {
store(message);
}
}
}
}
示例12: storeOffline
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void storeOffline(Message message) {
if (message != null) {
// Do nothing if the message was sent to the server itself, an anonymous user or a non-existent user
JID recipientJID = message.getTo();
if (recipientJID == null || serverAddress.equals(recipientJID) ||
recipientJID.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
return;
}
// Do not store messages of type groupchat, error or headline as specified in JEP-160
if (Message.Type.groupchat == message.getType() ||
Message.Type.error == message.getType() ||
Message.Type.headline == message.getType()) {
return;
}
// Do not store messages if communication is blocked
PrivacyList list =
PrivacyListManager.getInstance().getDefaultPrivacyList(recipientJID.getNode());
if (list != null && list.shouldBlockPacket(message)) {
Message result = message.createCopy();
result.setTo(message.getFrom());
result.setError(PacketError.Condition.service_unavailable);
XMPPServer.getInstance().getRoutingTable().routePacket(message.getFrom(), result, true);
return;
}
if (type == Type.bounce) {
bounce(message);
}
else if (type == Type.store) {
store(message);
}
else if (type == Type.store_and_bounce) {
if (underQuota(message)) {
store(message);
}
else {
bounce(message);
}
}
else if (type == Type.store_and_drop) {
if (underQuota(message)) {
store(message);
}
}
}
}