use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection in project Smack by igniterealtime.
the class XmppConnectionDescriptor method buildWebsocketDescriptor.
public static XmppConnectionDescriptor<ModularXmppClientToServerConnection, ModularXmppClientToServerConnectionConfiguration, ModularXmppClientToServerConnectionConfiguration.Builder> buildWebsocketDescriptor(String nickname, Class<? extends WebSocketFactory> factoryClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
WebSocketFactory factory;
try {
Field instanceField = factoryClass.getField("INSTANCE");
factory = (WebSocketFactory) instanceField.get(null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
factory = factoryClass.getConstructor().newInstance();
}
WebSocketFactory finalFactory = factory;
return XmppConnectionDescriptor.buildWith(ModularXmppClientToServerConnection.class, ModularXmppClientToServerConnectionConfiguration.class, ModularXmppClientToServerConnectionConfiguration.Builder.class).withNickname(nickname).applyExtraConfguration(cb -> {
cb.removeAllModules();
ModularXmppClientToServerConnectionModuleDescriptor webSocketModuleDescriptor = XmppWebSocketTransportModuleDescriptor.getBuilder(cb).setWebSocketFactory(finalFactory).build();
cb.addModule(webSocketModuleDescriptor);
}).build();
}
use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection in project Smack by igniterealtime.
the class SmackIntegrationTestXmppConnectionManagerTest method simpleXmppConnectionDescriptorTest.
@Test
public void simpleXmppConnectionDescriptorTest() throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, KeyManagementException, NoSuchAlgorithmException, XmppStringprepException, InstantiationException {
XmppConnectionDescriptor<ModularXmppClientToServerConnection, ModularXmppClientToServerConnectionConfiguration, ModularXmppClientToServerConnectionConfiguration.Builder> descriptor = XmppConnectionDescriptor.buildWith(ModularXmppClientToServerConnection.class, ModularXmppClientToServerConnectionConfiguration.class, ModularXmppClientToServerConnectionConfiguration.Builder.class).applyExtraConfguration(b -> b.removeAllModules().addModule(XmppTcpTransportModuleDescriptor.class)).build();
Configuration sinttestConfiguration = Configuration.builder().setService("example.org").build();
ModularXmppClientToServerConnection connection = descriptor.construct(sinttestConfiguration);
assertEquals("example.org", connection.getXMPPServiceDomain().toString());
}
use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection in project Smack by igniterealtime.
the class WebSocketConnectionTest 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).setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE);
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);
connection.addConnectionStateMachineListener((event, c) -> {
Logger.getAnonymousLogger().info("Connection event: " + event);
});
connection.connect();
connection.login();
if (messageTo != null) {
Message message = connection.getStanzaFactory().buildMessageStanza().to(messageTo).setBody("It is alive! " + XmppDateTime.formatXEP0082Date(new Date())).build();
connection.sendStanza(message);
}
Thread.sleep(1000);
connection.disconnect();
ModularXmppClientToServerConnection.Stats connectionStats = connection.getStats();
ServiceDiscoveryManager.Stats serviceDiscoveryManagerStats = ServiceDiscoveryManager.getInstanceFor(connection).getStats();
// CHECKSTYLE:OFF
System.out.println("WebSocket successfully finished, yeah!\n" + connectionStats + '\n' + serviceDiscoveryManagerStats);
// CHECKSTYLE:ON
}
use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection in project Smack by igniterealtime.
the class XmppConnectionIntegrationTest method allToAllMessageSendTest.
@SmackIntegrationTest(connectionCount = 4)
public void allToAllMessageSendTest(List<AbstractXMPPConnection> connections) throws InterruptedException, NotAllMessagesReceivedException, ErrorsWhileSendingOrReceivingException {
final long seed = 42;
// 100
final int messagesPerConnection = 3;
// 512
final int maxPayloadChunkSize = 16;
// 32
final int maxPayloadChunks = 4;
// true
final boolean intermixMessages = false;
XmppConnectionStressTest.Configuration stressTestConfiguration = new XmppConnectionStressTest.Configuration(seed, messagesPerConnection, maxPayloadChunkSize, maxPayloadChunks, intermixMessages);
XmppConnectionStressTest stressTest = new XmppConnectionStressTest(stressTestConfiguration);
stressTest.run(connections, timeout);
final Level connectionStatsLogLevel = Level.FINE;
if (LOGGER.isLoggable(connectionStatsLogLevel)) {
if (connections.get(0) instanceof ModularXmppClientToServerConnection) {
for (XMPPConnection connection : connections) {
ModularXmppClientToServerConnection xmppC2sConnection = (ModularXmppClientToServerConnection) connection;
ModularXmppClientToServerConnection.Stats stats = xmppC2sConnection.getStats();
LOGGER.log(connectionStatsLogLevel, "Connections stats for " + xmppC2sConnection + ":\n{}", stats);
}
}
}
}
use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection in project Smack by igniterealtime.
the class XmppWebSocketTransportModuleTest method createWebSocketModuleConnectionInstanceTest.
@Test
public void createWebSocketModuleConnectionInstanceTest() throws URISyntaxException, XmppStringprepException {
ModularXmppClientToServerConnectionConfiguration.Builder builder = ModularXmppClientToServerConnectionConfiguration.builder();
builder.removeAllModules();
builder.addModule(XmppWebSocketTransportModuleDescriptor.class);
builder.setXmppAddressAndPassword("user5@localhost.org", "user5");
builder.setHost("localhost.org");
XmppWebSocketTransportModuleDescriptor.Builder websocketBuilder = XmppWebSocketTransportModuleDescriptor.getBuilder(builder);
websocketBuilder.explicitlySetWebSocketEndpointAndDiscovery(new URI("wss://localhost.org:7443/ws/"), false);
ModularXmppClientToServerConnectionConfiguration config = builder.build();
ModularXmppClientToServerConnection connection = new ModularXmppClientToServerConnection(config);
assertNotNull(connection);
}
Aggregations