本文整理汇总了Java中org.xmpp.packet.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.xmpp.packet包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendErrorResponse
import org.xmpp.packet.Message; //导入依赖的package包/类
/**
* Send an error response to the passed incoming request. Throws
* IllegalArgumentException if the original packet is also an error, or is of
* the IQ result type.
*
* According to RFC 3920 (9.3.1), the error packet may contain the original
* packet. However, this implementation does not include it.
*
* @param request packet request, to/from is inverted for response
* @param error packet error describing error condition
*/
void sendErrorResponse(Packet request, PacketError error) {
if (request instanceof IQ) {
IQ.Type type = ((IQ) request).getType();
if (!(type.equals(IQ.Type.get) || type.equals(IQ.Type.set))) {
throw new IllegalArgumentException("May only return an error to IQ get/set, not: " + type);
}
} else if (request instanceof Message) {
Message message = (Message) request;
if (message.getType().equals(Message.Type.error)) {
throw new IllegalArgumentException("Can't return an error to another message error");
}
} else {
throw new IllegalArgumentException("Unexpected Packet subclass, expected Message/IQ: "
+ request.getClass());
}
LOG.fine("Sending error condition in response to " + request.getID() + ": "
+ error.getCondition().name());
// Note that this does not include the original packet; just the ID.
final Packet response = XmppUtil.createResponsePacket(request);
response.setError(error);
transport.sendPacket(response);
}
示例2: testUpdateNoReceipt
import org.xmpp.packet.Message; //导入依赖的package包/类
/**
* Test that a single update message, where a receipt is not requested, is
* correctly received and processed.
*/
public void testUpdateNoReceipt() throws EncodingException {
Message updateMessage = new Message();
Element waveletUpdate = addWaveletUpdate(updateMessage, false);
waveletUpdate.addElement("applied-delta").addCDATA(Base64Util.encode(DELTA_BYTESTRING));
manager.receivePacket(updateMessage);
ArgumentCaptor<WaveletUpdateCallback> deltaCallback =
ArgumentCaptor.forClass(WaveletUpdateCallback.class);
List<ByteString> expected = ImmutableList.of(DELTA_BYTESTRING);
verify(mockUpdateListener).waveletDeltaUpdate(eq(REMOTE_WAVELET), eq(expected),
deltaCallback.capture());
deltaCallback.getValue().onSuccess();
assertEquals(0, transport.packetsSent); // Do not expect a callback.
}
示例3: addWaveletUpdate
import org.xmpp.packet.Message; //导入依赖的package包/类
/**
* Add a single wavelet-update message to the given Message. Should (probably)
* not be called twice on the same Message.
*/
private Element addWaveletUpdate(Message updateMessage, boolean requestReceipt)
throws EncodingException {
updateMessage.setFrom(REMOTE_JID);
updateMessage.setTo(LOCAL_JID);
updateMessage.setID(TEST_ID);
if (requestReceipt) {
updateMessage.addChildElement("request", XmppNamespace.NAMESPACE_XMPP_RECEIPTS);
}
Element event = updateMessage.addChildElement("event", XmppNamespace.NAMESPACE_PUBSUB_EVENT);
Element waveletUpdate =
event.addElement("items").addElement("item").addElement("wavelet-update");
waveletUpdate.addAttribute("wavelet-name",
XmppUtil.waveletNameCodec.waveletNameToURI(REMOTE_WAVELET));
return waveletUpdate;
}
示例4: 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;
}
示例5: isAnnotated
import org.xmpp.packet.Message; //导入依赖的package包/类
@Override
public boolean isAnnotated(Message message) {
boolean rv = false;
Element mmx = message.getChildElement(Constants.MMX, Constants.MMX_NS_MSG_PAYLOAD);
Element internalMeta = mmx.element(Constants.MMX_MMXMETA);
String currentInternalMetaJSON = internalMeta != null ? internalMeta.getText() : null;
if (currentInternalMetaJSON != null && !currentInternalMetaJSON.isEmpty()) {
JsonParser parser = new JsonParser();
JsonElement jsonElement = parser.parse(currentInternalMetaJSON).getAsJsonObject();
JsonObject jsonObject = jsonElement.isJsonObject() ? jsonElement.getAsJsonObject() : null;
if (jsonObject != null) {
rv = jsonObject.has(MMXServerConstants.DISTRIBUTED_KEY);
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Checking if message :{} result:{}", message, rv);
}
return rv;
}
示例6: sendServerAckMessage
import org.xmpp.packet.Message; //导入依赖的package包/类
private void sendServerAckMessage(Message mmxMessage, String appId,
boolean badReceiver) {
Counter counter = mMulticastMsgs.get(mmxMessage.getID());
if (counter != null) {
return;
}
List<MMXMetaBuilder.MetaToEntry> badReceivers = null;
if (badReceiver) {
badReceivers = new ArrayList<MMXMetaBuilder.MetaToEntry>(1);
MMXMetaBuilder.MetaToEntry entry = new MMXMetaBuilder.MetaToEntry();
entry.setUserId(JIDUtil.getUserId(mmxMessage.getTo()));
entry.setDevId(mmxMessage.getTo().getResource());
badReceivers.add(entry);
}
ServerAckMessageBuilder serverAckMessageBuilder = new ServerAckMessageBuilder(
mmxMessage, appId, ServerAckMessageBuilder.Type.ONE_TIME)
.badReceivers(badReceivers)
.errorCode(badReceiver ? ErrorCode.SEND_MESSAGE_INVALID_RECIPIENT : ErrorCode.NO_ERROR);
Message serverAck = serverAckMessageBuilder.build();
sendSignalMessage(serverAck);
}
示例7: sendEndAckMessageOnce
import org.xmpp.packet.Message; //导入依赖的package包/类
private void sendEndAckMessageOnce(Message mmxMessage, String appId,
boolean badReceiver) {
Counter counter = mMulticastMsgs.get(mmxMessage.getID());
if (counter == null) {
return;
}
if (badReceiver) {
// Batching up the bad receivers.
counter.addBadReceiver(JIDUtil.getUserId(mmxMessage.getTo()),
mmxMessage.getTo().getResource());
}
if (counter.decrementAndGet() == 0) {
// send the end ack for the last recipient and remove the counter.
mMulticastMsgs.remove(mmxMessage.getID());
ServerAckMessageBuilder serverAckMessageBuilder = new ServerAckMessageBuilder(
mmxMessage, appId, ServerAckMessageBuilder.Type.BATCH_END)
.badReceivers(counter.badReceivers)
.errorCode(counter.badReceivers == null || counter.badReceivers.isEmpty() ?
ErrorCode.NO_ERROR : ErrorCode.SEND_MESSAGE_INVALID_RECIPIENT);
Message serverAck = serverAckMessageBuilder.build();
sendSignalMessage(serverAck);
}
}
示例8: sendSignalMessage
import org.xmpp.packet.Message; //导入依赖的package包/类
/**
* Send the signal message asynchronously.
*
* @param signalMessage
*/
protected void sendSignalMessage(final Message signalMessage) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Sending signal message:{}", signalMessage);
}
ExecutorService service = MMXExecutors.getOrCreate(SERVER_ACK_SENDER_POOL,
10);
service.submit(new Runnable() {
@Override
public void run() {
PacketRouter router = XMPPServer.getInstance().getPacketRouter();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Sending signal message:{}", signalMessage);
}
router.route(signalMessage);
}
});
}
示例9: routeGeoEvent
import org.xmpp.packet.Message; //导入依赖的package包/类
public void routeGeoEvent(final IQ geoIQ) {
if (componentJids.isEmpty()) {
// nothing to do
LOGGER.debug("no external component registered for geo event");
return;
}
String geoService = selectGeoService();
if (geoService != null && geoService.length() > 0) {
Message geoMessage = buildGeoMessageFromPubSubIQ(geoIQ);
if (geoMessage != null) {
geoMessage.setTo(geoService);
// TODO create a new message ID?
geoMessage.setID(geoIQ.getID());
LOGGER.debug("Sending geo event to external component: " + geoService);
// start attaching the pieces
PacketRouter router = XMPPServer.getInstance().getPacketRouter();
router.route(geoMessage);
}
}
}
示例10: isPubSubMessage
import org.xmpp.packet.Message; //导入依赖的package包/类
public static boolean isPubSubMessage(Message message) {
if (message == null) {
return false;
}
final String namespace = "http://jabber.org/protocol/pubsub#event";
final String event = "event";
final String items = "items";
PacketExtension extension = message.getExtension(event, namespace);
if (extension != null) {
Element eventElement = extension.getElement();
if (eventElement != null) {
Element itemElement = eventElement.element(items);
if (itemElement != null) {
return true;
}
}
} else {
return false;
}
return false;
}
示例11: processRPSLSInvitationMessage
import org.xmpp.packet.Message; //导入依赖的package包/类
/**
* Process the RPSLS invitation message.
* @param sourceFrom
* @param sourceTo
* @param gameInfo
*/
protected void processRPSLSInvitationMessage(final JID sourceFrom, final JID sourceTo, final RPSLSGameInfo gameInfo) {
//first build the acceptance message
LOGGER.debug("Building acceptance message");
Message acceptance = buildAcceptanceMessage(sourceFrom, sourceTo, gameInfo);
LOGGER.info("Sending the RPSLS acceptance message {}", acceptance);
connection.sendPacket(acceptance);
ExecutorService executor = MMXExecutors.getOrCreate(RPSLS_BOT_POOL_NAME, 5);
executor.execute(new Runnable() {
@Override
public void run() {
//sleep for two seconds and then send the message.
try {
//sleep for 2 seconds and then send the message
Thread.sleep(2000L);
} catch (InterruptedException e) {
LOGGER.debug("Interrupted exception", e);
} finally {
}
Message choiceMessage = buildChoiceMessage(sourceFrom, sourceTo, gameInfo);
LOGGER.debug("Sending choice message:{}", choiceMessage);
connection.sendPacket(choiceMessage);
}
});
}
示例12: testFilterMessageBodyWithMask
import org.xmpp.packet.Message; //导入依赖的package包/类
public void testFilterMessageBodyWithMask() {
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
// test message
Message message = new Message();
message.setBody("the quick brown fox jumped over the lazy dog");
boolean matched = filter.filter(message);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("the quick brown ** jumped over the lazy **", message
.getBody());
assertNull(message.getSubject());
}
示例13: messageReceived
import org.xmpp.packet.Message; //导入依赖的package包/类
public void messageReceived(Session arg0, net.sf.jml.net.Message message) throws Exception {
Log.debug("MSN: Session messageReceived for "+getSession().getRegistration().getUsername()+" : "+message);
// TODO: Kinda hacky, would like to improve on this later.
if (message.toString().startsWith("OUT OTH")) {
// Forced disconnect because account logged in elsewhere
getSession().setLoginStatus(TransportLoginStatus.DISCONNECTED);
getSession().setFailureStatus(ConnectionFailureReason.LOCKED_OUT);
getSession().sessionDisconnectedNoReconnect(LocaleUtils.getLocalizedString("gateway.msn.otherloggedin", "kraken"));
}
else if (message.toString().startsWith("OUT SDH")) {
// Forced disconnect from server for maintenance
getSession().setLoginStatus(TransportLoginStatus.DISCONNECTED);
getSession().setFailureStatus(ConnectionFailureReason.LOCKED_OUT);
getSession().sessionDisconnectedNoReconnect(LocaleUtils.getLocalizedString("gateway.msn.disconnect", "kraken"));
}
}
示例14: changeSubject
import org.xmpp.packet.Message; //导入依赖的package包/类
@Override
public void changeSubject(Message packet, MUCRole role) throws ForbiddenException {
if ((canOccupantsChangeSubject() && role.getRole().compareTo(MUCRole.Role.visitor) < 0) ||
MUCRole.Role.moderator == role.getRole()) {
// Set the new subject to the room
subject = packet.getSubject();
MUCPersistenceManager.updateRoomSubject(this);
// Notify all the occupants that the subject has changed
packet.setFrom(role.getRoleAddress());
send(packet);
// Fire event signifying that the room's subject has changed.
MUCEventDispatcher.roomSubjectChanged(getJID(), role.getUserAddress(), subject);
// Let other cluster nodes that the room has been updated
CacheFactory.doClusterTask(new RoomUpdatedEvent(this));
}
else {
throw new ForbiddenException();
}
}
示例15: sendInvitationRejection
import org.xmpp.packet.Message; //导入依赖的package包/类
@Override
public void sendInvitationRejection(JID to, String reason, JID sender) {
if (((MultiUserChatServiceImpl)mucService).getMUCDelegate() != null) {
switch(((MultiUserChatServiceImpl)mucService).getMUCDelegate().sendingInvitationRejection(this, to, sender, reason)) {
case HANDLED_BY_DELEGATE:
//if the delegate is taking care of it, there's nothing for us to do
return;
case HANDLED_BY_OPENFIRE:
//continue as normal if we're asked to handle it
break;
}
}
Message message = new Message();
message.setFrom(role.getRoleAddress());
message.setTo(to);
Element frag = message.addChildElement("x", "http://jabber.org/protocol/muc#user");
frag.addElement("decline").addAttribute("from", sender.toBareJID());
if (reason != null && reason.length() > 0) {
frag.element("decline").addElement("reason").setText(reason);
}
// Send the message with the invitation
router.route(message);
}