本文整理汇总了Java中org.jivesoftware.smack.SmackException类的典型用法代码示例。如果您正苦于以下问题:Java SmackException类的具体用法?Java SmackException怎么用?Java SmackException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SmackException类属于org.jivesoftware.smack包,在下文中一共展示了SmackException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForTransfer
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
private void waitForTransfer(FileTransfer transfer, long timeout) throws SmackException, InterruptedException {
double prevProgress = 0;
long counter = 0;
Thread.sleep(timeout / WAITING_CYCLES / 10); // optimistic
while (!transfer.isDone()) {
if (transfer.getStatus().equals(FileTransfer.Status.error)) {
throw new SmackException(transfer.getError().toString(), transfer.getException());
} else {
log.debug("Status: " + transfer.getStatus() + " " + transfer.getProgress());
}
if (transfer.getProgress() <= prevProgress) {
if (counter >= WAITING_CYCLES) {
throw new SmackException("File transfer timed out");
}
counter++;
Thread.sleep(timeout / WAITING_CYCLES);
} else {
counter = 0;
prevProgress = transfer.getProgress();
}
}
if (transfer.getProgress() == 0) {
throw new SmackException("No data transferred");
}
}
示例2: waitResponse
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
private SampleResult waitResponse(SampleResult res, String recipient) throws InterruptedException, SmackException {
long time = 0;
do {
Iterator<Message> packets = responseMessages.iterator();
Thread.sleep(conn.getPacketReplyTimeout() / 100); // optimistic
while (packets.hasNext()) {
Packet packet = packets.next();
Message response = (Message) packet;
if (XmppStringUtils.parseBareAddress(response.getFrom()).equals(recipient)) {
packets.remove();
res.setResponseData(response.toXML().toString().getBytes());
if (response.getError() != null) {
res.setSuccessful(false);
res.setResponseCode("500");
res.setResponseMessage(response.getError().toString());
}
return res;
}
}
time += conn.getPacketReplyTimeout() / 10;
Thread.sleep(conn.getPacketReplyTimeout() / 10);
} while (time < conn.getPacketReplyTimeout());
throw new SmackException.NoResponseException();
}
示例3: processPacket
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
@Override
public void processPacket(Packet packet) throws SmackException.NotConnectedException {
if (packet instanceof Message) {
Message inMsg = (Message) packet;
if (inMsg.getBody() != null) {
if (inMsg.getBody().endsWith(NEED_RESPONSE_MARKER)) {
if (inMsg.getExtension(NS_DELAYED) == null) {
log.debug("Will respond to message: " + inMsg.toXML());
sendResponseMessage(inMsg);
} else {
log.debug("Will not consider history message: " + inMsg.toXML());
}
} else if (inMsg.getBody().endsWith(RESPONSE_MARKER)) {
responseMessages.add(inMsg);
}
}
}
}
示例4: sendMessage
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
public void sendMessage(String body, String chatJid, long timestamp) throws SmackException {
Random random = new Random(timestamp + body.length() + chatJid.length());
Log.d(TAG, "Sending message to : " + chatJid);
MultiUserChat chat = MultiUserChatManager.getInstanceFor(groupChatConnection)
.getMultiUserChat(chatJid);
chat.addMessageListener(this);
Message message = new Message();
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("date_sent", timestamp + "");
message.setStanzaId(StanzaIdUtil.newStanzaId());
message.setBody(body);
message.addExtension(extension);
message.setType(Message.Type.chat);
chat.sendMessage(message);
}
示例5: sendDisplayedReceipt
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
public void sendDisplayedReceipt(String receiverJid, String stanzaId, String dialog_id) {
Chat chat;
if ((chat = privateChats.get(receiverJid)) == null) {
chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
privateChats.put(receiverJid, chat);
}
Message message = new Message(receiverJid);
Displayed read = new Displayed(stanzaId);
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("dialog_id", dialog_id);
message.setStanzaId(StanzaIdUtil.newStanzaId());
message.setType(Message.Type.chat);
message.addExtension(read);
message.addExtension(extension);
try {
chat.sendMessage(message);
} catch (SmackException.NotConnectedException ex) {
Logger.logExceptionToFabric(ex);
offlineMessages.add(message);
}
}
示例6: sendReceivedReceipt
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
public void sendReceivedReceipt(String receiverJid, String stanzaId, String dialog_id) {
Chat chat;
if ((chat = privateChats.get(receiverJid)) == null) {
chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
privateChats.put(receiverJid, chat);
}
Message message = new Message(receiverJid);
Received delivered = new Received(stanzaId);
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("dialog_id", dialog_id);
message.setStanzaId(StanzaIdUtil.newStanzaId());
message.setType(Message.Type.chat);
message.addExtension(delivered);
message.addExtension(extension);
try {
chat.sendMessage(message);
} catch (SmackException.NotConnectedException ex) {
offlineMessages.add(message);
}
}
示例7: sendPrivateMessage
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
public void sendPrivateMessage(String body, String receiverJid, long timestamp, String stanzaId) {
Log.d(TAG, "Sending message to : " + receiverJid);
Chat chat;
if ((chat = privateChats.get(receiverJid)) == null) {
chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
privateChats.put(receiverJid, chat);
}
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("date_sent", timestamp + "");
extension.setProperty("save_to_history", "1");
Message message = new Message(receiverJid);
message.setStanzaId(stanzaId);
message.setBody(body);
message.setType(Message.Type.chat);
message.addExtension(new Markable());
message.addExtension(extension);
try {
chat.sendMessage(message);
} catch (SmackException.NotConnectedException ex) {
offlineMessages.add(message);
}
}
示例8: sendPublicMessage
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
public void sendPublicMessage(String body, String chatJid, long timestamp, String stanzaId) {
Log.d(TAG, "Sending message to : " + chatJid);
MultiUserChat mucChat = publicChats.get(chatJid);
QuickbloxChatExtension extension = new QuickbloxChatExtension();
extension.setProperty("date_sent", timestamp + "");
extension.setProperty("save_to_history", "1");
Message message = new Message(chatJid);
message.setStanzaId(stanzaId);
message.setBody(body);
message.setType(Message.Type.groupchat);
message.addExtension(extension);
try {
if (mucChat != null) {
mucChat.sendMessage(message);
}
} catch (SmackException.NotConnectedException ex) {
offlineMessages.add(message);
}
}
示例9: reconnectionSuccessful
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
@Override
public void reconnectionSuccessful() {
connected = true;
if (!offlineMessages.isEmpty()) {
JobExecutor.getInstance().execute(() -> {
while (!offlineMessages.isEmpty()) {
try {
if (!publicChatToLeave.isEmpty()) {
publicChats.get(publicChatToLeave).leave();
publicChatToLeave = "";
}
Message message = offlineMessages.peek();
privateChatConnection.sendStanza(message);
} catch (SmackException ex) {
Logger.logExceptionToFabric(ex);
break;
}
offlineMessages.poll();
}
});
}
Log.d(TAG, "Reconnection successful");
}
示例10: getConfigFormWithInsufficientPriviliges
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException
{
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
PubSubManager mgr = new PubSubManager(con);
DiscoverInfo info = new DiscoverInfo();
Identity ident = new Identity("pubsub", null, "leaf");
info.addIdentity(ident);
con.addIQReply(info);
Node node = mgr.getNode("princely_musings");
PubSub errorIq = new PubSub();
XMPPError error = new XMPPError(Condition.forbidden);
errorIq.setError(error);
con.addIQReply(errorIq);
try
{
node.getNodeConfiguration();
}
catch (XMPPErrorException e)
{
Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
}
}
示例11: controlNotificationAlarm
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
private void controlNotificationAlarm(boolean torchMode) {
final XMPPTCPConnection connection = mXmppManager.getXmppConnection();
final EntityFullJid fullThingJid = mXmppManager.getFullThingJidOrNotify();
if (fullThingJid == null) return;
SetBoolData setTorch = new SetBoolData(Constants.NOTIFICATION_ALARM, torchMode);
IoTControlManager ioTControlManager = IoTControlManager.getInstanceFor(connection);
LOGGER.info("Trying to control " + fullThingJid + " set torchMode=" + torchMode);
try {
final IoTSetResponse ioTSetResponse = ioTControlManager.setUsingIq(fullThingJid, setTorch);
} catch (SmackException.NoResponseException | XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
mXmppManager.withMainActivity((ma) -> Toast.makeText(mContext, "Could not control thing: " + e, Toast.LENGTH_LONG).show());
LOGGER.log(Level.SEVERE, "Could not set data", e);
}
}
示例12: sendBlogPostComment
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
public BlogPostComment sendBlogPostComment(String content, BlogPost blogPost)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jid jid = XMPPSession.getInstance().getUser().asEntityBareJid();
String userName = XMPPUtils.fromJIDToUserName(jid.toString());
Jid pubSubServiceJid = XMPPSession.getInstance().getPubSubService();
// create stanza
PublishCommentExtension publishCommentExtension = new PublishCommentExtension(blogPost.getId(), userName, jid, content, new Date());
PubSub publishCommentPubSub = PubSub.createPubsubPacket(pubSubServiceJid, IQ.Type.set, publishCommentExtension, null);
// send stanza
XMPPSession.getInstance().sendStanza(publishCommentPubSub);
return new BlogPostComment(publishCommentExtension.getId(),
blogPost.getId(),
content,
userName,
jid.toString(),
publishCommentExtension.getPublished());
}
示例13: loginAnonymously
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
@Override
protected void loginAnonymously() throws XMPPException, SmackException, IOException {
// Wait with SASL auth until the SASL mechanisms have been received
saslFeatureReceived.checkIfSuccessOrWaitOrThrow();
if (saslAuthentication.hasAnonymousAuthentication()) {
saslAuthentication.authenticateAnonymously();
}
else {
// Authenticate using Non-SASL
throw new SmackException("No anonymous SASL authentication mechanism available");
}
bindResourceAndEstablishSession(null);
afterSuccessfulLogin(false);
}
示例14: doStart
import org.jivesoftware.smack.SmackException; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
if (connection == null) {
try {
connection = endpoint.createConnection();
} catch (SmackException e) {
if (endpoint.isTestConnectionOnStartup()) {
throw new RuntimeException("Could not connect to XMPP server: " + endpoint.getConnectionDescription(), e);
} else {
LOG.warn("Could not connect to XMPP server. {} Producer will attempt lazy connection when needed.", e.getMessage());
}
}
}
if (chat == null && connection != null) {
initializeChat();
}
super.doStart();
}
示例15: parse
import org.jivesoftware.smack.SmackException; //导入依赖的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);
}