public void createNodeToAllowComments(String blogPostId) { String nodeName = PublishCommentExtension.NODE + "/" + blogPostId; PubSubManager pubSubManager = PubSubManager.getInstance(XMPPSession.getInstance().getXMPPConnection()); try { // create node ConfigureForm configureForm = new ConfigureForm(DataForm.Type.submit); configureForm.setPublishModel(PublishModel.open); configureForm.setAccessModel(AccessModel.open); Node node = pubSubManager.createNode(nodeName, configureForm); // subscribe to comments String myJIDString = getUser().toString(); node.subscribe(myJIDString); } catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) { e.printStackTrace(); } }
private void XMPPPublisher(String xmlString, String SCHEMA, String mtype, Node pubNode){ SimplePayload payload = new SimplePayload(mtype,SCHEMA, xmlString); @SuppressWarnings({ "unchecked", "rawtypes" }) PayloadItem payloadItem = new PayloadItem(null, payload); Log.i(appTAG, classTAG+": Message Published to:"+pubNode.getId()); try { ((LeafNode)pubNode).publish(payloadItem); } catch (NotConnectedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private boolean isSubscribed(Node node, String user_jid) { boolean result = false; try { for (Subscription s: node.getSubscriptions()) { Log.i(TAG, "subscription: " + s.getJid()); if (s.getJid().equalsIgnoreCase(user_jid) && s.getState().equals(Subscription.State.subscribed)) { result = true; break; } } } catch (Exception e) {} logs.info("checking if user subscribet to xmpp pubsub node: " + String.valueOf(result)); return result; }
/** * Retrieves a pubsub node from the pubsub service. * @param nodeId The id of the node to retrieve. * @param pubsubService JID of the pubsub service component handling the the node. * @return The pubsub node. * @throws UnknownEntityException No node with the given ID exists. */ protected Node getNode(String nodeId, String pubsubService) throws UnknownEntityException { if (!pubsubManagers.containsKey(pubsubService)) { registerPubsubService(pubsubService); } PubSubManager manager = pubsubManagers.get(pubsubService); try { return manager.getNode(nodeId); } catch(XMPPException e){ throw new UnknownEntityException("The node " + nodeId + " couldn't be retrieved.", e); } }
/** * Publish item * @param xmlString : The XML string generated by the XMLGenerator * @param SCHEMA : The OMF Schema * @param mType : the OMF message type * @param pubNode : the node for the message to be published */ public void PublishItem(OMFMessage omfMessage, String mtype, Node pubNode) { //Node pubNode is for the aSmack only currently, i dont know whether AMQP will work that way. if (connectionType.equalsIgnoreCase("XMPP")) { XMPPPublisher(omfMessage.toXML(), SCHEMA, mtype, pubNode); } else if (connectionType.equalsIgnoreCase("AMQP")) { //TODO AMQP publisher } }
/** * XMPPClass Constructor * @param username : XMPP server username * @param password : XMPP server password * @param topicName : XMPP main topic name (RC topic name) * @param Server : XMPP Server name * @param appContext : The application context */ public XMPPCommunicator(String username, String password, String topicName, String Server, Context appContext){ NodeListeners = new HashMap<String, ItemEventCoordinator>(); Nodes = new HashMap<String, Node>(); Username = username; Password = password; Topic = topicName; ctx = appContext; flag = true; serverName = Server; msgPub = new MessagePublisher("XMPP"); //Init aSmack SmackAndroid.init(ctx); //Set the reply timeout of asmack in ms to avoid server not responding fast enough if busy //SmackConfiguration.setPacketReplyTimeout(10000); // XMPP CONNECTION connConfig = new ConnectionConfiguration(serverName,PORT); //connConfig.setSASLAuthenticationEnabled(true); connConfig.setCompressionEnabled(true); connConfig.setSecurityMode(SecurityMode.disabled); /* //Connection configuration - generates a warning on startup because the truststore path is set to null if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { connConfig.setKeystoreType("AndroidCAStore"); //connConfig.setKeystorePassword(null); connConfig.setKeystorePath(null); //connConfig.set } else { connConfig.setKeystoreType("BKS"); String path = System.getProperty("javax.net.ssl.trustStore"); if (path == null) path = System.getProperty("java.home") + File.separatorChar + "etc" + File.separatorChar + "security" + File.separatorChar + "cacerts.bks"; connConfig.setKeystorePath(path); } */ xmpp = new XMPPTCPConnection(connConfig); }