Search in sources :

Example 1 with XmppStringprepException

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);
}
Also used : Jid(org.jxmpp.jid.Jid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 2 with XmppStringprepException

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();
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) CustomSCRAMSHA1Mechanism(com.yellowmessenger.sdk.xmpp.CustomSCRAMSHA1Mechanism) MessageAcknowledgementEvent(com.yellowmessenger.sdk.events.MessageAcknowledgementEvent) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AndroidSmackInitializer(org.jivesoftware.smack.android.AndroidSmackInitializer) ExtensionsInitializer(org.jivesoftware.smack.extensions.ExtensionsInitializer) XMPPUser(com.yellowmessenger.sdk.models.XMPPUser)

Example 3 with XmppStringprepException

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);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Cursor(android.database.Cursor)

Example 4 with XmppStringprepException

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);
    }
}
Also used : XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 5 with XmppStringprepException

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);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) HashMap(java.util.HashMap) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Cursor(android.database.Cursor) HashSet(java.util.HashSet)

Aggregations

XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)47 AccountJid (com.xabber.android.data.entity.AccountJid)12 UserJid (com.xabber.android.data.entity.UserJid)11 DomainBareJid (org.jxmpp.jid.DomainBareJid)11 Jid (org.jxmpp.jid.Jid)9 Localpart (org.jxmpp.jid.parts.Localpart)7 Resourcepart (org.jxmpp.jid.parts.Resourcepart)7 ArrayList (java.util.ArrayList)6 Cursor (android.database.Cursor)5 HashMap (java.util.HashMap)5 SmackException (org.jivesoftware.smack.SmackException)4 NetworkException (com.xabber.android.data.NetworkException)3 Realm (io.realm.Realm)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 BareJid (org.jxmpp.jid.BareJid)3 EntityBareJid (org.jxmpp.jid.EntityBareJid)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 AccountRealm (com.xabber.android.data.database.realm.AccountRealm)2 ContactRealm (com.xabber.android.data.database.realm.ContactRealm)2