use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.
the class JingleSession method startOutgoing.
/**
* This is the starting point for intitiating a new session.
*
* @throws IllegalStateException
* @throws SmackException
* @throws InterruptedException
*/
public void startOutgoing() throws IllegalStateException, SmackException, InterruptedException {
updatePacketListener();
setSessionState(JingleSessionStatePending.getInstance());
Jingle jingle = new Jingle(JingleActionEnum.SESSION_INITIATE);
// Create a content negotiator for each media manager on the session.
for (JingleMediaManager mediaManager : getMediaManagers()) {
ContentNegotiator contentNeg = new ContentNegotiator(this, ContentNegotiator.INITIATOR, mediaManager.getName());
// Create the media negotiator for this content description.
contentNeg.setMediaNegotiator(new MediaNegotiator(this, mediaManager, mediaManager.getPayloads(), contentNeg));
JingleTransportManager transportManager = mediaManager.getTransportManager();
TransportResolver resolver = null;
try {
resolver = transportManager.getResolver(this);
} catch (XMPPException e) {
LOGGER.log(Level.WARNING, "exception", e);
}
if (resolver.getType().equals(TransportResolver.Type.rawupd)) {
contentNeg.setTransportNegotiator(new TransportNegotiator.RawUdp(this, resolver, contentNeg));
}
if (resolver.getType().equals(TransportResolver.Type.ice)) {
contentNeg.setTransportNegotiator(new TransportNegotiator.Ice(this, resolver, contentNeg));
}
addContentNegotiator(contentNeg);
}
// Give each of the content negotiators a chance to return a portion of the structure to make the Jingle packet.
for (ContentNegotiator contentNegotiator : contentNegotiators) {
jingle.addContent(contentNegotiator.getJingleContent());
}
// Save the session-initiate packet ID, so that we can respond to it.
sessionInitPacketID = jingle.getStanzaId();
sendStanza(jingle);
// Now setup to track the media negotiators, so that we know when (if) to send a session-accept.
setupListeners();
// Give each of the content negotiators a chance to start
// and return a portion of the structure to make the Jingle packet.
// Don't do this anymore. The problem is that the other side might not be ready.
// Later when we receive our first jingle packet from the other side we'll fire-up the negotiators
// before processing it. (See receivePacketAndRespond() above.
// for (ContentNegotiator contentNegotiator : contentNegotiators) {
// contentNegotiator.start();
// }
}
use of org.jivesoftware.smack.XMPPException in project openhab1-addons by openhab.
the class XMPP method chatXMPP.
/**
* Sends a message to an XMPP multi user chat.
*
* @param message the message to send
*
* @return <code>true</code>, if sending the message has been successful and
* <code>false</code> in all other cases.
*/
@ActionDoc(text = "Sends a message to an XMPP multi user chat.")
public static boolean chatXMPP(@ParamDoc(name = "message") String message) {
boolean success = false;
try {
MultiUserChat chat = XMPPConnect.getChat();
try {
while (message.length() >= 2000) {
chat.sendMessage(message.substring(0, 2000));
message = message.substring(2000);
}
chat.sendMessage(message);
logger.debug("Sent message '{}' to multi user chat.", message);
success = true;
} catch (XMPPException e) {
logger.warn("Error Delivering block", e);
} catch (NotConnectedException e) {
logger.warn("Error Delivering block", e);
}
} catch (NotInitializedException e) {
logger.warn("Could not send XMPP message as connection is not correctly initialized!");
}
return success;
}
use of org.jivesoftware.smack.XMPPException in project intellij-plugins by JetBrains.
the class JabberFacade_ConnectionTest method suite.
public static Test suite() {
TestSuite testSuite = new TestSuite();
XMPPConnection ourConnection;
try {
ourConnection = new XMPPConnection(LOCALHOST);
} catch (XMPPException e) {
return testSuite;
}
ourConnection.close();
testSuite.addTestSuite(JabberFacade_ConnectionTest.class);
return testSuite;
}
use of org.jivesoftware.smack.XMPPException in project Payara by payara.
the class XmppNotificationRunnable method run.
@Override
public void run() {
while (queue.size() > 0) {
try {
XmppMessage xmppMessage = queue.getMessage();
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
MultiUserChat multiUserChat = manager.getMultiUserChat(executionOptions.getRoomId() + "@" + executionOptions.getServiceName());
if (multiUserChat != null) {
if (!multiUserChat.isJoined()) {
multiUserChat.join(executionOptions.getUsername(), executionOptions.getPassword());
}
Message message = new Message();
message.setSubject(xmppMessage.getSubject());
message.setBody(xmppMessage.getMessage());
multiUserChat.sendMessage(message);
}
logger.log(Level.FINE, "Message sent successfully");
} catch (XMPPException | SmackException e) {
logger.log(Level.SEVERE, "Error occurred while sending message to room", e);
}
}
}
use of org.jivesoftware.smack.XMPPException in project wso2-axis2-transports by wso2.
the class XMPPClientConnectionFactory method connect.
/**
* Connects to a XMPP server based on the details available in serverCredentials object
* @param serverCredentials
* @throws XMPPException
*/
public XMPPConnection connect(final XMPPServerCredentials serverCredentials) throws AxisFault {
// XMPPConnection.DEBUG_ENABLED = true;
if (XMPPConstants.XMPP_SERVER_TYPE_JABBER.equals(serverCredentials.getServerType())) {
xmppConnection = new XMPPConnection(serverCredentials.getServerUrl());
try {
xmppConnection.connect();
} catch (XMPPException e) {
log.error("Failed to connect to server :" + serverCredentials.getServerUrl(), e);
throw new AxisFault("Failed to connect to server :" + serverCredentials.getServerUrl());
}
// This prevents random ssl exception from Smack API
try {
Thread.sleep(100);
} catch (InterruptedException e5) {
log.debug("Sleep interrupted ", e5);
}
if (xmppConnection.isConnected()) {
String resource = serverCredentials.getResource() + new Object().hashCode();
if (!xmppConnection.isAuthenticated()) {
try {
// xmppConnection.login(serverCredentials.getAccountName()+"@"+
// serverCredentials.getServerUrl(),
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
} catch (XMPPException e) {
try {
log.error("Login failed for " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + ".Retrying in 2 secs", e);
Thread.sleep(2000);
// xmppConnection.login(serverCredentials.getAccountName()+"@"+
// serverCredentials.getServerUrl(),
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
} catch (InterruptedException e1) {
log.error("Sleep interrupted.", e1);
} catch (XMPPException e2) {
log.error("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl(), e2);
throw new AxisFault("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl());
}
}
// Listen for Message type packets from specified server url
// packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
// new FromContainsFilter(serverCredentials.getServerUrl()));
packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());
}
}
} else if (XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK.equals(serverCredentials.getServerType())) {
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(XMPPConstants.GOOGLETALK_URL, XMPPConstants.GOOGLETALK_PORT, XMPPConstants.GOOGLETALK_SERVICE_NAME);
xmppConnection = new XMPPConnection(connectionConfiguration);
try {
xmppConnection.connect();
xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), serverCredentials.getResource(), true);
// packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
// new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM));
// packetFilter = new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM);
packetFilter = new ToContainsFilter("@gmail.com");
} catch (XMPPException e1) {
log.error("Error occured while connecting to Googletalk server.", e1);
throw new AxisFault("Error occured while connecting to Googletalk server.");
}
}
ConnectionListener connectionListener = null;
connectionListener = new ConnectionListener() {
public void connectionClosed() {
log.debug("Connection closed normally");
}
public void connectionClosedOnError(Exception e1) {
log.error("Connection to " + serverCredentials.getServerUrl() + " closed with error.", e1);
}
public void reconnectingIn(int seconds) {
log.error("Connection to " + serverCredentials.getServerUrl() + " failed. Reconnecting in " + seconds + "s");
}
public void reconnectionFailed(Exception e) {
log.error("Reconnection to " + serverCredentials.getServerUrl() + " failed.", e);
}
public void reconnectionSuccessful() {
log.debug("Reconnection to " + serverCredentials.getServerUrl() + " successful.");
}
};
if (xmppConnection != null && xmppConnection.isConnected()) {
xmppConnection.addConnectionListener(connectionListener);
log.info("Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
} else {
log.warn(" Not Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
}
return xmppConnection;
}
Aggregations