org.jivesoftware.smack.filter.IQReplyFilter Java Examples
The following examples show how to use
org.jivesoftware.smack.filter.IQReplyFilter.
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: StateService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
private static void sendPing(Jid full){ Ping req=new Ping(full); try { //iq发出后处理响应回调 Launcher.connection.sendStanzaWithResponseCallback(req, new IQReplyFilter( req, Launcher.connection ), stanza -> { IQ result = (IQ) stanza; String bareJid = result.getFrom().asEntityBareJidIfPossible().toString(); String fullJid = result.getFrom().asEntityFullJidIfPossible().toString(); if ( result.getType() == IQ.Type.error ) { // TODO error处理 onlineMap.remove(fullJid); } else { fullJidMap.put(bareJid, fullJid); onlineMap.put(fullJid, true); } }); } catch (NotConnectedException | InterruptedException e) { e.printStackTrace(); } }
Example #2
Source File: UserRegService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
public static void registerUser(XMPPConnection con, String gatewayDomain, String username, String password, String nickname, StanzaListener callback) throws SmackException.NotConnectedException { Map<String, String> attributes = new HashMap<>(); if (username != null) { attributes.put("username", username); } if (password != null) { attributes.put("password", password); } if (nickname != null) { attributes.put("nick", nickname); } Registration registration = new Registration( attributes ); registration.setType(IQ.Type.set); registration.setTo(gatewayDomain); registration.addExtension(new GatewayRegisterExtension()); try { con.sendStanzaWithResponseCallback( registration, new IQReplyFilter( registration, con ), callback); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #3
Source File: UserRegService.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
public static void unregister(XMPPConnection con, String gatewayDomain) throws SmackException.NotConnectedException { Map<String,String> map = new HashMap<>(); map.put("remove", ""); Registration registration = new Registration( map ); registration.setType(IQ.Type.set); registration.setTo(gatewayDomain); try { con.sendStanzaWithResponseCallback( registration, new IQReplyFilter( registration, con ), stanza -> { IQ response = (IQ) stanza; if (response.getType() == IQ.Type.error ) { //Log.warning( "Unable to unregister from gateway: " + stanza ); } } ); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #4
Source File: MamManager.java From Smack with Apache License 2.0 | 6 votes |
private MamQueryPage queryArchivePage(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException { final XMPPConnection connection = getAuthenticatedConnectionOrThrow(); MamFinIQ mamFinIQ; StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection)); StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration() .setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector); StanzaCollector cancelledResultCollector; try (StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration)) { connection.sendStanza(mamQueryIq); mamFinIQ = mamFinIQCollector.nextResultOrThrow(); cancelledResultCollector = resultCollector; } return new MamQueryPage(cancelledResultCollector, mamFinIQ); }
Example #5
Source File: TransportUtils.java From Spark with Apache License 2.0 | 6 votes |
/** * Registers a user with a gateway. * * @param con the XMPPConnection. * @param gatewayDomain the domain of the gateway (service name) * @param username the username. * @param password the password. * @param nickname the nickname. * @throws InterruptedException * @throws XMPPException thrown if there was an issue registering with the gateway. */ public static void registerUser(XMPPConnection con, DomainBareJid gatewayDomain, String username, String password, String nickname, StanzaListener callback) throws SmackException.NotConnectedException, InterruptedException { Map<String, String> attributes = new HashMap<>(); if (username != null) { attributes.put("username", username); } if (password != null) { attributes.put("password", password); } if (nickname != null) { attributes.put("nick", nickname); } Registration registration = new Registration( attributes ); registration.setType(IQ.Type.set); registration.setTo(gatewayDomain); registration.addExtension(new GatewayRegisterExtension()); con.sendStanzaWithResponseCallback( registration, new IQReplyFilter( registration, con ), callback); }
Example #6
Source File: TransportUtils.java From Spark with Apache License 2.0 | 6 votes |
/** * @param con the XMPPConnection. * @param gatewayDomain the domain of the gateway (service name) * @throws InterruptedException * @throws XMPPException thrown if there was an issue unregistering with the gateway. */ public static void unregister(XMPPConnection con, DomainBareJid gatewayDomain) throws SmackException.NotConnectedException, InterruptedException { Map<String,String> map = new HashMap<>(); map.put("remove", ""); Registration registration = new Registration( map ); registration.setType(IQ.Type.set); registration.setTo(gatewayDomain); con.sendStanzaWithResponseCallback( registration, new IQReplyFilter( registration, con ), stanza -> { IQ response = (IQ) stanza; if (response.getType() == IQ.Type.error ) { Log.warning( "Unable to unregister from gateway: " + stanza ); } } ); }
Example #7
Source File: CheckUpdates.java From Spark with Apache License 2.0 | 6 votes |
/** * Returns the latest version of Spark available via Spark Manager or Jive Software. * * @param connection the XMPPConnection to use. * @return the information for about the latest Spark Client. * @throws InterruptedException * @throws XMPPException If unable to retrieve latest version. */ public static SparkVersion getLatestVersion(XMPPConnection connection) throws SmackException, XMPPException.XMPPErrorException, InterruptedException { SparkVersion request = new SparkVersion(); request.setType(IQ.Type.get); request.setTo("updater." + connection.getXMPPServiceDomain()); // TODO: This should not use stanza collectors but simply createStanzaCollectorAndSend(IQ).nextResultOrThrow(); StanzaCollector collector = connection.createStanzaCollector(new IQReplyFilter( request, connection )); connection.sendStanza(request); SparkVersion response; try { response = collector.nextResult(); } finally { // Cancel the collector. collector.cancel(); } if (response == null) { throw SmackException.NoResponseException.newWith( connection, collector ); } XMPPException.XMPPErrorException.ifHasErrorThenThrow( response ); return response; }
Example #8
Source File: MultiUserChatLightManager.java From Smack with Apache License 2.0 | 5 votes |
private MUCLightBlockingIQ getBlockingList(DomainBareJid mucLightService) throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException { MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, null); mucLightBlockingIQ.setType(Type.get); mucLightBlockingIQ.setTo(mucLightService); StanzaFilter responseFilter = new IQReplyFilter(mucLightBlockingIQ, connection()); IQ responseIq = connection().createStanzaCollectorAndSend(responseFilter, mucLightBlockingIQ) .nextResultOrThrow(); MUCLightBlockingIQ mucLightBlockingIQResult = (MUCLightBlockingIQ) responseIq; return mucLightBlockingIQResult; }
Example #9
Source File: AbstractXMPPConnection.java From Smack with Apache License 2.0 | 5 votes |
@Override public StanzaCollector createStanzaCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException { StanzaFilter packetFilter = new IQReplyFilter(packet, this); // Create the packet collector before sending the packet StanzaCollector packetCollector = createStanzaCollectorAndSend(packetFilter, packet); return packetCollector; }
Example #10
Source File: AbstractXMPPConnection.java From Smack with Apache License 2.0 | 4 votes |
@Override public SmackFuture<IQ, Exception> sendIqRequestAsync(IQ request, long timeout) { StanzaFilter replyFilter = new IQReplyFilter(request, this); return sendAsync(request, replyFilter, timeout); }
Example #11
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); }