本文整理汇总了Java中org.xmpp.packet.Message.setTo方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setTo方法的具体用法?Java Message.setTo怎么用?Java Message.setTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Message
的用法示例。
在下文中一共展示了Message.setTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例3: sessionCreated
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void sessionCreated(Session session) {
if (isEnabled()) {
final Message message = new Message();
message.setTo(session.getAddress());
message.setFrom(serverAddress);
message.setSubject(getSubject());
message.setBody(getMessage());
TimerTask messageTask = new TimerTask() {
@Override
public void run() {
router.route(message);
}
};
TaskEngine.getInstance().schedule(messageTask, 5000);
}
}
示例4: notifyQueueDepartued
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void notifyQueueDepartued(JID sender, JID receiver, UserRequest request,
Request.CancelType type) {
// Get the chatbot session of the user
ChatbotSession session = getSession(receiver, false);
if (session != null) {
Message packet = new Message();
packet.setTo(receiver);
packet.setFrom(sender);
packet.setThread(session.getMessageThread());
if (session.getMessageThread() != null) {
packet.setType(Message.Type.chat);
}
packet.setBody(getDepartureConfirmedMessage());
send(packet);
// Remove the session of this user
removeSession(receiver);
}
}
示例5: MSNSession
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Create a MSN Session instance.
*
* @param registration Registration information used for logging in.
* @param jid JID associated with this session.
* @param transport Transport instance associated with this session.
* @param priority Priority of this session.
*/
public MSNSession(Registration registration, JID jid, MSNTransport transport, Integer priority) {
super(registration, jid, transport, priority);
setSupportedFeature(SupportedFeature.chatstates);
setSupportedFeature(SupportedFeature.attention);
if (Email.parseStr(registration.getUsername()) == null) {
Message m = new Message();
m.setType(Message.Type.error);
m.setTo(getJID());
m.setFrom(getTransport().getJID());
m.setBody(LocaleUtils.getLocalizedString("gateway.msn.illegalaccount", "kraken")+" "+registration.getUsername());
getTransport().sendPacket(m);
// TODO: this should probably be generic and done within base transport for -all- transports
// TODO: Also, this Email.parseStr could be used in the "is this a valid username" check
}
}
示例6: notifyQueueStatus
import org.xmpp.packet.Message; //导入方法依赖的package包/类
public void notifyQueueStatus(JID sender, JID receiver, UserRequest request, boolean isPolling) {
// Get the chatbot session of the user
ChatbotSession session = getSession(receiver, false);
if (session != null) {
Message packet = new Message();
packet.setTo(receiver);
packet.setFrom(sender);
packet.setThread(session.getMessageThread());
if (session.getMessageThread() != null) {
packet.setType(Message.Type.chat);
}
String body = getPositionMessage().replace("${position}",
String.valueOf(request.getPosition() + 1));
body = body.replace("${waitTime}", String.valueOf(request.getTimeStatus()));
packet.setBody(body);
send(packet);
}
}
示例7: testNamespaceOnStanzaWithNamespace
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Verifies that the default namespace is not set on stanzas that already have defined a default namespace.
*
* @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
*/
@Test
public void testNamespaceOnStanzaWithNamespace() throws Exception
{
// Setup fixture
final Message message = new Message();
message.getElement().setQName( QName.get( "message", "unit:test:preexisting:namespace" ) );
message.setTo( "[email protected]/test" );
message.addChildElement( "unittest", "unit:test:namespace" );
final List<Packet> packets = new ArrayList<>();
packets.add( message );
// Execute system under test
final HttpSession.Deliverable deliverable = new HttpSession.Deliverable( packets );
final String result = deliverable.getDeliverable();
// verify results
// Note that this assertion depends on the Openfire XML parser-specific ordering of attributes.
assertEquals( "<message xmlns=\"unit:test:preexisting:namespace\" to=\"[email protected]/test\"><unittest xmlns=\"unit:test:namespace\"/></message>", result );
}
示例8: sendErrorMessage
import org.xmpp.packet.Message; //导入方法依赖的package包/类
private void sendErrorMessage(String body) {
// Invitation request has failed. Inform inviter
userRequest.removeRelatedRequest(this);
Message message = new Message();
message.setError(PacketError.Condition.recipient_unavailable);
message.setTo(inviter);
message.setFrom(workgroup.getJID());
message.setBody(body);
Element element = message.addChildElement("transfer", "http://jabber.org/protocol/workgroup");
element.addAttribute("type", type.toString());
Element sessionElement = element.addElement("session", "http://jivesoftware.com/protocol/workgroup");
sessionElement.addAttribute("id", sessionID);
element.addElement("inviter").setText(inviter.toString());
element.addElement("invitee").setText(invitee.toString());
workgroup.send(message);
}
示例9: main
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* @param args
* @throws EvalError
*/
public static void main(String[] args) throws EvalError {
Message message = new Message();
message.setTo("[email protected]");
message.setFrom("mim.snda");
message.setBody("asdfqwerqwer阿斯顿发达");
Interpreter i = new Interpreter(); // Construct an interpreter
long start = TimeUtil.currentTimeMillis();
for (int j = 0; j < 100; j++) {
i.set("message", message); // Set variables
System.out.println(i.eval("message.to.node"));
i.unset("message");
}
System.out.println((TimeUtil.currentTimeMillis() - start) + "ms");
}
示例10: testDropInvalidResponseType
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Test that if (e.g.) an IQ is sent, then an IQ must be returned as a
* response. If a Message is returned instead, this should invoke an error
* callback.
*/
public void testDropInvalidResponseType() throws Exception {
IQ packet = server1.manager.createRequestIQ(server2.jid);
// Disable routing so we can intercept the packet.
server1.transport.router = null;
PacketCallback callback = mock(PacketCallback.class);
server1.manager.send(packet, callback, PACKET_TIMEOUT);
// Generate an explicit Message receipt.
Message response = new Message();
response.setTo(packet.getFrom());
response.setID(packet.getID());
response.setFrom(packet.getTo());
response.addChildElement("received", XmppNamespace.NAMESPACE_XMPP_RECEIPTS);
server1.manager.receivePacket(response);
// Confirm that an error callback is invoked.
ArgumentCaptor<FederationError> returnedError = ArgumentCaptor.forClass(FederationError.class);
verify(callback).error(returnedError.capture());
verify(callback, never()).run(any(Packet.class));
assertEquals(FederationError.Code.UNDEFINED_CONDITION, returnedError.getValue().getErrorCode());
// Confirm that sending a correct response now does nothing.
reset(callback);
IQ correctResponse = IQ.createResultIQ(packet);
server1.manager.receivePacket(correctResponse);
verifyZeroInteractions(callback);
}
示例11: build
import org.xmpp.packet.Message; //导入方法依赖的package包/类
/**
* Build an XMPP error message with MMX extension.
* @return
*/
public Message build() {
Message errorMsg = new Message();
String appId = JIDUtil.getAppId(mOrigMsg.getFrom());
errorMsg.setType(Type.error);
errorMsg.setTo(mOrigMsg.getFrom());
errorMsg.setFrom(appId + "%" + appId + "@" + XMPPServer.getInstance().getServerInfo().getXMPPDomain());
errorMsg.setID(mOrigMsg.getID());
errorMsg.addExtension(new MMXPacketExtension(mHeaders, mPayload));
return errorMsg;
}
示例12: build
import org.xmpp.packet.Message; //导入方法依赖的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;
}
示例13: 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);
}
示例14: buildDeliveryReceipt
import org.xmpp.packet.Message; //导入方法依赖的package包/类
protected Message buildDeliveryReceipt(String appId, String incomingMessageFromJID, String incomingMessageToJID,
String incomingMessageId) {
MessageIdGenerator generator = new MessageIdGeneratorImpl();
String id = generator.generate(incomingMessageFromJID, appId, null);
Message receipt = new Message();
receipt.setID(id);
receipt.setFrom(incomingMessageToJID);
receipt.setTo(incomingMessageFromJID);
Element received = receipt.addChildElement(Constants.XMPP_RECEIVED, Constants.XMPP_NS_RECEIPTS);
received.addAttribute(Constants.XMPP_ATTR_ID, incomingMessageId);
return receipt;
}
示例15: testDistribute1
import org.xmpp.packet.Message; //导入方法依赖的package包/类
@Test
public void testDistribute1() throws InterruptedException {
MessageDistributor distributor = new StubMessageDistributorImpl();
Message message = new Message();
message.setBody("body");
message.setSubject("subject");
String toNode1 = "magnet.way";
String fromNode = "thomas";
String appKey = "AAABSNIBKOstQST7";
String host = "mmx.magnet.com";
String resource = "device1";
message.setTo(new JID(toNode1 + JIDUtil.APP_ID_DELIMITER + appKey, host, resource));
message.setFrom(new JID(fromNode + JIDUtil.APP_ID_DELIMITER + appKey, host, resource));
MessageDistributor.DistributionContext context = new DistributionContextImpl(toNode1, appKey, host, resource);
PacketRouter router = new CountingPacketRouter();
MMXPresenceFinder finder = new AlwaysOnlinePresenceFinder();
((StubMessageDistributorImpl) distributor).setPacketRouter(router);
((StubMessageDistributorImpl) distributor).setPresenceFinder(finder);
MessageDistributor.DistributionResult result = distributor.distribute(message, context);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println("testDistribute1 thread is interrupted");
}
CountingPacketRouter countingPacketRouter = (CountingPacketRouter) router;
assertEquals("Non matching message packet count", 4, countingPacketRouter.messageCount.get());
assertFalse("User has devices but we are reporting he doesn't", result.noDevices());
}