Socks5IqHandler extends DefaultIQHandler { @Override protected List<Stanza> handleGet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext, StanzaBroker stanzaBroker) { StanzaBuilder builder = StanzaBuilder.createIQStanza(stanza.getTo(), stanza.getFrom(), IQStanzaType.RESULT, stanza.getID()) .startInnerElement("query", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS) .startInnerElement("streamhost", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS); if(DEFAULT_ADDRESS.equals(proxyAddress.getAddress())) { builder.addAttribute("host", jid.getFullQualifiedName()); } else { builder.addAttribute("host", proxyAddress.getHostName()); } builder.addAttribute("jid", jid.getFullQualifiedName()) .addAttribute("port", Integer.toString(proxyAddress.getPort())); return Collections.singletonList(builder.build()); } Socks5IqHandler(Entity jid, InetSocketAddress proxyAddress, Socks5ConnectionsRegistry connections);   }
@Test public void handleGet() throws BindException, XMLSemanticError { List<Stanza> responses = handler.handleGet(stanza, serverRuntimeContext, sessionContext, null); Stanza response = responses.get(0); Stanza expected = StanzaBuilder .createIQStanza(stanza.getTo(), stanza.getFrom(), IQStanzaType.RESULT, stanza.getID()) .startInnerElement("query", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS) .startInnerElement("streamhost", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS) .addAttribute("host", proxyAddress.getHostName()).addAttribute("jid", jid.getFullQualifiedName()) .addAttribute("port", Integer.toString(proxyAddress.getPort())).build(); StanzaAssert.assertEquals(expected, response); }
@Test public void handleGetDefaultAddress() throws BindException, XMLSemanticError { proxyAddress = new InetSocketAddress(12345); handler = new Socks5IqHandler(jid, proxyAddress, connectionsRegistry); List<Stanza> responses = handler.handleGet(stanza, serverRuntimeContext, sessionContext, null); Stanza response = responses.get(0); Stanza expected = StanzaBuilder .createIQStanza(stanza.getTo(), stanza.getFrom(), IQStanzaType.RESULT, stanza.getID()) .startInnerElement("query", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS) .startInnerElement("streamhost", NamespaceURIs.XEP0065_SOCKS5_BYTESTREAMS) .addAttribute("host", jid.getFullQualifiedName()).addAttribute("jid", jid.getFullQualifiedName()) .addAttribute("port", Integer.toString(proxyAddress.getPort())).build(); StanzaAssert.assertEquals(expected, response); }