本文整理汇总了Java中org.xmpp.packet.Message.createCopy方法的典型用法代码示例。如果您正苦于以下问题:Java Message.createCopy方法的具体用法?Java Message.createCopy怎么用?Java Message.createCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Message
的用法示例。
在下文中一共展示了Message.createCopy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例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) {
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);
}
}
示例3: distribute
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Override
public DistributionResult distribute(Message message, DistributionContext context) {
DeviceDAO deviceDAO = getDeviceDAO();
String bareUserId = context.getBareUserId();
String appKey = context.getAppId();
String domain = context.getServerHostname();
List<DeviceEntity> devices = deviceDAO.getDevices(appKey, bareUserId, DeviceStatus.ACTIVE);
LOGGER.info("distribute : Distributing messages for user={}, messageId={}, numDevices={} ", new Object[]{context.getBareUserId(), context.getMessageId(), devices.size()});
List<JID> distributed = new ArrayList<JID>();
List<JIDDevicePair> undistributed = new ArrayList<JIDDevicePair>();
boolean noDevices = (devices.size() == 0);
for (DeviceEntity entity : devices) {
String deviceId = entity.getDeviceId();
Message cloned = message.createCopy();
JID deviceSpecificJID = buildToAddress(bareUserId, appKey, domain, deviceId);
cloned.setTo(deviceSpecificJID);
MMXPresenceFinder finder = getPresenceFinder();
if(finder.isOnline(deviceSpecificJID)) {
LOGGER.trace("distribute : found online deviceSpecificJID={}", deviceSpecificJID);
route(cloned);
distributed.add(deviceSpecificJID);
} else {
LOGGER.trace("distribute : not found online deviceSpecificJID={}", deviceSpecificJID);
JIDDevicePairImpl pair = new JIDDevicePairImpl(deviceSpecificJID, entity);
undistributed.add(pair);
}
}
return new DistributionResultImpl(distributed, undistributed, noDevices);
}
示例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: Forwarded
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public Forwarded(Message message, Date delay, JID delayFrom) {
super("forwarded", "urn:xmpp:forward:0");
Message copy = message.createCopy();
populate(copy.getElement(), delay, delayFrom);
}
示例6: 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);
}
}
}
}