Example #1
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);
 }
Example #2
0
 public void deleteNode(String nodeId) throws SoxLibException {
   try {
     mPubSubManager.deleteNode(nodeId);
   } catch (XMPPException e) {
     throw new SoxLibException(e.getLocalizedMessage());
   }
 }
Example #3
0
  public PubSubNodeInfo getNodeDetails(String nodeId) throws SoxLibException {
    PubSubNodeInfo result = new PubSubNodeInfo();
    DiscoverInfo di = null;
    try {
      Node node = mPubSubManager.getNode(nodeId);
      if (!(node instanceof LeafNode)) {
        throw new SoxLibException("Expecting leaf node, but got something else:" + nodeId);
      }
      LeafNode leaf = (LeafNode) node;
      di = leaf.discoverInfo();
    } catch (XMPPException e) {
      throw new SoxLibException("Problem accessing node list:" + nodeId);
    }

    // Expect one and only one identity.
    Iterator<DiscoverInfo.Identity> iter = di.getIdentities();
    if (iter.hasNext()) {
      DiscoverInfo.Identity info = iter.next();
      // logger.log(Level.FINER, "type:" + info.getType());
      // logger.log(Level.FINER, "cat:" + info.getCategory());
      result.nodeType = info.getType();
      // Assert iter.hasNext == false
    }

    // If no form data, returns null for this field.
    result.nodeForm = (DataForm) di.getExtension("jabber:x:data");

    return result;
  }
Example #4
0
  @Test(expected = SmackException.class)
  public void getConfigFormWithTimeout() throws XMPPException, SmackException {
    ThreadedDummyConnection con = new ThreadedDummyConnection();
    PubSubManager mgr = new PubSubManager(con);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);

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

    SmackConfiguration.setDefaultPacketReplyTimeout(100);
    con.setTimeout();

    node.getNodeConfiguration();
  }
Example #5
0
 public void createEventNode(String nodeId) throws SoxLibException {
   ConfigureForm config = configureForEventNode("sox");
   try {
     mPubSubManager.createNode(nodeId, config);
   } catch (XMPPException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #6
0
 public Node getNode(String nodeName) {
   try {
     return mPubSubManager.getNode(nodeName);
   } catch (XMPPException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return null;
 }
Example #7
0
 public List<Subscription> getSubscribeNodeList() {
   try {
     List<Subscription> subList = mPubSubManager.getSubscriptions();
     return subList;
   } catch (XMPPException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return null;
 }
Example #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());
    }
  }
Example #9
0
  public void publishToNode(String nodeId, String name, String ns, String xml)
      throws SoxLibException {
    // name and ns don't seem to do anything yet.
    SimplePayload payload = new SimplePayload(name, ns, xml);

    PayloadItem<SimplePayload> pi = new PayloadItem<SimplePayload>(null, payload);
    try {
      Node node = mPubSubManager.getNode(nodeId);

      LeafNode lf = (LeafNode) node;
      lf.publish(pi);
    } catch (XMPPException e) {
      e.printStackTrace();
    }
  }
Example #10
0
  public String getLastItemXml(String nodeId) {
    try {
      LeafNode node = (LeafNode) mPubSubManager.getNode(nodeId);

      // getItems() can return subclasses of Item, but we don't
      // use that, so keep it simple.
      List<Item> items = node.getItems(1);
      String s = items.get(0).toXML();

      return s;
    } catch (XMPPException e) {
      throw new SoxLibException("problem accessing:" + nodeId + ":" + e.getLocalizedMessage());
    } catch (IndexOutOfBoundsException e) {
      throw new SoxLibException("nodeId item was empty:" + nodeId);
    }
  }
Example #11
0
  public void unsubscribeToNode(String nodeId, String subid) throws SoxLibException {
    Node node = null;
    try {
      node = mPubSubManager.getNode(nodeId);
    } catch (XMPPException e) {
      throw new SoxLibException(e.getLocalizedMessage());
    }

    LeafNode lf = (LeafNode) node;

    try {
      lf.unsubscribe(this.getBareJid(), subid);
    } catch (XMPPException e) {
      throw new SoxLibException(e.getLocalizedMessage());
    }
  }
Example #12
0
  public void subscribeToNode(String nodeId) {
    Node node = null;
    try {
      node = mPubSubManager.getNode(nodeId);
    } catch (XMPPException e) {
      e.printStackTrace();
    }

    LeafNode lf = (LeafNode) node;

    try {
      Subscription sub = lf.subscribe(this.getBareJid());
    } catch (XMPPException e) {
      e.printStackTrace();
    }
  }
Example #13
0
  public List<String> getTopLevelNodes() {
    List<String> nodeList = new ArrayList<String>();
    DiscoverItems items = null;
    try {
      items = mPubSubManager.discoverNodes(null);

    } catch (XMPPException e) {
      return nodeList;
    }

    Iterator<DiscoverItems.Item> i = items.getItems();
    while (i.hasNext()) {
      DiscoverItems.Item item = i.next();
      nodeList.add(item.getNode());
    }

    return nodeList;
  }
Example #14
0
  public List<String> getNodeItemList(String nodeId) {
    List<String> result = new ArrayList<String>();
    DiscoverItems ni = null;
    try {
      Node node = mPubSubManager.getNode(nodeId);
      LeafNode leaf = (LeafNode) node;
      ni = leaf.discoverItems();
    } catch (XMPPException e) {
      return result;
    }

    Iterator<DiscoverItems.Item> iter = ni.getItems();
    while (iter.hasNext()) {
      DiscoverItems.Item item = iter.next();
      result.add(item.getName());
    }

    return result;
  }
Example #15
0
 protected Packet sendPubsubPacket(Type type, NodeExtension ext, PubSubNamespace ns)
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   return PubSubManager.sendPubsubPacket(con, to, type, ext, ns);
 }
Example #16
0
 protected PubSub createPubsubPacket(Type type, PacketExtension ext, PubSubNamespace ns) {
   return PubSubManager.createPubsubPacket(to, type, ext, ns);
 }