Search in sources :

Example 1 with SecurityMode

use of org.jivesoftware.smack.ConnectionConfiguration.SecurityMode 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 2 with SecurityMode

use of org.jivesoftware.smack.ConnectionConfiguration.SecurityMode in project Smack by igniterealtime.

the class WebSocketConnectionAttemptState method establishWebSocketConnection.

/**
 * Establish  a websocket connection with one of the discoveredRemoteConnectionEndpoints.<br>
 *
 * @return {@link AbstractWebSocket} with which connection is establised
 * @throws InterruptedException if the calling thread was interrupted
 */
@SuppressWarnings({ "incomplete-switch", "MissingCasesInEnumSwitch" })
StateTransitionResult.Failure establishWebSocketConnection() throws InterruptedException {
    final WebSocketRemoteConnectionEndpointLookup.Result endpointLookupResult = discoveredEndpoints.result;
    final List<Exception> failures = new ArrayList<>(endpointLookupResult.discoveredEndpointCount());
    webSocket = null;
    SecurityMode securityMode = connectionInternal.connection.getConfiguration().getSecurityMode();
    switch(securityMode) {
        case required:
        case ifpossible:
            establishWebSocketConnection(endpointLookupResult.discoveredSecureEndpoints, failures);
            if (webSocket != null) {
                return null;
            }
    }
    establishWebSocketConnection(endpointLookupResult.discoveredInsecureEndpoints, failures);
    if (webSocket != null) {
        return null;
    }
    StateTransitionResult.Failure failure = FailedToConnectToAnyWebSocketEndpoint.create(failures);
    return failure;
}
Also used : WebSocketRemoteConnectionEndpointLookup(org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpointLookup) SecurityMode(org.jivesoftware.smack.ConnectionConfiguration.SecurityMode) ArrayList(java.util.ArrayList) StateTransitionResult(org.jivesoftware.smack.fsm.StateTransitionResult)

Aggregations

SecurityMode (org.jivesoftware.smack.ConnectionConfiguration.SecurityMode)2 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 ModularXmppClientToServerConnection (org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection)1 ModularXmppClientToServerConnectionConfiguration (org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration)1 SmackDebuggerFactory (org.jivesoftware.smack.debugger.SmackDebuggerFactory)1 StateTransitionResult (org.jivesoftware.smack.fsm.StateTransitionResult)1 WebSocketRemoteConnectionEndpointLookup (org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpointLookup)1