Java Code Examples for org.jivesoftware.smack.XMPPConnection#sendPacket()
The following examples show how to use
org.jivesoftware.smack.XMPPConnection#sendPacket() .
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: XmppLoginRunnable.java From yiim_v2 with GNU General Public License v2.0 | 6 votes |
@Override public XmppResult execute() { XmppResult result = createResult(); try { XMPPConnection connection = XmppConnectionUtils.getInstance() .getConnection(); if (connection.isAuthenticated()) { XmppConnectionUtils.getInstance().closeConnection(); connection = XmppConnectionUtils.getInstance().getConnection(); } connection.login(mUserName, mPasswd); Presence presence = new Presence(mType, mStatus, 1, mMode); connection.sendPacket(presence); FileDownloadListener.setRecieveFilePath(YiFileUtils.getStorePath() + "yiim/" + mUserName + "file_recv/"); result.status = Status.SUCCESS; } catch (Exception e) { result.obj = e.getMessage(); } return result; }
Example 2
Source File: RemoteSessionCountOverXMPP.java From olat with Apache License 2.0 | 5 votes |
/** */ @Override public int countSessions() { final XMPPConnection con = adminUser.getConnection(); if (con != null && con.isConnected()) { // TODO:gs may put in other thread??? SessionCount response; try { final IQ packet = new SessionCount(); packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); con.sendPacket(packet); response = (SessionCount) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { log.warn("Error while trying to count sessions at IM server. Response was null!"); return sessionCount; } if (response.getError() != null) { log.warn("Error while trying to count sessions at IM server. " + response.getError().getMessage()); return sessionCount; } else if (response.getType() == IQ.Type.ERROR) { log.warn("Error while trying to count sessions at IM server"); return sessionCount; } sessionCount = response.getNumberOfSessions(); if (sessionCount > 0) { return sessionCount - 1; } return sessionCount; } catch (final Exception e) { log.warn("Error while trying to count sessions at IM server. Response was null!", e); return sessionCount; } } return sessionCount; }
Example 3
Source File: RemoteGroupCreationOverXMPP.java From olat with Apache License 2.0 | 5 votes |
private boolean sendPacket(final IQ packet) { final XMPPConnection con = adminUser.getConnection(); try { packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); con.sendPacket(packet); final IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { log.error("Error while trying to create/delete group at IM server. Response was null! packet type: " + packet.getClass()); return false; } if (response.getError() != null) { if (response.getError().getCode() == 409) { // 409 -> conflict / group already exists return true; } else if (response.getError().getCode() == 404) { // 404 -> not found, does not matter when trying to delete return true; } log.error("Error while trying to create/delete group at IM server. " + response.getError().getMessage()); return false; } else if (response.getType() == IQ.Type.ERROR) { log.error("Error while trying to create/delete group at IM server"); return false; } return true; } catch (final RuntimeException e) { log.error("Error while trying to create/delete group at IM server"); return false; } }
Example 4
Source File: RemotePluginVersionOverXMPP.java From olat with Apache License 2.0 | 5 votes |
/** */ @Override public String getPluginVersion() { final XMPPConnection con = adminUser.getConnection(); if (con != null && con.isConnected()) { PluginVersion response; try { final IQ packet = new PluginVersion(); packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); // TODO:gs is sending packets over one connection thread save? con.sendPacket(packet); response = (PluginVersion) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { log.error("Error while trying to get version at IM server. Response was null!"); return version; } if (response.getError() != null) { log.error("Error while trying to get version at IM server. " + response.getError().getMessage()); return version; } else if (response.getType() == IQ.Type.ERROR) { log.error("Error while trying to get version at IM server"); return version; } return response.getVersion(); } catch (final Exception e) { log.error("Error while trying to get version at IM server. Response was null!", e); return version; } } return version; }
Example 5
Source File: RemoteSessionCountOverXMPP.java From olat with Apache License 2.0 | 5 votes |
/** */ @Override public int countSessions() { final XMPPConnection con = adminUser.getConnection(); if (con != null && con.isConnected()) { // TODO:gs may put in other thread??? SessionCount response; try { final IQ packet = new SessionCount(); packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); con.sendPacket(packet); response = (SessionCount) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { log.warn("Error while trying to count sessions at IM server. Response was null!"); return sessionCount; } if (response.getError() != null) { log.warn("Error while trying to count sessions at IM server. " + response.getError().getMessage()); return sessionCount; } else if (response.getType() == IQ.Type.ERROR) { log.warn("Error while trying to count sessions at IM server"); return sessionCount; } sessionCount = response.getNumberOfSessions(); if (sessionCount > 0) { return sessionCount - 1; } return sessionCount; } catch (final Exception e) { log.warn("Error while trying to count sessions at IM server. Response was null!", e); return sessionCount; } } return sessionCount; }
Example 6
Source File: RemoteGroupCreationOverXMPP.java From olat with Apache License 2.0 | 5 votes |
private boolean sendPacket(final IQ packet) { final XMPPConnection con = adminUser.getConnection(); try { packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); con.sendPacket(packet); final IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { log.error("Error while trying to create/delete group at IM server. Response was null! packet type: " + packet.getClass()); return false; } if (response.getError() != null) { if (response.getError().getCode() == 409) { // 409 -> conflict / group already exists return true; } else if (response.getError().getCode() == 404) { // 404 -> not found, does not matter when trying to delete return true; } log.error("Error while trying to create/delete group at IM server. " + response.getError().getMessage()); return false; } else if (response.getType() == IQ.Type.ERROR) { log.error("Error while trying to create/delete group at IM server"); return false; } return true; } catch (final RuntimeException e) { log.error("Error while trying to create/delete group at IM server"); return false; } }
Example 7
Source File: RemotePluginVersionOverXMPP.java From olat with Apache License 2.0 | 5 votes |
/** */ @Override public String getPluginVersion() { final XMPPConnection con = adminUser.getConnection(); if (con != null && con.isConnected()) { PluginVersion response; try { final IQ packet = new PluginVersion(); packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); // TODO:gs is sending packets over one connection thread save? con.sendPacket(packet); response = (PluginVersion) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { log.error("Error while trying to get version at IM server. Response was null!"); return version; } if (response.getError() != null) { log.error("Error while trying to get version at IM server. " + response.getError().getMessage()); return version; } else if (response.getType() == IQ.Type.ERROR) { log.error("Error while trying to get version at IM server"); return version; } return response.getVersion(); } catch (final Exception e) { log.error("Error while trying to get version at IM server. Response was null!", e); return version; } } return version; }
Example 8
Source File: RemoteAccountCreationOverXMPP.java From olat with Apache License 2.0 | 4 votes |
private boolean sendPacket(final IQ packet) { final XMPPConnection con = adminUser.getConnection(); try { packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); con.sendPacket(packet); final IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { // OLAT-5384: error happens frequently, lowering to WARN log.warn("Error while trying to create/delete user at IM server. Response was null!"); return false; } if (response.getError() != null) { if (response.getError().getCode() == 503) { // 503 code means service not available, IM server plugin may not installed log.error("Openfire and OLAT talk over an custom Openfire plugin. Please make sure you have it installed! " + "Download it under http://www.olat.org/downloads/stable/olatUserAndGroupService.jar"); } else if (response.getError().getCode() == 407 || response.getError().getCode() == 409) { // 407 or 409 -> conflict / user already exists return true; } else if (response.getError().getCode() == 404) { // 404 -> user not found, ok when trying to delete return true; } log.warn("Error while trying to create/delete user at IM server. Errorcode: " + response.getError().getCode()); return false; } else if (response.getType() == IQ.Type.ERROR) { log.error("Error while trying to create/delete user at IM server. Response type error"); return false; } if (response instanceof UserCheck) { final UserCheck check = (UserCheck) response; return check.hasAccount(); } return true; } catch (final Exception e) { log.error("Error while trying to create/delete user at IM server", e); return false; } }
Example 9
Source File: RemoteAccountCreationOverXMPP.java From olat with Apache License 2.0 | 4 votes |
private boolean sendPacket(final IQ packet) { final XMPPConnection con = adminUser.getConnection(); try { packet.setFrom(con.getUser()); final PacketCollector collector = con.createPacketCollector(new PacketIDFilter(packet.getPacketID())); con.sendPacket(packet); final IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); collector.cancel(); if (response == null) { // OLAT-5384: error happens frequently, lowering to WARN log.warn("Error while trying to create/delete user at IM server. Response was null!"); return false; } if (response.getError() != null) { if (response.getError().getCode() == 503) { // 503 code means service not available, IM server plugin may not installed log.error("Openfire and OLAT talk over an custom Openfire plugin. Please make sure you have it installed! " + "Download it under http://www.olat.org/downloads/stable/olatUserAndGroupService.jar"); } else if (response.getError().getCode() == 407 || response.getError().getCode() == 409) { // 407 or 409 -> conflict / user already exists return true; } else if (response.getError().getCode() == 404) { // 404 -> user not found, ok when trying to delete return true; } log.warn("Error while trying to create/delete user at IM server. Errorcode: " + response.getError().getCode()); return false; } else if (response.getType() == IQ.Type.ERROR) { log.error("Error while trying to create/delete user at IM server. Response type error"); return false; } if (response instanceof UserCheck) { final UserCheck check = (UserCheck) response; return check.hasAccount(); } return true; } catch (final Exception e) { log.error("Error while trying to create/delete user at IM server", e); return false; } }