Search in sources :

Example 1 with Version

use of org.jivesoftware.smackx.iqversion.packet.Version in project Smack by igniterealtime.

the class VersionTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    // @formatter:off
    String control = "<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>" + "<query xmlns='jabber:iq:version'/>" + "</iq>";
    // @formatter:on
    DummyConnection con = new DummyConnection();
    con.connect();
    // Enable version replys for this connection
    VersionManager.setAutoAppendSmackVersion(false);
    VersionManager.getInstanceFor(con).setVersion("Test", "0.23", "DummyOS");
    IQ versionRequest = PacketParserUtils.parseStanza(control);
    assertTrue(versionRequest instanceof Version);
    con.processStanza(versionRequest);
    Stanza replyPacket = con.getSentPacket();
    assertTrue(replyPacket instanceof Version);
    Version reply = (Version) replyPacket;
    // getFrom check is pending for SMACK-547
    // assertEquals("juliet@capulet.lit/balcony", reply.getFrom());
    assertThat("capulet.lit", equalsCharSequence(reply.getTo()));
    assertEquals("s2c1", reply.getStanzaId());
    assertEquals(IQ.Type.result, reply.getType());
    assertEquals("Test", reply.getName());
    assertEquals("0.23", reply.getVersion());
    assertEquals("DummyOS", reply.getOs());
}
Also used : Version(org.jivesoftware.smackx.iqversion.packet.Version) DummyConnection(org.jivesoftware.smack.DummyConnection) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.jupiter.api.Test)

Example 2 with Version

use of org.jivesoftware.smackx.iqversion.packet.Version in project Smack by igniterealtime.

the class VersionIntegrationTest method testVersion.

@SmackIntegrationTest
public void testVersion() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // TODO put into @BeforeClass method
    VersionManager.setAutoAppendSmackVersion(false);
    VersionManager versionManagerOne = VersionManager.getInstanceFor(conOne);
    VersionManager versionManagerTwo = VersionManager.getInstanceFor(conTwo);
    final String versionName = "Smack Integration Test " + testRunId;
    versionManagerTwo.setVersion(versionName, "1.0");
    assertTrue(versionManagerOne.isSupported(conTwo.getUser()));
    Version version = versionManagerOne.getVersion(conTwo.getUser());
    assertEquals(versionName, version.getName());
}
Also used : Version(org.jivesoftware.smackx.iqversion.packet.Version) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 3 with Version

use of org.jivesoftware.smackx.iqversion.packet.Version in project Spark by igniterealtime.

the class JabberVersion method initialize.

public void initialize() {
    // Create IQ Filter
    StanzaFilter packetFilter = new StanzaTypeFilter(IQ.class);
    SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
        IQ iq = (IQ) stanza;
        try {
            // Handle Version Request
            if (iq instanceof Version && iq.getType() == IQ.Type.get) {
                // Send Version
                Version version = new Version(JiveInfo.getName(), JiveInfo.getVersion(), JiveInfo.getOS());
                // Send back as a reply
                version.setStanzaId(iq.getStanzaId());
                version.setType(IQ.Type.result);
                version.setTo(iq.getFrom());
                version.setFrom(iq.getTo());
                SparkManager.getConnection().sendStanza(version);
            } else // Send time
            if (iq instanceof Time && iq.getType() == IQ.Type.get) {
                Time time = new Time();
                time.setStanzaId(iq.getStanzaId());
                time.setFrom(iq.getTo());
                time.setTo(iq.getFrom());
                time.setTime(new Date());
                time.setType(IQ.Type.result);
                // Send Time
                SparkManager.getConnection().sendStanza(time);
            }
        } catch (SmackException.NotConnectedException e) {
            Log.warning("Unable to answer request: " + stanza, e);
        }
    }, packetFilter);
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    contactList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F11"), "viewClient");
    contactList.addContextMenuListener(new ContextMenuListener() {

        public void poppingUp(final Object component, JPopupMenu popup) {
            if (!(component instanceof ContactItem)) {
                return;
            }
            ContactItem contactItem = (ContactItem) component;
            if (contactItem.getPresence() == null) {
                return;
            }
            Action versionRequest = new AbstractAction() {

                private static final long serialVersionUID = -5619737417315441711L;

                public void actionPerformed(ActionEvent e) {
                    viewClient();
                }
            };
            versionRequest.putValue(Action.NAME, Res.getString("menuitem.view.client.version"));
            popup.add(versionRequest);
        }

        public void poppingDown(JPopupMenu popup) {
        }

        public boolean handleDefaultAction(MouseEvent e) {
            return false;
        }
    });
    contactList.getActionMap().put("viewClient", new AbstractAction("viewClient") {

        private static final long serialVersionUID = 8282301357403753561L;

        public void actionPerformed(ActionEvent evt) {
            viewClient();
        }
    });
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) SmackException(org.jivesoftware.smack.SmackException) ContactItem(org.jivesoftware.spark.ui.ContactItem) IQ(org.jivesoftware.smack.packet.IQ) ContextMenuListener(org.jivesoftware.spark.plugin.ContextMenuListener) Time(org.jivesoftware.smackx.time.packet.Time) ContactList(org.jivesoftware.spark.ui.ContactList) Date(java.util.Date) JPopupMenu(javax.swing.JPopupMenu) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) Version(org.jivesoftware.smackx.iqversion.packet.Version) AbstractAction(javax.swing.AbstractAction)

Example 4 with Version

use of org.jivesoftware.smackx.iqversion.packet.Version in project Spark by igniterealtime.

the class VersionViewer method viewVersion.

public static void viewVersion(String jid) {
    final JPanel loadingCard = new JPanel();
    final ImageIcon icon = new ImageIcon(VersionViewer.class.getClassLoader().getResource("images/ajax-loader.gif"));
    loadingCard.add(new JLabel("loading... ", icon, JLabel.CENTER));
    loadingCard.setVisible(true);
    final JPanel dataCard = new JPanel();
    dataCard.setVisible(false);
    dataCard.setLayout(new GridBagLayout());
    JLabel timeLabel = new JLabel();
    JLabel softwareLabel = new JLabel();
    JLabel versionLabel = new JLabel();
    JLabel osLabel = new JLabel();
    final JTextField timeField = new JTextField();
    final JTextField softwareField = new JTextField();
    final JTextField versionField = new JTextField();
    final JTextField osField = new JTextField();
    // Add resources
    ResourceUtils.resLabel(timeLabel, timeField, Res.getString("label.local.time") + ":");
    ResourceUtils.resLabel(softwareLabel, softwareField, Res.getString("label.software") + ":");
    ResourceUtils.resLabel(versionLabel, versionField, Res.getString("label.version") + ":");
    ResourceUtils.resLabel(osLabel, osField, Res.getString("label.os") + ":");
    // Add Time Label
    dataCard.add(timeLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    dataCard.add(timeField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    dataCard.add(softwareLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    dataCard.add(softwareField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    dataCard.add(versionLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    dataCard.add(versionField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    dataCard.add(osLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    dataCard.add(osField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    osField.setEditable(false);
    versionField.setEditable(false);
    softwareField.setEditable(false);
    timeField.setEditable(false);
    final JPanel cards = new JPanel(new CardLayout());
    cards.add(loadingCard);
    cards.add(dataCard);
    final XMPPConnection connection = SparkManager.getConnection();
    try {
        // Load Version
        final Version versionRequest = new Version();
        versionRequest.setType(IQ.Type.get);
        versionRequest.setTo(jid);
        connection.sendStanzaWithResponseCallback(versionRequest, new IQReplyFilter(versionRequest, connection), stanza -> {
            final Version versionResult = (Version) stanza;
            softwareField.setText(versionResult.getName());
            versionField.setText(versionResult.getVersion());
            osField.setText(versionResult.getOs());
            ((CardLayout) (cards.getLayout())).last(cards);
        });
        // Time
        final Time time = new Time();
        time.setType(IQ.Type.get);
        time.setTo(jid);
        connection.sendStanzaWithResponseCallback(time, new IQReplyFilter(time, connection), stanza -> {
            ;
            timeField.setText(new SimpleDateFormat().format(((Time) stanza).getTime()));
            ((CardLayout) (cards.getLayout())).last(cards);
        });
    } catch (SmackException.NotConnectedException e) {
        Log.warning("Unable to query for version.", e);
        ((CardLayout) (cards.getLayout())).last(cards);
    }
    MessageDialog.showComponent(Res.getString("title.version.and.time"), Res.getString("message.client.information", UserManager.unescapeJID(jid)), SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_24x24), cards, SparkManager.getMainWindow(), 400, 300, false);
}
Also used : IQReplyFilter(org.jivesoftware.smack.filter.IQReplyFilter) SmackException(org.jivesoftware.smack.SmackException) Time(org.jivesoftware.smackx.time.packet.Time) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Version(org.jivesoftware.smackx.iqversion.packet.Version) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with Version

use of org.jivesoftware.smackx.iqversion.packet.Version in project jitsi-videobridge by jitsi.

the class ComponentImpl method handleVersionIQ.

/**
 * Handles a <tt>Version</tt> stanza which represents a request.
 *
 * @param versionRequest the <tt>Version</tt> stanza represents
 * the request to handle
 * @return an <tt>org.jivesoftware.smack.packet.IQ</tt> stanza which
 * represents the response to the specified request.
 */
private org.jivesoftware.smack.packet.IQ handleVersionIQ(org.jivesoftware.smackx.iqversion.packet.Version versionRequest) {
    VersionService versionService = getVersionService();
    if (versionService == null) {
        return org.jivesoftware.smack.packet.IQ.createErrorResponse(versionRequest, XMPPError.getBuilder(XMPPError.Condition.service_unavailable));
    }
    org.jitsi.service.version.Version currentVersion = versionService.getCurrentVersion();
    if (currentVersion == null) {
        return org.jivesoftware.smack.packet.IQ.createErrorResponse(versionRequest, XMPPError.getBuilder(XMPPError.Condition.internal_server_error));
    }
    // send packet
    org.jivesoftware.smackx.iqversion.packet.Version versionResult = new org.jivesoftware.smackx.iqversion.packet.Version(currentVersion.getApplicationName(), currentVersion.toString(), System.getProperty("os.name"));
    // to, from and packetId are set by the caller.
    // versionResult.setTo(versionRequest.getFrom());
    // versionResult.setFrom(versionRequest.getTo());
    // versionResult.setPacketID(versionRequest.getPacketID());
    versionResult.setType(org.jivesoftware.smack.packet.IQ.Type.result);
    return versionResult;
}
Also used : Version(org.jivesoftware.smackx.iqversion.packet.Version) Version(org.jivesoftware.smackx.iqversion.packet.Version) org.jivesoftware.smack.packet(org.jivesoftware.smack.packet) org.xmpp.packet(org.xmpp.packet) org.jitsi.service.version(org.jitsi.service.version)

Aggregations

Version (org.jivesoftware.smackx.iqversion.packet.Version)6 SmackException (org.jivesoftware.smack.SmackException)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 IQ (org.jivesoftware.smack.packet.IQ)2 Time (org.jivesoftware.smackx.time.packet.Time)2 ActionEvent (java.awt.event.ActionEvent)1 MouseEvent (java.awt.event.MouseEvent)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JPopupMenu (javax.swing.JPopupMenu)1 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)1 org.jitsi.service.version (org.jitsi.service.version)1 DummyConnection (org.jivesoftware.smack.DummyConnection)1 IQReplyFilter (org.jivesoftware.smack.filter.IQReplyFilter)1 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)1 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)1 org.jivesoftware.smack.packet (org.jivesoftware.smack.packet)1