use of org.jivesoftware.smack.SmackException.NoResponseException in project Smack by igniterealtime.
the class IntTestUtil method deleteViaIbr.
public static void deleteViaIbr(XMPPTCPConnection connection) throws InterruptedException {
// mechanisms
if (!connection.isConnected()) {
try {
connection.connect().login();
} catch (XMPPException | SmackException | IOException e) {
LOGGER.log(Level.WARNING, "Exception reconnection account for deletion", e);
}
}
final int maxAttempts = 3;
AccountManager am = AccountManager.getInstance(connection);
int attempts;
for (attempts = 0; attempts < maxAttempts; attempts++) {
try {
am.deleteAccount();
} catch (XMPPErrorException | NoResponseException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
} catch (NotConnectedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
try {
connection.connect().login();
} catch (XMPPException | SmackException | IOException e2) {
LOGGER.log(Level.WARNING, "Exception while trying to re-connect " + connection, e);
}
continue;
}
LOGGER.info("Successfully deleted account of " + connection);
break;
}
if (attempts > maxAttempts) {
LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
}
}
use of org.jivesoftware.smack.SmackException.NoResponseException in project Smack by igniterealtime.
the class IntTestUtil method deleteViaServiceAdministration.
public static void deleteViaServiceAdministration(XMPPTCPConnection connection, Configuration config) {
EntityBareJid accountToDelete = connection.getUser().asEntityBareJid();
final int maxAttempts = 3;
int attempts;
for (attempts = 0; attempts < maxAttempts; attempts++) {
connection.disconnect();
try {
connection.connect().login(config.adminAccountUsername, config.adminAccountPassword);
} catch (XMPPException | SmackException | IOException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
}
ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection);
try {
adminManager.deleteUser(accountToDelete);
} catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
}
}
if (attempts > maxAttempts) {
LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
}
}
use of org.jivesoftware.smack.SmackException.NoResponseException in project Smack by igniterealtime.
the class Socks5ClientForInitiator method getSocket.
@Override
public Socket getSocket(int timeout) throws IOException, InterruptedException, TimeoutException, XMPPException, SmackException {
Socket socket = null;
// check if stream host is the local SOCKS5 proxy
if (this.streamHost.getJID().equals(this.connection.get().getUser())) {
Socks5Proxy socks5Server = Socks5Proxy.getSocks5Proxy();
socket = socks5Server.getSocket(this.digest);
if (socket == null) {
throw new SmackException("target is not connected to SOCKS5 proxy");
}
} else {
socket = super.getSocket(timeout);
try {
activate();
} catch (XMPPException e1) {
socket.close();
throw e1;
} catch (NoResponseException e2) {
socket.close();
throw e2;
}
}
return socket;
}
use of org.jivesoftware.smack.SmackException.NoResponseException in project Smack by igniterealtime.
the class ServiceDiscoveryManager method findServicesDiscoverInfo.
/**
* Find all services under the users service that provide a given feature.
*
* @param feature the feature to search for
* @param stopOnFirst if true, stop searching after the first service was found
* @param useCache if true, query a cache first to avoid network I/O
* @return a possible empty list of services providing the given feature
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<DiscoverInfo> findServicesDiscoverInfo(String feature, boolean stopOnFirst, boolean useCache) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
List<DiscoverInfo> serviceDiscoInfo = null;
DomainBareJid serviceName = connection().getXMPPServiceDomain();
if (useCache) {
serviceDiscoInfo = services.lookup(feature);
if (serviceDiscoInfo != null) {
return serviceDiscoInfo;
}
}
serviceDiscoInfo = new LinkedList<>();
// Send the disco packet to the server itself
DiscoverInfo info;
try {
info = discoverInfo(serviceName);
} catch (XMPPErrorException e) {
// Be extra robust here: Return the empty linked list and log this situation
LOGGER.log(Level.WARNING, "Could not discover information about service", e);
return serviceDiscoInfo;
}
// Check if the server supports the feature
if (info.containsFeature(feature)) {
serviceDiscoInfo.add(info);
if (stopOnFirst) {
if (useCache) {
// Cache the discovered information
services.put(feature, serviceDiscoInfo);
}
return serviceDiscoInfo;
}
}
DiscoverItems items;
try {
// Get the disco items and send the disco packet to each server item
items = discoverItems(serviceName);
} catch (XMPPErrorException e) {
LOGGER.log(Level.WARNING, "Could not discover items about service", e);
return serviceDiscoInfo;
}
for (DiscoverItems.Item item : items.getItems()) {
try {
// TODO is it OK here in all cases to query without the node attribute?
// MultipleRecipientManager queried initially also with the node attribute, but this
// could be simply a fault instead of intentional.
info = discoverInfo(item.getEntityID());
} catch (XMPPErrorException | NoResponseException e) {
// Don't throw this exceptions if one of the server's items fail
LOGGER.log(Level.WARNING, "Exception while discovering info for feature " + feature + " of " + item.getEntityID() + " node: " + item.getNode(), e);
continue;
}
if (info.containsFeature(feature)) {
serviceDiscoInfo.add(info);
//serviceAddresses.add(item.getEntityID().asDomainBareJid());
if (stopOnFirst) {
break;
}
}
}
if (useCache) {
// Cache the discovered information
services.put(feature, serviceDiscoInfo);
}
return serviceDiscoInfo;
}
use of org.jivesoftware.smack.SmackException.NoResponseException in project opennms by OpenNMS.
the class XMPPNotificationManager method sendGroupChat.
/**
* send an xmpp message to a specified Chat Room.
*
* @param xmppChatRoom
* room to send message to.
* @param xmppMessage
* text to be sent in the body of the message
* @return true if message is sent, false otherwise
*/
public boolean sendGroupChat(String xmppChatRoom, String xmppMessage) {
MultiUserChat groupChat;
if (rooms.containsKey(xmppChatRoom)) {
groupChat = rooms.get(xmppChatRoom);
} else {
LOG.debug("Adding room: {}", xmppChatRoom);
groupChat = new MultiUserChat(xmpp, xmppChatRoom);
rooms.put(xmppChatRoom, groupChat);
}
if (!groupChat.isJoined()) {
LOG.debug("Joining room: {}", xmppChatRoom);
try {
groupChat.join(xmppUser);
} catch (XMPPException | NoResponseException | NotConnectedException e) {
LOG.error("XMPP Exception joining chat room ", e);
return false;
}
}
try {
groupChat.sendMessage(xmppMessage);
LOG.debug("XMPP Manager sent message to: {}", xmppChatRoom);
} catch (XMPPException | NotConnectedException e) {
LOG.error("XMPP Exception sending message to Chat room", e);
return false;
}
return true;
}
Aggregations