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());
}
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());
}
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();
}
});
}
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);
}
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;
}
Aggregations