本文整理匯總了Java中org.jivesoftware.smack.packet.IQ.getStanzaId方法的典型用法代碼示例。如果您正苦於以下問題:Java IQ.getStanzaId方法的具體用法?Java IQ.getStanzaId怎麽用?Java IQ.getStanzaId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.IQ
的用法示例。
在下文中一共展示了IQ.getStanzaId方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: IQReplyFilter
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Filters for packets which are a valid reply to an IQ request.
* <p>
* Such a stanza(/packet) must have the same stanza(/packet) id and must be an IQ stanza(/packet) of type
* <code>RESULT</code> or <code>ERROR</code>. Moreover, it is necessary to check
* the <code>from</code> address to ignore forged replies.
* <p>
* We accept a <code>from</code> address if one of the following is true:
* <ul>
* <li>It matches the <code>to</code> address of the request.
* <li>The <code>to</code> address of the request was empty and the
* <code>from</code> address matches either the bare jid of the server or the
* (bare or full jid) of the client.
* <li>To <code>to</code> was our bare address and the <code>from</code> is empty.
* </ul>
* <p>
* For a discussion of the issues, see the thread "Spoofing of iq ids and
* misbehaving servers" from 2014-01 on the [email protected] mailing list
* and following discussion in February and March.
*
* @param iqPacket An IQ request. Filter for replies to this packet.
*/
public IQReplyFilter(IQ iqPacket, XMPPConnection conn) {
if (!iqPacket.isRequestIQ()) {
throw new IllegalArgumentException("IQ must be a request IQ, i.e. of type 'get' or 'set'.");
}
if (iqPacket.getTo() != null) {
to = iqPacket.getTo().toLowerCase(Locale.US);
} else {
to = null;
}
final String localJid = conn.getUser();
if (localJid == null) {
throw new IllegalArgumentException("Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once");
}
local = localJid.toLowerCase(Locale.US);
server = conn.getServiceName().toLowerCase(Locale.US);
packetId = iqPacket.getStanzaId();
StanzaFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
StanzaFilter idFilter = new StanzaIdFilter(iqPacket);
iqAndIdFilter = new AndFilter(iqFilter, idFilter);
fromFilter = new OrFilter();
fromFilter.addFilter(FromMatchesFilter.createFull(to));
if (to == null) {
fromFilter.addFilter(FromMatchesFilter.createBare(local));
fromFilter.addFilter(FromMatchesFilter.createFull(server));
}
else if (to.equals(XmppStringUtils.parseBareJid(local))) {
fromFilter.addFilter(FromMatchesFilter.createFull(null));
}
}
示例2: testInvalidNamespace
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Check that the server responds a 503 error code when the client sends an IQ stanza(/packet) with an
* invalid namespace.
*/
public void testInvalidNamespace() {
IQ iq = new IQ() {
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:anything\">");
buf.append("</query>");
return buf.toString();
}
};
PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()),
new StanzaTypeFilter(IQ.class));
PacketCollector collector = getConnection(0).createPacketCollector(filter);
// Send the iq packet with an invalid namespace
getConnection(0).sendStanza(iq);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
fail("No response from server");
}
else if (result.getType() != IQ.Type.error) {
fail("The server didn't reply with an error packet");
}
else {
assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
}
}
示例3: testIqId
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
@Test
public void testIqId() {
IQ iq1 = new TestIQ();
String iq1Id = iq1.getStanzaId();
assertTrue(StringUtils.isNotEmpty(iq1Id));
IQ iq2 = new TestIQ();
String iq2Id = iq2.getStanzaId();
assertTrue(StringUtils.isNotEmpty(iq2Id));
assertFalse(iq1Id.equals(iq2Id));
}
示例4: receivePacketAndRespond
import org.jivesoftware.smack.packet.IQ; //導入方法依賴的package包/類
/**
* Process and respond to an incoming packet. <p/> This method is called
* from the stanza(/packet) listener dispatcher when a new stanza(/packet) has arrived. The
* method is responsible for recognizing the stanza(/packet) type and, depending on
* the current state, delivering it to the right event handler and wait for
* a response. The response will be another Jingle stanza(/packet) that will be sent
* to the other end point.
*
* @param iq
* the stanza(/packet) received
* @throws XMPPException
* @throws SmackException
*/
public synchronized void receivePacketAndRespond(IQ iq) throws XMPPException, SmackException {
List<IQ> responses = new ArrayList<IQ>();
String responseId = null;
LOGGER.fine("Packet: " + iq.toXML());
try {
// Dispatch the packet to the JingleNegotiators and get back a list of the results.
responses.addAll(dispatchIncomingPacket(iq, null));
if (iq != null) {
responseId = iq.getStanzaId();
// Send the IQ to each of the content negotiators for further processing.
// Each content negotiator may pass back a list of JingleContent for addition to the response packet.
for (ContentNegotiator contentNegotiator : contentNegotiators) {
// If at this point the content negotiator isn't started, it's because we sent a session-init jingle
// packet from startOutgoing() and we're waiting for the other side to let us know they're ready
// to take jingle packets. (This packet might be a session-terminate, but that will get handled
// later.
if (!contentNegotiator.isStarted()) {
contentNegotiator.start();
}
responses.addAll(contentNegotiator.dispatchIncomingPacket(iq, responseId));
}
}
// Acknowledge the IQ reception
// Not anymore. The state machine generates an appropriate response IQ that
// gets sent back at the end of this routine.
//sendAck(iq);
} catch (JingleException e) {
// Send an error message, if present
JingleError error = e.getError();
if (error != null) {
responses.add(createJingleError(iq, error));
}
// Notify the session end and close everything...
triggerSessionClosedOnError(e);
}
// // If the response is anything other than a RESULT then send it now.
// if ((response != null) && (!response.getType().equals(IQ.Type.result))) {
// getConnection().sendStanza(response);
// }
// Loop through all of the responses and send them.
for (IQ response : responses) {
sendStanza(response);
}
}