本文整理汇总了Java中org.jivesoftware.smack.packet.Stanza类的典型用法代码示例。如果您正苦于以下问题:Java Stanza类的具体用法?Java Stanza怎么用?Java Stanza使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Stanza类属于org.jivesoftware.smack.packet包,在下文中一共展示了Stanza类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accept
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
public boolean accept(Stanza packet) {
// sender equals remote peer
if (!packet.getFrom().equalsIgnoreCase(remoteJID)) {
return false;
}
DataPacketExtension data;
if (packet instanceof Data) {
data = ((Data) packet).getDataPacketExtension();
} else {
// stanza contains data packet extension
data = packet.getExtension(
DataPacketExtension.ELEMENT,
DataPacketExtension.NAMESPACE);
if (data == null) {
return false;
}
}
// session ID equals this session ID
if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) {
return false;
}
return true;
}
示例2: processReceived
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
void processReceived(String fromJid, String toJid, String receiptId, Stanza receipt) {
JobExecutor.getInstance().execute(() -> {
MessageModel messageModel = daoSession.getMessageModelDao()
.queryBuilder()
.where(MessageModelDao.Properties.MessageId.eq(receiptId))
.unique();
QueryBuilder<MessageModel> builder = daoSession.getMessageModelDao()
.queryBuilder();
List<MessageModel> messages = builder.where(
builder.and(MessageModelDao.Properties.DateSent.le(messageModel.getDateSent()),
MessageModelDao.Properties.ChatDialogId.eq(messageModel.getChatDialogId()),
MessageModelDao.Properties.SenderId.eq(CurrentUser.getInstance().getCurrentUserId().intValue()),
MessageModelDao.Properties.Read.eq(MessageState.DEFAULT)))
.list();
for (MessageModel message : messages) {
message.setRead(MessageState.DELIVERED);
}
EventBus.getDefault().post(new ReceivedEvent(messages));
daoSession.getMessageModelDao().updateInTx(messages);
});
}
示例3: processDisplayed
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
void processDisplayed(String fromJid, String toJid, String receiptId, Stanza receipt) {
JobExecutor.getInstance().execute(() -> {
MessageModel messageModel = daoSession.getMessageModelDao()
.queryBuilder()
.where(MessageModelDao.Properties.MessageId.eq(receiptId))
.unique();
QueryBuilder<MessageModel> builder = daoSession.getMessageModelDao()
.queryBuilder();
List<MessageModel> messages = builder.where(
builder.and(MessageModelDao.Properties.DateSent.le(messageModel.getDateSent()),
MessageModelDao.Properties.ChatDialogId.eq(messageModel.getChatDialogId()),
MessageModelDao.Properties.SenderId.eq(CurrentUser.getInstance().getCurrentUserId().intValue()),
MessageModelDao.Properties.Read.notEq(MessageState.READ)))
.list();
for (MessageModel message : messages) {
message.setRead(MessageState.READ);
}
EventBus.getDefault().post(new DisplayedEvent(messages));
daoSession.getMessageModelDao().updateInTx(messages);
});
}
示例4: parse
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Override
public Transcript parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
String sessionID = parser.getAttributeValue("", "sessionID");
List<Stanza> packets = new ArrayList<Stanza>();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("message")) {
packets.add(PacketParserUtils.parseMessage(parser));
}
else if (parser.getName().equals("presence")) {
packets.add(PacketParserUtils.parsePresence(parser));
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("transcript")) {
done = true;
}
}
}
return new Transcript(sessionID, packets);
}
示例5: processPacket
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Override
public void processPacket(Stanza packet) throws NotConnectedException {
try {
if (packet instanceof Message) {
Message msg = (Message) packet;
logger.info("Agreement status message received from => {}, body => {}", msg.getFrom(), msg.getBody());
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(new SimpleDateFormat("dd-MM-yyyy HH:mm"));
// Construct message
AgreementStatusMessageImpl message = mapper.readValue(msg.getBody(), AgreementStatusMessageImpl.class);
message.setFrom(msg.getFrom());
if (subscriber != null) {
subscriber.messageReceived(message);
logger.debug("Notified subscriber => {}", subscriber);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
示例6: processPacket
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Override
public void processPacket(Stanza packet) throws NotConnectedException {
try {
if (packet instanceof Message) {
Message msg = (Message) packet;
logger.info("Script result message received from => {}, body => {}", msg.getFrom(), msg.getBody());
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(new SimpleDateFormat("dd-MM-yyyy HH:mm"));
// Construct message
ScriptResultMessageImpl message = mapper.readValue(msg.getBody(), ScriptResultMessageImpl.class);
message.setFrom(msg.getFrom());
if (subscriber != null) {
subscriber.messageReceived(message);
logger.debug("Notified subscriber => {}", subscriber);
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
示例7: bareCompareMatchingServiceJid
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Test
public void bareCompareMatchingServiceJid()
{
FromMatchesFilter filter = FromMatchesFilter.createBare(SERVICE_JID1);
Stanza packet = new Stanza() {
@Override
public String toXML() { return null; }
};
packet.setFrom(SERVICE_JID1);
assertTrue(filter.accept(packet));
packet.setFrom(SERVICE_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID1);
assertFalse(filter.accept(packet));
packet.setFrom(FULL_JID1_R1);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID3);
assertFalse(filter.accept(packet));
}
示例8: multipleMessageBodiesParsingTest
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Test
public void multipleMessageBodiesParsingTest() throws Exception {
String control = XMLBuilder.create("message")
.a("from", "[email protected]/orchard")
.a("to", "[email protected]/balcony")
.a("id", "zid615d9")
.a("type", "chat")
.a("xml:lang", "en")
.e("body")
.t("This is a test of the emergency broadcast system, 1.")
.up()
.e("body")
.a("xml:lang", "ru")
.t("This is a test of the emergency broadcast system, 2.")
.up()
.e("body")
.a("xml:lang", "sp")
.t("This is a test of the emergency broadcast system, 3.")
.asString(outputProperties);
Stanza message = PacketParserUtils.parseStanza(control);
XmlUnitUtils.assertSimilar(control, message.toXML());
}
示例9: checkProvider
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Test
public void checkProvider() throws Exception {
XMLBuilder xml = XMLBuilder.create("iq");
xml.a("from", "[email protected]/orchard")
.a("id", "last2")
.a("to", "[email protected]/balcony")
.a("type", "get")
.e("query")
.namespace(LastActivity.NAMESPACE);
DummyConnection c = new DummyConnection();
c.connect();
IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString());
assertTrue(lastRequest instanceof LastActivity);
c.processPacket(lastRequest);
Stanza reply = c.getSentPacket();
assertTrue(reply instanceof LastActivity);
LastActivity l = (LastActivity) reply;
assertEquals("last2", l.getStanzaId());
assertEquals(IQ.Type.result, l.getType());
}
示例10: addOneTimeSyncCallback
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Override
public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
final StanzaListener packetListener = new StanzaListener() {
@Override
public void processPacket(Stanza packet) throws NotConnectedException {
try {
callback.processPacket(packet);
} finally {
removeSyncStanzaListener(this);
}
}
};
addSyncStanzaListener(packetListener, packetFilter);
removeCallbacksService.schedule(new Runnable() {
@Override
public void run() {
removeSyncStanzaListener(packetListener);
}
}, getPacketReplyTimeout(), TimeUnit.MILLISECONDS);
}
示例11: sendAndWaitForResponse
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
/**
* Send the given top level stream element and wait for a response.
*
* @param request the plain stream element to send.
* @throws NoResponseException if no response was received.
* @throws NotConnectedException if the connection is not connected.
*/
public void sendAndWaitForResponse(TopLevelStreamElement request) throws NoResponseException,
NotConnectedException {
assert (state == State.Initial);
connectionLock.lock();
try {
if (request != null) {
if (request instanceof Stanza) {
connection.sendStanza((Stanza) request);
}
else if (request instanceof PlainStreamElement){
connection.send((PlainStreamElement) request);
} else {
throw new IllegalStateException("Unsupported element type");
}
state = State.RequestSent;
}
waitForConditionOrTimeout();
}
finally {
connectionLock.unlock();
}
checkForResponse();
}
示例12: autoCompareMatchingServiceJid
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Test
public void autoCompareMatchingServiceJid()
{
FromMatchesFilter filter = FromMatchesFilter.create(SERVICE_JID1);
Stanza packet = new Stanza() {
@Override
public String toXML() { return null; }
};
packet.setFrom(SERVICE_JID1);
assertTrue(filter.accept(packet));
packet.setFrom(SERVICE_JID2);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID1);
assertFalse(filter.accept(packet));
packet.setFrom(FULL_JID1_R1);
assertFalse(filter.accept(packet));
packet.setFrom(BASE_JID3);
assertFalse(filter.accept(packet));
}
示例13: accept
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
@Override
public boolean accept(Stanza packet) {
// First filter out everything that is not an IQ stanza and does not have the correct ID set.
if (!iqAndIdFilter.accept(packet))
return false;
// Second, check if the from attributes are correct and log potential IQ spoofing attempts
if (fromFilter.accept(packet)) {
return true;
} else {
String msg = String.format("Rejected potentially spoofed reply to IQ-packet. Filter settings: "
+ "packetId=%s, to=%s, local=%s, server=%s. Received packet with from=%s",
packetId, to, local, server, packet.getFrom());
LOGGER.log(Level.WARNING, msg , packet);
return false;
}
}
示例14: getDataPacketListener
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
protected StanzaListener getDataPacketListener() {
return new StanzaListener() {
public void processPacket(Stanza packet) {
// get data packet extension
DataPacketExtension data = (DataPacketExtension) packet.getExtension(
DataPacketExtension.ELEMENT,
DataPacketExtension.NAMESPACE);
// check if encoded data is valid
if (data.getDecodedData() == null) {
/*
* TODO once a majority of XMPP server implementation support XEP-0079
* Advanced Message Processing the invalid message could be answered with an
* appropriate error. For now we just ignore the packet. Subsequent packets
* with an increased sequence will cause the input stream to close the
* stream/session.
*/
return;
}
// data is valid; add to data queue
dataQueue.offer(data);
// TODO confirm packet once XMPP servers support XEP-0079
}
};
}
示例15: sendStanza
import org.jivesoftware.smack.packet.Stanza; //导入依赖的package包/类
public void sendStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
if (Preferences.isTesting()) {
try {
getXMPPConnection().sendStanza(stanza);
} catch (SmackException.NotConnectedException | InterruptedException e) {
e.printStackTrace();
}
} else {
getXMPPConnection().sendStanza(stanza);
}
}