This is an automated email from the ASF dual-hosted git repository. ralaoui pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mina-vysper.git
The following commit(s) were added to refs/heads/master by this push: new 01d18d1 Upgrade to smack 4 01d18d1 is described below commit 01d18d1cd9a42ad62ed22cacb7ed06d3b5adef28 Author: Réda Housni Alaoui <reda.housniala...@gmail.com> AuthorDate: Wed Aug 21 02:24:35 2019 +0200 Upgrade to smack 4 --- examples/pubsub-client/pom.xml | 19 ++- .../vysper/demo/pubsub/client/PubsubClientGUI.java | 11 +- .../demo/pubsub/client/PubsubClientModel.java | 55 ++++--- .../pubsub/client/PubsubCreateButtonListener.java | 3 +- .../pubsub/client/PubsubDeleteButtonListener.java | 3 +- .../demo/pubsub/client/PubsubEventListener.java | 2 +- .../pubsub/client/PubsubPublishButtonListener.java | 6 +- pom.xml | 26 +++- server/admin-console/pom.xml | 16 ++- .../vysper/console/AdHocCommandDataBuilder.java | 9 +- .../vysper/console/AdminConsoleController.java | 116 ++++++++------- .../vysper/console/ExtendedXMPPConnection.java | 74 +++++----- .../org/apache/vysper/console/HtmlFormBuilder.java | 61 ++++---- .../console/AdHocCommandDataBuilderTest.java | 12 +- .../vysper/console/AdminConsoleControllerTest.java | 21 ++- .../apache/vysper/console/HtmlFormBuilderTest.java | 52 ++++--- server/core-inttest/pom.xml | 22 ++- .../java/org/apache/vysper/smack/BasicClient.java | 114 +++++++-------- .../AbstractIntegrationTestCase.java | 53 ++++--- .../extension/xep0199_xmppping/PingPacket.java | 10 +- .../XmppPingIntegrationTestCase.java | 7 +- .../XmppPingNoSupportIntegrationTestCase.java | 9 +- .../vysper/xmpp/server/s2s/RunS2SServers.java | 159 ++++++++++----------- server/core/pom.xml | 22 ++- .../NonCheckingX509TrustManagerFactory.java | 2 +- .../server/s2s/DefaultXMPPServerConnector.java | 2 +- .../vysper/xmpp/server/s2s/Server2Server.java | 65 +++++---- server/extensions/xep0045-muc-inttest/pom.xml | 22 ++- .../inttest/AbstractIntegrationTestCase.java | 49 ++++--- .../inttest/AbstractMUCIntegrationTestCase.java | 17 ++- .../inttest/EnterExitRoomIntegrationTestCase.java | 38 ++--- .../inttest/ModerationIntegrationTestCase.java | 6 +- .../inttest/ParticipantStatusListenerAdapter.java | 63 ++++++-- server/extensions/xep0065-socks/pom.xml | 19 ++- .../xep0065_socks/Socks5IntegrationTest.java | 63 ++++---- 35 files changed, 730 insertions(+), 498 deletions(-) diff --git a/examples/pubsub-client/pom.xml b/examples/pubsub-client/pom.xml index 1803ff7..bb52efc 100644 --- a/examples/pubsub-client/pom.xml +++ b/examples/pubsub-client/pom.xml @@ -32,12 +32,27 @@ <dependencies> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smack</artifactId> + <artifactId>smack-tcp</artifactId> </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smackx</artifactId> + <artifactId>smack-resolver-javax</artifactId> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-sasl-javax</artifactId> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-java7</artifactId> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-extensions</artifactId> </dependency> </dependencies> diff --git a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientGUI.java b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientGUI.java index 9613859..ef986b3 100644 --- a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientGUI.java +++ b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientGUI.java @@ -19,6 +19,8 @@ */ package org.apache.vysper.demo.pubsub.client; +import org.jxmpp.stringprep.XmppStringprepException; + import java.awt.BorderLayout; import java.awt.GridLayout; @@ -122,11 +124,16 @@ public class PubsubClientGUI implements Runnable, ListSelectionListener { createAndShowGUI(); registerShutDownHook(); - login(); + try { + login(); + } catch (XmppStringprepException e) { + e.printStackTrace(); + return; + } pcm.refresh(); } - public void login() { + public void login() throws XmppStringprepException { do { askForCredentials(); } while (pcm.login() == false); diff --git a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientModel.java b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientModel.java index 440a995..b72351f 100644 --- a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientModel.java +++ b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientModel.java @@ -19,22 +19,28 @@ */ package org.apache.vysper.demo.pubsub.client; +import java.io.IOException; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; import javax.swing.DefaultListModel; +import org.jivesoftware.smack.AbstractXMPPConnection; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smackx.packet.DiscoverItems; -import org.jivesoftware.smackx.packet.DiscoverItems.Item; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smackx.disco.packet.DiscoverItems; +import org.jivesoftware.smackx.disco.packet.DiscoverItems.Item; import org.jivesoftware.smackx.pubsub.Affiliation; import org.jivesoftware.smackx.pubsub.Node; +import org.jivesoftware.smackx.pubsub.PubSubException; import org.jivesoftware.smackx.pubsub.PubSubManager; import org.jivesoftware.smackx.pubsub.Subscription; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; public class PubsubClientModel { private Map<String, DefaultListModel> nodeMessages = new TreeMap<String, DefaultListModel>(); @@ -43,7 +49,7 @@ public class PubsubClientModel { private PubsubEventListener pel = new PubsubEventListener(this); - private XMPPConnection connection; + private AbstractXMPPConnection connection; private PubSubManager pubsubMgr; @@ -69,7 +75,8 @@ public class PubsubClientModel { return jid; } - private void discoverAffiliations(Map<String, PubsubNode> lookup) throws XMPPException { + private void discoverAffiliations(Map<String, PubsubNode> lookup) throws XMPPException, + SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { List<Affiliation> lAffiliations = pubsubMgr.getAffiliations(); for (Affiliation affiliation : lAffiliations) { System.out.print(affiliation.getType()); @@ -81,7 +88,8 @@ public class PubsubClientModel { } } - private void discoverSubscriptions(Map<String, PubsubNode> lookup) throws XMPPException { + private void discoverSubscriptions(Map<String, PubsubNode> lookup) throws XMPPException, + SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { List<Subscription> lSubscriptions = pubsubMgr.getSubscriptions(); for (Subscription subscription : lSubscriptions) { System.out.print(subscription.getState()); @@ -95,11 +103,11 @@ public class PubsubClientModel { } } - private void discoverNodes(Map<String, PubsubNode> lookup) throws XMPPException { + private void discoverNodes(Map<String, PubsubNode> lookup) throws XMPPException, + SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { DiscoverItems di = pubsubMgr.discoverNodes(null); - Iterator<Item> iIt = di.getItems(); - while (iIt.hasNext()) { - Item i = iIt.next(); + List<Item> iIt = di.getItems(); + for (Item i : iIt) { System.out.println("Adding " + i.getNode()); PubsubNode n = new PubsubNode(i.getNode()); @@ -109,45 +117,48 @@ public class PubsubClientModel { } } - public boolean login() { - XMPPConnection.DEBUG_ENABLED = false; + public boolean login() throws XmppStringprepException { try { connection = connect(username, password, hostname); - } catch (XMPPException e) { + } catch (XMPPException | IOException | InterruptedException | SmackException e) { System.err.println("Login failed for user " + username); e.printStackTrace(); return false; } - pubsubMgr = new PubSubManager(connection, "pubsub.vysper.org"); + pubsubMgr = PubSubManager.getInstance(connection, JidCreate.bareFrom("pubsub.vysper.org")); return true; } - private XMPPConnection connect(String username, String password, String host) throws XMPPException { - XMPPConnection connection = new XMPPConnection(host); + private AbstractXMPPConnection connect(String username, String password, String host) + throws XMPPException, IOException, InterruptedException, SmackException { + AbstractXMPPConnection connection = new XMPPTCPConnection(username, password, host); connection.connect(); - connection.login(username, password); + connection.login(); return connection; } public void refresh() { - Map<String, PubsubNode> lookup = new HashMap<String, PubsubNode>(); + Map<String, PubsubNode> lookup = new HashMap<>(); try { discoverNodes(lookup); - } catch (XMPPException e) { + } catch (XMPPException | SmackException.NotConnectedException | InterruptedException + | SmackException.NoResponseException e) { e.printStackTrace(); } try { discoverSubscriptions(lookup); - } catch (XMPPException e) { + } catch (XMPPException | SmackException.NotConnectedException | InterruptedException + | SmackException.NoResponseException e) { e.printStackTrace(); } try { discoverAffiliations(lookup); - } catch (XMPPException e) { + } catch (XMPPException | SmackException.NotConnectedException | InterruptedException + | SmackException.NoResponseException e) { e.printStackTrace(); } @@ -160,7 +171,7 @@ public class PubsubClientModel { Node node = pubsubMgr.getNode(n.getNode()); node.removeItemEventListener(pel); // remove the listener in cases we already know the node node.addItemEventListener(pel); // add the listener for events - } catch (XMPPException e) { + } catch (XMPPException | SmackException.NoResponseException | SmackException.NotConnectedException | InterruptedException | PubSubException.NotAPubSubNodeException e) { e.printStackTrace(); } } diff --git a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubCreateButtonListener.java b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubCreateButtonListener.java index f3bb9da..bd6324c 100644 --- a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubCreateButtonListener.java +++ b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubCreateButtonListener.java @@ -29,6 +29,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; public class PubsubCreateButtonListener implements ActionListener { @@ -50,7 +51,7 @@ public class PubsubCreateButtonListener implements ActionListener { parent.getPubsubMgr().createNode(nodeID); System.out.println("Node created " + nodeID); parent.refresh(); - } catch (XMPPException e1) { + } catch (XMPPException | SmackException.NoResponseException | SmackException.NotConnectedException | InterruptedException e1) { System.err.println("Couldn't create node " + nodeID); e1.printStackTrace(); } diff --git a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubDeleteButtonListener.java b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubDeleteButtonListener.java index 84764ce..1ea9adf 100644 --- a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubDeleteButtonListener.java +++ b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubDeleteButtonListener.java @@ -27,6 +27,7 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; public class PubsubDeleteButtonListener implements ActionListener { @@ -47,7 +48,7 @@ public class PubsubDeleteButtonListener implements ActionListener { parent.getPubsubMgr().deleteNode(nodeID); System.out.println("Node deleted: " + nodeID); parent.refresh(); - } catch (XMPPException e1) { + } catch (XMPPException | SmackException.NoResponseException | SmackException.NotConnectedException | InterruptedException e1) { System.err.println("Couldn't delete node " + nodeID); e1.printStackTrace(); } diff --git a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubEventListener.java b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubEventListener.java index ccf355c..24cb8cd 100644 --- a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubEventListener.java +++ b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubEventListener.java @@ -38,7 +38,7 @@ public class PubsubEventListener implements ItemEventListener<PayloadItem<Simple System.out.println("Got something from " + e.getNodeId()); for (PayloadItem<SimplePayload> i : e.getItems()) { - lm.add(0, i.getPayload().toXML()); //alwasy add to the top + lm.add(0, i.getPayload().toXML(null)); //alwasy add to the top } } } diff --git a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubPublishButtonListener.java b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubPublishButtonListener.java index 66e901b..8ab004c 100644 --- a/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubPublishButtonListener.java +++ b/examples/pubsub-client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubPublishButtonListener.java @@ -24,10 +24,12 @@ import java.awt.event.ActionListener; import javax.swing.JTextField; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.pubsub.LeafNode; import org.jivesoftware.smackx.pubsub.Node; import org.jivesoftware.smackx.pubsub.PayloadItem; +import org.jivesoftware.smackx.pubsub.PubSubException; import org.jivesoftware.smackx.pubsub.PubSubManager; import org.jivesoftware.smackx.pubsub.SimplePayload; @@ -76,7 +78,7 @@ public class PubsubPublishButtonListener implements ActionListener { } else { throw new IllegalArgumentException("Can only send to leaf nodes"); } - } catch (XMPPException e1) { + } catch (XMPPException | SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e1) { System.err.println("Couldn't send an item to " + nodeID); e1.printStackTrace(); } @@ -92,7 +94,7 @@ public class PubsubPublishButtonListener implements ActionListener { Node node = null; try { node = pubsubMgr.getNode(nodeID); - } catch (XMPPException e1) { + } catch (XMPPException | SmackException.NoResponseException | SmackException.NotConnectedException | InterruptedException | PubSubException.NotAPubSubNodeException e1) { System.err.println("Couldn't get the node object for " + nodeID); e1.printStackTrace(); } diff --git a/pom.xml b/pom.xml index e1ca8a0..b3470ee 100644 --- a/pom.xml +++ b/pom.xml @@ -262,14 +262,32 @@ <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smack</artifactId> - <version>3.2.1</version> + <artifactId>smack-tcp</artifactId> + <version>4.3.4</version> </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smackx</artifactId> - <version>3.2.1</version> + <artifactId>smack-resolver-javax</artifactId> + <version>4.3.4</version> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-sasl-javax</artifactId> + <version>4.3.4</version> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-java7</artifactId> + <version>4.3.4</version> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-extensions</artifactId> + <version>4.3.4</version> </dependency> <dependency> diff --git a/server/admin-console/pom.xml b/server/admin-console/pom.xml index 335fc00..dfdc7bc 100644 --- a/server/admin-console/pom.xml +++ b/server/admin-console/pom.xml @@ -31,11 +31,23 @@ <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smack</artifactId> + <artifactId>smack-tcp</artifactId> </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smackx</artifactId> + <artifactId>smack-resolver-javax</artifactId> + </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-sasl-javax</artifactId> + </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-java7</artifactId> + </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-extensions</artifactId> </dependency> <dependency> diff --git a/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java b/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java index 01eb269..1caf79b 100644 --- a/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java +++ b/server/admin-console/src/main/java/org/apache/vysper/console/AdHocCommandDataBuilder.java @@ -22,9 +22,10 @@ package org.apache.vysper.console; import java.util.Map; import java.util.Map.Entry; -import org.jivesoftware.smackx.FormField; -import org.jivesoftware.smackx.packet.AdHocCommandData; -import org.jivesoftware.smackx.packet.DataForm; +import org.jivesoftware.smackx.commands.packet.AdHocCommandData; +import org.jivesoftware.smackx.xdata.packet.DataForm; +import org.apache.vysper.xmpp.stanza.dataforms.Field; +import org.jivesoftware.smackx.xdata.FormField; /** * Builds {@link AdHocCommandData} from posted data @@ -42,7 +43,7 @@ public class AdHocCommandDataBuilder { AdHocCommandData commandData = new AdHocCommandData(); commandData.setSessionID(getSingleValue(parameters, AdminConsoleController.SESSION_FIELD)); - DataForm form = new DataForm("submit"); + DataForm form = new DataForm(DataForm.Type.submit); for(Entry<String, String[]> entry : parameters.entrySet()) { if(!AdminConsoleController.SESSION_FIELD.equals(entry.getKey())) { diff --git a/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java b/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java index d3dbcf6..106d98b 100644 --- a/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java +++ b/server/admin-console/src/main/java/org/apache/vysper/console/AdminConsoleController.java @@ -19,6 +19,7 @@ */ package org.apache.vysper.console; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -27,16 +28,17 @@ import javax.servlet.http.HttpSession; import org.apache.vysper.xmpp.addressing.Entity; import org.apache.vysper.xmpp.addressing.EntityImpl; -import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ.Type; -import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.Stanza; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; import org.jivesoftware.smackx.commands.AdHocCommand.Action; import org.jivesoftware.smackx.commands.AdHocCommand.Status; import org.jivesoftware.smackx.commands.AdHocCommandNote; -import org.jivesoftware.smackx.packet.AdHocCommandData; -import org.jivesoftware.smackx.packet.DataForm; +import org.jivesoftware.smackx.commands.packet.AdHocCommandData; +import org.jivesoftware.smackx.xdata.packet.DataForm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; @@ -46,33 +48,34 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; /** - * MVC controller + * MVC controller * * @author The Apache MINA Project (d...@mina.apache.org) */ @Controller public class AdminConsoleController { - + private static final String MODEL_AUTHENTICATED = "authenticated"; public static final String SESSION_ATTRIBUTE = "smack.client"; public static final String SESSION_FIELD = "vysper-admingui-sessionid"; - + public static final Map<String, String> COMMANDS = new HashMap<String, String>(); static { COMMANDS.put("get-online-users-num", "Get online users"); COMMANDS.put("add-user", "Add user"); COMMANDS.put("change-user-password", "Change user password"); } - - private ConnectionConfiguration connectionConfiguration; - + + private XMPPTCPConnectionConfiguration connectionConfiguration; + private AdHocCommandDataBuilder adHocCommandDataBuilder = new AdHocCommandDataBuilder(); + private HtmlFormBuilder htmlFormBuilder = new HtmlFormBuilder(); - + @Autowired - public AdminConsoleController(ConnectionConfiguration connectionConfiguration) { + public AdminConsoleController(XMPPTCPConnectionConfiguration connectionConfiguration) { this.connectionConfiguration = connectionConfiguration; } @@ -82,10 +85,10 @@ public class AdminConsoleController { @RequestMapping("/") public ModelAndView index(HttpSession session) throws XMPPException { ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE); - if(client == null) { + if (client == null) { // login return login(); - } else if(!client.isConnected()) { + } else if (!client.isConnected()) { return login("Disconnected from XMPP server, please log in again"); } else { ModelAndView mav = new ModelAndView("index"); @@ -93,58 +96,59 @@ public class AdminConsoleController { return mav; } } - + private String getUserName(XMPPConnection client) { - Entity entity = EntityImpl.parseUnchecked(client.getUser()); + Entity entity = EntityImpl.parseUnchecked(client.getUser().toString()); return entity.getBareJID().getFullQualifiedName(); } - + /** * Show the initial command form - */ - @RequestMapping(value="/{command}", method=RequestMethod.GET) + */ + @RequestMapping(value = "/{command}", method = RequestMethod.GET) public ModelAndView command(@PathVariable("command") String command, HttpSession session) throws XMPPException { ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE); - if(client == null) { + if (client == null) { // login return login(); - } else if(!client.isConnected()) { + } else if (!client.isConnected()) { return login("Disconnected from XMPP server, please log in again"); } else { - if(!COMMANDS.keySet().contains(command)) { + if (!COMMANDS.keySet().contains(command)) { throw new ResourceNotFoundException(); } - + AdHocCommandData requestCommand = new AdHocCommandData(); - requestCommand.setType(Type.SET); + requestCommand.setType(Type.set); requestCommand.setFrom(client.getUser()); - requestCommand.setTo(client.getServiceName()); + requestCommand.setTo(client.getXMPPServiceDomain()); requestCommand.setAction(Action.execute); requestCommand.setNode("http://jabber.org/protocol/admin#" + command); - + return sendRequestAndGenerateForm(command, client, requestCommand); } } /** * Handle a submitted form and show the result or additional form - */ - @RequestMapping(value="/{command}", method=RequestMethod.POST) - public ModelAndView submitCommand(@PathVariable("command") String command, HttpServletRequest request, HttpSession session) throws XMPPException { + */ + @RequestMapping(value = "/{command}", method = RequestMethod.POST) + public ModelAndView submitCommand(@PathVariable("command") String command, HttpServletRequest request, + HttpSession session) throws XMPPException { ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE); - if(client == null) { + if (client == null) { // login return login(); - } else if(!client.isConnected()) { + } else if (!client.isConnected()) { return login("Disconnected from XMPP server, please log in again"); } else { @SuppressWarnings("unchecked") AdHocCommandData requestCommand = adHocCommandDataBuilder.build(request.getParameterMap()); - requestCommand.setType(Type.SET); + requestCommand.setType(Type.set); requestCommand.setFrom(client.getUser()); - requestCommand.setTo(client.getServiceName()); + requestCommand.setTo(client.getXMPPServiceDomain()); requestCommand.setNode("http://jabber.org/protocol/admin#" + command); - + return sendRequestAndGenerateForm(command, client, requestCommand); } } @@ -152,25 +156,26 @@ public class AdminConsoleController { private ModelAndView sendRequestAndGenerateForm(String command, ExtendedXMPPConnection client, AdHocCommandData requestCommand) { try { - Packet response = client.sendSync(requestCommand); - + Stanza response = client.sendSync(requestCommand); + StringBuffer htmlForm = new StringBuffer(); - if(response != null) { + if (response != null) { AdHocCommandData responseData = (AdHocCommandData) response; DataForm form = responseData.getForm(); - - for(AdHocCommandNote note : responseData.getNotes()) { + + for (AdHocCommandNote note : responseData.getNotes()) { htmlForm.append("<p class='note " + note.getType() + "'>" + note.getValue() + "</p>"); } - + htmlForm.append("<form action='' method='post'>"); - htmlForm.append("<input type='hidden' name='" + SESSION_FIELD + "' value='" + responseData.getSessionID() + "' />"); - + htmlForm.append("<input type='hidden' name='" + SESSION_FIELD + "' value='" + + responseData.getSessionID() + "' />"); + htmlForm.append(htmlFormBuilder.build(form)); - if(Status.executing.equals(responseData.getStatus())) { + if (Status.executing.equals(responseData.getStatus())) { htmlForm.append("<input type='submit' value='" + COMMANDS.get(command) + "' />"); - } else if(Status.completed.equals(responseData.getStatus())) { - if(form == null || form.getFields() == null || !form.getFields().hasNext()) { + } else if (Status.completed.equals(responseData.getStatus())) { + if (form == null || form.getFields() == null || form.getFields().isEmpty()) { // no field, print success htmlForm.append("<p>Command successful</p>"); } @@ -178,14 +183,14 @@ public class AdminConsoleController { htmlForm.append("</form>"); } else { htmlForm.append("<p class='note error'>Timeout waiting for response from XMPP server</p>"); - + } - + ModelAndView mav = new ModelAndView("command"); mav.addObject(MODEL_AUTHENTICATED, getUserName(client)); mav.addObject("form", htmlForm.toString()); return mav; - } catch (InterruptedException e) { + } catch (InterruptedException | SmackException.NotConnectedException e) { throw new RuntimeException(e); } } @@ -203,19 +208,20 @@ public class AdminConsoleController { protected ExtendedXMPPConnection createXMPPConnection() { return new ExtendedXMPPConnection(connectionConfiguration); } - + /** - * Connect and authenticate the user + * Connect and authenticate the user */ - @RequestMapping(value="/login", method=RequestMethod.POST) - public ModelAndView login(@RequestParam("username") String username, @RequestParam("password") String password, HttpSession session) { + @RequestMapping(value = "/login", method = RequestMethod.POST) + public ModelAndView login(@RequestParam("username") String username, @RequestParam("password") String password, + HttpSession session) { ExtendedXMPPConnection client = createXMPPConnection(); try { client.connect(); client.login(username, password); session.setAttribute(SESSION_ATTRIBUTE, client); return new ModelAndView("redirect:"); - } catch (XMPPException e) { + } catch (XMPPException | SmackException | IOException | InterruptedException e) { ModelAndView mav = new ModelAndView("index"); mav.addObject("error", "Failed to login to server: " + e.getMessage()); return mav; @@ -225,10 +231,10 @@ public class AdminConsoleController { /** * Log out and disconnect the user */ - @RequestMapping(value="/logout") + @RequestMapping(value = "/logout") public ModelAndView logout(HttpSession session) { ExtendedXMPPConnection client = (ExtendedXMPPConnection) session.getAttribute(SESSION_ATTRIBUTE); - if(client != null) { + if (client != null) { client.disconnect(); session.removeAttribute(SESSION_ATTRIBUTE); } diff --git a/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java b/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java index caa8790..4ecf501 100644 --- a/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java +++ b/server/admin-console/src/main/java/org/apache/vysper/console/ExtendedXMPPConnection.java @@ -24,76 +24,74 @@ import java.util.concurrent.TimeUnit; import javax.security.auth.callback.CallbackHandler; -import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.StanzaListener; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.filter.PacketFilter; -import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.filter.StanzaFilter; +import org.jivesoftware.smack.packet.Stanza; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; /** - * Extends {@link XMPPConnection} to add support for synchronous request-response + * Extends {@link XMPPConnection} to add support for synchronous + * request-response * * @author The Apache MINA Project (d...@mina.apache.org) */ -public class ExtendedXMPPConnection extends XMPPConnection { - - public ExtendedXMPPConnection(ConnectionConfiguration config, CallbackHandler callbackHandler) { - super(config, callbackHandler); - } +public class ExtendedXMPPConnection extends XMPPTCPConnection { - public ExtendedXMPPConnection(ConnectionConfiguration config) { + public ExtendedXMPPConnection(XMPPTCPConnectionConfiguration config) { super(config); } - public ExtendedXMPPConnection(String serviceName, CallbackHandler callbackHandler) { - super(serviceName, callbackHandler); - } +// public ExtendedXMPPConnection(String serviceName) { +// super(serviceName); +// } - public ExtendedXMPPConnection(String serviceName) { - super(serviceName); - } - - public static class IdPacketFilter implements PacketFilter { + public static class IdPacketFilter implements StanzaFilter { private String id; public IdPacketFilter(String id) { this.id = id; } - public boolean accept(Packet packet) { - return id.equals(packet.getPacketID()); + @Override + public boolean accept(Stanza stanza) { + return id.equals(stanza.getStanzaId()); } } - - public static class SyncPacketListener implements PacketListener { - private LinkedBlockingQueue<Packet> queue; - public SyncPacketListener(LinkedBlockingQueue<Packet> queue) { + public static class SyncPacketListener implements StanzaListener { + private LinkedBlockingQueue<Stanza> queue; + + public SyncPacketListener(LinkedBlockingQueue<Stanza> queue) { this.queue = queue; } - public void processPacket(Packet packet) { + @Override + public void processStanza(Stanza packet) { queue.offer(packet); } } - + /** * Send a request and wait for the response. + * * @param request * @return * @throws InterruptedException */ - public Packet sendSync(Packet request) throws InterruptedException { - LinkedBlockingQueue<Packet> queue = new LinkedBlockingQueue<Packet>(); - PacketListener listener = new SyncPacketListener(queue); - PacketFilter filter = new IdPacketFilter(request.getPacketID()); - - addPacketListener(listener, filter); - sendPacket(request); - - Packet response = queue.poll(10000, TimeUnit.MILLISECONDS); - removePacketListener(listener); - + public Stanza sendSync(Stanza request) throws InterruptedException, SmackException.NotConnectedException { + LinkedBlockingQueue<Stanza> queue = new LinkedBlockingQueue<>(); + StanzaListener listener = new SyncPacketListener(queue); + StanzaFilter filter = new IdPacketFilter(request.getPacketID()); + + addSyncStanzaListener(listener, filter); + sendStanza(request); + + Stanza response = queue.poll(10000, TimeUnit.MILLISECONDS); + removeSyncStanzaListener(listener); + return response; } } diff --git a/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java b/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java index 27acfdf..00002fd 100644 --- a/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java +++ b/server/admin-console/src/main/java/org/apache/vysper/console/HtmlFormBuilder.java @@ -23,9 +23,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.jivesoftware.smackx.FormField; -import org.jivesoftware.smackx.FormField.Option; -import org.jivesoftware.smackx.packet.DataForm; +import org.jivesoftware.smackx.xdata.FormField; +import org.jivesoftware.smackx.xdata.packet.DataForm; /** * Builds an HTML form from a {@link DataForm} @@ -44,36 +43,36 @@ public class HtmlFormBuilder { return ""; StringBuilder sb = new StringBuilder(); - Iterator<String> instructions = form.getInstructions(); - while (instructions.hasNext()) { - sb.append("<p class='instruction'>" + instructions.next() + "</p>"); + List<String> instructions = form.getInstructions(); + for (String instruction: instructions) { + sb.append("<p class='instruction'>" + instruction + "</p>"); } - Iterator<FormField> fields = form.getFields(); + Iterator<FormField> fields = form.getFields().iterator(); while (fields.hasNext()) { FormField field = fields.next(); - String type = field.getType(); + FormField.Type type = field.getType(); sb.append("<p>"); - if ("hidden".equals(type)) { + if (type == FormField.Type.hidden) { sb.append(hiddenFieldToHtml(field)); - } else if ("fixed".equals(type)) { + } else if (type == FormField.Type.fixed) { sb.append(fixedFieldToHtml(field)); - } else if ("jid-single".equals(type)) { + } else if (type == FormField.Type.jid_single) { sb.append(jidSingleFieldToHtml(field)); - } else if ("text-single".equals(type) || type == null) { + } else if (type == FormField.Type.text_single || type == null) { sb.append(textSingleFieldToHtml(field)); - } else if ("text-private".equals(type)) { + } else if (type == FormField.Type.text_private) { sb.append(textPrivateFieldToHtml(field)); - } else if ("text-multi".equals(type)) { + } else if (type == FormField.Type.text_multi) { sb.append(textMultiFieldToHtml(field)); - } else if ("list-single".equals(type)) { + } else if (type == FormField.Type.list_single) { sb.append(listSingleFieldToHtml(field)); - } else if ("list-multi".equals(type)) { + } else if (type == FormField.Type.list_multi) { sb.append(listMultiFieldToHtml(field)); - } else if ("jid-multi".equals(type)) { + } else if (type == FormField.Type.jid_multi) { // for now, do jid-multi as a textarea sb.append(textMultiFieldToHtml(field)); - } else if ("boolean".equals(type)) { + } else if (type == FormField.Type.bool) { sb.append(booleanFieldToHtml(field)); } else { throw new RuntimeException("Unknown field type: " + type); @@ -111,7 +110,7 @@ public class HtmlFormBuilder { StringBuilder sb = new StringBuilder(); if (field.getLabel() != null) sb.append(field.getLabel()); - sb.append(" <span>" + field.getValues().next() + "</span>"); + sb.append(" <span>" + field.getValues().get(0) + "</span>"); return sb.toString(); } @@ -141,7 +140,7 @@ public class HtmlFormBuilder { sb.append("'>"); boolean first = true; - Iterator<String> values = field.getValues(); + Iterator<CharSequence> values = field.getValues().iterator(); while(values.hasNext()) { if(!first) sb.append("\r\n"); sb.append(values.next()); @@ -153,16 +152,16 @@ public class HtmlFormBuilder { } private String listSingleFieldToHtml(FormField field) { - Iterator<String> fieldValues = field.getValues(); - List<String> values = new ArrayList<String>(); + Iterator<CharSequence> fieldValues = field.getValues().iterator(); + List<CharSequence> values = new ArrayList<>(); if(fieldValues.hasNext()) values.add(fieldValues.next()); return listFieldToHtml(field, values, false); } private String listMultiFieldToHtml(FormField field) { - Iterator<String> fieldValues = field.getValues(); - List<String> values = new ArrayList<String>(); + Iterator<CharSequence> fieldValues = field.getValues().iterator(); + List<CharSequence> values = new ArrayList<>(); while(fieldValues.hasNext()) { values.add(fieldValues.next()); } @@ -170,7 +169,7 @@ public class HtmlFormBuilder { return listFieldToHtml(field, values, true); } - private String listFieldToHtml(FormField field, List<String> values, boolean multiple) { + private String listFieldToHtml(FormField field, List<CharSequence> values, boolean multiple) { StringBuilder sb = new StringBuilder(); sb.append(labelToHtml(field)); sb.append("<select id='"); @@ -183,10 +182,10 @@ public class HtmlFormBuilder { } sb.append(">"); - Iterator<Option> options = field.getOptions(); + Iterator<FormField.Option> options = field.getOptions().iterator(); while(options.hasNext()) { - Option option = options.next(); + FormField.Option option = options.next(); sb.append("<option value='"); sb.append(option.getValue()); sb.append("'"); @@ -214,7 +213,7 @@ public class HtmlFormBuilder { private String booleanFieldToHtml(FormField field) { StringBuilder sb = new StringBuilder(); - boolean value = (field.getValues().hasNext() && "true".equals(field.getValues().next())); + boolean value = (!field.getValues().isEmpty() && "true".equals(field.getValues().get(0).toString())); sb.append(labelToHtml(field)); sb.append("<input name='"); @@ -257,9 +256,9 @@ public class HtmlFormBuilder { return field.isRequired() ? "required" : ""; } - private String getSingleValue(FormField field) { - if (field.getValues().hasNext()) { - return field.getValues().next(); + private CharSequence getSingleValue(FormField field) { + if (!field.getValues().isEmpty()) { + return field.getValues().get(0); } else { return ""; } diff --git a/server/admin-console/src/test/java/org/apache/vysper/console/AdHocCommandDataBuilderTest.java b/server/admin-console/src/test/java/org/apache/vysper/console/AdHocCommandDataBuilderTest.java index 2112c1f..5bd8e1c 100644 --- a/server/admin-console/src/test/java/org/apache/vysper/console/AdHocCommandDataBuilderTest.java +++ b/server/admin-console/src/test/java/org/apache/vysper/console/AdHocCommandDataBuilderTest.java @@ -23,9 +23,9 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.jivesoftware.smackx.FormField; -import org.jivesoftware.smackx.packet.AdHocCommandData; -import org.jivesoftware.smackx.packet.DataForm; +import org.jivesoftware.smackx.commands.packet.AdHocCommandData; +import org.jivesoftware.smackx.xdata.FormField; +import org.jivesoftware.smackx.xdata.packet.DataForm; import org.junit.Assert; import org.junit.Test; @@ -57,10 +57,10 @@ public class AdHocCommandDataBuilderTest { AdHocCommandData commandData = builder.build(parameters); DataForm form = commandData.getForm(); - Assert.assertTrue(form.getFields().hasNext()); - FormField field = form.getFields().next(); + Assert.assertFalse(form.getFields().isEmpty()); + FormField field = form.getFields().get(0); - Iterator<String> values = field.getValues(); + Iterator<CharSequence> values = field.getValues().iterator(); Assert.assertEquals("value 1", values.next()); Assert.assertEquals("value 2", values.next()); Assert.assertFalse(values.hasNext()); diff --git a/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java b/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java index dae3522..4611cd8 100644 --- a/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java +++ b/server/admin-console/src/test/java/org/apache/vysper/console/AdminConsoleControllerTest.java @@ -21,19 +21,24 @@ package org.apache.vysper.console; import javax.servlet.http.HttpServletRequest; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import org.springframework.web.servlet.ModelAndView; +import java.io.IOException; + +import static org.mockito.Mockito.mock; + public class AdminConsoleControllerTest { private static final String ENTITY = "t...@vysper.org"; private static final String PASSWORD = "password"; - private ExtendedXMPPConnection connection = Mockito.mock(ExtendedXMPPConnection.class); + private ExtendedXMPPConnection connection = mock(ExtendedXMPPConnection.class); private AdminConsoleController controller = new AdminConsoleController(null) { @Override @@ -42,11 +47,11 @@ public class AdminConsoleControllerTest { } }; - private HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + private HttpServletRequest request = mock(HttpServletRequest.class); private MockHttpSession session = new MockHttpSession(); @Test - public void login() throws XMPPException { + public void login() throws XMPPException, InterruptedException, IOException, SmackException { ModelAndView mav = controller.login(ENTITY, PASSWORD, session); Mockito.verify(connection).connect(); @@ -57,8 +62,9 @@ public class AdminConsoleControllerTest { } @Test - public void failedLogin() throws XMPPException { - Mockito.doThrow(new XMPPException()).when(connection).login(ENTITY, PASSWORD); + public void failedLogin() throws XMPPException, InterruptedException, IOException, SmackException { + XMPPException xmppException = mock(XMPPException.class); + Mockito.doThrow(xmppException).when(connection).login(ENTITY, PASSWORD); ModelAndView mav = controller.login(ENTITY, PASSWORD, session); @@ -72,8 +78,9 @@ public class AdminConsoleControllerTest { } @Test - public void failedConnect() throws XMPPException { - Mockito.doThrow(new XMPPException()).when(connection).connect(); + public void failedConnect() throws XMPPException, InterruptedException, IOException, SmackException { + XMPPException xmppException = mock(XMPPException.class); + Mockito.doThrow(xmppException).when(connection).connect(); ModelAndView mav = controller.login(ENTITY, PASSWORD, session); diff --git a/server/admin-console/src/test/java/org/apache/vysper/console/HtmlFormBuilderTest.java b/server/admin-console/src/test/java/org/apache/vysper/console/HtmlFormBuilderTest.java index 54ad4b5..cd6250b 100644 --- a/server/admin-console/src/test/java/org/apache/vysper/console/HtmlFormBuilderTest.java +++ b/server/admin-console/src/test/java/org/apache/vysper/console/HtmlFormBuilderTest.java @@ -19,9 +19,8 @@ */ package org.apache.vysper.console; -import org.jivesoftware.smackx.FormField; -import org.jivesoftware.smackx.FormField.Option; -import org.jivesoftware.smackx.packet.DataForm; +import org.jivesoftware.smackx.xdata.FormField; +import org.jivesoftware.smackx.xdata.packet.DataForm; import org.junit.Assert; import org.junit.Test; @@ -33,13 +32,13 @@ public class HtmlFormBuilderTest { private static final String VALUE2 = "Value 2"; private static final String VALUE3 = "Value 3"; - private DataForm form = new DataForm("form"); + private DataForm form = new DataForm(DataForm.Type.form); private HtmlFormBuilder builder = new HtmlFormBuilder(); @Test public void testHiddenField() { FormField field = new FormField("abc def"); - field.setType("hidden"); + field.setType(FormField.Type.hidden); field.addValue(VALUE1); form.addField(field); @@ -52,7 +51,7 @@ public class HtmlFormBuilderTest { @Test public void testTextPrivateField() { FormField field = new FormField("abc def"); - field.setType("text-private"); + field.setType(FormField.Type.text_private); field.addValue(VALUE1); form.addField(field); @@ -65,7 +64,7 @@ public class HtmlFormBuilderTest { @Test public void testTextSingleField() { FormField field = new FormField("abc def"); - field.setType("text-single"); + field.setType(FormField.Type.text_single); field.addValue(VALUE1); form.addField(field); @@ -77,8 +76,7 @@ public class HtmlFormBuilderTest { @Test public void testFixedField() { - FormField field = new FormField("abc def"); - field.setType("fixed"); + FormField field = new FormField(); field.addValue(VALUE1); field.setLabel(LABEL); form.addField(field); @@ -92,7 +90,7 @@ public class HtmlFormBuilderTest { @Test public void testJidSingleField() { FormField field = new FormField("abc def"); - field.setType("jid-single"); + field.setType(FormField.Type.jid_single); field.addValue(VALUE1); form.addField(field); @@ -105,7 +103,7 @@ public class HtmlFormBuilderTest { @Test public void testTextMultiField() { FormField field = new FormField("abc def"); - field.setType("text-multi"); + field.setType(FormField.Type.text_multi); field.addValue(VALUE1); field.addValue(VALUE2); field.addValue(VALUE3); @@ -120,7 +118,7 @@ public class HtmlFormBuilderTest { @Test public void testJidMultiField() { FormField field = new FormField("abc def"); - field.setType("jid-multi"); + field.setType(FormField.Type.jid_multi); field.addValue(VALUE1); field.addValue(VALUE2); field.addValue(VALUE3); @@ -135,9 +133,9 @@ public class HtmlFormBuilderTest { @Test public void listSingleFieldNoValue() { FormField field = new FormField("abc def"); - field.setType("list-single"); - field.addOption(new Option("Label 1", VALUE1)); - field.addOption(new Option(VALUE2)); + field.setType(FormField.Type.list_single); + field.addOption(new FormField.Option("Label 1", VALUE1)); + field.addOption(new FormField.Option(VALUE2)); form.addField(field); String actual = builder.build(form); @@ -149,9 +147,9 @@ public class HtmlFormBuilderTest { @Test public void listSingleFieldWithValue() { FormField field = new FormField("abc def"); - field.setType("list-single"); - field.addOption(new Option("Label 1", VALUE1)); - field.addOption(new Option(VALUE2)); + field.setType(FormField.Type.list_single); + field.addOption(new FormField.Option("Label 1", VALUE1)); + field.addOption(new FormField.Option(VALUE2)); field.addValue(VALUE1); form.addField(field); @@ -164,9 +162,9 @@ public class HtmlFormBuilderTest { @Test public void listMultiFieldNoValue() { FormField field = new FormField("abc def"); - field.setType("list-multi"); - field.addOption(new Option("Label 1", VALUE1)); - field.addOption(new Option(VALUE2)); + field.setType(FormField.Type.list_multi); + field.addOption(new FormField.Option("Label 1", VALUE1)); + field.addOption(new FormField.Option(VALUE2)); form.addField(field); String actual = builder.build(form); @@ -178,10 +176,10 @@ public class HtmlFormBuilderTest { @Test public void listMultiFieldWithValue() { FormField field = new FormField("abc def"); - field.setType("list-multi"); - field.addOption(new Option("Label 1", VALUE1)); - field.addOption(new Option(VALUE2)); - field.addOption(new Option(VALUE3)); + field.setType(FormField.Type.list_multi); + field.addOption(new FormField.Option("Label 1", VALUE1)); + field.addOption(new FormField.Option(VALUE2)); + field.addOption(new FormField.Option(VALUE3)); field.addValue(VALUE1); field.addValue(VALUE3); form.addField(field); @@ -200,7 +198,7 @@ public class HtmlFormBuilderTest { @Test public void testBooleanFieldDefault() { FormField field = new FormField("abc def"); - field.setType("boolean"); + field.setType(FormField.Type.bool); form.addField(field); String actual = builder.build(form); @@ -212,7 +210,7 @@ public class HtmlFormBuilderTest { @Test public void testBooleanFieldWithValue() { FormField field = new FormField("abc def"); - field.setType("boolean"); + field.setType(FormField.Type.bool); field.addValue("true"); form.addField(field); diff --git a/server/core-inttest/pom.xml b/server/core-inttest/pom.xml index 6ce5ad4..2516969 100644 --- a/server/core-inttest/pom.xml +++ b/server/core-inttest/pom.xml @@ -55,13 +55,31 @@ <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smack</artifactId> + <artifactId>smack-tcp</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smackx</artifactId> + <artifactId>smack-resolver-javax</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-sasl-javax</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-java7</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-extensions</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/server/core-inttest/src/test/java/org/apache/vysper/smack/BasicClient.java b/server/core-inttest/src/test/java/org/apache/vysper/smack/BasicClient.java index c58c18c..80f177e 100644 --- a/server/core-inttest/src/test/java/org/apache/vysper/smack/BasicClient.java +++ b/server/core-inttest/src/test/java/org/apache/vysper/smack/BasicClient.java @@ -21,44 +21,52 @@ package org.apache.vysper.smack; import java.util.Random; -import org.jivesoftware.smack.Chat; +import org.apache.vysper.xmpp.authentication.Plain; +import org.apache.vysper.xmpp.cryptography.NonCheckingX509TrustManagerFactory; import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.MessageListener; -import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.SASLAuthentication; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.StanzaListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.chat2.Chat; +import org.jivesoftware.smack.chat2.ChatManager; +import org.jivesoftware.smack.debugger.ConsoleDebugger; +import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.IQ; -import org.jivesoftware.smack.packet.Message; -import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smackx.packet.Time; -import org.jivesoftware.smackx.packet.Version; +import org.jivesoftware.smack.packet.Stanza; +import org.jivesoftware.smack.roster.Roster; +import org.jivesoftware.smack.sasl.SASLMechanism; +import org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; +import org.jivesoftware.smackx.iqversion.packet.Version; +import org.jivesoftware.smackx.time.packet.Time; +import org.jxmpp.jid.impl.JidCreate; /** */ public class BasicClient { - static class IQListener implements PacketListener { + static class IQListener implements StanzaListener { - public void processPacket(Packet packet) { + public void processStanza(Stanza packet) { IQ iq = (IQ) packet; String iqString = iq.toString(); - System.out.println("T" + System.currentTimeMillis() + " IQ: " + iqString + ": " + iq.toXML()); + System.out.println("T" + System.currentTimeMillis() + " IQ: " + iqString + ": " + iq.toXML(null)); } } - static class PresenceListener implements PacketListener { + static class PresenceListener implements StanzaListener { - public void processPacket(Packet packet) { + public void processStanza(Stanza packet) { Presence presence = (Presence) packet; String iqString = presence.toString(); - final PacketExtension extension = presence.getExtension("http://jabber.org/protocol/caps"); + final ExtensionElement extension = presence.getExtension("http://jabber.org/protocol/caps"); if (extension != null) - System.out.println("T" + System.currentTimeMillis() + " Pres: " + iqString + ": " + presence.toXML()); + System.out + .println("T" + System.currentTimeMillis() + " Pres: " + iqString + ": " + presence.toXML(null)); } } @@ -68,39 +76,23 @@ public class BasicClient { String to = args.length < 2 ? null : args[1]; try { - ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost"); - // ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("xmpp.eu"); - connectionConfiguration.setCompressionEnabled(false); - connectionConfiguration.setSelfSignedCertificateEnabled(true); - connectionConfiguration.setExpiredCertificatesCheckEnabled(false); - connectionConfiguration.setDebuggerEnabled(true); - connectionConfiguration.setSASLAuthenticationEnabled(true); - connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required); - XMPPConnection.DEBUG_ENABLED = true; - XMPPConnection connection = new XMPPConnection(connectionConfiguration); + XMPPTCPConnectionConfiguration connectionConfiguration = XMPPTCPConnectionConfiguration.builder() + .setHost("localhost").setCompressionEnabled(false) + .setCustomX509TrustManager(NonCheckingX509TrustManagerFactory.X509) + .setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE) + .addEnabledSaslMechanism(SASLMechanism.PLAIN) + .setSecurityMode(ConnectionConfiguration.SecurityMode.required).build(); + + XMPPTCPConnection connection = new XMPPTCPConnection(connectionConfiguration); connection.connect(); - SASLAuthentication saslAuthentication = connection.getSASLAuthentication(); - // saslAuthentication.authenticateAnonymously(); - // saslAuthentication.authenticate("us...@vysper.org", "password1", "test"); - - // if (!saslAuthentication.isAuthenticated()) return; - connection.login(me + "@vysper.org", "password1"); - connection.getRoster().setSubscriptionMode(Roster.SubscriptionMode.accept_all); + Roster.getInstanceFor(connection).setSubscriptionMode(Roster.SubscriptionMode.accept_all); - connection.addPacketListener(new IQListener(), new PacketFilter() { - public boolean accept(Packet packet) { - return packet instanceof IQ; - } - }); + connection.addSyncStanzaListener(new IQListener(), packet -> packet instanceof IQ); - connection.addPacketListener(new PresenceListener(), new PacketFilter() { - public boolean accept(Packet packet) { - return packet instanceof Presence; - } - }); + connection.addSyncStanzaListener(new PresenceListener(), packet -> packet instanceof Presence); Chat chat = null; if (to != null) { @@ -108,16 +100,16 @@ public class BasicClient { presence.setFrom(connection.getUser()); String toEntity = to + "@vysper.org"; presence.setTo(toEntity); - connection.sendPacket(presence); + connection.sendStanza(presence); - chat = connection.getChatManager().createChat(toEntity, new MessageListener() { - public void processMessage(Chat inchat, Message message) { - System.out.println("log received message: " + message.getBody()); - } + ChatManager chatManager = ChatManager.getInstanceFor(connection); + chat = chatManager.chatWith(JidCreate.entityBareFrom(toEntity)); + chatManager.addIncomingListener((from, message, chat1) -> { + System.out.println("log received message: " + message.getBody()); }); } - connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available)); + connection.sendStanza(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available)); Thread.sleep(1000); @@ -127,19 +119,20 @@ public class BasicClient { // query server time sendIQGetWithTimestamp(connection, new Time()); - /* while (to != null) { - // chat.sendMessage("Hello " + to + " at " + new Date()); - try { Thread.sleep((new Random().nextInt(15)+1)*1000 ); } catch (InterruptedException e) { ; } - }*/ + /* + * while (to != null) { // chat.sendMessage("Hello " + to + " at " + new + * Date()); try { Thread.sleep((new Random().nextInt(15)+1)*1000 ); } catch + * (InterruptedException e) { ; } } + */ for (int i = 0; i < 10; i++) { - connection.sendPacket(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available)); + connection.sendStanza(new Presence(Presence.Type.available, "pommes", 1, Presence.Mode.available)); try { Thread.sleep((new Random().nextInt(15) + 10) * 1000); } catch (InterruptedException e) { ; } - connection.sendPacket(new Presence(Presence.Type.available, "nickes", 1, Presence.Mode.away)); + connection.sendStanza(new Presence(Presence.Type.available, "nickes", 1, Presence.Mode.away)); try { Thread.sleep((new Random().nextInt(15) + 10) * 1000); } catch (InterruptedException e) { @@ -162,14 +155,15 @@ public class BasicClient { } catch (InterruptedException ie) { ; } - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. } System.exit(0); } - private static void sendIQGetWithTimestamp(XMPPConnection connection, IQ iq) { - iq.setType(IQ.Type.GET); - connection.sendPacket(iq); + private static void sendIQGetWithTimestamp(XMPPConnection connection, IQ iq) + throws SmackException.NotConnectedException, InterruptedException { + iq.setType(IQ.Type.get); + connection.sendStanza(iq); System.out.println("T" + System.currentTimeMillis() + " IQ request sent"); } } diff --git a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/AbstractIntegrationTestCase.java b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/AbstractIntegrationTestCase.java index bde7baf..34d3058 100644 --- a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/AbstractIntegrationTestCase.java +++ b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/AbstractIntegrationTestCase.java @@ -31,16 +31,27 @@ import org.apache.vysper.storage.StorageProviderRegistry; import org.apache.vysper.storage.inmemory.MemoryStorageProviderRegistry; import org.apache.vysper.xmpp.addressing.EntityImpl; import org.apache.vysper.xmpp.authentication.AccountManagement; +import org.apache.vysper.xmpp.cryptography.NonCheckingX509TrustManagerFactory; import org.apache.vysper.xmpp.server.XMPPServer; import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.StanzaCollector; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.debugger.ConsoleDebugger; import org.jivesoftware.smack.filter.PacketIDFilter; +import org.jivesoftware.smack.filter.StanzaIdFilter; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.Stanza; +import org.jivesoftware.smack.sasl.SASLMechanism; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLSession; + /** */ public abstract class AbstractIntegrationTestCase extends TestCase { @@ -59,7 +70,7 @@ public abstract class AbstractIntegrationTestCase extends TestCase { private static final int DEFAULT_SERVER_PORT = 25222; - protected XMPPConnection client; + protected XMPPTCPConnection client; private XMPPServer server; @@ -72,7 +83,7 @@ public abstract class AbstractIntegrationTestCase extends TestCase { @Override protected void setUp() throws Exception { // make sure Smack times out after 5 seconds - SmackConfiguration.setPacketReplyTimeout(5000); + SmackConfiguration.setDefaultReplyTimeout(5000); port = findFreePort(); @@ -105,30 +116,34 @@ public abstract class AbstractIntegrationTestCase extends TestCase { Thread.sleep(200); } - protected XMPPConnection connectClient(int port, String username, String password) throws Exception { - ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost", port); - connectionConfiguration.setCompressionEnabled(false); - connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required); - connectionConfiguration.setSASLAuthenticationEnabled(true); - connectionConfiguration.setDebuggerEnabled(false); - connectionConfiguration.setKeystorePath("src/main/config/bogus_mina_tls.cert"); - connectionConfiguration.setTruststorePath("src/main/config/bogus_mina_tls.cert"); - connectionConfiguration.setTruststorePassword("boguspw"); - - XMPPConnection.DEBUG_ENABLED = true; - XMPPConnection client = new XMPPConnection(connectionConfiguration); + protected XMPPTCPConnection connectClient(int port, String username, String password) throws Exception { + XMPPTCPConnectionConfiguration connectionConfiguration = XMPPTCPConnectionConfiguration + .builder() + .setHost("localhost") + .setXmppDomain(SERVER_DOMAIN) + .setPort(port) + .setCompressionEnabled(false) + .setSecurityMode(ConnectionConfiguration.SecurityMode.required) + .addEnabledSaslMechanism(SASLMechanism.PLAIN) + .setHostnameVerifier((hostname, session) -> true) + .setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE) + .setKeystorePath("src/main/config/bogus_mina_tls.cert") + .setCustomX509TrustManager(NonCheckingX509TrustManagerFactory.X509) + .build(); + + XMPPTCPConnection client = new XMPPTCPConnection(connectionConfiguration); client.connect(); - client.login(username, password); + return client; } - protected Packet sendSync(XMPPConnection client, Packet request) { + protected Stanza sendSync(XMPPConnection client, Stanza request) throws SmackException.NotConnectedException, InterruptedException { // Create a packet collector to listen for a response. - PacketCollector collector = client.createPacketCollector(new PacketIDFilter(request.getPacketID())); + StanzaCollector collector = client.createStanzaCollector(new StanzaIdFilter(request.getStanzaId())); - client.sendPacket(request); + client.sendStanza(request); // Wait up to 5 seconds for a result. return collector.nextResult(5000); diff --git a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/PingPacket.java b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/PingPacket.java index 8599872..7683c20 100644 --- a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/PingPacket.java +++ b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/PingPacket.java @@ -22,9 +22,15 @@ package org.apache.vysper.xmpp.modules.extension.xep0199_xmppping; import org.jivesoftware.smack.packet.IQ; public class PingPacket extends IQ { + + public PingPacket() { + super("ping", "urn:xmpp:ping"); + } + @Override - public String getChildElementXML() { - return "<ping xmlns='urn:xmpp:ping'/>"; + protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { + xml.setEmptyElement(); + return xml; } } \ No newline at end of file diff --git a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingIntegrationTestCase.java b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingIntegrationTestCase.java index ccb5289..44a1773 100644 --- a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingIntegrationTestCase.java +++ b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingIntegrationTestCase.java @@ -33,15 +33,14 @@ public class XmppPingIntegrationTestCase extends AbstractIntegrationTestCase { public void testClientServerPing() throws Exception { PingPacket pingRequest = new PingPacket(); - pingRequest.setType(IQ.Type.GET); + pingRequest.setType(IQ.Type.get); pingRequest.setTo(SERVER_DOMAIN); pingRequest.setFrom(TEST_USERNAME1); IQ result = (IQ) sendSync(client, pingRequest); assertNotNull(result); - assertEquals(IQ.Type.RESULT, result.getType()); - assertEquals(SERVER_DOMAIN, result.getFrom()); - assertEquals(TEST_USERNAME1, result.getTo()); + assertEquals(IQ.Type.result, result.getType()); + assertEquals(SERVER_DOMAIN, result.getFrom().toString()); } } diff --git a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingNoSupportIntegrationTestCase.java b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingNoSupportIntegrationTestCase.java index 038981e..68bc169 100644 --- a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingNoSupportIntegrationTestCase.java +++ b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0199_xmppping/XmppPingNoSupportIntegrationTestCase.java @@ -33,16 +33,15 @@ public class XmppPingNoSupportIntegrationTestCase extends AbstractIntegrationTes public void testClientServerPing() throws Exception { PingPacket pingRequest = new PingPacket(); - pingRequest.setType(IQ.Type.GET); + pingRequest.setType(IQ.Type.get); pingRequest.setTo(SERVER_DOMAIN); pingRequest.setFrom(TEST_USERNAME1); IQ result = (IQ) sendSync(client, pingRequest); assertNotNull(result); - assertEquals(IQ.Type.ERROR, result.getType()); - assertEquals(SERVER_DOMAIN, result.getFrom()); - assertEquals(TEST_USERNAME1, result.getTo()); - assertEquals("service-unavailable", result.getError().getCondition()); + assertEquals(IQ.Type.error, result.getType()); + assertEquals(SERVER_DOMAIN, result.getFrom().toString()); + assertEquals("service-unavailable", result.getError().getCondition().toString()); } } diff --git a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/server/s2s/RunS2SServers.java b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/server/s2s/RunS2SServers.java index 83d40a5..89d88f4 100644 --- a/server/core-inttest/src/test/java/org/apache/vysper/xmpp/server/s2s/RunS2SServers.java +++ b/server/core-inttest/src/test/java/org/apache/vysper/xmpp/server/s2s/RunS2SServers.java @@ -27,10 +27,6 @@ import java.io.IOException; import java.util.Properties; import java.util.concurrent.LinkedBlockingQueue; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - import org.apache.vysper.mina.C2SEndpoint; import org.apache.vysper.mina.S2SEndpoint; import org.apache.vysper.storage.StorageProviderRegistry; @@ -39,19 +35,26 @@ import org.apache.vysper.xmpp.addressing.Entity; import org.apache.vysper.xmpp.addressing.EntityImpl; import org.apache.vysper.xmpp.authentication.AccountCreationException; import org.apache.vysper.xmpp.authentication.AccountManagement; +import org.apache.vysper.xmpp.cryptography.NonCheckingX509TrustManagerFactory; import org.apache.vysper.xmpp.server.XMPPServer; -import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.Stanza; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; +import org.jxmpp.jid.impl.JidCreate; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; public class RunS2SServers extends TestCase { private static final String FILE_FILTER = "s2s-p"; - + public static Test suite() { File testsDir = new File("."); File[] testFiles = testsDir.listFiles(new FilenameFilter() { @@ -59,9 +62,9 @@ public class RunS2SServers extends TestCase { return name.startsWith(FILE_FILTER); } }); - + TestSuite suite = new TestSuite("S2S integration tests"); - for(File testFile : testFiles) { + for (File testFile : testFiles) { try { suite.addTest(new RunS2SServers(testFile)); } catch (IOException e) { @@ -70,10 +73,11 @@ public class RunS2SServers extends TestCase { } return suite; } - + private File testFile; + private Properties config = new Properties(); - + public RunS2SServers(File testFile) throws IOException { this.testFile = testFile; config.load(new FileInputStream(testFile)); @@ -95,9 +99,9 @@ public class RunS2SServers extends TestCase { String keystorePath = config.getProperty("keystore.path"); String keystorePassword = config.getProperty("keystore.password"); - + XMPPServer server = createLocalServer(localServer, localUser, localPassword, keystorePath, keystorePassword); - + Thread.sleep(2000); System.out.println(); @@ -105,12 +109,13 @@ public class RunS2SServers extends TestCase { System.out.println("Connecting local client"); System.out.println(); System.out.println(); - - LinkedBlockingQueue<Packet> localClientPackages = new LinkedBlockingQueue<Packet>(); - LinkedBlockingQueue<Packet> remoteClientPackages = new LinkedBlockingQueue<Packet>(); - - XMPPConnection localClient = connectClient(localConnect, localUser.getFullQualifiedName(), localPassword, keystorePath, keystorePassword, localClientPackages); -// XMPPConnection localClient = null; + + LinkedBlockingQueue<Stanza> localClientPackages = new LinkedBlockingQueue<>(); + LinkedBlockingQueue<Stanza> remoteClientPackages = new LinkedBlockingQueue<>(); + + XMPPTCPConnection localClient = connectClient(localConnect, localUser.getFullQualifiedName(), localPassword, + keystorePath, keystorePassword, localClientPackages); + // XMPPConnection localClient = null; System.out.println(); System.out.println(); @@ -118,8 +123,9 @@ public class RunS2SServers extends TestCase { System.out.println(); System.out.println(); -// XMPPConnection remoteClient = connectClient(remoteServer, remoteUser, remotePassword, keystorePath, keystorePassword, remoteClientPackages); - XMPPConnection remoteClient = null; + // XMPPConnection remoteClient = connectClient(remoteServer, remoteUser, + // remotePassword, keystorePath, keystorePassword, remoteClientPackages); + XMPPTCPConnection remoteClient = null; Thread.sleep(3000); @@ -130,39 +136,39 @@ public class RunS2SServers extends TestCase { System.out.println(); remoteClientPackages.clear(); - Message msg = new Message(remoteUser); + Message msg = new Message(JidCreate.from(remoteUser)); msg.setBody("Hello world"); - - localClient.sendPacket(msg); - -// Packet packet = remoteClientPackages.poll(15000, TimeUnit.MILLISECONDS); -// if(packet != null && packet instanceof Message) { -// System.out.println("!!!!!!" + ((Message)packet).getBody()); -// } else { -// fail("Message not received by remote client"); -// } -// -// Thread.sleep(3000); -// -// System.out.println(); -// System.out.println(); -// System.out.println("Sending message from remote to local"); -// System.out.println(); -// System.out.println(); -// -// localClientPackages.clear(); -// msg = new Message(localUser.getFullQualifiedName()); -// msg.setBody("Hello world"); -// -// remoteClient.sendPacket(msg); -// -// packet = localClientPackages.poll(15000, TimeUnit.MILLISECONDS); -// if(packet != null && packet instanceof Message) { -// System.out.println("!!!!!!" + ((Message)packet).getBody()); -// } else { -// fail("Message not received by local client"); -// } - + + localClient.sendStanza(msg); + + // Packet packet = remoteClientPackages.poll(15000, TimeUnit.MILLISECONDS); + // if(packet != null && packet instanceof Message) { + // System.out.println("!!!!!!" + ((Message)packet).getBody()); + // } else { + // fail("Message not received by remote client"); + // } + // + // Thread.sleep(3000); + // + // System.out.println(); + // System.out.println(); + // System.out.println("Sending message from remote to local"); + // System.out.println(); + // System.out.println(); + // + // localClientPackages.clear(); + // msg = new Message(localUser.getFullQualifiedName()); + // msg.setBody("Hello world"); + // + // remoteClient.sendPacket(msg); + // + // packet = localClientPackages.poll(15000, TimeUnit.MILLISECONDS); + // if(packet != null && packet instanceof Message) { + // System.out.println("!!!!!!" + ((Message)packet).getBody()); + // } else { + // fail("Message not received by local client"); + // } + Thread.sleep(15000); System.out.println(); System.out.println(); @@ -172,35 +178,28 @@ public class RunS2SServers extends TestCase { remoteClient.disconnect(); localClient.disconnect(); - + Thread.sleep(5000); - + server.stop(); } - private XMPPConnection connectClient(String host, String user, String password, String keystorePath, String keystorePassword, final LinkedBlockingQueue<Packet> packageQueue) - throws XMPPException { -// ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(host, 5222); - ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(host, 5222, "protocol7.com"); - connectionConfiguration.setKeystorePath(keystorePath); - connectionConfiguration.setTruststorePath(keystorePath); - connectionConfiguration.setTruststorePassword(keystorePassword); - XMPPConnection client = new XMPPConnection(connectionConfiguration); - + private XMPPTCPConnection connectClient(String host, String user, String password, String keystorePath, + String keystorePassword, final LinkedBlockingQueue<Stanza> packageQueue) + throws XMPPException, IOException, InterruptedException, SmackException { + XMPPTCPConnectionConfiguration connectionConfiguration = XMPPTCPConnectionConfiguration.builder().setHost(host) + .setPort(5222).setXmppDomain("protocol7.com").setKeystorePath(keystorePath) + .setCustomX509TrustManager(NonCheckingX509TrustManagerFactory.X509).build(); + + XMPPTCPConnection client = new XMPPTCPConnection(connectionConfiguration); + client.connect(); client.login(user, password); - client.addPacketListener(new PacketListener() { - public void processPacket(Packet packet) { - System.out.println("# " + packet); - packageQueue.add(packet); - } - }, new PacketFilter() { - public boolean accept(Packet arg0) { - return true; - } - }); + client.addSyncStanzaListener(packet -> { + System.out.println("# " + packet); + packageQueue.add(packet); + }, arg0 -> true); - return client; } @@ -210,7 +209,7 @@ public class RunS2SServers extends TestCase { StorageProviderRegistry providerRegistry = new MemoryStorageProviderRegistry(); final AccountManagement accountManagement = (AccountManagement) providerRegistry - .retrieve(AccountManagement.class); + .retrieve(AccountManagement.class); if (!accountManagement.verifyAccountExists(localUser)) { accountManagement.addUser(localUser, password); @@ -218,13 +217,13 @@ public class RunS2SServers extends TestCase { // S2S endpoint server.addEndpoint(new S2SEndpoint()); - + // C2S endpoint server.addEndpoint(new C2SEndpoint()); - + server.setStorageProviderRegistry(providerRegistry); server.setTLSCertificateInfo(new File(keystorePath), keystorePassword); - + server.start(); return server; } diff --git a/server/core/pom.xml b/server/core/pom.xml index 38d5901..1f388d6 100644 --- a/server/core/pom.xml +++ b/server/core/pom.xml @@ -136,13 +136,31 @@ <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smack</artifactId> + <artifactId>smack-tcp</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smackx</artifactId> + <artifactId>smack-resolver-javax</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-sasl-javax</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-java7</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-extensions</artifactId> <scope>test</scope> </dependency> diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/NonCheckingX509TrustManagerFactory.java b/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/NonCheckingX509TrustManagerFactory.java index 4c3ff4e..c50c9b5 100644 --- a/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/NonCheckingX509TrustManagerFactory.java +++ b/server/core/src/main/java/org/apache/vysper/xmpp/cryptography/NonCheckingX509TrustManagerFactory.java @@ -46,7 +46,7 @@ public class NonCheckingX509TrustManagerFactory extends TrustManagerFactorySpi i static final Logger logger = LoggerFactory.getLogger(NonCheckingX509TrustManagerFactory.class); - static final X509TrustManager X509 = new X509TrustManager() { + public static final X509TrustManager X509 = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { logger.error("this XMPP Vysper instance uses NonCheckingTrustManagerFactory, clients certificates are not checked"); } diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnector.java b/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnector.java index 20046f8..6287769 100644 --- a/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnector.java +++ b/server/core/src/main/java/org/apache/vysper/xmpp/server/s2s/DefaultXMPPServerConnector.java @@ -138,7 +138,7 @@ public class DefaultXMPPServerConnector implements XmppPingListener, XMPPServerC LOG.warn("XMPP handshake with {} at {} timed out", remoteServer, ipAddress); } } catch (InterruptedException e) { - throw new RemoteServerTimeoutException("Connection to " + remoteServer + " was interrupted", e); + throw new RemoteServerTimeoutException("XMPPConnection to " + remoteServer + " was interrupted", e); } } diff --git a/server/core/src/test/java/org/apache/vysper/xmpp/server/s2s/Server2Server.java b/server/core/src/test/java/org/apache/vysper/xmpp/server/s2s/Server2Server.java index 29d5cc9..87e997d 100644 --- a/server/core/src/test/java/org/apache/vysper/xmpp/server/s2s/Server2Server.java +++ b/server/core/src/test/java/org/apache/vysper/xmpp/server/s2s/Server2Server.java @@ -19,7 +19,11 @@ */ package org.apache.vysper.xmpp.server.s2s; import java.io.File; +import java.io.IOException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import org.apache.mina.filter.ssl.BogusTrustManagerFactory; import org.apache.vysper.mina.C2SEndpoint; import org.apache.vysper.mina.S2SEndpoint; import org.apache.vysper.storage.StorageProviderRegistry; @@ -27,6 +31,7 @@ import org.apache.vysper.storage.inmemory.MemoryStorageProviderRegistry; import org.apache.vysper.xmpp.addressing.Entity; import org.apache.vysper.xmpp.addressing.EntityImpl; import org.apache.vysper.xmpp.authentication.AccountManagement; +import org.apache.vysper.xmpp.cryptography.NonCheckingX509TrustManagerFactory; import org.apache.vysper.xmpp.protocol.NamespaceURIs; import org.apache.vysper.xmpp.server.ServerRuntimeContext; import org.apache.vysper.xmpp.server.XMPPServer; @@ -34,14 +39,27 @@ import org.apache.vysper.xmpp.stanza.Stanza; import org.apache.vysper.xmpp.stanza.StanzaBuilder; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.StanzaListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.filter.StanzaFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.stringprep.XmppStringprepException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.X509TrustManager; public class Server2Server { + + private static final Logger LOG = LoggerFactory.getLogger(Server2Server.class); public static void main(String[] args) throws Exception { Entity localServer = EntityImpl.parseUnchecked(args[0]); @@ -111,42 +129,41 @@ public class Server2Server { private static void sendMessagesUsingClients(Entity localUser, Entity remoteServer, Entity remoteUser, String remotePassword, String keystorePath, String keystorePassword) throws XMPPException, - InterruptedException { - ConnectionConfiguration localConnectionConfiguration = new ConnectionConfiguration("localhost", 5222); - localConnectionConfiguration.setKeystorePath(keystorePath); - localConnectionConfiguration.setTruststorePath(keystorePath); - localConnectionConfiguration.setTruststorePassword(keystorePassword); - XMPPConnection localClient = new XMPPConnection(localConnectionConfiguration); + InterruptedException, IOException, SmackException { + XMPPTCPConnectionConfiguration localConnectionConfiguration = XMPPTCPConnectionConfiguration + .builder() + .setHost("localhost") + .setPort(5222) + .setKeystorePath(keystorePath) + .setCustomX509TrustManager(NonCheckingX509TrustManagerFactory.X509) + .build(); + + XMPPTCPConnection localClient = new XMPPTCPConnection(localConnectionConfiguration); localClient.connect(); localClient.login(localUser.getNode(), "password1"); - localClient.addPacketListener(new PacketListener() { - public void processPacket(Packet packet) { - System.out.println("# " + packet); - } - }, new PacketFilter() { - public boolean accept(Packet arg0) { - return true; - } - }); - - - ConnectionConfiguration remoteConnectionConfiguration = new ConnectionConfiguration(remoteServer.getFullQualifiedName(), 5222); - remoteConnectionConfiguration.setKeystorePath(keystorePath); - remoteConnectionConfiguration.setTruststorePath(keystorePath); - remoteConnectionConfiguration.setTruststorePassword(keystorePassword); - XMPPConnection remoteClient = new XMPPConnection(remoteConnectionConfiguration); + localClient.addSyncStanzaListener(packet -> System.out.println("# " + packet), stanza -> false); + + XMPPTCPConnectionConfiguration remoteConnectionConfiguration = XMPPTCPConnectionConfiguration + .builder() + .setHost(remoteServer.getFullQualifiedName()) + .setPort(5222) + .setKeystorePath(keystorePath) + .setCustomX509TrustManager(NonCheckingX509TrustManagerFactory.X509) + .build(); + + XMPPTCPConnection remoteClient = new XMPPTCPConnection(remoteConnectionConfiguration); remoteClient.connect(); remoteClient.login(remoteUser.getNode(), remotePassword); Thread.sleep(3000); - Message msg = new Message(remoteUser.getFullQualifiedName()); + Message msg = new Message(JidCreate.entityFrom(remoteUser.getFullQualifiedName())); // Message msg = new Message(localUser.getFullQualifiedName()); msg.setBody("Hello world"); - localClient.sendPacket(msg); + localClient.sendStanza(msg); // remoteClient.sendPacket(msg); diff --git a/server/extensions/xep0045-muc-inttest/pom.xml b/server/extensions/xep0045-muc-inttest/pom.xml index 0c26fc0..de7c748 100644 --- a/server/extensions/xep0045-muc-inttest/pom.xml +++ b/server/extensions/xep0045-muc-inttest/pom.xml @@ -55,13 +55,31 @@ <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smack</artifactId> + <artifactId>smack-tcp</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smackx</artifactId> + <artifactId>smack-resolver-javax</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-sasl-javax</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-java7</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-extensions</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractIntegrationTestCase.java b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractIntegrationTestCase.java index 3d42e16..0bd17d3 100644 --- a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractIntegrationTestCase.java +++ b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractIntegrationTestCase.java @@ -23,24 +23,30 @@ import java.io.File; import java.io.IOException; import java.net.ServerSocket; -import junit.framework.TestCase; - import org.apache.vysper.mina.C2SEndpoint; import org.apache.vysper.mina.TCPEndpoint; import org.apache.vysper.storage.StorageProviderRegistry; import org.apache.vysper.storage.inmemory.MemoryStorageProviderRegistry; import org.apache.vysper.xmpp.addressing.EntityImpl; import org.apache.vysper.xmpp.authentication.AccountManagement; +import org.apache.vysper.xmpp.cryptography.NonCheckingX509TrustManagerFactory; import org.apache.vysper.xmpp.server.XMPPServer; import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.PacketCollector; import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.SmackException; +import org.jivesoftware.smack.StanzaCollector; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.filter.PacketIDFilter; -import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.debugger.ConsoleDebugger; +import org.jivesoftware.smack.filter.StanzaIdFilter; +import org.jivesoftware.smack.packet.Stanza; +import org.jivesoftware.smack.sasl.SASLMechanism; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import junit.framework.TestCase; + /** */ public abstract class AbstractIntegrationTestCase extends TestCase { @@ -50,7 +56,7 @@ public abstract class AbstractIntegrationTestCase extends TestCase { protected static final String TLS_CERTIFICATE_PATH = "src/main/config/bogus_mina_tls.cert"; protected static final String TLS_CERTIFICATE_PASSWORD = "boguspw"; - + protected static final String SERVER_DOMAIN = "vysper.org"; protected static final String TEST_USERNAME1 = "te...@vysper.org"; @@ -63,7 +69,7 @@ public abstract class AbstractIntegrationTestCase extends TestCase { private static final int DEFAULT_SERVER_PORT = 25222; - protected XMPPConnection client; + protected XMPPTCPConnection client; private XMPPServer server; @@ -76,7 +82,7 @@ public abstract class AbstractIntegrationTestCase extends TestCase { @Override protected void setUp() throws Exception { // make sure Smack times out after 5 seconds - SmackConfiguration.setPacketReplyTimeout(5000); + SmackConfiguration.setDefaultReplyTimeout(5000); port = findFreePort(); @@ -109,18 +115,16 @@ public abstract class AbstractIntegrationTestCase extends TestCase { Thread.sleep(200); } - protected XMPPConnection connectClient(int port, String username, String password) throws Exception { - ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost", port); - connectionConfiguration.setCompressionEnabled(false); - connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required); - connectionConfiguration.setSASLAuthenticationEnabled(true); - connectionConfiguration.setDebuggerEnabled(false); - connectionConfiguration.setKeystorePath(TLS_CERTIFICATE_PATH); - connectionConfiguration.setTruststorePath(TLS_CERTIFICATE_PATH); - connectionConfiguration.setTruststorePassword(TLS_CERTIFICATE_PASSWORD); + protected XMPPTCPConnection connectClient(int port, String username, String password) throws Exception { + XMPPTCPConnectionConfiguration connectionConfiguration = XMPPTCPConnectionConfiguration.builder() + .setHost("localhost").setPort(port).setXmppDomain(SERVER_DOMAIN) + .setHostnameVerifier((hostname, session) -> true).setCompressionEnabled(false) + .setSecurityMode(ConnectionConfiguration.SecurityMode.required) + .addEnabledSaslMechanism(SASLMechanism.PLAIN).setDebuggerFactory(ConsoleDebugger.Factory.INSTANCE) + .setKeystorePath(TLS_CERTIFICATE_PATH) + .setCustomX509TrustManager(NonCheckingX509TrustManagerFactory.X509).build(); - XMPPConnection.DEBUG_ENABLED = true; - XMPPConnection client = new XMPPConnection(connectionConfiguration); + XMPPTCPConnection client = new XMPPTCPConnection(connectionConfiguration); client.connect(); @@ -128,11 +132,12 @@ public abstract class AbstractIntegrationTestCase extends TestCase { return client; } - protected Packet sendSync(XMPPConnection client, Packet request) { + protected Stanza sendSync(XMPPConnection client, Stanza request) + throws SmackException.NotConnectedException, InterruptedException { // Create a packet collector to listen for a response. - PacketCollector collector = client.createPacketCollector(new PacketIDFilter(request.getPacketID())); + StanzaCollector collector = client.createStanzaCollector(new StanzaIdFilter(request.getStanzaId())); - client.sendPacket(request); + client.sendStanza(request); // Wait up to 5 seconds for a result. return collector.nextResult(5000); diff --git a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractMUCIntegrationTestCase.java b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractMUCIntegrationTestCase.java index 60ecc52..bf2f953 100644 --- a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractMUCIntegrationTestCase.java +++ b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/AbstractMUCIntegrationTestCase.java @@ -24,23 +24,28 @@ import org.apache.vysper.xmpp.modules.extension.xep0045_muc.MUCModule; import org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Conference; import org.apache.vysper.xmpp.server.XMPPServer; import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; import org.jivesoftware.smackx.muc.MultiUserChat; +import org.jivesoftware.smackx.muc.MultiUserChatManager; +import org.jxmpp.jid.EntityBareJid; +import org.jxmpp.jid.impl.JidCreate; +import org.jxmpp.jid.parts.Resourcepart; /** */ public abstract class AbstractMUCIntegrationTestCase extends AbstractIntegrationTestCase { - protected static final String NICK1 = "Nick"; + protected static final Resourcepart NICK1 = Resourcepart.fromOrThrowUnchecked("Nick"); - protected static final String NICK2 = "Nick2"; + protected static final Resourcepart NICK2 = Resourcepart.fromOrThrowUnchecked("Nick2"); protected static final String MUC_SUBDOMAIN = "chat"; - protected static final String ROOM_JID = "r...@chat.vysper.org"; + protected static final EntityBareJid ROOM_JID = JidCreate.entityBareFromOrThrowUnchecked("r...@chat.vysper.org"); protected Conference conference = new Conference("test conference", new MUCFeatures()); - protected XMPPConnection client2; + protected XMPPTCPConnection client2; protected MultiUserChat chat; @@ -57,8 +62,8 @@ public abstract class AbstractMUCIntegrationTestCase extends AbstractIntegration client2 = connectClient(port, TEST_USERNAME2, TEST_PASSWORD2); - chat = new MultiUserChat(client, ROOM_JID); - chat2 = new MultiUserChat(client2, ROOM_JID); + chat = MultiUserChatManager.getInstanceFor(client).getMultiUserChat(ROOM_JID); + chat2 = MultiUserChatManager.getInstanceFor(client2).getMultiUserChat(ROOM_JID); } @Override diff --git a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/EnterExitRoomIntegrationTestCase.java b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/EnterExitRoomIntegrationTestCase.java index 33c1ecc..2013b3b 100644 --- a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/EnterExitRoomIntegrationTestCase.java +++ b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/EnterExitRoomIntegrationTestCase.java @@ -27,46 +27,48 @@ import org.apache.vysper.xmpp.addressing.EntityImpl; import org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Occupant; import org.apache.vysper.xmpp.modules.extension.xep0045_muc.model.Room; import org.jivesoftware.smack.packet.Message; +import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.parts.Resourcepart; /** */ public class EnterExitRoomIntegrationTestCase extends AbstractMUCIntegrationTestCase { public void testEnterRoom() throws Exception { - chat.join("Nick"); + chat.join(Resourcepart.from("Nick")); - Room room = conference.findRoom(EntityImpl.parseUnchecked(ROOM_JID)); + Room room = conference.findRoom(EntityImpl.parseUnchecked(ROOM_JID.toString())); assertEquals(1, room.getOccupantCount()); Occupant occupant = room.getOccupants().iterator().next(); assertEquals(TEST_USERNAME1, occupant.getJid().getBareJID().getFullQualifiedName()); assertEquals("Nick", occupant.getNick()); - final BlockingQueue<String> joinedQueue = new LinkedBlockingQueue<String>(); + final BlockingQueue<EntityFullJid> joinedQueue = new LinkedBlockingQueue<>(); chat.addParticipantStatusListener(new ParticipantStatusListenerAdapter() { @Override - public void joined(String participant) { + public void joined(EntityFullJid participant) { joinedQueue.add(participant); } }); - chat2.join("Nick2"); + chat2.join(Resourcepart.from("Nick2")); assertEquals(2, room.getOccupantCount()); // chat should be notified - assertEquals(ROOM_JID + "/Nick2", joinedQueue.poll(5000, TimeUnit.MILLISECONDS)); + assertEquals(ROOM_JID + "/Nick2", joinedQueue.poll(5000, TimeUnit.MILLISECONDS).toString()); } public void testExitRoom() throws Exception { - chat.join("Nick"); - chat2.join("Nick2"); + chat.join(Resourcepart.from("Nick")); + chat2.join(Resourcepart.from("Nick2")); - Room room = conference.findRoom(EntityImpl.parseUnchecked(ROOM_JID)); + Room room = conference.findRoom(EntityImpl.parseUnchecked(ROOM_JID.toString())); assertEquals(2, room.getOccupantCount()); - final BlockingQueue<String> leftQueue = new LinkedBlockingQueue<String>(); + final BlockingQueue<EntityFullJid> leftQueue = new LinkedBlockingQueue<>(); chat.addParticipantStatusListener(new ParticipantStatusListenerAdapter() { @Override - public void left(String participant) { + public void left(EntityFullJid participant) { leftQueue.add(participant); } }); @@ -74,27 +76,27 @@ public class EnterExitRoomIntegrationTestCase extends AbstractMUCIntegrationTest chat2.leave(); // wait for status update - assertEquals(ROOM_JID + "/Nick2", leftQueue.poll(5000, TimeUnit.MILLISECONDS)); + assertEquals(ROOM_JID + "/Nick2", leftQueue.poll(5000, TimeUnit.MILLISECONDS).toString()); assertEquals(1, room.getOccupantCount()); } public void testSendMessageToRoom() throws Exception { - chat.join("Nick"); - chat2.join("Nick2"); + chat.join(Resourcepart.from("Nick")); + chat2.join(Resourcepart.from("Nick2")); chat.sendMessage("Fooo"); Message message = chat.nextMessage(5000); assertNotNull(message); assertEquals("Fooo", message.getBody()); - assertEquals(ROOM_JID + "/Nick", message.getFrom()); - assertEquals(TEST_USERNAME1, EntityImpl.parse(message.getTo()).getBareJID().getFullQualifiedName()); + assertEquals(ROOM_JID + "/Nick", message.getFrom().toString()); + assertEquals(TEST_USERNAME1, EntityImpl.parse(message.getTo().toString()).getBareJID().getFullQualifiedName()); message = chat2.nextMessage(5000); assertNotNull(message); assertEquals("Fooo", message.getBody()); - assertEquals(ROOM_JID + "/Nick", message.getFrom()); - assertEquals(TEST_USERNAME2, EntityImpl.parse(message.getTo()).getBareJID().getFullQualifiedName()); + assertEquals(ROOM_JID + "/Nick", message.getFrom().toString()); + assertEquals(TEST_USERNAME2, EntityImpl.parse(message.getTo().toString()).getBareJID().getFullQualifiedName()); } } diff --git a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ModerationIntegrationTestCase.java b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ModerationIntegrationTestCase.java index ef34c5b..355e6c3 100644 --- a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ModerationIntegrationTestCase.java +++ b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ModerationIntegrationTestCase.java @@ -30,12 +30,12 @@ public class ModerationIntegrationTestCase extends AbstractMUCIntegrationTestCas public void testGrantModeration() throws Exception { chat.join(NICK1); - Room room = conference.findRoom(EntityImpl.parseUnchecked(ROOM_JID)); - assertEquals(Role.Moderator, room.findOccupantByNick(NICK1).getRole()); + Room room = conference.findRoom(EntityImpl.parseUnchecked(ROOM_JID.toString())); + assertEquals(Role.Moderator, room.findOccupantByNick(NICK1.toString()).getRole()); chat2.join(NICK2); chat.grantModerator(NICK2); - assertEquals(Role.Moderator, room.findOccupantByNick(NICK2).getRole()); + assertEquals(Role.Moderator, room.findOccupantByNick(NICK2.toString()).getRole()); } } diff --git a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ParticipantStatusListenerAdapter.java b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ParticipantStatusListenerAdapter.java index e4fd754..eaed5d9 100644 --- a/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ParticipantStatusListenerAdapter.java +++ b/server/extensions/xep0045-muc-inttest/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/inttest/ParticipantStatusListenerAdapter.java @@ -20,53 +20,86 @@ package org.apache.vysper.xmpp.modules.extension.xep0045_muc.inttest; import org.jivesoftware.smackx.muc.ParticipantStatusListener; +import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.parts.Resourcepart; /** */ public class ParticipantStatusListenerAdapter implements ParticipantStatusListener { - public void adminGranted(String participant) { + @Override + public void joined(EntityFullJid participant) { + } - public void adminRevoked(String participant) { + @Override + public void left(EntityFullJid participant) { + } - public void banned(String participant, String actor, String reason) { + @Override + public void kicked(EntityFullJid participant, Jid actor, String reason) { + } - public void joined(String participant) { + @Override + public void voiceGranted(EntityFullJid participant) { + } - public void kicked(String participant, String actor, String reason) { + @Override + public void voiceRevoked(EntityFullJid participant) { + } - public void left(String participant) { + @Override + public void banned(EntityFullJid participant, Jid actor, String reason) { + } - public void membershipGranted(String participant) { + @Override + public void membershipGranted(EntityFullJid participant) { + } - public void membershipRevoked(String participant) { + @Override + public void membershipRevoked(EntityFullJid participant) { + } - public void moderatorGranted(String participant) { + @Override + public void moderatorGranted(EntityFullJid participant) { + } - public void moderatorRevoked(String participant) { + @Override + public void moderatorRevoked(EntityFullJid participant) { + } - public void nicknameChanged(String participant, String newNickname) { + @Override + public void ownershipGranted(EntityFullJid participant) { + } - public void ownershipGranted(String participant) { + @Override + public void ownershipRevoked(EntityFullJid participant) { + } - public void ownershipRevoked(String participant) { + @Override + public void adminGranted(EntityFullJid participant) { + } - public void voiceGranted(String participant) { + @Override + public void adminRevoked(EntityFullJid participant) { + } - public void voiceRevoked(String participant) { + @Override + public void nicknameChanged(EntityFullJid participant, Resourcepart newNickname) { + } } diff --git a/server/extensions/xep0065-socks/pom.xml b/server/extensions/xep0065-socks/pom.xml index e845658..1e9dc7a 100644 --- a/server/extensions/xep0065-socks/pom.xml +++ b/server/extensions/xep0065-socks/pom.xml @@ -61,12 +61,27 @@ </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smack</artifactId> + <artifactId>smack-tcp</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-resolver-javax</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-sasl-javax</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.igniterealtime.smack</groupId> + <artifactId>smack-java7</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>org.igniterealtime.smack</groupId> - <artifactId>smackx</artifactId> + <artifactId>smack-extensions</artifactId> <scope>test</scope> </dependency> diff --git a/server/extensions/xep0065-socks/src/test/java/org/apache/vysper/xmpp/extension/xep0065_socks/Socks5IntegrationTest.java b/server/extensions/xep0065-socks/src/test/java/org/apache/vysper/xmpp/extension/xep0065_socks/Socks5IntegrationTest.java index 2c44f95..4d63419 100644 --- a/server/extensions/xep0065-socks/src/test/java/org/apache/vysper/xmpp/extension/xep0065_socks/Socks5IntegrationTest.java +++ b/server/extensions/xep0065-socks/src/test/java/org/apache/vysper/xmpp/extension/xep0065_socks/Socks5IntegrationTest.java @@ -37,30 +37,33 @@ import org.apache.vysper.xmpp.modules.roster.RosterItem; import org.apache.vysper.xmpp.modules.roster.SubscriptionType; import org.apache.vysper.xmpp.modules.roster.persistence.RosterManager; import org.apache.vysper.xmpp.server.XMPPServer; -import org.jivesoftware.smack.ConnectionConfiguration; -import org.jivesoftware.smack.SmackConfiguration; -import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.roster.Roster; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; +import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; import org.jivesoftware.smackx.bytestreams.BytestreamListener; import org.jivesoftware.smackx.bytestreams.BytestreamRequest; import org.jivesoftware.smackx.bytestreams.BytestreamSession; import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager; import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession; +import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.jxmpp.jid.Jid; +import org.jxmpp.jid.impl.JidCreate; /** * Integration test for SOCKS5 mediated connections * - * This test requires that "vysper.org" and "socks.vysper.org" resolves to 127.0.0.1 - * and is therefore disabled by default. - * - * On Linux/OS X, add the following to /etc/hosts: - * 127.0.0.1 vysper.org - * 127.0.0.1 socks.vysper.org + * This test requires that "vysper.org" and "socks.vysper.org" resolves to + * 127.0.0.1 and is therefore disabled by default. + * + * On Linux/OS X, add the following to /etc/hosts: 127.0.0.1 vysper.org + * 127.0.0.1 socks.vysper.org * * @author The Apache MINA Project (d...@mina.apache.org) */ @@ -68,18 +71,24 @@ import org.junit.Test; public class Socks5IntegrationTest { private static final String SUBDOMAIN = "socks"; + private static final String SERVER = "vysper.org"; + private static final Entity USER1 = EntityImpl.parseUnchecked("us...@vysper.org"); + private static final Entity USER2 = EntityImpl.parseUnchecked("us...@vysper.org"); + private static final String PASSWORD = "password"; - private static final String CHARSET = "ASCII"; + private static final String TEST_DATA = "hello world"; private XMPPServer server; - private XMPPConnection requestor; - private XMPPConnection target; + + private XMPPTCPConnection requestor; + + private XMPPTCPConnection target; @Before public void before() throws Exception { @@ -95,7 +104,7 @@ public class Socks5IntegrationTest { server.addModule(new Socks5Module(SUBDOMAIN)); // disable direct connections - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); assertTransfer(); } @@ -103,12 +112,13 @@ public class Socks5IntegrationTest { @Test public void directConnectionTransfer() throws Exception { // enable direct connections - SmackConfiguration.setLocalSocks5ProxyEnabled(true); + Socks5Proxy.setLocalSocks5ProxyEnabled(true); assertTransfer(); } - private void assertTransfer() throws InterruptedException, XMPPException, IOException, UnsupportedEncodingException { + private void assertTransfer() + throws InterruptedException, XMPPException, IOException, UnsupportedEncodingException, SmackException { LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<String>(); Socks5BytestreamManager mng2 = Socks5BytestreamManager.getBytestreamManager(target); @@ -120,7 +130,8 @@ public class Socks5IntegrationTest { System.out.println("Starting SOCKS5 transfer"); System.out.println("##################"); - String targetJid = requestor.getRoster().getPresence(USER2.getFullQualifiedName()).getFrom(); + Jid targetJid = Roster.getInstanceFor(requestor).getPresence(JidCreate.bareFrom(USER2.getFullQualifiedName())) + .getFrom(); Socks5BytestreamManager mng1 = Socks5BytestreamManager.getBytestreamManager(requestor); Socks5BytestreamSession session = mng1.establishSession(targetJid); @@ -134,21 +145,21 @@ public class Socks5IntegrationTest { private final class TestByteStreamListener implements BytestreamListener { private final LinkedBlockingQueue<String> queue; - + private TestByteStreamListener(LinkedBlockingQueue<String> queue) { this.queue = queue; } - + public void incomingBytestreamRequest(BytestreamRequest request) { BytestreamSession session; try { session = request.accept(); - + byte[] b = new byte[TEST_DATA.getBytes(CHARSET).length]; InputStream in = session.getInputStream(); in.read(b); in.close(); - + queue.put(new String(b)); } catch (Exception e) { Assert.fail(e.getMessage()); @@ -164,9 +175,11 @@ public class Socks5IntegrationTest { server.stop(); } - private XMPPConnection connectClient(Entity username) throws XMPPException { - ConnectionConfiguration config = new ConnectionConfiguration(SERVER, 5222); - XMPPConnection conn = new XMPPConnection(config); + private XMPPTCPConnection connectClient(Entity username) + throws XMPPException, InterruptedException, IOException, SmackException { + XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder().setXmppDomain(SERVER) + .setPort(5222).build(); + XMPPTCPConnection conn = new XMPPTCPConnection(config); conn.connect(); conn.login(username.getFullQualifiedName(), PASSWORD); return conn; @@ -189,8 +202,8 @@ public class Socks5IntegrationTest { server.start(); System.out.println("vysper server is running..."); - RosterManager rosterManager = (RosterManager) server.getServerRuntimeContext().getStorageProvider( - RosterManager.class); + RosterManager rosterManager = (RosterManager) server.getServerRuntimeContext() + .getStorageProvider(RosterManager.class); rosterManager.addContact(USER1, new RosterItem(USER2, SubscriptionType.BOTH)); rosterManager.addContact(USER2, new RosterItem(USER1, SubscriptionType.BOTH));