http://community.igniterealtime.org/message/191463#191463
http://community.igniterealtime.org/message/196048#196048
http://www.digipedia.pl/usenet/thread/10917/2269/
http://www.apache.org/dyn/closer.cgi/mina/vysper/0.7/vysper-0.7-src.zip
Pubsub - hello
world example
Re: Pubsub -
hello world example
This is a simple example using the pubsub extensions I wrote here
Create and publish
ConfigureForm
form = new ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
PubSubManager
manager = new PubSubManager(connection, "pubsub.my.openfire.server");
Node myNode =
manager.createNode("TestNode", form);
SimplePayload
payload = new SimplePayload("book","pubsub:test:book",
"<book xmlns='pubsub:test:book'><title>Lord of the
Rings</title></book>");
Item<SimplePayload> item = new Item<SimplePayload>(itemId,
payload);
// Required to
recieve the events being published
myNode.addItemEventListener(myEventHandler);
// Publish
item
myNode.publish(item);
Get node and listen (different user)
Node eventNode
= manager.getNode("TestNode");
eventNode.addItemEventListener(myEventHandler);
eventNode.subscribe("myJID");
I have included the work I have done for adding pubsub support to
Smack. The three jars contain the binaries, source and javadoc. I
will try to create some user documentation as soon as I get the chance.
It was suggested to upload it as an eclipse patch, but this is entirely new
code with no alterations to the existing Smack library, so I just uploaded the
source code as is.
This code has been tested against a customized version of OpenFire in
which I fixed a couple of existing bugs, I will be uploading those as real
patches as soon as possible. It was designed around version 1.12 of the
spec, and the current OpenFire implementation supports 1.8 (I believe).
Some of the basic functionality should still work with that spec, I will try to
document the issues when I get the chance.
For anyone that wants to give it a try, start at the PubSubManager
class, it should be pretty simple from there (famous last words).
I have created a new thread instead of posting to the existing one (http://www.igniterealtime.org/community/message/191247#191247)
since I wasn't sure if the patch tag would get picked up by the powers that be.
Updated to version 0.6 - Fixed some bugs - Node from previous version is
now LeafNode. Node is a base class for LeafNode and CollectionNode.
Please note though, CollectionNode exists as a placeholder for future usage, it
has not been tested! That being said, some of the basic functionality
from the base class (Node) should still work since it is not specific to either
node type. - There is now an Item and PayloadItem vs. the
Item<PacketExtension> type that previously existed. - Source code jar has
been removed and will now only reside in the <a href="http://www.igniterealtime.org/issues/browse/ SMACK-272"
target="_blank">JIRA task</a>. Javadoc still needs to be
updated to reflect these changes.
附件:
- smackx-pubsub-doc.jar
(525.9 K)
- smackx-pubsub.0.6.jar
(111.1 K)
Re: Pubsub
Extensions for Smack
Awesome.
rcollier, I hope you don't mind, I've mavenised this and
started making the tests work with ejabberd too. It's up at github: http://github.com/squaremo/smackx-pubsub/tree/master
At the minute I am pointing to your profile here as the
original author. Let me know if I can do better.
cheers
mikeb
Re: Pubsub
Extensions for Smack
OK, I probably don't have permissions for updating the source, so I will
include the file here.
I replaces the existing one in org.jivesoftware.smackx.pubsub
附件:
- PubSubManager.java
(9.7 K)
Re: Pubsub
Extensions for Smack
The new LeafNode/CollectionNode and Item/PayloadItem
organization is much better than 0.4. Thanks for your job!
BTW, the PubSubManager.getNodes() was missing in 0.6. Is
there any alternative?
Re: Pubsub
Extensions for Smack
Thanks for the feedback and I am glad you like the changes.
I removed it since it didn't actually do as was advertised (get all
nodes). It was only returning all nodes under root, the same as
discoverNodes(), and then creating ready to use Node objects. Since the
node creation could also be an issue fi there were a significant number of
nodes, I removed it. You can use discoverNodes() to get the same list of
node id's and then call getNode(id) to retrieve the actual Node object, so no
actual functionality is missing.
I am hoping to get a chance to work on the CollectionNode in the near
future so that will have the ability to get the child nodes and drill down a
hierarchy.
Re: Pubsub
Extensions for Smack
we use the library of rcollier I added this connection
and I installed Openfire on my machine but there is always a connection
problem, where is the problem?
can you help me!!
public class Test
{
public static void main(String[] args) {
//PubSubManager
test = new PubSubManager(connection, "");
XMPPConnection connection = new XMPPConnection("127.0.0");
PubSubManager
test = new PubSubManager("127.0.0");
test.connection("127.0.0");
test.createNode("firstnode");
//System.out.println(test.createNode);
System.out.println(test.getNodes());
}
}
Re: Pubsub
Extensions for Smack by rcollier
You still need smack.jar and smackx.jar on your classpath (before
smacx-pubsub.jar). You have classpath issues, plus the output is not even
from the Test class specified, but from another one called Toto?!? There
is also no connection method on PubSubManager. Please look at the Hello World
example as that is working code. The only thing missing is the connect
and login to your server. Look at the last posting which explains how to
setup the PubSubManager.
Re: Pubsub
Extensions for Smack
I took the code hellow word and I add the connection
public class Toto1
{
public static void main(String[] args) {
XMPPConnection
connection = new XMPPConnection("127.0.0.1", 5222);
//XMPPConnection connection =
new XMPPConnection("localhost",5222);
//connection.login("admin", "admin");
ConfigureForm form = new
ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
PubSubManager manager = new
PubSubManager(connection);
myNode =
manager.createNode("TestNode", form);
//public SimplePayload(String
elementName, String namespace, String xmlPayload)
SimplePayload payload = new
SimplePayload("book","pubsub:test:book", "<book
xmlns='pubsub:test:book'><title>Lord of the
Rings</title></book>");
Item<SimplePayload> item
= new Item<SimplePayload>(itemId, payload);
// Required to recieve the
events being published
myNode.addItemEventListener(myEventHandler);
// Publish item
myNode.publish(item);
eventNode =
manager.getNode("TestNode");
eventNode.addItemEventListener(myEventHandler);
eventNode.subscribe("myJID");
connection.close();
}
}
in fiel "PubSubManager"
final public class PubSubManager
{
/** Server name */
public static final String
SERVER_NAME = "localhost";
/** Server port */
public static final int SERVER_PORT = 5222;
/** user - for login */
private final String user;
/** Client password - for
login*/
private final String password;
private XMPPConnection con;
private String to;
private ConcurrentHashMap<String, Node> nodeMap =
new ConcurrentHashMap<String, Node>();
// Create a connection to the igniterealtime.org XMPP
server.
XMPPConnection connection = new XMPPConnection("localhost",5222);
// Connect to the server
connection.connect();
// Most servers require you to login before
performing other tasks.
connection.login("user",
"password");
/**
* Create a pubsub manager associated to the
specified connection.
*
* @param connection The XMPP connection
*/
public PubSubManager(XMPPConnection connection)
{
con = connection;
}
|
|
|
|
|
// Disconnect from the server
connection.disconnect();
}
error ???????????
C:\Documents and
Settings\Bureau\noeudspubsub\org\jivesoftware\smackx\pubsub\Toto1.java:10:
cannot find symbol
symbol : class
XMPPConnection
location: class Toto1
XMPPConnection connection = new XMPPConnection("127.0.0.1", 5222);
^
C:\Documents and
Settings\Bureau\noeudspubsub\org\jivesoftware\smackx\pubsub\Toto1.java:10:
cannot find symbol
symbol : class
XMPPConnection
location: class Toto1
XMPPConnection connection = new XMPPConnection("127.0.0.1", 5222);
^
C:\Documents and
Settings\Bureau\noeudspubsub\org\jivesoftware\smackx\pubsub\Toto1.java:16:
cannot access ConfigureForm
bad class file:
.\ConfigureForm.class
class file contains wrong
class: org.jivesoftware.smackx.pubsub.ConfigureForm
Please remove or make sure it
appears in the correct subdirectory of the classpath.
ConfigureForm form = new ConfigureForm(FormType.submit);
^
3 errors
Processus terminé avec code
quitter 1
where is the probleme ??
Re: Pubsub
Extensions for Smack
1.can someone post workabout example of helloworld with
"xmppconnection" ?
2.is there any configuration need to add/edit at openfire server?
3. is openfire port 5222 open by default for the connection?
Re: Pubsub
Extensions for Smack
The subscriber will only receive content from the moment he is
subscripting to a node and all old content published by publisher will not be
received by subscriber. Is this correct? May i know, what do i need
to do in order for subscriber to receive all previous old content ?
Re: Pubsub
Extensions for Smack
Old content can only be retrieved if the node is persistent. If it
is configured this way, then calling LeafNode.getItems() will retrieve
all persisted items.
Re: Pubsub
Extensions for Smack
The pubsub extensions for Smack have now been committed to the codebase
(in trunk) and can be obtained if you retrieve it from svn. From what I
can tell, the nightly builds are no longer done or published, which is too bad
as this would be a much easier way to obtain and use it.
Re: Pubsub
Extensions for Smack
Hi there,
thanks to your great contribution I was able to integrate XEP-0118 (Tune)
into my application. Publishing my current track works as expected and could be
confirmed with Psi at the other end. However now I'm quite confused on how to
react on PubSub Events on my side. E.g. what do I have to do to process for ex.
Tune Events from other users?
Could anybody be so kind and point me into the right direction or even
post a small example?
Thanks in Advance,
Maui
Re: Pubsub
Extensions for Smack by rcollier
You have several options.
No customization:
You can deal with the XML via the SimplePayload class which will already
be returned in the PayloadItem. This requires no extra work, but is not
overly friendly to deal with. In all likelihood, you will want to have a
custom class to represent a Tune element.
Create custom TunePayload:
The best thing to do is
1) create a TunePayloadProvider that implements PacketExtensionProvider
that will parse the Tune element of the item and return a TunePayload which
extends PacketExtension
2) register this provider in the smack.providers file by its namespace
"http://jabber.org/protocol/tune"
3) Now a call to PayloadItem.getItem() will return a TunePayload.
This also has the added benefit of being able to create TunePayload
objects to publish as well.
Sorry but I don't have more time to elaborate with examples, but this is
the basics of what you should do.
Good luck.
Robin
Re: Pubsub
Extensions for Smack by treffer
Here is our samplecode:
@SuppressWarnings("unchecked")
@Override
public
void processPacket(Packet packet) {
try {
if (packet instanceof
Message) {
Message message = (Message) packet;
for (PacketExtension packetExtension :
message.getExtensions()) {
if (!(packetExtension instanceof EventElement)) {
continue;
}
EventElement event = (EventElement) packetExtension;
for (PacketExtension eventExtension :
event.getExtensions()) {
if (!(eventExtension instanceof ItemsExtension)) {
continue;
}
ItemsExtension items = (ItemsExtension) eventExtension;
String node = items.getNode();
for (PacketExtension itemsExtension :
items.getExtensions()) {
if (!(itemsExtension instanceof PayloadItem)) {
continue;
}
PayloadItem payload = (PayloadItem) itemsExtension;
if (payload.getPayload() instanceof BCAtom) {
Works so far. Just replace BCAtom with your
payload.
Re: Pubsub
Extensions for Smack by rcollier
If you register a listener for the node, then you don't need any of the
code you are using since the method, handlePublishedItems(ItemPublishEvent<T>
items) will be called on your listener. The ItemPublishEvent contains
the list of items already.
Your code sample shows how to filter incoming packets manually to get the
item events, but this is not really necessary.