本文整理汇总了Java中org.xmpp.packet.Message.getFrom方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getFrom方法的具体用法?Java Message.getFrom怎么用?Java Message.getFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Message
的用法示例。
在下文中一共展示了Message.getFrom方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.xmpp.packet.Message; //导入方法依赖的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;
}
示例2: bounce
import org.xmpp.packet.Message; //导入方法依赖的package包/类
private void bounce(Message message) {
// Do nothing if the sender was the server itself
if (message.getFrom() == null || message.getFrom().equals( serverAddress )) {
return;
}
try {
// Generate a rejection response to the sender
Message errorResponse = message.createCopy();
// return an error stanza to the sender, which SHOULD be <service-unavailable/>
errorResponse.setError(PacketError.Condition.service_unavailable);
errorResponse.setFrom(message.getTo());
errorResponse.setTo(message.getFrom());
// Send the response
router.route(errorResponse);
// Inform listeners that an offline message was bounced
if (!listeners.isEmpty()) {
for (OfflineMessageListener listener : listeners) {
listener.messageBounced(message);
}
}
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
示例3: bounce
import org.xmpp.packet.Message; //导入方法依赖的package包/类
private void bounce(Message message) {
// Do nothing if the sender was the server itself
if (message.getFrom() == null) {
return;
}
try {
// Generate a rejection response to the sender
Message errorResponse = message.createCopy();
errorResponse.setError(new PacketError(PacketError.Condition.item_not_found,
PacketError.Type.continue_processing));
errorResponse.setFrom(message.getTo());
errorResponse.setTo(message.getFrom());
// Send the response
router.route(errorResponse);
// Inform listeners that an offline message was bounced
if (!listeners.isEmpty()) {
for (OfflineMessageListener listener : listeners) {
listener.messageBounced(message);
}
}
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
示例4: broadcast
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void broadcast(BroadcastMessageRequest messageRequest) {
Message message = messageRequest.getMessage();
// Add message to the room history
roomHistory.addMessage(message);
// Send message to occupants connected to this JVM
for (MUCRole occupant : occupantsByFullJID.values()) {
// Do not send broadcast messages to deaf occupants or occupants hosted in
// other cluster nodes
if (occupant.isLocal() && !occupant.isVoiceOnly()) {
occupant.send(message);
}
}
if (messageRequest.isOriginator() && isLogEnabled()) {
MUCRole senderRole = null;
JID senderAddress;
// convert the MUC nickname/role JID back into a real user JID
if (message.getFrom() != null && message.getFrom().getResource() != null) {
// get the first MUCRole for the sender
List<MUCRole> occupants = occupantsByNickname.get(message.getFrom().getResource().toLowerCase());
senderRole = occupants == null ? null : occupants.get(0);
}
if (senderRole == null) {
// The room itself is sending the message
senderAddress = getRole().getRoleAddress();
}
else {
// An occupant is sending the message
senderAddress = senderRole.getUserAddress();
}
// Log the conversation
mucService.logConversation(this, message, senderAddress);
}
mucService.messageBroadcastedTo(messageRequest.getOccupants());
}
示例5: 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()));
}
}
}
}
}
示例6: broadcast
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void broadcast(BroadcastMessageRequest messageRequest) {
Message message = messageRequest.getMessage();
// Add message to the room history
roomHistory.addMessage(message);
// Send message to occupants connected to this JVM
for (MUCRole occupant : occupants.values()) {
// Do not send broadcast messages to deaf occupants or occupants hosted in
// other cluster nodes
if (occupant.isLocal() && !occupant.isVoiceOnly()) {
occupant.send(message);
}
}
if (messageRequest.isOriginator() && isLogEnabled()) {
MUCRole senderRole = null;
JID senderAddress;
if (message.getFrom() != null && message.getFrom().getResource() != null) {
senderRole = occupants.get(message.getFrom().getResource().toLowerCase());
}
if (senderRole == null) {
// The room itself is sending the message
senderAddress = getRole().getRoleAddress();
}
else {
// An occupant is sending the message
senderAddress = senderRole.getUserAddress();
}
// Log the conversation
mucService.logConversation(this, message, senderAddress);
}
mucService.messageBroadcastedTo(messageRequest.getOccupants());
}
示例7: 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()));
}
}
}
}
}
示例8: sendMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
void sendMessage(Chat chat, Message message) {
for (Map.Entry<PacketInterceptor, PacketFilter> interceptor : interceptors
.entrySet()) {
PacketFilter filter = interceptor.getValue();
if (filter != null && filter.accept(message)) {
interceptor.getKey().interceptPacket(message);
}
}
// Ensure that messages being sent have a proper FROM value
if (message.getFrom() == null) {
message.setFrom(connection.getUser());
}
connection.sendPacket(message);
}
示例9: broadcast
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void broadcast(BroadcastMessageRequest messageRequest) {
Message message = messageRequest.getMessage();
// Add message to the room history
roomHistory.addMessage(message);
// Send message to occupants connected to this JVM
for (MUCRole occupant : occupantsByFullJID.values()) {
// Do not send broadcast messages to deaf occupants or occupants hosted in
// other cluster nodes
if (occupant.isLocal() && !occupant.isVoiceOnly()) {
occupant.send(message);
}
}
if (messageRequest.isOriginator() && isLogEnabled()) {
MUCRole senderRole = null;
JID senderAddress;
// convert the MUC nickname/role JID back into a real user JID
if (message.getFrom() != null && message.getFrom().getResource() != null) {
// get the first MUCRole for the sender
List<MUCRole> occupants = occupantsByNickname.get(message.getFrom().getResource().toLowerCase());
senderRole = occupants == null ? null : occupants.get(0);
}
if (senderRole == null) {
// The room itself is sending the message
senderAddress = getRole().getRoleAddress();
}
else {
// An occupant is sending the message
senderAddress = senderRole.getUserAddress();
}
// Log the conversation
mucService.logConversation(this, message, senderAddress);
}
mucService.messageBroadcastedTo(messageRequest.getOccupants());
}
示例10: 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);
}
}
}
示例11: test2Build
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Test with content containing XML characters.
* @throws Exception
*/
@Test
public void test2Build() throws Exception {
SendMessageRequest request = new SendMessageRequest();
request.setRecipientUserIds(Collections.singletonList("test"));
String message = "<message><subject>This is a test</subject><content>Tell me a story</content></message>";
Map<String, String> contentMap = new HashMap<String, String>();
contentMap.put("content", message);
contentMap.put("contentType", "text");
request.setContent(contentMap);
request.setReceipt(true);
AppEntity app = new AppEntity();
app.setAppId("i1cglsw8dsa");
app.setServerUserId("admin");
String msgId = new MessageIdGeneratorImpl().generateItemIdentifier(app.getAppId());
MessageBuilder builder = new MessageBuilder();
builder.setAppId(app.getAppId());
builder.setDomain("localhost");
builder.setMetadata(request.getContent());
builder.setUtcTime(System.currentTimeMillis());
builder.setId(msgId);
builder.setSenderId(app.getServerUserId());
builder.setUserId(request.getRecipientUserIds().get(0));
Message m = builder.build();
assertNotNull("Message shouldn't be null", m);
Element mmx = m.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
assertNotNull("mmx element is null", mmx);
Element payload = mmx.element(Constants.MMX_PAYLOAD);
assertNotNull("payload element is null", payload);
String content = payload.getText();
assertNotNull("payload content is null", content);
assertEquals("Non matching content", "", content);
JID from = m.getFrom();
assertEquals ("Non matching from jid", "admin%[email protected]", from.toString());
String body = m.getBody();
assertEquals("Message body is not expected", MMXServerConstants.MESSAGE_BODY_DOT, body);
}
示例12: 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);
}
}
示例13: 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);
}
}