本文整理汇总了Java中org.jivesoftware.smack.packet.Bind类的典型用法代码示例。如果您正苦于以下问题:Java Bind类的具体用法?Java Bind怎么用?Java Bind使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bind类属于org.jivesoftware.smack.packet包,在下文中一共展示了Bind类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseResourceBinding
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
private static Bind parseResourceBinding(XmlPullParser parser) throws IOException,
XmlPullParserException {
Bind bind = new Bind();
boolean done = false;
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("resource")) {
bind.setResource(parser.nextText());
}
else if (parser.getName().equals("jid")) {
bind.setJid(parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("bind")) {
done = true;
}
}
}
return bind;
}
示例2: parseIQ
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
private IQ parseIQ(Element doc) {
Element pingEl = doc.element(Ping.ELEMENT);
if (pingEl != null
&& pingEl.getNamespace().getURI().equals(Ping.NAMESPACE)) {
return new Ping(doc);
}
Element bindEl = doc.element(Bind.ELEMENT);
if (bindEl != null
&& bindEl.getNamespace().getURI().equals(Bind.NAMESPACE)) {
return new Bind(doc);
}
Element query = doc.element("query");
if (query != null) {
if ("jabber:iq:roster".equals(query.getNamespaceURI())) {
return new Roster(doc);
}
if ("jabber:iq:auth".equals(query.getNamespaceURI())) {
return new Authentication(doc);
}
}
return new IQ(doc);
}
示例3: bindResourceAndEstablishSession
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
@SuppressWarnings("deprecation")
protected void bindResourceAndEstablishSession(String resource) throws XMPPErrorException,
IOException, SmackException {
// Wait until either:
// - the servers last features stanza has been parsed
// - the timeout occurs
LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
lastFeaturesReceived.checkIfSuccessOrWait();
if (!hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
// Server never offered resource binding, which is REQURIED in XMPP client and
// server implementations as per RFC6120 7.2
throw new ResourceBindingNotOfferedException();
}
// Resource binding, see RFC6120 7.
// Note that we can not use IQReplyFilter here, since the users full JID is not yet
// available. It will become available right after the resource has been successfully bound.
Bind bindResource = Bind.newSet(resource);
PacketCollector packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
Bind response = packetCollector.nextResultOrThrow();
// Set the connections user to the result of resource binding. It is important that we don't infer the user
// from the login() arguments and the configurations service name, as, for example, when SASL External is used,
// the username is not given to login but taken from the 'external' certificate.
user = response.getJid();
serviceName = XmppStringUtils.parseDomain(user);
Session.Feature sessionFeature = getFeature(Session.ELEMENT, Session.NAMESPACE);
// Only bind the session if it's announced as stream feature by the server, is not optional and not disabled
// For more information see http://tools.ietf.org/html/draft-cridland-xmpp-session-01
if (sessionFeature != null && !sessionFeature.isOptional() && !getConfiguration().isLegacySessionDisabled()) {
Session session = new Session();
packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(session), session);
packetCollector.nextResultOrThrow();
}
}
示例4: parse
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
@Override
public Bind parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
SmackException {
String name;
Bind bind = null;
outerloop: while (true) {
int eventType = parser.next();
switch (eventType) {
case XmlPullParser.START_TAG:
name = parser.getName();
switch (name) {
case "resource":
bind = Bind.newSet(parser.nextText());
break;
case "jid":
bind = Bind.newResult(parser.nextText());
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return bind;
}
示例5: parseFeatures
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException {
streamFeatures.clear();
final int initialDepth = parser.getDepth();
while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) {
ExtensionElement streamFeature = null;
String name = parser.getName();
String namespace = parser.getNamespace();
switch (name) {
case StartTls.ELEMENT:
streamFeature = PacketParserUtils.parseStartTlsFeature(parser);
break;
case Mechanisms.ELEMENT:
streamFeature = new Mechanisms(PacketParserUtils.parseMechanisms(parser));
break;
case Bind.ELEMENT:
streamFeature = Bind.Feature.INSTANCE;
break;
case Session.ELEMENT:
streamFeature = PacketParserUtils.parseSessionFeature(parser);
break;
case Compress.Feature.ELEMENT:
streamFeature = PacketParserUtils.parseCompressionFeature(parser);
break;
default:
ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
if (provider != null) {
streamFeature = provider.parse(parser);
}
break;
}
if (streamFeature != null) {
// 将特性放入列表中
addStreamFeature(streamFeature);
}
}
else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initialDepth) {
break;
}
}
if (hasFeature(Mechanisms.ELEMENT, Mechanisms.NAMESPACE)) {
// Only proceed with SASL auth if TLS is disabled or if the server doesn't announce it
if (!hasFeature(StartTls.ELEMENT, StartTls.NAMESPACE)
|| config.getSecurityMode() == SecurityMode.disabled) {
// connecting算事完成了
saslFeatureReceived.reportSuccess();
}
}
// If the server reported the bind feature then we are that that we did SASL and maybe
// STARTTLS. We can then report that the last 'stream:features' have been parsed
if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
if (!hasFeature(Compress.Feature.ELEMENT, Compress.NAMESPACE)
|| !config.isCompressionEnabled()) {
// This was was last features from the server is either it did not contain
// compression or if we disabled it
lastFeaturesReceived.reportSuccess();
}
}
afterFeaturesReceived();
}
示例6: bindResourceAndEstablishSession
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
private String bindResourceAndEstablishSession(String resource) throws XMPPException {
// Wait until server sends response containing the <bind> element
synchronized (this) {
if (!resourceBinded) {
try {
wait(30000);
}
catch (InterruptedException e) {
// Ignore
}
}
}
if (!resourceBinded) {
// Server never offered resource binding
throw new XMPPException("Resource binding not offered by server");
}
Bind bindResource = new Bind();
bindResource.setResource(resource);
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(bindResource.getPacketID()));
// Send the packet
connection.sendPacket(bindResource);
// Wait up to a certain number of seconds for a response from the server.
Bind response = (Bind) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
String userJID = response.getJid();
if (sessionSupported) {
Session session = new Session();
collector = connection.createPacketCollector(new PacketIDFilter(session.getPacketID()));
// Send the packet
connection.sendPacket(session);
// Wait up to a certain number of seconds for a response from the server.
IQ ack = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (ack == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (ack.getType() == IQ.Type.ERROR) {
throw new XMPPException(ack.getError());
}
}
else {
// Server never offered session establishment
throw new XMPPException("Session establishment not offered by server");
}
return userJID;
}
示例7: bindResourceAndEstablishSession
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
private String bindResourceAndEstablishSession(String resource) throws XMPPException {
// Wait until server sends response containing the <bind> element
synchronized (this) {
long endTime = System.currentTimeMillis() + 30000;
while (!resourceBinded && (System.currentTimeMillis() < endTime)) {
try {
wait(Math.abs(System.currentTimeMillis() - endTime));
}
catch (InterruptedException e) {
// Ignore
}
}
}
if (!resourceBinded) {
// Server never offered resource binding
throw new XMPPException("Resource binding not offered by server");
}
Bind bindResource = new Bind();
bindResource.setResource(resource);
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(bindResource.getPacketID()));
// Send the packet
connection.sendPacket(bindResource);
// Wait up to a certain number of seconds for a response from the server.
Bind response = (Bind) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
String userJID = response.getJid();
if (sessionSupported) {
Session session = new Session();
collector = connection.createPacketCollector(new PacketIDFilter(session.getPacketID()));
// Send the packet
connection.sendPacket(session);
// Wait up to a certain number of seconds for a response from the server.
IQ ack = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (ack == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (ack.getType() == IQ.Type.ERROR) {
throw new XMPPException(ack.getError());
}
}
else {
// Server never offered session establishment
throw new XMPPException("Session establishment not offered by server");
}
return userJID;
}
示例8: bindResourceAndEstablishSession
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
private String bindResourceAndEstablishSession(String resource) throws XMPPException {
// Wait until server sends response containing the <bind> element
synchronized (this) {
if (!resourceBinded) {
try {
wait(30000);
}
catch (InterruptedException e) {
// Ignore
}
}
}
if (!resourceBinded) {
// Server never offered resource binding
throw new XMPPException("Resource binding not offered by server");
}
Bind bindResource = new Bind();
bindResource.setResource(resource);
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(bindResource.getPacketID()));
// Send the packet
connection.sendPacket(bindResource);
// Wait up to a certain number of seconds for a response from the server.
Bind response = (Bind) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
String userJID = response.getJid();
if (sessionSupported) {
Session session = new Session();
collector = connection.createPacketCollector(new PacketIDFilter(session.getPacketID()));
// Send the packet
connection.sendPacket(session);
// Wait up to a certain number of seconds for a response from the server.
IQ ack = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (ack == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (ack.getType() == IQ.Type.ERROR) {
throw new XMPPException(ack.getError());
}
}
return userJID;
}
示例9: bindResourceAndEstablishSession
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
private String bindResourceAndEstablishSession(String resource)
throws XMPPException {
// Wait until server sends response containing the <bind> element
synchronized (this) {
if (!resourceBinded) {
try {
wait(30000);
} catch (InterruptedException e) {
// Ignore
}
}
}
if (!resourceBinded) {
// Server never offered resource binding
throw new XMPPException("Resource binding not offered by server");
}
Bind bindResource = new Bind();
bindResource.setResource(resource);
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(bindResource
.getPacketID()));
// Send the packet
connection.sendPacket(bindResource);
// Wait up to a certain number of seconds for a response from the
// server.
Bind response = (Bind) collector.nextResult(SmackConfiguration
.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
String userJID = response.getJid();
if (sessionSupported) {
Session session = new Session();
collector = connection.createPacketCollector(new PacketIDFilter(
session.getPacketID()));
// Send the packet
connection.sendPacket(session);
// Wait up to a certain number of seconds for a response from the
// server.
IQ ack = (IQ) collector.nextResult(SmackConfiguration
.getPacketReplyTimeout());
collector.cancel();
if (ack == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (ack.getType() == IQ.Type.ERROR) {
throw new XMPPException(ack.getError());
}
} else {
// Server never offered session establishment
throw new XMPPException(
"Session establishment not offered by server");
}
return userJID;
}
示例10: bindResourceAndEstablishSession
import org.jivesoftware.smack.packet.Bind; //导入依赖的package包/类
private String bindResourceAndEstablishSession(String resource)
throws XMPPException {
// Wait until server sends response containing the <bind> element
synchronized (this) {
if (!resourceBinded) {
try {
wait(30000);
} catch (InterruptedException e) {
// Ignore
}
}
}
if (!resourceBinded) {
// Server never offered resource binding
throw new XMPPException("Resource binding not offered by server");
}
Bind bindResource = new Bind();
bindResource.setResource(resource);
PacketCollector collector = connection
.createPacketCollector(new PacketIDFilter(bindResource.getID()));
// Send the packet
connection.sendPacket(bindResource);
// Wait up to a certain number of seconds for a response from the
// server.
Bind response = (Bind) collector.nextResult(SmackConfiguration
.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.error) {
throw new XMPPException(response.getError());
}
String userJID = response.getJid();
if (sessionSupported) {
Session session = new Session();
collector = connection.createPacketCollector(new PacketIDFilter(
session.getID()));
// Send the packet
connection.sendPacket(session);
// Wait up to a certain number of seconds for a response from the
// server.
IQ ack = (IQ) collector.nextResult(SmackConfiguration
.getPacketReplyTimeout());
collector.cancel();
if (ack == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (ack.getType() == IQ.Type.error) {
throw new XMPPException(ack.getError());
}
}
return userJID;
}