use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.
the class Stanza method setFrom.
/**
* Sets who the stanza(/packet) is being sent "from". The XMPP protocol often
* makes the "from" attribute optional, so it does not always need to
* be set.
*
* @param from who the stanza(/packet) is being sent to.
* @throws IllegalArgumentException if from is not a valid JID String.
* @deprecated use {@link #setFrom(Jid)} instead.
*/
@Deprecated
public void setFrom(String from) {
Jid jid;
try {
jid = JidCreate.from(from);
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
setFrom(jid);
}
use of org.jxmpp.stringprep.XmppStringprepException in project yellowmessenger-sdk by yellowmessenger.
the class XMPPService method createConnection.
private void createConnection() throws XmppStringprepException, NoSuchAlgorithmException {
if (mConnection == null) {
AndroidSmackInitializer androidSmackInitializer = new AndroidSmackInitializer();
androidSmackInitializer.initialize();
ExtensionsInitializer extensionsInitializer = new ExtensionsInitializer();
extensionsInitializer.initialize();
XMPPUser xmppUser = PreferencesManager.getInstance(XMPPService.this.getApplicationContext()).getXMPPUser();
XMPPTCPConnectionConfiguration connConfig = XMPPTCPConnectionConfiguration.builder().setXmppDomain(JidCreate.domainBareFrom(DOMAIN)).setHost(HOST).setPort(PORT).setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible).setCustomSSLContext(SSLContext.getInstance("TLS")).setSocketFactory(SSLSocketFactory.getDefault()).setUsernameAndPassword(xmppUser.getUsername(), xmppUser.getPassword()).build();
SmackConfiguration.setDefaultPacketReplyTimeout(5000);
XMPPTCPConnection.setUseStreamManagementDefault(true);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
mConnection = new XMPPTCPConnection(connConfig);
mConnection.setPacketReplyTimeout(5000);
mConnection.setPreferredResumptionTime(10);
mConnection.setUseStreamManagement(true);
mConnection.setUseStreamManagementResumption(true);
mConnection.addAsyncStanzaListener(packetListener, packetFilter);
mConnection.addAsyncStanzaListener(pingPacketListener, pingPacketFilter);
mConnection.addStanzaAcknowledgedListener(new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException {
// TODO Acknowledgement
ChatMessage chatMessage = ChatMessageDAO.getChatMessageByStanzaId(packet.getStanzaId());
if (chatMessage != null) {
chatMessage.setAcknowledged(true);
chatMessage.save();
EventBus.getDefault().post(new MessageAcknowledgementEvent(chatMessage, chatMessage.getAcknowledged()));
}
}
});
SASLAuthentication.unregisterSASLMechanism("org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism");
SASLAuthentication.registerSASLMechanism(new CustomSCRAMSHA1Mechanism());
mConnection.addConnectionListener(connectionListener);
ServerPingWithAlarmManager.getInstanceFor(mConnection).setEnabled(true);
// ReconnectionManager.getInstanceFor(mConnection).enableAutomaticReconnection();
}
try {
if (!mConnection.isConnected() && !mConnection.isAuthenticated()) {
mConnection.connect();
} else if (mConnection.isConnected() && !mConnection.isAuthenticated()) {
mConnection.login();
}
} catch (Exception e) {
// e.printStackTrace();
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.
the class NotificationManager method onLoad.
@Override
public void onLoad() {
final Collection<MessageNotification> messageNotifications = new ArrayList<>();
Cursor cursor = NotificationTable.getInstance().list();
try {
if (cursor.moveToFirst()) {
do {
try {
messageNotifications.add(new MessageNotification(AccountJid.from(NotificationTable.getAccount(cursor)), UserJid.from(NotificationTable.getUser(cursor)), NotificationTable.getText(cursor), NotificationTable.getTimeStamp(cursor), NotificationTable.getCount(cursor)));
} catch (UserJid.UserJidCreateException | XmppStringprepException e) {
LogManager.exception(this, e);
}
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
onLoaded(messageNotifications);
}
});
}
use of org.jxmpp.stringprep.XmppStringprepException in project Zom-Android by zom.
the class ChatSession method initJid.
private void initJid() {
try {
mJid = JidCreate.from(mParticipant.getAddress().getAddress());
mXa = new XmppAddress(mJid.toString());
if (mJid.hasNoResource()) {
if (!TextUtils.isEmpty(mParticipant.getAddress().getResource())) {
mJid = JidCreate.from(mParticipant.getAddress().getAddress());
} else if (mParticipant instanceof Contact) {
String resource = ((Contact) mParticipant).getPresence().getResource();
if (!TextUtils.isEmpty(resource)) {
mJid = JidCreate.from(mParticipant.getAddress().getBareAddress() + '/' + resource);
}
}
mXa = new XmppAddress(mJid.toString());
}
// not for groups yet
if (mParticipant instanceof Contact) {
// if we can't omemo, check it again to be sure
if (!mCanOmemo) {
mCanOmemo = mManager.resourceSupportsOmemo(mJid);
}
}
} catch (XmppStringprepException xe) {
throw new RuntimeException("Error with address that shouldn't happen: " + xe);
}
}
use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.
the class AvatarManager method onLoad.
@Override
public void onLoad() {
final Map<Jid, String> hashes = new HashMap<>();
final Map<String, Bitmap> bitmaps = new HashMap<>();
Cursor cursor = AvatarTable.getInstance().list();
try {
if (cursor.moveToFirst()) {
do {
String hash = AvatarTable.getHash(cursor);
try {
Jid jid = JidCreate.from(AvatarTable.getUser(cursor));
hashes.put(jid, hash == null ? EMPTY_HASH : hash);
} catch (XmppStringprepException e) {
LogManager.exception(this, e);
}
} while (cursor.moveToNext());
}
} finally {
cursor.close();
}
for (String hash : new HashSet<>(hashes.values())) if (!hash.equals(EMPTY_HASH)) {
Bitmap bitmap = makeBitmap(AvatarStorage.getInstance().read(hash));
bitmaps.put(hash, bitmap == null ? EMPTY_BITMAP : bitmap);
}
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
onLoaded(hashes, bitmaps);
}
});
}
Aggregations