Socks5Module extends DefaultDiscoAwareModule implements Component, ComponentInfoRequestListener, ItemRequestListener { @Override public void initialize(ServerRuntimeContext serverRuntimeContext) { super.initialize(serverRuntimeContext); fullDomain = EntityUtils.createComponentDomain(subdomain, serverRuntimeContext); try { startProxy(); } catch (Exception e) { throw new RuntimeException("Failed to start SOCKS5 proxy", e); } } Socks5Module(String subdomain, InetSocketAddress proxyAddress);  Socks5Module(String subdomain);  Socks5Module(); @Override void initialize(ServerRuntimeContext serverRuntimeContext); void close(); @Override String getName(); @Override String getVersion(); String getSubdomain(); @Override List<StanzaHandler> getComponentHandlers(Entity fullDomain); @Override List<NamespaceHandlerDictionary> getComponentHandlerDictionnaries(Entity fullDomain); List<Item> getItemsFor(InfoRequest request, StanzaBroker stanzaBroker); List<InfoElement> getComponentInfosFor(InfoRequest request, StanzaBroker stanzaBroker); void setConnectionsRegistry(Socks5ConnectionsRegistry connectionsRegistry);  }
@Test public void discoComponentInfo() throws Exception { ServiceCollector collector = new ServiceCollector(); when(serverRuntimeContext.getServerRuntimeContextService( ServiceDiscoveryRequestListenerRegistry.SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY)) .thenReturn(collector); module = new Socks5Module("socks"); module.initialize(serverRuntimeContext); InfoRequest infoRequest = new InfoRequest(FROM, COMPONENT, null, "id1"); List<InfoElement> infoElements = collector.processComponentInfoRequest(infoRequest, null); List<InfoElement> expected = Arrays.asList(new Identity("proxy", "bytestreams", "File Transfer Relay"), new Feature(NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS)); Assert.assertEquals(expected, infoElements); }
@Test public void proxy() throws Exception { int port = findFreePort(); InetSocketAddress address = new InetSocketAddress(port); module = new Socks5Module("socks", address); module.initialize(serverRuntimeContext); Thread.sleep(200); assertSocket(port); }
@Test public void proxyDefaultAddress() throws Exception { int port = findFreePort(); module = new Socks5Module("socks", new InetSocketAddress(port)); module.initialize(serverRuntimeContext); Thread.sleep(200); assertSocket(port); }
@Test public void discoItems() throws Exception { ServiceCollector collector = new ServiceCollector(); when(serverRuntimeContext.getServerRuntimeContextService( ServiceDiscoveryRequestListenerRegistry.SERVICE_DISCOVERY_REQUEST_LISTENER_REGISTRY)) .thenReturn(collector); module = new Socks5Module("socks"); module.initialize(serverRuntimeContext); InfoRequest infoRequest = new InfoRequest(FROM, SERVER, null, "id1"); List<Item> items = collector.processItemRequest(infoRequest, null); List<Item> expected = Arrays.asList(new Item(COMPONENT)); Assert.assertEquals(expected, items); }