Refine search
private static Version generateVersionFrom(String name, String version, String os) { if (autoAppendSmackVersion) { name += " (Smack " + SmackConfiguration.getVersion() + ')'; } return new Version(name, version, os); } }
/** * Add a Collection of SASL mechanisms to the list to be used. * * @param mechs the Collection of SASL mechanisms to be added */ public static void addSaslMechs(Collection<String> mechs) { for (String mech : mechs) { addSaslMech(mech); } }
SmackConfiguration.addDisabledSmackClass("org.jivesoftware.smack.debugger.JulDebugger"); SmackConfiguration.DEBUG = true; SmackConfiguration.setDefaultReplyTimeout(config.replyTimeout);
@Ignore @Test public void smackconfigurationVersionShouldInitialzieSmacktTest() { SmackConfiguration.getVersion(); // Only a call to SmackConfiguration.getVersion() should cause Smack to become initialized. assertTrue(SmackConfiguration.isSmackInitialized()); } }
@Ignore @Test public void smackConfigurationShouldNotCauseInitializationTest() { SmackConfiguration.getDefaultReplyTimeout(); // Only a call to SmackConfiguration.getVersion() should cause Smack to become initialized. assertFalse(SmackConfiguration.isSmackInitialized()); }
/** * Gets the account registration info from the server. * * @throws XMPPException if an error occurs. */ private synchronized void getRegistrationInfo() throws XMPPException { Registration reg = new Registration(); reg.setTo(connection.getServiceName()); PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } else if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError()); } else { info = (Registration)result; } } }
/** * Deletes all offline messages of the user. * * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public void deleteMessages() throws XMPPException { OfflineMessageRequest request = new OfflineMessageRequest(); request.setPurge(true); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(request.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send the deletion request to the server. connection.sendPacket(request); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } } }
public String authenticateAnonymously() throws XMPPException { // Create the authentication packet we'll send to the server. Authentication auth = new Authentication(); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(auth.getPacketID())); // Send the packet. connection.sendPacket(auth); // Wait up to a certain number of seconds for a response from the server. IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (response == null) { throw new XMPPException("Anonymous login failed."); } else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } // We're done with the collector, so explicitly cancel it. collector.cancel(); if (response.getTo() != null) { return response.getTo(); } else { return connection.getServiceName() + "/" + ((Authentication) response).getResource(); } } }
public InputStream call() throws Exception { Packet streamInitiation = collector.nextResult( SmackConfiguration.getPacketReplyTimeout() * 2); if (streamInitiation == null) { throw new XMPPException("No response from remote client"); } StreamNegotiator negotiator = determineNegotiator(streamInitiation); return negotiator.negotiateIncomingStream(streamInitiation); } }
/** * Returns true if the workgroup is available for receiving new requests. The workgroup will be * available only when agents are available for this workgroup. * * @return true if the workgroup is available for receiving new requests. */ public boolean isAvailable() { Presence directedPresence = new Presence(Presence.Type.available); directedPresence.setTo(workgroupJID); PacketFilter typeFilter = new PacketTypeFilter(Presence.class); PacketFilter fromFilter = new FromContainsFilter(workgroupJID); PacketCollector collector = connection.createPacketCollector(new AndFilter(fromFilter, typeFilter)); connection.sendPacket(directedPresence); Presence response = (Presence)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Cancel the collector. collector.cancel(); if (response == null) { return false; } else if (response.getError() != null) { return false; } else { return Presence.Type.available == response.getType(); } }
static public Packet getReply(Connection connection, Packet packet) throws XMPPException { return getReply(connection, packet, SmackConfiguration.getPacketReplyTimeout()); } }
/** * Sets the number of milliseconds to wait for a response from * the server. * * @param timeout the milliseconds to wait for a response from the server * @deprecated use {@link #setDefaultReplyTimeout(int)} instead. */ @Deprecated public static void setDefaultPacketReplyTimeout(int timeout) { setDefaultReplyTimeout(timeout); }
@Override public void start(BundleContext bundleContext) throws Exception { XmppProtocolActivator.bundleContext = bundleContext; SmackConfiguration.setDefaultReplyTimeout(15000); // if there is a parsing error, do not break the connection to // the server(the default behaviour) as we need it for // the other conferences SmackConfiguration.setDefaultParsingExceptionCallback( new ExceptionLoggingCallback()); Socks5Proxy.setLocalSocks5ProxyEnabled(false); registerXmppExtensions(); XmppProviderFactory focusFactory = new XmppProviderFactory( bundleContext, ProtocolNames.JABBER); Hashtable<String, String> hashtable = new Hashtable<>(); // Register XMPP hashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.JABBER); focusRegistration = bundleContext.registerService( ProtocolProviderFactory.class.getName(), focusFactory, hashtable); }
/** * Add the given class names to the list of disabled Smack classes. * * @param classNames the Smack classes to disable. * @see #addDisabledSmackClass(String) */ public static void addDisabledSmackClasses(String... classNames) { for (String className : classNames) { addDisabledSmackClass(className); } }
/** * Get compression handlers. * * @deprecated use {@link #getCompressionHandlers()} instead. */ @Deprecated public static List<XMPPInputOutputStream> getCompresionHandlers() { return getCompressionHandlers(); }
/** * Returns the number of milliseconds to wait for a response from * the server. The default value is 5000 ms. * * @return the milliseconds to wait for a response from the server * @deprecated use {@link #getDefaultReplyTimeout()} instead. */ @Deprecated public static int getDefaultPacketReplyTimeout() { return getDefaultReplyTimeout(); }
/** * Starts the keep alive process. A white space (aka heartbeat) is going to be * sent to the server every 30 seconds (by default) since the last stanza was sent * to the server. */ void startKeepAliveProcess() { // Schedule a keep-alive task to run if the feature is enabled. will write // out a space character each time it runs to keep the TCP/IP connection open. int keepAliveInterval = SmackConfiguration.getKeepAliveInterval(); if (keepAliveInterval > 0) { KeepAliveTask task = new KeepAliveTask(keepAliveInterval); keepAliveThread = new Thread(task); task.setThread(keepAliveThread); keepAliveThread.setDaemon(true); keepAliveThread.setName("Smack Keep Alive (" + connection.connectionCounterValue + ")"); keepAliveThread.start(); } }
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class)); PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); throw new XMPPException("No response from server."); else if (result.getType() == IQ.Type.ERROR) { throw new XMPPException(result.getError());
/** * Deletes all offline messages of the user. * * @throws XMPPException If the user is not allowed to make this request or the server does * not support offline message retrieval. */ public void deleteMessages() throws XMPPException { OfflineMessageRequest request = new OfflineMessageRequest(); request.setPurge(true); // Filter packets looking for an answer from the server. PacketFilter responseFilter = new PacketIDFilter(request.getPacketID()); PacketCollector response = connection.createPacketCollector(responseFilter); // Send the deletion request to the server. connection.sendPacket(request); // Wait up to a certain number of seconds for a reply. IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout()); // Stop queuing results response.cancel(); if (answer == null) { throw new XMPPException("No response from server."); } else if (answer.getError() != null) { throw new XMPPException(answer.getError()); } } }
public String authenticateAnonymously() throws XMPPException { // Create the authentication packet we'll send to the server. Authentication auth = new Authentication(); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(auth.getPacketID())); // Send the packet. connection.sendPacket(auth); // Wait up to a certain number of seconds for a response from the server. IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); if (response == null) { throw new XMPPException("Anonymous login failed."); } else if (response.getType() == IQ.Type.ERROR) { throw new XMPPException(response.getError()); } // We're done with the collector, so explicitly cancel it. collector.cancel(); if (response.getTo() != null) { return response.getTo(); } else { return connection.getServiceName() + "/" + ((Authentication) response).getResource(); } } }