Esempio n. 1
0
 /**
  * Get the options for configuring the specified subscription.
  *
  * @param jid JID the subscription is registered under
  * @param subscriptionId The subscription id
  * @return The subscription option form
  * @throws XMPPErrorException
  * @throws NoResponseException
  * @throws NotConnectedException
  */
 public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId)
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   PubSub packet =
       (PubSub) sendPubsubPacket(Type.get, new OptionsExtension(jid, getId(), subscriptionId));
   FormNode ext = (FormNode) packet.getExtension(PubSubElementType.OPTIONS);
   return new SubscribeForm(ext.getForm());
 }
Esempio n. 2
0
 /**
  * Gets the affiliations on the root node.
  *
  * @return List of affiliations
  * @throws XMPPException
  */
 public List<Affiliation> getAffiliations() throws XMPPException {
   PubSub reply =
       (PubSub) sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.AFFILIATIONS));
   AffiliationsExtension listElem =
       (AffiliationsExtension) reply.getExtension(PubSubElementType.AFFILIATIONS);
   return listElem.getAffiliations();
 }
Esempio n. 3
0
 /**
  * The user subscribes to the node using the supplied jid and subscription options. The bare jid
  * portion of this one must match the jid for the connection.
  *
  * <p>Please note that the {@link Subscription.State} should be checked on return since more
  * actions may be required by the caller. {@link Subscription.State#pending} - The owner must
  * approve the subscription request before messages will be received. {@link
  * Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, the
  * caller must configure the subscription before messages will be received. If it is false the
  * caller can configure it but is not required to do so.
  *
  * @param jid The jid to subscribe as.
  * @return The subscription
  * @throws XMPPErrorException
  * @throws NoResponseException
  * @throws NotConnectedException
  */
 public Subscription subscribe(String jid, SubscribeForm subForm)
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
   request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm));
   PubSub reply = (PubSub) PubSubManager.sendPubsubPacket(con, jid, Type.set, request);
   return (Subscription) reply.getExtension(PubSubElementType.SUBSCRIPTION);
 }
Esempio n. 4
0
 /**
  * Get the subscriptions currently associated with this node.
  *
  * @return List of {@link Subscription}
  * @throws XMPPErrorException
  * @throws NoResponseException
  * @throws NotConnectedException
  */
 public List<Subscription> getSubscriptions()
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   PubSub reply =
       (PubSub)
           sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()));
   SubscriptionsExtension subElem =
       (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS);
   return subElem.getSubscriptions();
 }
Esempio n. 5
0
  /**
   * Creates an instant node, if supported.
   *
   * @return The node that was created
   * @exception XMPPException
   */
  public LeafNode createNode() throws XMPPException {
    PubSub reply = (PubSub) sendPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.CREATE));
    NodeExtension elem =
        (NodeExtension) reply.getExtension("create", PubSubNamespace.BASIC.getXmlns());

    LeafNode newNode = new LeafNode(con, elem.getNode());
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);

    return newNode;
  }
Esempio n. 6
0
  static PubSub createPubsubPacket(String to, Type type, PacketExtension ext, PubSubNamespace ns) {
    PubSub request = new PubSub();
    request.setTo(to);
    request.setType(type);

    if (ns != null) {
      request.setPubSubNamespace(ns);
    }
    request.addExtension(ext);

    return request;
  }
Esempio n. 7
0
  /**
   * Creates a node with specified configuration.
   *
   * <p>Note: This is the only way to create a collection node.
   *
   * @param name The name of the node, which must be unique within the pubsub service
   * @param config The configuration for the node
   * @return The node that was created
   * @exception XMPPException
   */
  public Node createNode(String name, Form config) throws XMPPException {
    PubSub request =
        createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));
    boolean isLeafNode = true;

    if (config != null) {
      request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
      FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());

      if (nodeTypeField != null)
        isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString());
    }

    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(con, to, Type.SET, request);
    Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);

    return newNode;
  }
Esempio n. 8
0
  @Test
  public void getConfigFormWithInsufficientPriviliges()
      throws XMPPException, SmackException, IOException, InterruptedException {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);

    Node node = mgr.getNode("princely_musings");

    PubSub errorIq = new PubSub();
    XMPPError error = new XMPPError(Condition.forbidden);
    errorIq.setError(error);
    con.addIQReply(errorIq);

    try {
      node.getNodeConfiguration();
    } catch (XMPPErrorException e) {
      Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
    }
  }
Esempio n. 9
0
 /**
  * The user subscribes to the node using the supplied jid. The bare jid portion of this one must
  * match the jid for the connection.
  *
  * <p>Please note that the {@link Subscription.State} should be checked on return since more
  * actions may be required by the caller. {@link Subscription.State#pending} - The owner must
  * approve the subscription request before messages will be received. {@link
  * Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, the
  * caller must configure the subscription before messages will be received. If it is false the
  * caller can configure it but is not required to do so.
  *
  * @param jid The jid to subscribe as.
  * @return The subscription
  * @throws XMPPErrorException
  * @throws NoResponseException
  * @throws NotConnectedException
  */
 public Subscription subscribe(String jid)
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   PubSub reply = (PubSub) sendPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
   return (Subscription) reply.getExtension(PubSubElementType.SUBSCRIPTION);
 }