org.jivesoftware.smack.XMPPException.XMPPErrorException Java Examples

The following examples show how to use org.jivesoftware.smack.XMPPException.XMPPErrorException. 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: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static MucRoomInfo mucGetInfo(String jid) {
	// MultiUserChatManager manager =
	// MultiUserChatManager.getInstanceFor(Launcher.connection);
	// RoomInfo info;
	try {
		// info = manager.getRoomInfo(JidCreate.entityBareFrom(jid));
		MucRoomInfo info = new MucRoomInfo(getRoomInfo(JidCreate.entityBareFrom(jid)));
		DebugUtil.debug("Room jid:" + info.getRoom().toString());
		DebugUtil.debug("Room of occupants:" + info.getOccupantsCount());
		DebugUtil.debug("Room getName:" + info.getName());
		DebugUtil.debug("Room getOwnerJid:" + info.getOwnerJid());
		DebugUtil.debug("Room getAdminJid:" + info.getAdminJid());

		return info;

	} catch (NoResponseException | XMPPErrorException | NotConnectedException | XmppStringprepException
			| InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example #2
Source File: RosterGroup.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a roster entry from this group. If the entry does not belong to any other group
 * then it will be considered as unfiled, therefore it will be added to the list of unfiled
 * entries.
 * Note that this is a synchronous call -- Smack must wait for the server
 * to receive the updated roster.
 *
 * @param entry a roster entry.
 * @throws XMPPErrorException if an error occurred while trying to remove the entry from the group.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void removeEntry(RosterEntry entry) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // Only remove the entry if it's in the entry list.
    // Remove the entry locally, if we wait for RosterPacketListenerProcess>>Packet(Packet)
    // to take place the entry will exist in the group until a packet is received from the
    // server.
    synchronized (entries) {
        if (entries.contains(entry)) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.set);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.removeGroupName(this.getName());
            packet.addRosterItem(item);
            // Wait up to a certain number of seconds for a reply from the server.
            connection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
        }
    }
}
 
Example #3
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void join(Message message) {
	// TODO 收到加入群的离线消息,被邀请进入群
	MucInvitation mi = message.getExtension("x", "xytalk:muc:invitation");
	String jid = mi.getRoomid();
	String roomname = mi.getRoomName();
	MultiUserChat muc;
	try {
		muc = MultiUserChatManager.getInstanceFor(Launcher.connection)
				.getMultiUserChat(JidCreate.entityBareFrom(jid));
		muc.join(Resourcepart.from(UserCache.CurrentUserName + "-" + UserCache.CurrentUserRealName));
		// 更新左侧panel,将群组UI新建出来
		createNewRoomByInvitation(jid, roomname);
	} catch (NotAMucServiceException | NoResponseException | XMPPErrorException | NotConnectedException
			| XmppStringprepException | InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example #4
Source File: PubSubManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Check if it is possible to create PubSub nodes on this service. It could be possible that the
 * PubSub service allows only certain XMPP entities (clients) to create nodes and publish items
 * to them.
 * <p>
 * Note that since XEP-60 does not provide an API to determine if an XMPP entity is allowed to
 * create nodes, therefore this method creates an instant node calling {@link #createNode()} to
 * determine if it is possible to create nodes.
 * </p>
 *
 * @return <code>true</code> if it is possible to create nodes, <code>false</code> otherwise.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws XMPPErrorException if there was an XMPP error returned.
 */
public boolean canCreateNodesAndPublishItems() throws NoResponseException, NotConnectedException, InterruptedException, XMPPErrorException {
    LeafNode leafNode = null;
    try {
        leafNode = createNode();
    }
    catch (XMPPErrorException e) {
        if (e.getStanzaError().getCondition() == StanzaError.Condition.forbidden) {
            return false;
        }
        throw e;
    } finally {
        if (leafNode != null) {
            deleteNode(leafNode.getId());
        }
    }
    return true;
}
 
Example #5
Source File: BookmarkManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a new url or updates an already existing url in the bookmarks.
 *
 * @param URL the url of the bookmark
 * @param name the name of the bookmark
 * @param isRSS whether or not the url is an rss feed
 * @throws XMPPErrorException thrown when there is an error retriving or saving bookmarks from or to
 * the server
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void addBookmarkedURL(String URL, String name, boolean isRSS) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    retrieveBookmarks();
    BookmarkedURL bookmark = new BookmarkedURL(URL, name, isRSS);
    List<BookmarkedURL> urls = bookmarks.getBookmarkedURLS();
    if (urls.contains(bookmark)) {
        BookmarkedURL oldURL = urls.get(urls.indexOf(bookmark));
        if (oldURL.isShared()) {
            throw new IllegalArgumentException("Cannot modify shared bookmarks");
        }
        oldURL.setName(name);
        oldURL.setRss(isRSS);
    }
    else {
        bookmarks.addBookmarkedURL(bookmark);
    }
    privateDataManager.setPrivateData(bookmarks);
}
 
Example #6
Source File: MultiUserChat.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of <code>Occupant</code> that have the specified room role.
 *
 * @param role the role of the occupant in the room.
 * @return a list of <code>Occupant</code> that have the specified room role.
 * @throws XMPPErrorException if an error occurred while performing the request to the server or you
 *         don't have enough privileges to get this information.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
private List<Occupant> getOccupants(MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.get);
    // Set the specified role. This may request the list of moderators/participants.
    MUCItem item = new MUCItem(role);
    iq.addItem(item);

    MUCAdmin answer = (MUCAdmin) connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
    // Get the list of participants from the server's answer
    List<Occupant> participants = new ArrayList<Occupant>();
    for (MUCItem mucadminItem : answer.getItems()) {
        participants.add(new Occupant(mucadminItem));
    }
    return participants;
}
 
Example #7
Source File: BookmarkManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a conference from the bookmarks.
 *
 * @param jid the jid of the conference to be removed.
 * @throws XMPPErrorException thrown when there is a problem with the connection attempting to
 * retrieve the bookmarks or persist the bookmarks.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws IllegalArgumentException thrown when the conference being removed is a shared
 * conference
 */
public void removeBookmarkedConference(EntityBareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    retrieveBookmarks();
    Iterator<BookmarkedConference> it = bookmarks.getBookmarkedConferences().iterator();
    while (it.hasNext()) {
        BookmarkedConference conference = it.next();
        if (conference.getJid().equals(jid)) {
            if (conference.isShared()) {
                throw new IllegalArgumentException("Conference is shared and can't be removed");
            }
            it.remove();
            privateDataManager.setPrivateData(bookmarks);
            return;
        }
    }
}
 
Example #8
Source File: OutgoingFileTransfer.java    From Smack with Apache License 2.0 6 votes vote down vote up
private void handleXMPPException(XMPPErrorException e) {
    StanzaError error = e.getStanzaError();
    if (error != null) {
        switch (error.getCondition()) {
        case forbidden:
            setStatus(Status.refused);
            return;
        case bad_request:
            setStatus(Status.error);
            setError(Error.not_acceptable);
            break;
        default:
            setStatus(FileTransfer.Status.error);
        }
    }

    setException(e);
}
 
Example #9
Source File: HttpFileUploadIntegrationTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
public HttpFileUploadIntegrationTest(SmackIntegrationTestEnvironment environment) throws XMPPErrorException,
                NotConnectedException, NoResponseException, InterruptedException, TestNotPossibleException {
    super(environment);
    hfumOne = HttpFileUploadManager.getInstanceFor(conOne);
    if (!hfumOne.discoverUploadService()) {
        throw new TestNotPossibleException(
                        "HttpFileUploadManager was unable to discover a HTTP File Upload service");
    }
    UploadService uploadService = hfumOne.getDefaultUploadService();
    if (!uploadService.acceptsFileOfSize(FILE_SIZE)) {
        throw new TestNotPossibleException("The upload service at " + uploadService.getAddress()
                        + " does not accept files of size " + FILE_SIZE
                        + ". It only accepts files with  a maximum size of " + uploadService.getMaxFileSize());
    }
    if (environment.configuration.sslContextFactory != null) {
        hfumOne.setTlsContext(environment.configuration.sslContextFactory.createSslContext());
    }
}
 
Example #10
Source File: IoTDiscoveryIntegrationTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static ThingState registerThing(IoTDiscoveryManager iotDiscoveryManager, Thing thing)
                throws XMPPErrorException, InterruptedException, SmackException.SmackMessageException,
                NotConnectedException, NoResponseException {
    int attempts = 0;
    while (true) {
        try {
            return iotDiscoveryManager.registerThing(thing);
        }
        catch (IoTClaimedException e) {
            iotDiscoveryManager.unregister();
        }
        if (attempts++ > 3) {
            throw new SmackException.SmackMessageException("Could no register thing");
        }
    }
}
 
Example #11
Source File: PubSubIntegrationTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that an event notification (publication without item) can be published to
 * a node that is both 'notification-only' as well as 'transient'.
 *
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
@SmackIntegrationTest
public void transientNotificationOnlyNodeWithoutItemTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final String nodename = "sinttest-transient-notificationonly-withoutitem-nodename-" + testRunId;
    ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration();
    FillableConfigureForm config = defaultConfiguration.getFillableForm();
    // Configure the node as "Notification-Only Node".
    config.setDeliverPayloads(false);
    // Configure the node as "transient" (set persistent_items to 'false')
    config.setPersistentItems(false);
    Node node = pubSubManagerOne.createNode(nodename, config);
    try {
        LeafNode leafNode = (LeafNode) node;
        leafNode.publish();
    }
    finally {
        pubSubManagerOne.deleteNode(nodename);
    }
}
 
Example #12
Source File: InBandBytestreamManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Establishes an In-Band Bytestream with the given user using the given session ID and returns
 * the session to send/receive data to/from the user.
 *
 * @param targetJID the JID of the user an In-Band Bytestream should be established
 * @param sessionID the session ID for the In-Band Bytestream request
 * @return the session to send/receive data to/from the user
 * @throws XMPPErrorException if the user doesn't support or accept in-band bytestreams, or if the
 *         user prefers smaller block sizes
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
@Override
public InBandBytestreamSession establishSession(Jid targetJID, String sessionID)
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Open byteStreamRequest = new Open(sessionID, this.defaultBlockSize, this.stanza);
    byteStreamRequest.setTo(targetJID);

    final XMPPConnection connection = connection();

    // sending packet will throw exception on timeout or error reply
    connection.createStanzaCollectorAndSend(byteStreamRequest).nextResultOrThrow();

    InBandBytestreamSession inBandBytestreamSession = new InBandBytestreamSession(
                    connection, byteStreamRequest, targetJID);
    this.sessions.put(sessionID, inBandBytestreamSession);

    return inBandBytestreamSession;
}
 
Example #13
Source File: AccountManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
public boolean isSupported()
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();

    ExtensionElement extensionElement = connection.getFeature(Registration.Feature.ELEMENT,
                    Registration.Feature.NAMESPACE);
    if (extensionElement != null) {
        return true;
    }

    // Fallback to disco#info only if this connection is authenticated, as otherwise we won't have an full JID and
    // won't be able to do IQs.
    if (connection.isAuthenticated()) {
        return ServiceDiscoveryManager.getInstanceFor(connection).serverSupportsFeature(Registration.NAMESPACE);
    }

    return false;
}
 
Example #14
Source File: BookmarkManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Adds or updates a conference in the bookmarks.
 *
 * @param name the name of the conference
 * @param jid the jid of the conference
 * @param isAutoJoin whether or not to join this conference automatically on login
 * @param nickname the nickname to use for the user when joining the conference
 * @param password the password to use for the user when joining the conference
 * @throws XMPPErrorException thrown when there is an issue retrieving the current bookmarks from
 * the server.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void addBookmarkedConference(String name, EntityBareJid jid, boolean isAutoJoin,
        Resourcepart nickname, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    retrieveBookmarks();
    BookmarkedConference bookmark
            = new BookmarkedConference(name, jid, isAutoJoin, nickname, password);
    List<BookmarkedConference> conferences = bookmarks.getBookmarkedConferences();
    if (conferences.contains(bookmark)) {
        BookmarkedConference oldConference = conferences.get(conferences.indexOf(bookmark));
        if (oldConference.isShared()) {
            throw new IllegalArgumentException("Cannot modify shared bookmark");
        }
        oldConference.setAutoJoin(isAutoJoin);
        oldConference.setName(name);
        oldConference.setNickname(nickname);
        oldConference.setPassword(password);
    }
    else {
        bookmarks.addBookmarkedConference(bookmark);
    }
    privateDataManager.setPrivateData(bookmarks);
}
 
Example #15
Source File: IoTDiscoveryManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public boolean isRegistry(BareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Objects.requireNonNull(jid, "JID argument must not be null");
    // At some point 'usedRegistries' will also contain the registry returned by findRegistry(), but since this is
    // not the case from the beginning, we perform findRegistry().equals(jid) too.
    Jid registry = findRegistry();
    if (jid.equals(registry)) {
        return true;
    }
    if (usedRegistries.contains(jid)) {
        return true;
    }
    return false;
}
 
Example #16
Source File: PrivacyListManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Client declines the use of active lists.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void declineActiveList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // The request of the list is an privacy message with an empty list
    Privacy request = new Privacy();
    request.setDeclineActiveList(true);

    // Send the package to the server
    setRequest(request);
}
 
Example #17
Source File: ServiceAdministrationManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public void addUser(final EntityBareJid userJid, final String password)
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    RemoteCommand command = addUser();
    command.execute();

    FillableForm answerForm = new FillableForm(command.getForm());

    answerForm.setAnswer("accountjid", userJid);
    answerForm.setAnswer("password", password);
    answerForm.setAnswer("password-verify", password);

    command.execute(answerForm);
    assert command.isCompleted();
}
 
Example #18
Source File: LeafNode.java    From Smack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends Item> List<T> getItems(PubSub request,
                List<ExtensionElement> returnedExtensions) throws NoResponseException,
                XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub result = pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
    ItemsExtension itemsElem = result.getExtension(PubSubElementType.ITEMS);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(result.getExtensions());
    }
    return (List<T>) itemsElem.getItems();
}
 
Example #19
Source File: LeafNode.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Delete the items with the specified id's from the node.
 *
 * @param itemIds The list of id's of items to delete
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    List<Item> items = new ArrayList<>(itemIds.size());

    for (String id : itemIds) {
         items.add(new Item(id));
    }
    PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
    pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
 
Example #20
Source File: MultiUserChatManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the provided domain bare JID provides a MUC service.
 *
 * @param domainBareJid the domain bare JID to check.
 * @return <code>true</code> if the provided JID provides a MUC service, <code>false</code> otherwise.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @see <a href="http://xmpp.org/extensions/xep-0045.html#disco-service-features">XEP-45 § 6.2 Discovering the Features Supported by a MUC Service</a>
 * @since 4.2
 */
public boolean providesMucService(DomainBareJid domainBareJid) throws NoResponseException,
                XMPPErrorException, NotConnectedException, InterruptedException {
    boolean contains = KNOWN_MUC_SERVICES.containsKey(domainBareJid);
    if (!contains) {
        if (serviceDiscoveryManager.supportsFeature(domainBareJid,
                    MUCInitialPresence.NAMESPACE)) {
            KNOWN_MUC_SERVICES.put(domainBareJid, null);
            return true;
        }
    }

    return contains;
}
 
Example #21
Source File: MultiUserChatLightManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private void sendBlockUsers(DomainBareJid mucLightService, HashMap<Jid, Boolean> users)
        throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
    MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
    mucLightBlockingIQ.setType(Type.set);
    mucLightBlockingIQ.setTo(mucLightService);
    connection().createStanzaCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
 
Example #22
Source File: PrivacyListManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Answer the privacy list items under listName with the allowed and blocked permissions.
 *
 * @param listName the name of the list to get the allowed and blocked permissions.
 * @return a list of privacy items under the list listName.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
private List<PrivacyItem> getPrivacyListItems(String listName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException  {
    assert StringUtils.isNotEmpty(listName);
    // The request of the list is an privacy message with an empty list
    Privacy request = new Privacy();
    request.setPrivacyList(listName, new ArrayList<PrivacyItem>());

    // Send the package to the server and get the answer
    Privacy privacyAnswer = getRequest(request);

    return privacyAnswer.getPrivacyList(listName);
}
 
Example #23
Source File: PubSubManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the requested node, if it exists.  It will throw an
 * exception if it does not.
 *
 * @param id - The unique id of the node
 *
 * @return the node
 * @throws XMPPErrorException The node does not exist
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NotAPubSubNodeException if a involved node is not a PubSub node.
 */
public Node getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAPubSubNodeException {
    StringUtils.requireNotNullNorEmpty(id, "The node ID can not be null or the empty string");
    Node node = nodeMap.get(id);

    if (node == null) {
        XMPPConnection connection = connection();
        DiscoverInfo info = DiscoverInfo.builder(connection)
                .to(pubSubService)
                .setNode(id)
                .build();

        DiscoverInfo infoReply = connection.createStanzaCollectorAndSend(info).nextResultOrThrow();

        if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) {
            node = new LeafNode(this, id);
        }
        else if (infoReply.hasIdentity(PubSub.ELEMENT, "collection")) {
            node = new CollectionNode(this, id);
        }
        else {
            throw new PubSubException.NotAPubSubNodeException(id, infoReply);
        }
        nodeMap.put(id, node);
    }
    return node;
}
 
Example #24
Source File: PrivacyListManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Answer the active privacy list. Returns <code>null</code> if there is no active list.
 *
 * @return the privacy list of the active list.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public PrivacyList getActiveList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException  {
    Privacy privacyAnswer = this.getPrivacyWithListNames();
    String listName = privacyAnswer.getActiveName();
    if (StringUtils.isNullOrEmpty(listName)) {
        return null;
    }
    boolean isDefaultAndActive = listName != null && listName.equals(privacyAnswer.getDefaultName());
    return new PrivacyList(true, isDefaultAndActive, listName, getPrivacyListItems(listName));
}
 
Example #25
Source File: IoTProvisioningManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public Jid getConfiguredProvisioningServer()
                throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (configuredProvisioningServer == null) {
        configuredProvisioningServer = findProvisioningServerComponent();
    }
    return configuredProvisioningServer;
}
 
Example #26
Source File: PubSubIntegrationTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that an error is returned when a publish request to a node that is both
 * 'notification-only' as well as 'transient' contains an item element.
 *
 * <p>From XEP-0060 § 7.1.3.6:</p>
 * <blockquote>
 * If the event type is notification + transient and the publisher provides an item,
 * the service MUST bounce the publication request with a &lt;bad-request/&gt; error
 * and a pubsub-specific error condition of &lt;item-forbidden/&gt;.
 * </blockquote>
 *
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @see <a href="https://xmpp.org/extensions/xep-0060.html#publisher-publish-error-badrequest">
 *     7.1.3.6 Request Does Not Match Configuration</a>
 */
@SmackIntegrationTest
public void transientNotificationOnlyNodeWithItemTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final String nodename = "sinttest-transient-notificationonly-withitem-nodename-" + testRunId;
    final String itemId = "sinttest-transient-notificationonly-withitem-itemid-" + testRunId;

    ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration();
    FillableConfigureForm config = defaultConfiguration.getFillableForm();
    // Configure the node as "Notification-Only Node".
    config.setDeliverPayloads(false);
    // Configure the node as "transient" (set persistent_items to 'false')
    config.setPersistentItems(false);
    Node node = pubSubManagerOne.createNode(nodename, config);

    // Add a dummy payload. If there is no payload, but just an item ID, then ejabberd will *not* return an error,
    // which I believe to be non-compliant behavior (although, granted, the XEP is not very clear about this). A user
    // which sends an empty item with ID to an node that is configured to be notification-only and transient probably
    // does something wrong, as the item's ID will never appear anywhere. Hence it would be nice if the user would be
    // made aware of this issue by returning an error. Sadly ejabberd does not do so.
    // See also https://github.com/processone/ejabberd/issues/2864#issuecomment-500741915
    final StandardExtensionElement dummyPayload = StandardExtensionElement.builder("dummy-payload",
                    SmackConfiguration.SMACK_URL_STRING).setText(testRunId).build();

    try {
        XMPPErrorException e = assertThrows(XMPPErrorException.class, () -> {
            LeafNode leafNode = (LeafNode) node;

            Item item = new PayloadItem<>(itemId, dummyPayload);
            leafNode.publish(item);
        });
        assertEquals(StanzaError.Type.MODIFY, e.getStanzaError().getType());
        assertNotNull(e.getStanzaError().getExtension("item-forbidden", "http://jabber.org/protocol/pubsub#errors"));
    }
    finally {
        pubSubManagerOne.deleteNode(nodename);
    }
}
 
Example #27
Source File: BlockingCommandManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the block list.
 *
 * @return the blocking list
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public List<Jid> getBlockList()
        throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {

    if (blockListCached == null) {
        BlockListIQ blockListIQ = new BlockListIQ();
        BlockListIQ blockListIQResult = connection().createStanzaCollectorAndSend(blockListIQ).nextResultOrThrow();
        blockListCached = blockListIQResult.getBlockedJidsCopy();
    }

    return Collections.unmodifiableList(blockListCached);
}
 
Example #28
Source File: RosterGroup.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the name of the group. Changing the group's name is like moving all the group entries
 * of the group to a new group specified by the new name. Since this group won't have entries
 * it will be removed from the roster. This means that all the references to this object will
 * be invalid and will need to be updated to the new group specified by the new name.
 *
 * @param name the name of the group.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void setName(String name) throws NotConnectedException, NoResponseException, XMPPErrorException, InterruptedException {
    synchronized (entries) {
        for (RosterEntry entry : entries) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.set);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.removeGroupName(this.name);
            item.addGroupName(name);
            packet.addRosterItem(item);
            connection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
        }
    }
}
 
Example #29
Source File: AgentSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
public boolean hasMonitorPrivileges(XMPPConnection con) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException  {
    MonitorPacket request = new MonitorPacket();
    request.setType(IQ.Type.get);
    request.setTo(workgroupJID);

    MonitorPacket response = connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
    return response.isMonitor();
}
 
Example #30
Source File: IoTControlManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private IoTControlManager(XMPPConnection connection) {
    super(connection);

    connection.registerIQRequestHandler(new IoTIqRequestHandler(IoTSetRequest.ELEMENT, IoTSetRequest.NAMESPACE, IQ.Type.set, Mode.async) {
        @Override
        public IQ handleIoTIqRequest(IQ iqRequest) {
            // TODO Lookup thing and provide data.
            IoTSetRequest iotSetRequest = (IoTSetRequest) iqRequest;

            // TODO Add support for multiple things(/NodeInfos).
            final Thing thing = things.get(NodeInfo.EMPTY);
            if (thing == null) {
                // TODO return error if not at least one thing registered.
                return null;
            }

            ThingControlRequest controlRequest = thing.getControlRequestHandler();
            if (controlRequest == null) {
                // TODO return error if no request handler for things.
                return null;
            }

            try {
                controlRequest.processRequest(iotSetRequest.getFrom(), iotSetRequest.getSetData());
            } catch (XMPPErrorException e) {
                return IQ.createErrorResponse(iotSetRequest, e.getStanzaError());
            }

            return new IoTSetResponse(iotSetRequest);
        }
    });
}