use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration 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.ModularXmppClientToServerConnectionConfiguration 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.ModularXmppClientToServerConnectionConfiguration in project Smack by igniterealtime.
the class ModularXmppClientToServerConnectionTool method printStateGraph.
public static void printStateGraph(PrintWriter pw, boolean breakStateName) throws XmppStringprepException {
ModularXmppClientToServerConnectionConfiguration.Builder configurationBuilder = ModularXmppClientToServerConnectionConfiguration.builder().setUsernameAndPassword("user", "password").setXmppDomain("example.org");
ModularXmppClientToServerConnectionConfiguration configuration = configurationBuilder.build();
configuration.printStateGraphInDotFormat(pw, breakStateName);
pw.flush();
}
use of org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration 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.ModularXmppClientToServerConnectionConfiguration 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