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");
}
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;
}
Aggregations