org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration Java Examples

The following examples show how to use org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoX.java    From Smack with Apache License 2.0 7 votes vote down vote up
public static XMPPTCPConnection runDoxResolver(String jid, String password)
        throws XMPPException, SmackException, IOException, InterruptedException {
    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            .setXmppAddressAndPassword(jid, password)
            .setResource("dns")
            .setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE)
            .build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);

    connection.connect().login();

    DnsOverXmppManager dox = DnsOverXmppManager.getInstanceFor(connection);
    dox.setDnsOverXmppResolver(DnsOverXmppMiniDnsResolver.INSTANCE);

    dox.enable();

    return connection;
}
 
Example #2
Source File: XmppLogin.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {

		try {

			DebugUtil.debug("login:" + getUsername() + "--" + getPassword() + "--" + Launcher.HOSTPORT + "--"
					+ Launcher.DOMAIN + "--" + InetAddress.getByName(Launcher.HOSTNAME));

			XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder()
					.setUsernameAndPassword(getUsername(), getPassword()).setResource(Launcher.RESOURCE)
					.setPort(Launcher.HOSTPORT).setConnectTimeout(5000).setXmppDomain(Launcher.DOMAIN)
					.setHost(Launcher.HOSTNAME).setHostAddress(InetAddress.getByName(Launcher.HOSTNAME)) .setSecurityMode(SecurityMode.disabled)
					.setDebuggerEnabled(true).setSendPresence(true);
			DebugUtil.debug("builder:" + builder.toString());
			return builder.build();

		} catch (Exception e) {

			e.printStackTrace();
		}
		return null;
	}
 
Example #3
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 6 votes vote down vote up
private KeyStore configKeyStore(XMPPTCPConnectionConfiguration.Builder builder) throws KeyStoreException {
    KeyStore keyStore;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder.setKeystorePath(null);
        builder.setKeystoreType("AndroidCAStore");
        keyStore = KeyStore.getInstance("AndroidCAStore");
    } else {
        builder.setKeystoreType("BKS");
        keyStore = KeyStore.getInstance("BKS");

        String path = System.getProperty("javax.net.ssl.trustStore");
        if (path == null)
            path = System.getProperty("java.home") + File.separator + "etc"
                    + File.separator + "security" + File.separator
                    + "cacerts.bks";
        builder.setKeystorePath(path);
    }
    return keyStore;
}
 
Example #4
Source File: XmppTools.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static boolean createAccount(DomainBareJid xmppDomain, Localpart username, String password)
        throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException,
        InterruptedException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        if (!supportsIbr(connection))
            return false;

        AccountManager accountManager = AccountManager.getInstance(connection);
        accountManager.createAccount(username, password);
        return true;
    } finally {
        connection.disconnect();
    }
}
 
Example #5
Source File: StanzaThread.java    From tutorials with MIT License 6 votes vote down vote up
@Override
public void run() {
    XMPPTCPConnectionConfiguration config = null;
    try {
        config = XMPPTCPConnectionConfiguration.builder()
                .setUsernameAndPassword("baeldung2","baeldung2")
                .setXmppDomain("jabb3r.org")
                .setHost("jabb3r.org")
                .build();

        AbstractXMPPConnection connection = new XMPPTCPConnection(config);
        connection.connect();
        connection.login();

        ChatManager chatManager = ChatManager.getInstanceFor(connection);

        Chat chat = chatManager.chatWith(JidCreate.from("[email protected]").asEntityBareJidOrThrow());

        chat.send("Hello!");

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example #6
Source File: SmackIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@BeforeClass
public static void setup() throws IOException, InterruptedException, XMPPException, SmackException {

    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword("baeldung","baeldung")
            .setXmppDomain("jabb3r.org")
            .setHost("jabb3r.org")
            .build();

    XMPPTCPConnectionConfiguration config2 = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword("baeldung2","baeldung2")
            .setXmppDomain("jabb3r.org")
            .setHost("jabb3r.org")
            .build();

    connection = new XMPPTCPConnection(config);
    connection.connect();
    connection.login();

}
 
Example #7
Source File: XMPPIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(XMPPIntegrationTest.class.getResourceAsStream("/server.jks"), "secret".toCharArray());

    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keyStore);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());

    String port = AvailablePortFinder.readServerData("xmpp-port");

    ConnectionConfiguration connectionConfig = XMPPTCPConnectionConfiguration.builder()
        .setXmppDomain(JidCreate.domainBareFrom("apache.camel"))
        .setHostAddress(InetAddress.getLocalHost())
        .setPort(Integer.parseInt(port))
        .setCustomSSLContext(sslContext)
        .setHostnameVerifier((hostname, session) -> true)
        .build();

    context.bind("customConnectionConfig", connectionConfig);
}
 
Example #8
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
private void configSSLContext(XMPPTCPConnectionConfiguration.Builder builder, KeyStore keyStore) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    TrustManagerFactory trustManagerFactory = TrustManagerFactory
            .getInstance(KeyManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keyStore);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());

    builder.setCustomSSLContext(sslContext);
}
 
Example #9
Source File: XMPP.java    From XMPPSample_Studio with Apache License 2.0 5 votes vote down vote up
private XMPPTCPConnectionConfiguration buildConfiguration() throws XmppStringprepException {
    XMPPTCPConnectionConfiguration.Builder builder =
            XMPPTCPConnectionConfiguration.builder();


    builder.setHost(HOST1);
    builder.setPort(PORT);
    builder.setCompressionEnabled(false);
    builder.setDebuggerEnabled(true);
    builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    builder.setSendPresence(true);
    if (Build.VERSION.SDK_INT >= 14) {
        builder.setKeystoreType("AndroidCAStore");
        // config.setTruststorePassword(null);
        builder.setKeystorePath(null);
    } else {
        builder.setKeystoreType("BKS");
        String str = System.getProperty("javax.net.ssl.trustStore");
        if (str == null) {
            str = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security"
                    + File.separator + "cacerts.bks";
        }
        builder.setKeystorePath(str);
    }
    DomainBareJid serviceName = JidCreate.domainBareFrom(HOST);
    builder.setServiceName(serviceName);


    return builder.build();
}
 
Example #10
Source File: IoT.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static void iotScenario(String dataThingJidString, String dataThingPassword, String readingThingJidString,
        String readingThingPassword, IotScenario scenario) throws Exception {
    final EntityBareJid dataThingJid = JidCreate.entityBareFrom(dataThingJidString);
    final EntityBareJid readingThingJid = JidCreate.entityBareFrom(readingThingJidString);

    final XMPPTCPConnectionConfiguration dataThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword(dataThingJid.getLocalpart(), dataThingPassword)
            .setXmppDomain(dataThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled)
            .enableDefaultDebugger().build();
    final XMPPTCPConnectionConfiguration readingThingConnectionConfiguration = XMPPTCPConnectionConfiguration
            .builder().setUsernameAndPassword(readingThingJid.getLocalpart(), readingThingPassword)
            .setXmppDomain(readingThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled)
            .enableDefaultDebugger().build();

    final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration);
    final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration);

    dataThingConnection.setReplyTimeout(TIMEOUT);
    readingThingConnection.setReplyTimeout(TIMEOUT);

    dataThingConnection.setUseStreamManagement(false);
    readingThingConnection.setUseStreamManagement(false);

    try {
        dataThingConnection.connect().login();
        readingThingConnection.connect().login();
        scenario.iotScenario(dataThingConnection, readingThingConnection);
    } finally {
        dataThingConnection.disconnect();
        readingThingConnection.disconnect();
    }
}
 
Example #11
Source File: XmppTools.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static boolean supportsIbr(DomainBareJid xmppDomain) throws SmackException, IOException, XMPPException,
        InterruptedException, KeyManagementException, NoSuchAlgorithmException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        return supportsIbr(connection);
    } finally {
        connection.disconnect();
    }
}
 
Example #12
Source File: SmackConnection.java    From SmackAndroidDemo with Apache License 2.0 3 votes vote down vote up
public void connect() throws IOException, XMPPException, SmackException {
    Log.i(TAG, "connect()");

    XMPPTCPConnectionConfiguration.XMPPTCPConnectionConfigurationBuilder builder = XMPPTCPConnectionConfiguration.builder();
    builder.setServiceName(mServiceName);
    builder.setResource("SmackAndroidTestClient");
    builder.setUsernameAndPassword(mUsername, mPassword);
    builder.setRosterLoadedAtLogin(true);


    mConnection = new XMPPTCPConnection(builder.build());

    //Set ConnectionListener here to catch initial connect();
    mConnection.addConnectionListener(this);

    mConnection.connect();
    mConnection.login();

    PingManager.setDefaultPingInterval(600); //Ping every 10 minutes
    PingManager pingManager = PingManager.getInstanceFor(mConnection);
    pingManager.registerPingFailedListener(this);

    setupSendMessageReceiver();

    ChatManager.getInstanceFor(mConnection).addChatListener(this);
    mConnection.getRoster().addRosterListener(this);

}
 
Example #13
Source File: SmackIntegrationTestFramework.java    From Smack with Apache License 2.0 3 votes vote down vote up
static XMPPTCPConnectionConfiguration.Builder getConnectionConfigurationBuilder(Configuration config) {
    XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();

    config.configurationApplier.applyConfigurationTo(builder);

    return builder;
}