Java Code Examples for org.jivesoftware.smack.AbstractXMPPConnection#connect()

The following examples show how to use org.jivesoftware.smack.AbstractXMPPConnection#connect() . 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: 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 2
Source File: Connect.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection();
    conn.connect();
    res.setResponseData(sampler.getXMPPConnection().getConnectionID().getBytes());
    return res;
}
 
Example 3
Source File: XmppConnectionManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private AbstractXMPPConnection getConnectedMainConnectionFor(AccountNum accountNum) throws SmackException, IOException, XMPPException,
        InterruptedException, KeyManagementException, NoSuchAlgorithmException, InstantiationException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    String middlefix;
    String accountUsername;
    String accountPassword;
    switch (accountNum) {
    case One:
        accountUsername = sinttestConfiguration.accountOneUsername;
        accountPassword = sinttestConfiguration.accountOnePassword;
        middlefix = "one";
        break;
    case Two:
        accountUsername = sinttestConfiguration.accountTwoUsername;
        accountPassword = sinttestConfiguration.accountTwoPassword;
        middlefix = "two";
        break;
    case Three:
        accountUsername = sinttestConfiguration.accountThreeUsername;
        accountPassword = sinttestConfiguration.accountThreePassword;
        middlefix = "three";
        break;
    default:
        throw new IllegalStateException();
    }

    // Note that it is perfectly fine for account(Username|Password) to be 'null' at this point.
    final String finalAccountUsername = StringUtils.isNullOrEmpty(accountUsername) ? USERNAME_PREFIX + '-' + middlefix + '-' + testRunId : accountUsername;
    final String finalAccountPassword = StringUtils.isNullOrEmpty(accountPassword) ? StringUtils.insecureRandomString(16) : accountPassword;

    if (sinttestConfiguration.isAccountRegistrationPossible()) {
        registerAccount(finalAccountUsername, finalAccountPassword);
    }

    AbstractXMPPConnection mainConnection = defaultConnectionDescriptor.construct(sinttestConfiguration, builder -> {
        try {
            builder.setUsernameAndPassword(finalAccountUsername, finalAccountPassword)
                .setResource(middlefix + '-' + testRunId);
        } catch (XmppStringprepException e) {
            throw new IllegalArgumentException(e);
        }
    });

    connections.add(mainConnection);

    mainConnection.connect();
    mainConnection.login();

    return mainConnection;
}