本文整理了Java中org.jivesoftware.smack.packet.Message.setFrom()
方法的一些代码示例,展示了Message.setFrom()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setFrom()
方法的具体详情如下:
包路径:org.jivesoftware.smack.packet.Message
类名称:Message
方法名:setFrom
暂无
代码示例来源:origin: igniterealtime/Smack
private static Message createChatPacket(final String threadId, final boolean isEntityFullJid) {
Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat);
chatMsg.setBody("the body message - " + System.currentTimeMillis());
Jid jid;
if (isEntityFullJid) {
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
} else {
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
}
chatMsg.setFrom(jid);
chatMsg.setThread(threadId);
return chatMsg;
}
代码示例来源:origin: igniterealtime/Smack
message.setStanzaId(parser.getAttributeValue("", "id"));
message.setTo(ParserUtils.getJidAttribute(parser, "to"));
message.setFrom(ParserUtils.getJidAttribute(parser, "from"));
String typeString = parser.getAttributeValue("", "type");
if (typeString != null) {
代码示例来源:origin: igniterealtime/Smack
/**
* Send a ratchet update message. This can be used to advance the ratchet of a session in order to maintain forward
* secrecy.
*
* @param recipient recipient
* @throws CorruptedOmemoKeyException When the used identityKeys are corrupted
* @throws CryptoFailedException When something fails with the crypto
* @throws CannotEstablishOmemoSessionException When we can't establish a session with the recipient
* @throws SmackException.NotLoggedInException
* @throws InterruptedException
* @throws SmackException.NoResponseException
* @throws NoSuchAlgorithmException
* @throws SmackException.NotConnectedException
*/
public void sendRatchetUpdateMessage(OmemoDevice recipient)
throws SmackException.NotLoggedInException, CorruptedOmemoKeyException, InterruptedException,
SmackException.NoResponseException, NoSuchAlgorithmException, SmackException.NotConnectedException,
CryptoFailedException, CannotEstablishOmemoSessionException {
synchronized (LOCK) {
Message message = new Message();
message.setFrom(getOwnJid());
message.setTo(recipient.getJid());
OmemoElement element = getOmemoService()
.createRatchetUpdateElement(new LoggedInOmemoManager(this), recipient);
message.addExtension(element);
// Set MAM Storage hint
StoreHint.set(message);
connection().sendStanza(message);
}
}
代码示例来源:origin: igniterealtime/Smack
@Test
public void receiptManagerListenerTest() throws Exception {
DummyConnection c = new DummyConnection();
c.connect();
DeliveryReceiptManager drm = DeliveryReceiptManager.getInstanceFor(c);
TestReceiptReceivedListener rrl = new TestReceiptReceivedListener();
drm.addReceiptReceivedListener(rrl);
Message m = new Message(JidCreate.from("romeo@montague.com"), Message.Type.normal);
m.setFrom(JidCreate.from("julia@capulet.com"));
m.setStanzaId("reply-id");
m.addExtension(new DeliveryReceipt("original-test-id"));
c.processStanza(m);
rrl.waitUntilInvocationOrTimeout();
}
代码示例来源:origin: igniterealtime/Smack
@Test
public void checkMamQueryResults() throws Exception {
Message message = new Message();
message.setStanzaId("iasd207");
message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
DelayInformation delay = new DelayInformation(date);
Message forwardedMessage = new Message();
forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
forwardedMessage.setType(Type.chat);
forwardedMessage.setBody("Thrice the brinded cat hath mew.");
Forwarded forwarded = new Forwarded(delay, forwardedMessage);
message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded));
// FIXME: The order of assertEquals is reversed, fix it by switching it.
Assert.assertEquals(message.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), mamQueryResultExample);
MamResultExtension mamResultExtension = MamResultExtension.from(message);
Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620");
Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date);
Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza();
Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
Assert.assertEquals(resultMessage.getType(), Type.chat);
Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew.");
}
代码示例来源:origin: igniterealtime/Smack
@Test
public void receiptManagerAutoReplyTest() throws Exception {
DummyConnection c = new DummyConnection();
c.connect();
DeliveryReceiptManager drm = DeliveryReceiptManager.getInstanceFor(c);
drm.setAutoReceiptMode(AutoReceiptMode.always);
assertEquals(AutoReceiptMode.always, drm.getAutoReceiptMode());
// test auto-receipts
Message m = new Message(JidCreate.from("julia@capulet.com"), Message.Type.normal);
m.setFrom(JidCreate.from("romeo@montague.com"));
m.setStanzaId("test-receipt-request");
DeliveryReceiptRequest.addTo(m);
// the DRM will send a reply-packet
c.processStanza(m);
Stanza reply = c.getSentPacket();
DeliveryReceipt r = DeliveryReceipt.from((Message) reply);
assertThat("romeo@montague.com", equalsCharSequence(reply.getTo()));
assertEquals("test-receipt-request", r.getId());
}
}
代码示例来源:origin: spring-projects/spring-integration
if (StringUtils.hasText(from)) {
try {
target.setFrom(JidCreate.from(from));
代码示例来源:origin: spring-projects/spring-integration
@Test
public void toHeadersStandardOnly() throws XmppStringprepException {
DefaultXmppHeaderMapper mapper = new DefaultXmppHeaderMapper();
Message source = new Message(JidCreate.from("test.to"), Message.Type.headline);
source.setFrom(JidCreate.from("test.from"));
source.setSubject("test.subject");
source.setThread("test.thread");
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
Map<String, Object> headers = mapper.toHeadersFromRequest(source);
assertEquals("test.to", headers.get(XmppHeaders.TO).toString());
assertEquals("test.from", headers.get(XmppHeaders.FROM).toString());
assertEquals("test.subject", headers.get(XmppHeaders.SUBJECT));
assertEquals("test.thread", headers.get(XmppHeaders.THREAD));
assertEquals(Message.Type.headline, headers.get(XmppHeaders.TYPE));
assertNull(headers.get("userDefined1"));
assertNull(headers.get("userDefined2"));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void toHeadersUserDefinedOnly() throws XmppStringprepException {
DefaultXmppHeaderMapper mapper = new DefaultXmppHeaderMapper();
mapper.setReplyHeaderNames("userDefined*");
Message source = new Message(JidCreate.from("test.to"), Message.Type.headline);
source.setFrom(JidCreate.from("test.from"));
source.setSubject("test.subject");
source.setThread("test.thread");
JivePropertiesManager.addProperty(source, "userDefined1", "foo");
JivePropertiesManager.addProperty(source, "userDefined2", "bar");
Map<String, Object> headers = mapper.toHeadersFromReply(source);
assertNull(headers.get(XmppHeaders.TO));
assertNull(headers.get(XmppHeaders.FROM));
assertNull(headers.get(XmppHeaders.SUBJECT));
assertNull(headers.get(XmppHeaders.THREAD));
assertNull(headers.get(XmppHeaders.TYPE));
assertEquals("foo", headers.get("userDefined1"));
assertEquals("bar", headers.get("userDefined2"));
}
代码示例来源:origin: org.springframework.ws/spring-ws-support
@Override
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
requestMessage.setFrom(connection.getUser());
try {
connection.sendStanza(requestMessage);
} catch (SmackException.NotConnectedException e) {
throw new IOException(e);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
代码示例来源:origin: spring-projects/spring-ws
@Override
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
requestMessage.setFrom(connection.getUser());
try {
connection.sendStanza(requestMessage);
} catch (SmackException.NotConnectedException e) {
throw new IOException(e);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
代码示例来源:origin: apache/servicemix-bundles
@Override
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
requestMessage.setFrom(connection.getUser());
try {
connection.sendStanza(requestMessage);
} catch (SmackException.NotConnectedException e) {
throw new IOException(e);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
代码示例来源:origin: org.igniterealtime.smack/smack
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);
}
代码示例来源:origin: tiandawu/IotXmpp
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);
}
代码示例来源:origin: org.littleshoot/smack-xmpp-3-2-2
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);
}
代码示例来源:origin: igniterealtime/Spark
/**
* Adds a new message to the transcript history.
*
* @param to who the message is to.
* @param from who the message was from.
* @param body the body of the message.
* @param date when the message was received.
*/
public void addToTranscript(String to, String from, String body, Date date) {
final Message newMessage = new Message();
newMessage.setTo(to);
newMessage.setFrom(from);
newMessage.setBody(body);
final Map<String, Object> properties = new HashMap<>();
properties.put( "date", new Date() );
newMessage.addExtension( new JivePropertiesExtension( properties ) );
transcript.add(newMessage);
}
代码示例来源:origin: loldevs/riotapi
public void sendToUser(String to, String message) throws Exception {
Message packet = new Message(to);
packet.setBody(message);
packet.setType(Message.Type.chat);
packet.setFrom(getUser().split("/")[0]);
sendPacket(packet);
}
代码示例来源:origin: spring-projects/spring-ws
@Override
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
responseMessage = new Message(requestMessage.getFrom(), Message.Type.chat);
responseMessage.setFrom(connection.getUser());
responseMessage.setThread(requestMessage.getThread());
}
代码示例来源:origin: org.springframework.ws/spring-ws-support
@Override
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
responseMessage = new Message(requestMessage.getFrom(), Message.Type.chat);
responseMessage.setFrom(connection.getUser());
responseMessage.setThread(requestMessage.getThread());
}
代码示例来源:origin: apache/servicemix-bundles
@Override
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
responseMessage = new Message(requestMessage.getFrom(), Message.Type.chat);
responseMessage.setFrom(connection.getUser());
responseMessage.setThread(requestMessage.getThread());
}
内容来源于网络,如有侵权,请联系作者删除!