org.jivesoftware.smackx.iqversion.packet.Version Java Examples
The following examples show how to use
org.jivesoftware.smackx.iqversion.packet.Version.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VersionManager.java From Smack with Apache License 2.0 | 6 votes |
private VersionManager(final XMPPConnection connection) { super(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Version.NAMESPACE); connection.registerIQRequestHandler(new AbstractIqRequestHandler(Version.ELEMENT, Version.NAMESPACE, IQ.Type.get, Mode.async) { @Override public IQ handleIQRequest(IQ iqRequest) { if (ourVersion == null) { return IQ.createErrorResponse(iqRequest, Condition.not_acceptable); } return Version.createResultFor(iqRequest, ourVersion); } }); }
Example #2
Source File: VersionProvider.java From Smack with Apache License 2.0 | 5 votes |
@Override public Version parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { String name = null, version = null, os = null; outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); switch (eventType) { case START_ELEMENT: String tagName = parser.getName(); switch (tagName) { case "name": name = parser.nextText(); break; case "version": version = parser.nextText(); break; case "os": os = parser.nextText(); break; } break; case END_ELEMENT: if (parser.getDepth() == initialDepth && parser.getName().equals(IQ.QUERY_ELEMENT)) { break outerloop; } break; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } if (name == null && version == null && os == null) { return new Version(); } return new Version(name, version, os); }
Example #3
Source File: VersionTest.java From Smack with Apache License 2.0 | 5 votes |
@Test public void checkProvider() throws Exception { // @formatter:off String control = "<iq from='capulet.lit' to='[email protected]/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("[email protected]/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()); }
Example #4
Source File: VersionIntegrationTest.java From Smack with Apache License 2.0 | 5 votes |
@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()); }
Example #5
Source File: XmppCommon.java From jitsi-videobridge with Apache License 2.0 | 5 votes |
/** * 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 IQ handleVersionIQ(Version versionRequest) { VersionService versionService = getVersionService(); if (versionService == null) { return IQ.createErrorResponse( versionRequest, XMPPError.getBuilder(XMPPError.Condition.service_unavailable)); } org.jitsi.utils.version.Version currentVersion = versionService.getCurrentVersion(); if (currentVersion == null) { return IQ.createErrorResponse( versionRequest, XMPPError.getBuilder(XMPPError.Condition.internal_server_error)); } // send packet Version versionResult = new 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(IQ.Type.result); return versionResult; }
Example #6
Source File: VersionManager.java From Smack with Apache License 2.0 | 4 votes |
public boolean isSupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Version.NAMESPACE); }
Example #7
Source File: VersionManager.java From Smack with Apache License 2.0 | 4 votes |
private static Version generateVersionFrom(String name, String version, String os) { if (autoAppendSmackVersion) { name += " (Smack " + SmackConfiguration.getVersion() + ')'; } return new Version(name, version, os); }
Example #8
Source File: VersionViewer.java From Spark with Apache License 2.0 | 4 votes |
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 | InterruptedException 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); }
Example #9
Source File: XmppCommon.java From jitsi-videobridge with Apache License 2.0 | 4 votes |
/** * Handles an IQ request (of type 'get' or 'set'). */ private IQ handleIQRequest(IQ request) { Videobridge videobridge = getVideobridge(); if (videobridge == null) { return IQUtils.createError( request, XMPPError.Condition.internal_server_error, "No Videobridge service is running"); } IQ response; long start = System.currentTimeMillis(); DelayStats delayStats = null; try { // Requests can be categorized in pieces of Videobridge functionality // based on the org.jivesoftware.smack.packet.IQ runtime type (of their // child element) and forwarded to specialized Videobridge methods for // convenience. if (request instanceof Version) { delayStats = versionDelayStats; response = handleVersionIQ((Version) request); } else if (request instanceof ColibriConferenceIQ) { delayStats = colibriDelayStats; response = videobridge.handleColibriConferenceIQ( (ColibriConferenceIQ) request); } else if (request instanceof HealthCheckIQ) { delayStats = healthDelayStats; response = videobridge.handleHealthCheckIQ((HealthCheckIQ) request); } else if (request instanceof ShutdownIQ) { response = videobridge.handleShutdownIQ((ShutdownIQ) request); } else { logger.error("Unsupported IQ request " + request.getChildElementName() + " received"); response = IQUtils.createError( request, XMPPError.Condition.service_unavailable, "Unsupported IQ request " + request.getChildElementName()); } } catch (Exception e) { logger.error("Exception handling IQ request", e); response = IQUtils.createError( request, XMPPError.Condition.internal_server_error, e.getMessage() ); } if (delayStats != null) { long delay = System.currentTimeMillis() - start; if (delay > 100) { logger.warn("Took " + delay + " ms to handle IQ: " + request.toXML()); } delayStats.addDelay(delay); } return response; }
Example #10
Source File: VersionManager.java From Smack with Apache License 2.0 | 3 votes |
/** * Request version information from a given JID. * * @param jid TODO javadoc me please * @return the version information or {@code null} if not supported by JID * @throws NoResponseException if there was no response from the remote entity. * @throws XMPPErrorException if there was an XMPP error returned. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public Version getVersion(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (!isSupported(jid)) { return null; } return connection().createStanzaCollectorAndSend(new Version(jid)).nextResultOrThrow(); }