本文整理了Java中org.jivesoftware.smack.packet.Message.getTo()
方法的一些代码示例,展示了Message.getTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getTo()
方法的具体详情如下:
包路径:org.jivesoftware.smack.packet.Message
类名称:Message
方法名:getTo
暂无
代码示例来源:origin: igniterealtime/Smack
@Override
public void processStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
Message message = (Message) stanza;
if (!shouldAcceptMessage(message)) {
return;
}
final EntityBareJid to = message.getTo().asEntityBareJidOrThrow();
final Chat chat = chatWith(to);
for (OutgoingChatMessageListener listener : outgoingListeners) {
listener.newOutgoingMessage(to, message, chat);
}
}
}, OUTGOING_MESSAGE_FILTER);
代码示例来源:origin: igniterealtime/Smack
@Test
public void checkResultsParse() throws Exception {
Message message = PacketParserUtils.parseStanza(exampleResultMessage);
MamResultExtension mamResultExtension = MamResultExtension.from(message);
Assert.assertEquals(mamResultExtension.getQueryId(), "f27");
Assert.assertEquals(mamResultExtension.getId(), "28482-98726-73623");
GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
Forwarded forwarded = mamResultExtension.getForwarded();
Assert.assertEquals(forwarded.getDelayInformation().getStamp(), date);
Message forwardedMessage = (Message) forwarded.getForwardedStanza();
Assert.assertEquals(forwardedMessage.getFrom().toString(), "witch@shakespeare.lit");
Assert.assertEquals(forwardedMessage.getTo().toString(), "macbeth@shakespeare.lit");
Assert.assertEquals(forwardedMessage.getBody(), "Hail to thee");
}
代码示例来源:origin: igniterealtime/Smack
@Test
public void checkMamResultProvider() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(exampleMamResultXml);
MamResultExtension mamResultExtension = new MamResultProvider().parse(parser);
Assert.assertEquals(mamResultExtension.getQueryId(), "f27");
Assert.assertEquals(mamResultExtension.getId(), "28482-98726-73623");
GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
Forwarded forwarded = mamResultExtension.getForwarded();
Assert.assertEquals(forwarded.getDelayInformation().getStamp(), date);
Message message = (Message) forwarded.getForwardedStanza();
Assert.assertEquals(message.getFrom().toString(), "romeo@montague.lit/orchard");
Assert.assertEquals(message.getTo().toString(), "juliet@capulet.lit/balcony");
Assert.assertEquals(message.getBody(),
"Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.");
}
代码示例来源:origin: igniterealtime/Smack
assertEquals(messageBody, mamMessage.getBody());
assertEquals(conOne.getUser(), mamMessage.getFrom());
assertEquals(userTwo, mamMessage.getTo());
代码示例来源:origin: spring-projects/spring-integration
@Override
protected Map<String, Object> extractStandardHeaders(Message source) {
Map<String, Object> headers = new HashMap<>();
Jid from = source.getFrom();
if (from != null) {
headers.put(XmppHeaders.FROM, from.toString());
}
String subject = source.getSubject();
if (StringUtils.hasText(subject)) {
headers.put(XmppHeaders.SUBJECT, subject);
}
String thread = source.getThread();
if (StringUtils.hasText(thread)) {
headers.put(XmppHeaders.THREAD, thread);
}
Jid to = source.getTo();
if (to != null) {
headers.put(XmppHeaders.TO, to.toString());
}
Message.Type type = source.getType();
if (type != null) {
headers.put(XmppHeaders.TYPE, type);
}
return headers;
}
代码示例来源:origin: spring-projects/spring-integration
@Test //INT-2275
public void testOutboundChannelAdapterInsideChain() throws Exception {
MessageChannel channel = context.getBean("outboundChainChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload("hello").setHeader(XmppHeaders.TO, "artem").build();
XMPPConnection connection = context.getBean("testConnection", XMPPConnection.class);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
assertEquals("artem", xmppMessage.getTo().toString());
assertEquals("hello", xmppMessage.getBody());
return null;
}).when(connection).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
channel.send(message);
verify(connection, times(1)).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
Mockito.reset(connection);
}
代码示例来源:origin: spring-projects/spring-integration
@SuppressWarnings("rawtypes")
@Test
public void withHeaderMapper() throws Exception {
Object pollingConsumer = context.getBean("withHeaderMapper");
assertTrue(pollingConsumer instanceof PollingConsumer);
assertEquals(headerMapper, TestUtils.getPropertyValue(pollingConsumer, "handler.headerMapper"));
MessageChannel channel = context.getBean("outboundEventChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload("hello").setHeader(XmppHeaders.TO, "oleg").
setHeader("foobar", "foobar").build();
XMPPConnection connection = context.getBean("testConnection", XMPPConnection.class);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
assertEquals("oleg", xmppMessage.getTo().toString());
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
return null;
}).when(connection).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
channel.send(message);
verify(connection, times(1)).sendStanza(Mockito.any(org.jivesoftware.smack.packet.Message.class));
Mockito.reset(connection);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testExtensionProvider() throws Exception {
XMPPConnection connection = mock(XMPPConnection.class);
ChatMessageSendingMessageHandler handler = new ChatMessageSendingMessageHandler(connection);
GcmExtensionProvider extensionElementProvider = spy(new GcmExtensionProvider());
handler.setExtensionProvider(extensionElementProvider);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
final String json = "{\"foo\": \"bar\"}";
Message<?> message = MessageBuilder.withPayload(" <f foo='foo'>" + json + "</f> ")
.setHeader(XmppHeaders.TO, "kermit@frog.com")
.build();
handler.handleMessage(message);
ArgumentCaptor<org.jivesoftware.smack.packet.Message> argumentCaptor =
ArgumentCaptor.forClass(org.jivesoftware.smack.packet.Message.class);
verify(connection).sendStanza(argumentCaptor.capture());
org.jivesoftware.smack.packet.Message smackMessage = argumentCaptor.getValue();
assertNull(smackMessage.getBody());
assertEquals("kermit@frog.com", smackMessage.getTo().toString());
GcmPacketExtension gcmPacketExtension = GcmPacketExtension.from(smackMessage);
assertNotNull(gcmPacketExtension);
assertEquals(json, gcmPacketExtension.getJson());
verify(extensionElementProvider).from(eq(json));
}
代码示例来源:origin: spring-projects/spring-integration
.sendStanza(Mockito.argThat((org.jivesoftware.smack.packet.Message smackMessage) -> {
boolean bodyMatches = smackMessage.getBody().equals("Test Message");
boolean toMatches = smackMessage.getTo().equals("kermit@frog.com");
return bodyMatches & toMatches;
}));
.sendStanza(Mockito.argThat((org.jivesoftware.smack.packet.Message smackMessage) -> {
boolean bodyMatches = smackMessage.getBody().equals("Hello Kitty");
boolean toMatches = smackMessage.getTo().equals("kermit@frog.com");
boolean threadIdMatches = smackMessage.getThread().equals("123");
return bodyMatches & toMatches & threadIdMatches;
.sendStanza(Mockito.argThat((org.jivesoftware.smack.packet.Message smackMessage) -> {
boolean bodyMatches = smackMessage.getBody() == null;
boolean toMatches = smackMessage.getTo().equals("kermit@frog.com");
GcmPacketExtension gcmPacketExtension = GcmPacketExtension.from(smackMessage);
boolean jsonMatches = gcmPacketExtension != null && gcmPacketExtension.getJson().equals(json);
代码示例来源:origin: spring-projects/spring-integration
@Test
public void fromHeadersStandardOutbound() {
DefaultXmppHeaderMapper mapper = new DefaultXmppHeaderMapper();
Map<String, Object> headerMap = new HashMap<>();
headerMap.put("userDefined1", "foo");
headerMap.put("userDefined2", "bar");
headerMap.put(XmppHeaders.THREAD, "test.thread");
headerMap.put(XmppHeaders.TO, "test.to");
headerMap.put(XmppHeaders.FROM, "test.from");
headerMap.put(XmppHeaders.SUBJECT, "test.subject");
headerMap.put(XmppHeaders.TYPE, "headline");
MessageHeaders headers = new MessageHeaders(headerMap);
Message target = new Message();
mapper.fromHeadersToRequest(headers, target);
// "standard" XMPP headers
assertEquals("test.thread", target.getThread());
assertEquals("test.to", target.getTo().toString());
assertEquals("test.from", target.getFrom().toString());
assertEquals("test.subject", target.getSubject());
assertEquals(Message.Type.headline, target.getType());
// user-defined headers not included by default
assertNull(JivePropertiesManager.getProperty(target, "userDefined1"));
assertNull(JivePropertiesManager.getProperty(target, "userDefined2"));
// transient headers should not be copied
assertNull(JivePropertiesManager.getProperty(target, "id"));
assertNull(JivePropertiesManager.getProperty(target, "timestamp"));
}
代码示例来源:origin: spring-projects/spring-integration
assertNull(target.getTo());
assertNull(target.getFrom());
assertNull(target.getSubject());
代码示例来源:origin: spring-projects/spring-ws
/**
* Converts the given XMPP destination into a {@code xmpp} URI.
*/
public static URI toUri(Message requestMessage) throws URISyntaxException {
return new URI(XmppTransportConstants.XMPP_URI_SCHEME,
requestMessage.getTo().asUnescapedString(), null);
}
代码示例来源:origin: org.springframework.ws/spring-ws-support
/**
* Converts the given XMPP destination into a {@code xmpp} URI.
*/
public static URI toUri(Message requestMessage) throws URISyntaxException {
return new URI(XmppTransportConstants.XMPP_URI_SCHEME,
requestMessage.getTo().asUnescapedString(), null);
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Converts the given XMPP destination into a {@code xmpp} URI.
*/
public static URI toUri(Message requestMessage) throws URISyntaxException {
return new URI(XmppTransportConstants.XMPP_URI_SCHEME,
requestMessage.getTo().asUnescapedString(), null);
}
代码示例来源:origin: igniterealtime/Spark
public void fireOutgoingMessageSending( Message message )
{
for ( final MessageEventListener listener : messageEventListeners )
{
try
{
listener.sendingMessage( message );
}
catch ( Exception e )
{
Log.error( "A MessageEventListener ('" + listener + "') threw an exception while processing an outgoing message (to '" + message.getTo() + "').", e );
}
}
}
代码示例来源:origin: igniterealtime/Spark
/**
* Notifies all <code>GlobalMessageListeners</code> of a new message sent.
*
* @param chatRoom the <code>ChatRoom</code> where the message was sent from.
* @param message the <code>Message</code> sent.
*/
public void fireGlobalMessageSentListeners( ChatRoom chatRoom, Message message )
{
for ( GlobalMessageListener listener : globalMessageListeners )
{
try
{
listener.messageSent( chatRoom, message );
}
catch ( Exception e )
{
Log.error( "A GlobalMessageListener ('" + listener + "') threw an exception while processing an outgoing chat message (to '" + message.getTo() + "') in a chat room ('" + chatRoom + "').", e );
}
}
}
代码示例来源:origin: spring-projects/spring-integration-extensions
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
assertEquals("artem", xmppMessage.getTo());
assertEquals("hello", xmppMessage.getBody());
return null;
}
代码示例来源:origin: spring-projects/spring-integration-extensions
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
org.jivesoftware.smack.packet.Message xmppMessage = (org.jivesoftware.smack.packet.Message) args[0];
assertEquals("oleg", xmppMessage.getTo());
assertEquals("foobar", JivePropertiesManager.getProperty(xmppMessage, "foobar"));
return null;
}
})
代码示例来源:origin: org.mobicents.resources/mobicents-slee-ra-xmpp-library
private void sendCancelMessage(Message message) {
IQ error = FileTransferNegotiator.createIQ(message.getPacketID(), message.getFrom(), message.getTo(),
IQ.Type.ERROR);
error.setError(new XMPPError(504));
connection.sendPacket(error);
}
代码示例来源:origin: igniterealtime/Spark
private void checkEvents(Jid from, String packetID, MessageEvent messageEvent) {
if (messageEvent.isDelivered() || messageEvent.isDisplayed()) {
// Create the message to send
Message msg = new Message(from);
// Create a MessageEvent Package and add it to the message
MessageEvent event = new MessageEvent();
if (messageEvent.isDelivered()) {
event.setDelivered(true);
}
if (messageEvent.isDisplayed()) {
event.setDisplayed(true);
}
event.setStanzaId(packetID);
msg.addExtension(event);
// Send the packet
try
{
SparkManager.getConnection().sendStanza(msg);
}
catch ( SmackException.NotConnectedException | InterruptedException e )
{
Log.warning( "Unable to send message to " + msg.getTo(), e );
}
}
}
内容来源于网络,如有侵权,请联系作者删除!