Search in sources :

Example 6 with ModularXmppClientToServerConnection

use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection in project Smack by igniterealtime.

the class Nio method doNio.

public static void doNio(String username, String password, String service) throws SmackException, IOException, XMPPException, InterruptedException {
    boolean useTls = true;
    boolean useStreamMangement = false;
    boolean useCompression = true;
    boolean useFullFlush = true;
    boolean javaNetDebug = false;
    boolean smackDebug = true;
    if (useFullFlush) {
        XMPPInputOutputStream.setFlushMethod(FlushMethod.FULL_FLUSH);
    }
    if (javaNetDebug) {
        System.setProperty("javax.net.debug", "all");
    }
    final SecurityMode securityMode;
    if (useTls) {
        securityMode = SecurityMode.required;
    } else {
        securityMode = SecurityMode.disabled;
    }
    final SmackDebuggerFactory smackDebuggerFactory;
    if (smackDebug) {
        smackDebuggerFactory = ConsoleDebugger.Factory.INSTANCE;
    } else {
        smackDebuggerFactory = null;
    }
    ModularXmppClientToServerConnectionConfiguration.Builder configurationBuilder = ModularXmppClientToServerConnectionConfiguration.builder().setUsernameAndPassword(username, password).setXmppDomain(service).setDebuggerFactory(smackDebuggerFactory).setSecurityMode(securityMode).removeAllModules().addModule(XmppTcpTransportModuleDescriptor.class);
    if (useCompression) {
        configurationBuilder.addModule(CompressionModuleDescriptor.class);
        configurationBuilder.setCompressionEnabled(true);
    }
    if (useStreamMangement) {
        configurationBuilder.addModule(StreamManagementModuleDescriptor.class);
    }
    ModularXmppClientToServerConnectionConfiguration configuration = configurationBuilder.build();
    PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)));
    configuration.printStateGraphInDotFormat(printWriter, false);
    printWriter.flush();
    ModularXmppClientToServerConnection connection = new ModularXmppClientToServerConnection(configuration);
    connection.setReplyTimeout(5 * 60 * 1000);
    XmppTools.modularConnectionTest(connection, "flo@geekplace.eu");
}
Also used : SmackDebuggerFactory(org.jivesoftware.smack.debugger.SmackDebuggerFactory) ModularXmppClientToServerConnectionConfiguration(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration) SecurityMode(org.jivesoftware.smack.ConnectionConfiguration.SecurityMode) OutputStreamWriter(java.io.OutputStreamWriter) ModularXmppClientToServerConnection(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 7 with ModularXmppClientToServerConnection

use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection in project Smack by igniterealtime.

the class WebSocketConnection method testWebSocketConnection.

public static void testWebSocketConnection(String jid, String password, String websocketEndpoint, String messageTo) throws URISyntaxException, SmackException, IOException, XMPPException, InterruptedException {
    ModularXmppClientToServerConnectionConfiguration.Builder builder = ModularXmppClientToServerConnectionConfiguration.builder();
    builder.removeAllModules().setXmppAddressAndPassword(jid, password);
    XmppWebSocketTransportModuleDescriptor.Builder websocketBuilder = XmppWebSocketTransportModuleDescriptor.getBuilder(builder);
    websocketBuilder.explicitlySetWebSocketEndpointAndDiscovery(websocketEndpoint, false);
    builder.addModule(websocketBuilder.build());
    ModularXmppClientToServerConnectionConfiguration config = builder.build();
    ModularXmppClientToServerConnection connection = new ModularXmppClientToServerConnection(config);
    connection.setReplyTimeout(5 * 60 * 1000);
    XmppTools.modularConnectionTest(connection, messageTo);
}
Also used : XmppWebSocketTransportModuleDescriptor(org.jivesoftware.smack.websocket.XmppWebSocketTransportModuleDescriptor) ModularXmppClientToServerConnectionConfiguration(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration) ModularXmppClientToServerConnection(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection)

Aggregations

ModularXmppClientToServerConnection (org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection)7 ModularXmppClientToServerConnectionConfiguration (org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration)6 XmppWebSocketTransportModuleDescriptor (org.jivesoftware.smack.websocket.XmppWebSocketTransportModuleDescriptor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Test (org.junit.jupiter.api.Test)2 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 URI (java.net.URI)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1