@Override protected PacketFilter createFilter() { return new PacketIDFilter(pattern); } }
/** * Notify server to change the carbons state. This method returns * immediately and changes the variable when the reply arrives. * * You should first check for support using isSupportedByServer(). * * @param new_state whether carbons should be enabled or disabled */ public void sendCarbonsEnabled(final boolean new_state) { IQ setIQ = carbonsEnabledIQ(new_state); connection.addPacketListener(new PacketListener() { public void processPacket(Packet packet) { IQ result = (IQ)packet; if (result.getType() == IQ.Type.RESULT) { enabled_state = new_state; } connection.removePacketListener(this); } }, new PacketIDFilter(setIQ.getPacketID())); connection.sendPacket(setIQ); }
/** @throws NotConnectedException */ private boolean sendPing() throws NotConnectedException { IQ req = new IQ() { public String getChildElementXML() { return "<ping xmlns='urn:xmpp:ping'/>"; } }; req.setType(IQ.Type.GET); PacketFilter filter = new AndFilter( new PacketIDFilter(req.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(req); IQ result = (IQ) collector.nextResult(timeout); if (result == null) { LOGGER.warning("ping timeout"); return false; } collector.cancel(); return true; }
/** * Reloads the entire roster from the server. This is an asynchronous operation, * which means the method will return immediately, and the roster will be * reloaded at a later point when the server responds to the reload request. * * @throws IllegalStateException if connection is not logged in or logged in anonymously */ public void reload() { if (!connection.isAuthenticated()) { throw new IllegalStateException("Not logged in to server."); } if (connection.isAnonymous()) { throw new IllegalStateException("Anonymous users can't have a roster."); } RosterPacket packet = new RosterPacket(); if (persistentStorage != null) { packet.setVersion(persistentStorage.getRosterVersion()); } requestPacketId = packet.getPacketID(); PacketFilter idFilter = new PacketIDFilter(requestPacketId); connection.addPacketListener(new RosterResultListener(), idFilter); connection.sendPacket(packet); }
private static Packet sendXmppMessage(final XMPPConnection conn, final String query, final Type iqType) { LOG.debug("Sending XMPP stanza message..."); final IQ iq = new IQ() { @Override public String getChildElementXML() { return query; } }; final String jid = conn.getUser(); iq.setTo(jidToUser(jid)); iq.setFrom(jid); iq.setType(iqType); final PacketCollector collector = conn.createPacketCollector( new PacketIDFilter(iq.getPacketID())); LOG.debug("Sending XMPP stanza packet:\n"+iq.toXML()); conn.sendPacket(iq); final Packet response = collector.nextResult(40000); return response; }
static public Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException { PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); connection.sendPacket(packet); // Wait up to a certain number of seconds for a reply. Packet result = response.nextResult(timeout); // Stop queuing results response.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getError() != null) { throw new XMPPException(result.getError()); } return result; }
static public Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException { PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); connection.sendPacket(packet); // Wait up to a certain number of seconds for a reply. Packet result = response.nextResult(timeout); // Stop queuing results response.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getError() != null) { throw new XMPPException(result.getError()); } return result; }
static public Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException { PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); connection.sendPacket(packet); // Wait up to a certain number of seconds for a reply. Packet result = response.nextResult(timeout); // Stop queuing results response.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getError() != null) { throw new XMPPException(result.getError()); } return result; }
/** * Pings the given jid and returns the IQ response which is either of * IQ.Type.ERROR or IQ.Type.RESULT. If we are not connected or if there was * no reply, null is returned. * * You should use isPingSupported(jid) to determine if XMPP Ping is * supported by the user. * * @param jid * @param pingTimeout * @return */ public IQ ping(String jid, long pingTimeout) { // Make sure we actually connected to the server if (!connection.isAuthenticated()) return null; Ping ping = new Ping(connection.getUser(), jid); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(ping.getPacketID())); connection.sendPacket(ping); IQ result = (IQ) collector.nextResult(pingTimeout); collector.cancel(); return result; }
static public Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException { PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); connection.sendPacket(packet); // Wait up to a certain number of seconds for a reply. Packet result = response.nextResult(timeout); // Stop queuing results response.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getError() != null) { throw new XMPPException(result.getError()); } return result; }
static public Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException { PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); connection.sendPacket(packet); // Wait up to a certain number of seconds for a reply. Packet result = response.nextResult(timeout); // Stop queuing results response.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getError() != null) { throw new XMPPException(result.getError()); } return result; }
public static String[] getServiceFactoryNames(XMPPConnection connection) throws XMPPException { RequestServiceFactoriesIQ iq = new RequestServiceFactoriesIQ(); PacketCollector collector = connection .createPacketCollector(new PacketIDFilter(iq.getPacketID())); connection.sendPacket(iq); IQ result = (IQ) collector.nextResult(); if (result == null) { throw new XMPPException("No response from the server."); } if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } return ((ResultServiceFactoriesIQ) result).getServiceFactoryNames(); }
static public Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException { PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); connection.sendPacket(packet); // Wait up to a certain number of seconds for a reply. Packet result = response.nextResult(timeout); // Stop queuing results response.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getError() != null) { throw new XMPPException(result.getError()); } return result; }
private void doLoad(XMPPConnection connection, String user) throws XMPPException { setType(Type.GET); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(getPacketID())); connection.sendPacket(this); VCard result = null; try { result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (result == null) { throw new XMPPException(new XMPPError(408, "Timeout getting VCard information")); } if (result.getError() != null) { throw new XMPPException(result.getError()); } } catch (ClassCastException e) { System.out.println("No VCard for " + user); } copyFieldsFrom(result); }
private void doLoad(Connection connection, String user) throws XMPPException { setType(Type.GET); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(getPacketID())); connection.sendPacket(this); VCard result = null; try { result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (result == null) { String errorMessage = "Timeout getting VCard information"; throw new XMPPException(errorMessage, new XMPPError( XMPPError.Condition.request_timeout, errorMessage)); } if (result.getError() != null) { throw new XMPPException(result.getError()); } } catch (ClassCastException e) { System.out.println("No VCard for " + user); } copyFieldsFrom(result); }
private void doLoad(Connection connection, String user) throws XMPPException { setType(Type.GET); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(getPacketID())); connection.sendPacket(this); VCard result = null; try { result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (result == null) { String errorMessage = "Timeout getting VCard information"; throw new XMPPException(errorMessage, new XMPPError( XMPPError.Condition.request_timeout, errorMessage)); } if (result.getError() != null) { throw new XMPPException(result.getError()); } } catch (ClassCastException e) { System.out.println("No VCard for " + user); } copyFieldsFrom(result); }
private void doLoad(Connection connection, String user) throws XMPPException { setType(Type.GET); PacketCollector collector = connection.createPacketCollector( new PacketIDFilter(getPacketID())); connection.sendPacket(this); VCard result = null; try { result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (result == null) { String errorMessage = "Timeout getting VCard information"; throw new XMPPException(errorMessage, new XMPPError( XMPPError.Condition.request_timeout, errorMessage)); } if (result.getError() != null) { throw new XMPPException(result.getError()); } } catch (ClassCastException e) { System.out.println("No VCard for " + user); } copyFieldsFrom(result); }
/** * Get a new STUN Server Address and port from the server. * If a error occurs or the server don't support STUN Service, null is returned. * * @param connection * @return */ public static STUN getSTUNServer(Connection connection) { if (!connection.isConnected()) { return null; } STUN stunPacket = new STUN(); stunPacket.setTo(DOMAIN + "." + connection.getServiceName()); PacketCollector collector = connection .createPacketCollector(new PacketIDFilter(stunPacket.getPacketID())); connection.sendPacket(stunPacket); STUN response = (STUN) collector .nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); return response; }
public static ResultServiceFactoryIQ.ServiceDescriptor[] getServiceDescriptors( XMPPConnection connection, String serviceFactoryName) throws XMPPException { RequestServiceFactoryIQ iq = new RequestServiceFactoryIQ(); iq.setServiceFactoryName(serviceFactoryName); PacketCollector collector = connection .createPacketCollector(new PacketIDFilter(iq.getPacketID())); connection.sendPacket(iq); IQ result = (IQ) collector.nextResult(); if (result == null) { throw new XMPPException("No response from the server."); } if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } return ((ResultServiceFactoryIQ) result).getServiceDescriptors(); }
private void refreshRegisterInfo(){ Registration packet = new Registration(); packet.setFrom(connection.getUser()); packet.setType(IQ.Type.GET); packet.setTo(entityJID); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packet.getPacketID())); connection.sendPacket(packet); Packet result = collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if(result instanceof Registration && result.getError()==null){ Registration register = (Registration)result; this.registerInfo = register; } }