Java Code Examples for org.jxmpp.stringprep.XmppStringprepException

The following examples show how to use org.jxmpp.stringprep.XmppStringprepException. These examples are extracted from open source projects. 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 Project: Smack   Source File: OmemoDeviceTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test, if the equals() method works as intended.
 */
@Test
public void testEquals() {
    BareJid romeo, juliet, guyUnderTheBalcony;
    try {
        romeo = JidCreate.bareFrom("[email protected]");
        guyUnderTheBalcony = JidCreate.bareFrom("[email protected]/underTheBalcony");
        juliet = JidCreate.bareFrom("[email protected]");
    } catch (XmppStringprepException e) {
        Assert.fail(e.getMessage());
        return;
    }

    OmemoDevice r = new OmemoDevice(romeo, 1);
    OmemoDevice g = new OmemoDevice(guyUnderTheBalcony, 1);
    OmemoDevice r2 = new OmemoDevice(romeo, 2);
    OmemoDevice j = new OmemoDevice(juliet, 3);
    OmemoDevice j2 = new OmemoDevice(juliet, 1);

    assertTrue(r.equals(g));
    assertFalse(r.equals(r2));
    assertFalse(j.equals(j2));
    assertFalse(j2.equals(r2));
}
 
Example 2
Source Project: Smack   Source File: DigestMd5SaslTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void runTest(boolean useAuthzid) throws SmackException, InterruptedException, XmppStringprepException {
    EntityBareJid authzid = null;
    if (useAuthzid) {
        authzid = JidCreate.entityBareFrom("[email protected]");
    }
    saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null);
    byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
    String responseString = new String(response, StandardCharsets.UTF_8);
    String[] responseParts = responseString.split(",");
    Map<String, String> responsePairs = new HashMap<String, String>();
    for (String part : responseParts) {
        String[] keyValue = part.split("=", 2);
        String key = keyValue[0];
        String value = keyValue[1].replace("\"", "");
        responsePairs.put(key, value);
    }
    if (useAuthzid) {
      assertMapValue("authzid", "[email protected]", responsePairs);
    } else {
      assertTrue (!responsePairs.containsKey("authzid"));
    }
    assertMapValue("username", "florian", responsePairs);
    assertMapValue("realm", "xmpp.org", responsePairs);
    assertMapValue("digest-uri", "xmpp/xmpp.org", responsePairs);
    assertMapValue("qop", "auth", responsePairs);
}
 
Example 3
Source Project: Smack   Source File: IQResponseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test creating a error response based on an IQ request.
 * @throws XmppStringprepException if the provided string is invalid.
 */
@Test
public void testGeneratingValidErrorResponse() throws XmppStringprepException {
    final StanzaError error = StanzaError.getBuilder(StanzaError.Condition.bad_request).build();
    final IQ request = new TestIQ(ELEMENT, NAMESPACE);

    request.setType(IQ.Type.set);
    request.setFrom(JidCreate.from("[email protected]/Smack"));
    request.setTo(JidCreate.from("[email protected]/Smack"));

    final IQ result = IQ.createErrorResponse(request, error);

    assertEquals(IQ.Type.error, result.getType());
    assertNotNull(result.getStanzaId());
    assertEquals(request.getStanzaId(), result.getStanzaId());
    assertEquals(request.getFrom(), result.getTo());
    assertEquals(error.toXML().toString(), result.getError().toXML().toString());
    // TODO this test was never valid
    // assertEquals(CHILD_ELEMENT, result.getChildElementXML());
}
 
Example 4
public static void requestOfflineFile(org.jivesoftware.smack.packet.Message message) {
	// TODO 向离线文件机器人发送请求
	// 将接收到的离线文件消息,原封不动的发给离线文件机器人 ,
	//	离线机器人接收后,会立即将已存储的文件发过来,同时会发送一条消息回执,发送成功后,删除文件
	//	用户收到回执后,需要对聊天UI进行处理,注意:此时的fromJid是机器人,应处理为实际发送者,即senderFullJid
	Chat chat;
	try {
		chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(JidCreate.entityBareFrom(Launcher.OFFLINEFILEROBOTJID));
        
		chat.send(message); //发送请求到机器人,然后机器人会把文件发给我
		OfflineFile of = (OfflineFile)message.getExtension(OfflineFile.NAMESPACE);
		offlineFileJidMap.put(of.getFileName(), of.getSenderFullJid());
		DebugUtil.debug( "send offlinefile request:"+ message.toXML());	
		
	} catch (XmppStringprepException |NotConnectedException | InterruptedException e) {
		
	}
}
 
Example 5
Source Project: Smack   Source File: IQResponseTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * According to <a href="http://xmpp.org/rfcs/rfc3920.html#stanzas-semantics-iq"
 * >RFC3920: IQ Semantics</a> we shouldn't respond to an IQ of type error.
 * @throws XmppStringprepException if the provided string is invalid.
 */
@Test
public void testGeneratingErrorBasedOnError() throws XmppStringprepException {
    final StanzaError error = StanzaError.getBuilder(StanzaError.Condition.bad_request).build();
    final IQ request = new TestIQ(ELEMENT, NAMESPACE);

    request.setType(IQ.Type.error);
    request.setFrom(JidCreate.from("[email protected]/Smack"));
    request.setTo(JidCreate.from("[email protected]/Smack"));
    request.setError(error);

    try {
        IQ.createErrorResponse(request, error);
    }
    catch (IllegalArgumentException e) {
        return;
    }

    fail("It shouldn't be possible to generate a response for a error IQ!");
}
 
Example 6
Source Project: mangosta-android   Source File: RosterManager.java    License: Apache License 2.0 6 votes vote down vote up
public void removeContact(String jidString)
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException, XmppStringprepException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }

    BareJid jid = JidCreate.bareFrom(jidString);
    roster.removeEntry(roster.getEntry(jid));

    Presence presence = new Presence(Presence.Type.unsubscribe);
    presence.setTo(JidCreate.from(jidString));
    XMPPSession.getInstance().sendStanza(presence);
}
 
Example 7
Source Project: jxmpp   Source File: JidCreate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get a domain bare JID.
 *
 * @param jid the JID String.
 * @param context the JXMPP context.
 * @return a domain bare JID.
 * @throws XmppStringprepException if an error occurs.
 */
public static DomainBareJid domainBareFrom(String jid, JxmppContext context) throws XmppStringprepException {
	DomainBareJid domainJid;
	if (context.isCachingEnabled()) {
		domainJid = DOMAINJID_CACHE.lookup(jid);
		if (domainJid != null) {
			return domainJid;
		}
	}

	String domain = XmppStringUtils.parseDomain(jid);
	try {
		domainJid = new DomainpartJid(domain, context);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}

	if (context.isCachingEnabled()) {
		DOMAINJID_CACHE.put(jid, domainJid);
	}
	return domainJid;
}
 
Example 8
Source Project: XMPPSample_Studio   Source File: DataProvider.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public static MyListWrapper<MessageItem> getMessages(String jid) throws XmppStringprepException {
	if (get().messages.containsKey(JidCreate.domainBareFrom(jid))) {
		return get().messages.get(JidCreate.domainBareFrom(jid));
	}

	MyListWrapper<MessageItem> msgs = null;
	try {
		msgs = new MyListWrapper(DatabaseHelper.getInstance(LiveApp.get())
				.getDao(MessageItem.class)
				.queryForEq("opponent", JidCreate.domainBareFrom(jid)));
	} catch (SQLException e) {
		msgs = new MyListWrapper<MessageItem>();
	}
	get().messages.put((jid), msgs);
	return msgs;
}
 
Example 9
Source Project: Spark   Source File: ChatArgumentsPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initialize() {
       EntityBareJid start_chat_jid = null;
       try {
           start_chat_jid = JidCreate.entityBareFromUnescaped(Spark.getArgumentValue("start_chat_jid"));
       } catch (XmppStringprepException e1) {
       }
       EntityBareJid start_chat_muc = null;
       try {
           start_chat_muc = JidCreate.entityBareFromUnescaped(Spark.getArgumentValue("start_chat_muc"));
       } catch (XmppStringprepException e) {
       }

       if (start_chat_jid != null) {
           Localpart nickname = start_chat_jid.getLocalpart();
           SparkManager.getChatManager().createChatRoom(start_chat_jid, nickname.toString(), start_chat_jid.toString());
       }

       if (start_chat_muc != null) {
           ConferenceUtils.joinConferenceOnSeperateThread(start_chat_muc, start_chat_muc, null);
       }

   }
 
Example 10
Source Project: Spark   Source File: TransportUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the user is registered with a gateway.
 *
 * @param con       the XMPPConnection.
 * @param transport the transport.
 * @return true if the user is registered with the transport.
 */
public static boolean isRegistered(XMPPConnection con, Transport transport) {
    if (!con.isConnected()) {
        return false;
    }

    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con);
    try {
        Jid jid = JidCreate.from(transport.getXMPPServiceDomain());
        DiscoverInfo info = discoveryManager.discoverInfo(jid);
        return info.containsFeature("jabber:iq:registered");
    }
    catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
 
Example 11
Source Project: Conversations   Source File: Jid.java    License: GNU General Public License v3.0 6 votes vote down vote up
static Jid of(CharSequence local, CharSequence domain, CharSequence resource) {
    if (local == null) {
        if (resource == null) {
            return ofDomain(domain);
        } else {
            return ofDomainAndResource(domain, resource);
        }
    }
    if (resource == null) {
        return ofLocalAndDomain(local, domain);
    }
    try {
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.fromUnescaped(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 12
Source Project: Pix-Art-Messenger   Source File: Jid.java    License: GNU General Public License v3.0 6 votes vote down vote up
static Jid ofEscaped(CharSequence local, CharSequence domain, CharSequence resource) {
    try {
        if (resource == null) {
            return new WrappedJid(
                    JidCreate.bareFrom(
                            Localpart.from(local.toString()),
                            Domainpart.from(domain.toString())
                    )
            );
        }
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.from(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 13
Source Project: Smack   Source File: RosterTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests that roster pushes with invalid from are ignored.
 * @throws XmppStringprepException if the provided string is invalid.
 *
 * @see <a href="http://xmpp.org/rfcs/rfc6121.html#roster-syntax-actions-push">RFC 6121, Section 2.1.6</a>
 */
@Test
public void testIgnoreInvalidFrom() throws XmppStringprepException {
    final BareJid spammerJid = JidCreate.entityBareFrom("[email protected]");
    RosterPacket packet = new RosterPacket();
    packet.setType(Type.set);
    packet.setTo(connection.getUser());
    packet.setFrom(JidCreate.entityBareFrom("[email protected]"));
    packet.addRosterItem(new Item(spammerJid, "Cool products!"));

    final String requestId = packet.getStanzaId();
    // Simulate receiving the roster push
    connection.processStanza(packet);

    // Smack should reply with an error IQ
    ErrorIQ errorIQ = connection.getSentPacket();
    assertEquals(requestId, errorIQ.getStanzaId());
    assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition());

    assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry(spammerJid));
}
 
Example 14
Source Project: jxmpp   Source File: Domainpart.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the {@link Domainpart} representing the input String.
 *
 * @param domain the input String.
 * @param context the JXMPP context.
 * @return the domainpart.
 * @throws XmppStringprepException if an error occurs.
 */
public static Domainpart from(String domain, JxmppContext context) throws XmppStringprepException {
	if (domain == null) {
		throw new XmppStringprepException(domain, "Input 'domain' must not be null");
	}
	// TODO cache
	// RFC 6122 § 2.2 "If the domainpart includes a final character considered to be a label
	// separator (dot) by [IDNA2003] or [DNS], this character MUST be stripped …"
	if (domain.length() > 0 && domain.charAt(domain.length() - 1) == '.') {
		domain = domain.substring(0, domain.length() - 1);
	}
	domain = XmppStringPrepUtil.domainprep(domain, context);
	// First prep the String, then assure the limits of the *result*
	assertNotLongerThan1023BytesOrEmpty(domain);
	return new Domainpart(domain);
}
 
Example 15
Source Project: Smack   Source File: STUN.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 TODO javadoc me please
 * @return the STUN server address
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException {

    if (!connection.isConnected()) {
        return null;
    }

    STUN stunPacket = new STUN();
    DomainBareJid jid;
    try {
        jid = JidCreate.domainBareFrom(DOMAIN + "." + connection.getXMPPServiceDomain());
    } catch (XmppStringprepException e) {
        throw new AssertionError(e);
    }
    stunPacket.setTo(jid);

    StanzaCollector collector = connection.createStanzaCollectorAndSend(stunPacket);

    STUN response = collector.nextResult();

    // Cancel the collector.
    collector.cancel();

    return response;
}
 
Example 16
Source Project: jxmpp   Source File: JidCreateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void jidResourcepartWithAtSignTest() throws XmppStringprepException {
	Jid jid = JidCreate.from("a.example.com/[email protected]");

	assertEquals(Domainpart.from("a.example.com"), jid.getDomain());
	assertEquals(Resourcepart.from("[email protected]"), jid.getResourceOrNull());
}
 
Example 17
public static void joinAllRooms() throws XmppStringprepException, XMPPErrorException, NoResponseException,
		NotConnectedException, InterruptedException, NotAMucServiceException {
	// TODO 启动MUC房间订阅,订阅全部房间
	// 在sqlite库中查询MUC群组
	List<Room> dbMucRooms = Launcher.roomService.findByType("m");
	for (Room roomDb : dbMucRooms) {
		if (roomDb.getRoomId() != null && !roomDb.getRoomId().isEmpty() && roomDb.getRoomId().contains("@")) {
			MultiUserChat room = MultiUserChatManager.getInstanceFor(Launcher.connection)
					.getMultiUserChat(JidCreate.entityBareFrom(roomDb.getRoomId()));
			// 将room加入堆缓存,以便重复利用
			// roomCacheService.put(roomDb.getRoomId(),room);
			// 以“username-真实姓名”为nickname进入群
			// room.join(Resourcepart.from(UserCache.CurrentUserName + "-" +
			// UserCache.CurrentUserRealName));
			MucEnterConfiguration.Builder builder = room.getEnterConfigurationBuilder(
					Resourcepart.from(UserCache.CurrentUserName + "-" + UserCache.CurrentUserRealName));
			// 只获取最后10条历史记录
			// builder.requestMaxStanzasHistory(10);
			// 只获取该房间最后一条消息的时间戳到当前时间戳的离线
			int historySince = MucChatService.getHistoryOffsize(roomDb.getLastChatAt());
			builder.requestHistorySince(historySince);
			// 只获取2018-5-1以来的历史记录
			// builder.requestHistorySince(new Date(2018,5,1));
			MucEnterConfiguration mucEnterConfiguration = builder.build();
			room.join(mucEnterConfiguration);

		}
	}
}
 
Example 18
Source Project: jxmpp   Source File: JidCreate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link EntityFullJid} from a given {@link CharSequence} or {@code null} if the input does not represent a JID.
 *
 * @param cs the input {@link CharSequence}
 * @return a JID or {@code null}
 */
public static EntityFullJid entityFullFromOrNull(CharSequence cs) {
	try {
		return entityFullFrom(cs);
	} catch (XmppStringprepException e) {
		return null;
	}
}
 
Example 19
Source Project: Spark   Source File: UserManager.java    License: Apache License 2.0 5 votes vote down vote up
public static String unescapeJID(CharSequence jid) {
    BareJid bareJid;
    try {
        bareJid = JidCreate.bareFrom(jid);
    } catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
    return unescapeJID(bareJid);
}
 
Example 20
public static void sendPing(String barejid){
	try {
			sendPing(JidCreate.from(barejid + "/Android"));
			sendPing(JidCreate.from(barejid + "/ios"));
			sendPing(JidCreate.from(barejid + "/pc"));
			sendPing(JidCreate.from(barejid + "/Spark"));
		} catch (XmppStringprepException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 21
Source Project: Spark   Source File: UriManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
    * Handles the ?remove URI
    * 
    * @param uri
    *            the decoded uri
    * @throws Exception
    */
   public void handleRemove(URI uri) throws Exception {
// xmpp:[email protected]?remove

   BareJid jid;
   try {
       jid = JidCreate.bareFrom(retrieveJID(uri));
   } catch (XmppStringprepException e) {
       throw new IllegalStateException(e);
   }

   Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
RosterEntry entry = roster.getEntry(jid);
roster.removeEntry(entry);
   }
 
Example 22
Source Project: Spark   Source File: ConferenceUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void addUnclosableChatRoom(String jidString) {
    EntityBareJid jid;
       try {
           jid = JidCreate.entityBareFrom(jidString);
       } catch (XmppStringprepException e) {
           throw new IllegalArgumentException(e);
       }
    synchronized (ConferenceUtils.class) {
        unclosableChatRooms.add(jid);
    }
}
 
Example 23
/**
   * 删除MucRoom,即解散群
   *
   * @param roomId
   * @throws XmppStringprepException 
   */
  private void deleteGroup(String roomId) throws XmppStringprepException
  {
      JOptionPane.showMessageDialog(null, "删除群聊:" + roomId, "删除群聊", JOptionPane.INFORMATION_MESSAGE);
      MultiUserChat muc = 
		MultiUserChatManager.getInstanceFor(Launcher.connection).getMultiUserChat(JidCreate.entityBareFrom(roomId));
      
      //发送删除消息
      List<Jid> memberForKick = new ArrayList<Jid>();

if (room.getMember()!=null && !room.getMember().isEmpty()){
	String[] oldMembers = room.getMember().split(",");
	for (String user : oldMembers){
		memberForKick.add(JidCreate.from(user + "@" + Launcher.DOMAIN) );
	} 
	MucChatService.sendKickMessage(memberForKick,room.getRoomId(),room.getName());
}
    	      
      try {
	muc.destroy("解散群组", JidCreate.entityBareFrom(roomId));
} catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
      
      //自我删除Room数据
      Launcher.roomService.delete(roomId);
      DebugUtil.debug("解散群组:"+roomId);
      //更新左侧房间UI
      RoomsPanel.getContext().notifyDataSetChanged(false);
  }
 
Example 24
Source Project: Spark   Source File: PrivacyPresenceHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Send Unavailable (offline status) to jid .
 * 
 * @param jid
 *            JID to send offline status
 * @deprecated use {#link {@link #sendUnavailableTo(Jid)}} instead. 
 */
@Deprecated
public void sendUnavailableTo(String jidString) throws SmackException.NotConnectedException
{
    Jid jid;
    try {
        jid = JidCreate.from(jidString);
    } catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
    sendUnavailableTo(jid);
}
 
Example 25
Source Project: jitsi   Source File: ProtocolProviderServiceJabberImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if our account is a Gmail or a Google Apps ones.
 *
 * @return true if our account is a Gmail or a Google Apps ones.
 */
public boolean isGmailOrGoogleAppsAccount()
{
    try
    {
        String domain = JidCreate.domainBareFrom(
            getAccountID().getUserID()).toString();
        return isGmailOrGoogleAppsAccount(domain);
    }
    catch (XmppStringprepException e)
    {
        return false;
    }
}
 
Example 26
Source Project: mangosta-android   Source File: RoomManager.java    License: Apache License 2.0 5 votes vote down vote up
private void getSubject(Chat chatRoom) {
    try {
        MultiUserChatLight multiUserChatLight = XMPPSession.getInstance().getMUCLightManager().getMultiUserChatLight(JidCreate.from(chatRoom.getJid()).asEntityBareJidIfPossible());
        MUCLightRoomConfiguration configuration = multiUserChatLight.getConfiguration();
        chatRoom.setSubject(configuration.getSubject());
    } catch (XmppStringprepException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 27
Source Project: jxmpp   Source File: JidCreate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link DomainBareJid} from a given {@link CharSequence} or {@code null} if the input does not represent a JID.
 *
 * @param cs the input {@link CharSequence}
 * @return a JID or {@code null}
 */
public static DomainBareJid domainBareFromOrNull(CharSequence cs) {
	try {
		return domainBareFrom(cs);
	} catch (XmppStringprepException e) {
		return null;
	}
}
 
Example 28
Source Project: mangosta-android   Source File: RoomManager.java    License: Apache License 2.0 5 votes vote down vote up
public void removeFromMUCLight(User user, String chatJID) {
    MultiUserChatLightManager multiUserChatLightManager = XMPPSession.getInstance().getMUCLightManager();
    try {
        MultiUserChatLight mucLight = multiUserChatLightManager.getMultiUserChatLight(JidCreate.from(chatJID).asEntityBareJidIfPossible());

        Jid jid = JidCreate.from(XMPPUtils.fromUserNameToJID(user.getLogin()));

        HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
        affiliations.put(jid, MUCLightAffiliation.none);

        mucLight.changeAffiliations(affiliations);
    } catch (XmppStringprepException | InterruptedException | SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException e) {
        e.printStackTrace();
    }
}
 
Example 29
Source Project: mangosta-android   Source File: RosterManager.java    License: Apache License 2.0 5 votes vote down vote up
public void removeContact(User user)
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException, XmppStringprepException {
    String jidString = XMPPUtils.fromUserNameToJID(user.getLogin());
    removeContact(jidString);
}
 
Example 30
Source Project: Spark   Source File: BuzzRoomDecorator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
       Jid jid;
       try {
           jid = JidCreate.from(((ChatRoomImpl)chatRoom).getParticipantJID());
       } catch (XmppStringprepException exception) {
           throw new IllegalStateException(exception);
       }
       Message message = new Message();
       message.setTo(jid);
       message.addExtension(new BuzzPacket());
       try
       {
           SparkManager.getConnection().sendStanza(message);
       }
       catch ( SmackException.NotConnectedException | InterruptedException e1 )
       {
           Log.warning( "Unable to send stanza to " + jid, e1 );
       }

       chatRoom.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.sent"), ChatManager.NOTIFICATION_COLOR);
       buzzButton.setEnabled(false);

       // Enable the button after 30 seconds to prevent abuse.
       final TimerTask enableTask = new SwingTimerTask() {
           @Override
		public void doRun() {
               buzzButton.setEnabled(true);
           }
       };

       TaskEngine.getInstance().schedule(enableTask, 30000);
   }