Hi Bernd and Niklas, thanks for your time!
I have been trying to use the pubsub client in SVN, but am unable to get it
working. I suspect my issue is more related to smackx-pubsub. What version
are you using? I'm running the example client from trunk (vysper: tags/0.5)
and had to modify the vysper client sources to get it to compile. Attached is
a vysper pubsub client patch that works against trunk smackx-pubsub.
After making my source modifications to the example client, running
PubsubclientGUI results in this exception upon run:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
org.jivesoftware.smack.util.PacketParserUtils$2 cannot be cast to
org.jivesoftware.smackx.packet.DiscoverItems
at
org.jivesoftware.smackx.pubsub.PubSubManager.discoverNodes(PubSubManager.java:195)
at
org.apache.vysper.demo.pubsub.client.PubsubClientModel.discoverNodes(PubsubClientModel.java:96)
at
org.apache.vysper.demo.pubsub.client.PubsubClientModel.refresh(PubsubClientModel.java:133)
at
org.apache.vysper.demo.pubsub.client.PubsubClientGUI.run(PubsubClientGUI.java:123)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:602)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
I spent a few hours debugging these issues and began some heavy modifications
to smackx-pubsub but then stopped because I just don't know enough. So, where
can I get the smackx-pubsub library you are using that works? Also, is it
possible to use another XMPP client other than smackx? Can vysper/mina be used
as an XMPP-PubSub client?
Thanks!
ken
----- Original Message -----
From: "Bernd Fondermann" <[email protected]>
To: [email protected]
Sent: Saturday, June 5, 2010 5:13:47 PM GMT -05:00 US/Canada Eastern
Subject: Re: XMPP PubSub Helloworld with Vysper and Smackx-PubSub
Hi Ken,
sorry for replying late, too.
We have a (unreleased!) sample PubSub client available in svn at
http://svn.apache.org/repos/asf/mina/vysper/trunk/demo/pubsub/client/
which also uses smackx-pubsub.
It works for me after applying the patch given below from revision
938927 to the server code.
This patch is a workaround only, but all I can give right now to make
the pubsub demo client run.
Maybe this helps you getting your client to run with Vysper/PubSub.
Please note that this kind of discussion should ideally be continued
at the [email protected] list.
HTH,
Bernd
Modified:
mina/vysper/trunk/nbxml/src/main/java/org/apache/vysper/xml/fragment/Renderer.java
URL:
http://svn.apache.org/viewvc/mina/vysper/trunk/nbxml/src/main/java/org/apache/vysper/xml/fragment/Renderer.java?rev=938927&r1=938926&r2=938927&view=diff
==============================================================================
---
mina/vysper/trunk/nbxml/src/main/java/org/apache/vysper/xml/fragment/Renderer.java
(original)
+++
mina/vysper/trunk/nbxml/src/main/java/org/apache/vysper/xml/fragment/Renderer.java
Wed Apr 28 11:24:22 2010
@@ -70,12 +70,15 @@ public class Renderer {
for(Entry<String, String> nsAttr : nsAttrs.entrySet()) {
openElementBuffer.append(" ");
String name;
- if(nsAttr.getKey().length() == 0) {
+ String value = nsAttr.getValue();
+ if(value == null || value.length() == 0) {
+ continue; // don't issue "xmlns=''", this will only
confuse clients
+ } else if(nsAttr.getKey().length() == 0) {
name = "xmlns";
} else {
name = "xmlns:" + nsAttr.getKey();
}
- renderAttribute(openElementBuffer, name, nsAttr.getValue());
+ renderAttribute(openElementBuffer, name, value);
}
for (Attribute attribute : element.getAttributes()) {
On Sat, Jun 5, 2010 at 22:18, Bernd Fondermann
<[email protected]> wrote:
> Hi! This is my first post to the Mina ML. I am currently evaluating Mina and
> Vysper. I am trying to setup the basic XMPP PubSub demo as described here:
>
> http://www.igniterealtime.org/community/message/196048#196048
>
> I'm running Vysper 0.5, and using the Smackx-pubsub-0.6 client library, all on
> the same host. Using the users created in ServerMain I am able to connect to
> my
> local Vysper instance, however when I execute the following line the
> connection
> is terminated and my client dies:
>
> Node myNode = manager.createNode("TestNode", form);
>
> Error message is:
>
> java.net.SocketException: Connection closed by remote host at
> sun.security.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1301) at
> sun.security.ssl.AppOutputStream.write(AppOutputStream.java:62) at
> sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:220) at
> sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:290) at
> sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:294) at
> sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:140) at
> java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229) at
> java.io.BufferedWriter.flush(BufferedWriter.java:253) at
> org.jivesoftware.smack.PacketWriter.writePackets(PacketWriter.java:274)
> at org.jivesoftware.smack.PacketWriter.access$000(PacketWriter.java:40)
> at org.jivesoftware.smack.PacketWriter$1.run(PacketWriter.java:87)
> java.io.EOFException: no more data available - expected end tag
> </stream:stream>
> to close start tag <stream:stream> from line 1, parser stopped on END_TAG seen
> ...to="[email protected]/ba1f394ff13848a6879468a34a85b585"></presence>...
> @1:934 at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3035) at
> org.xmlpull.mxp1.MXParser.more(MXParser.java:3046) at
> org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1144) at
> org.xmlpull.mxp1.MXParser.next(MXParser.java:1093) at
> org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:368)
> at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
> at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76) No
> response from server.: at
> org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:50)
> at
> org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:61)
> at
> org.jivesoftware.smackx.pubsub.PubSubManager.sendPubsubPacket(PubSubManager.java:324)
> at
> org.jivesoftware.smackx.pubsub.PubSubManager.sendPubsubPacket(PubSubManager.java:318)
> at
> org.jivesoftware.smackx.pubsub.PubSubManager.createNode(PubSubManager.java:134)
> at
> org.apache.vysper.demo.pubsub.client.PubsubHelloWorld.run(PubsubHelloWorld.java:36)
> at
> org.apache.vysper.demo.pubsub.client.PubsubHelloWorld.main(PubsubHelloWorld.java:21)
>
> And Vysper tells me this:
>
> 14:42:55,966 | INFO |
> org.apache.vysper.xmpp.modules.core.im.handler.PresenceAvailabilityHandler |
> [email protected]/ba1f394ff13848a6879468a34a85b585 has become
> available 14:43:01,202 | DEBUG |
> org.apache.vysper.xmpp.protocol.SessionStateHolder |
> session state changed to = CLOSED 14:43:01,203 | WARN |
> org.apache.mina.filter.logging.LoggingFilter | EXCEPTION :
> org.apache.mina.core.write.WriteToClosedSessionException at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.clearWriteRequestQueue(AbstractPollingIoProcessor.java:573)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.removeNow(AbstractPollingIoProcessor.java:525)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.removeSessions(AbstractPollingIoProcessor.java:497)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:61)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:974)
> at
> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:636) 14:43:01,203 | WARN |
> org.apache.vysper.mina.XmppIoHandlerAdapter | error caught
> on transportation layer: {}
> org.apache.mina.core.write.WriteToClosedSessionException at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.clearWriteRequestQueue(AbstractPollingIoProcessor.java:573)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.removeNow(AbstractPollingIoProcessor.java:525)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.removeSessions(AbstractPollingIoProcessor.java:497)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:61)
> at
> org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:974)
> at
> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:636) 14:43:01,205 | WARN |
> org.apache.vysper.mina.codec.StanzaWriterProtocolEncoder |
> unhandled StanzaWriterProtocolEncoder.dispose() 14:43:01,206 | WARN |
> org.apache.vysper.xmpp.modules.core.base.handler.XMPPCoreStanzaHandler | no
> 'from' attribute, and cannot uniquely determine sending resource for
> initiating
> entity [email protected] in session 17cca8fbfbed4bab9f265fc609019357
> 14:43:01,206 | DEBUG |
> org.apache.vysper.xmpp.protocol.SessionStateHolder |
> session state changed to = CLOSED
>
> Here is the whole PubSub Helloworld class adapted from the ignite post:
> http://pastebin.com/ui7gHUfg
>
> I'm less interested in debugging this demo code rather I am trying to get to
> get
> the basics of XMPP PubSub working with Vysper. Any tips/suggestions/working
> solutions would be greatly appreciated .
>
> thx ken
>
Index: client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientModel.java
===================================================================
--- client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientModel.java (revision 952258)
+++ client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubClientModel.java (working copy)
@@ -91,7 +91,7 @@
}
private void discoverNodes(Map<String, PubsubNode> lookup) throws XMPPException {
- DiscoverItems di = pubsubMgr.discoverNodes();
+ DiscoverItems di = pubsubMgr.discoverNodes(null);
Iterator<Item> iIt = di.getItems();
while(iIt.hasNext()) {
Item i = iIt.next();
Index: client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubEventListener.java
===================================================================
--- client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubEventListener.java (revision 952258)
+++ client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubEventListener.java (working copy)
@@ -19,6 +19,8 @@
*/
package org.apache.vysper.demo.pubsub.client;
+import java.util.Iterator;
+
import javax.swing.DefaultListModel;
import org.jivesoftware.smackx.pubsub.Item;
@@ -36,9 +38,16 @@
public void handlePublishedItems(ItemPublishEvent e) {
DefaultListModel lm = parent.getListModel(e.getNodeId());
System.out.println("Got something from " + e.getNodeId());
- for(Item<SimplePayload> i : e.getItems()) {
- lm.add(0,i.getPayload().toXML()); //alwasy add to the top
+
+ for (Iterator i = e.getItems().iterator(); i.hasNext();) {
+ SimplePayload sp = (SimplePayload) i.next();
+
+ lm.add(0, sp.toXML());
}
+
+ /*for(Item<SimplePayload> i : e.getItems()) {
+ lm.add(0,i.getPayload().toXML()); //alwasy add to the top
+ }*/
}
}
Index: client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubPublishButtonListener.java
===================================================================
--- client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubPublishButtonListener.java (revision 952258)
+++ client/src/main/java/org/apache/vysper/demo/pubsub/client/PubsubPublishButtonListener.java (working copy)
@@ -21,14 +21,18 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.util.Iterator;
import javax.swing.JTextField;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.Item;
+import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.Node;
+import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;
+import org.jivesoftware.smackx.pubsub.Subscription;
public class PubsubPublishButtonListener implements ActionListener {
@@ -52,9 +56,9 @@
String message = getMessage();
- Item<SimplePayload> item = createItem(message);
+ Item item = createItem(message);
- sendItem(node, item);
+ sendItem((LeafNode) node, item);
}
private String getMessage() {
@@ -63,8 +67,9 @@
return message;
}
- private void sendItem(Node node, Item<SimplePayload> item) {
+ private void sendItem(LeafNode node, Item item) {
try {
+
node.send(item);
} catch (XMPPException e1) {
System.err.println("Couldn't send an item to " + nodeID);
@@ -72,9 +77,9 @@
}
}
- private Item<SimplePayload> createItem(String message) {
+ private Item createItem(String message) {
String itemId = "demoID"+System.currentTimeMillis();
- Item<SimplePayload> item = new Item<SimplePayload>(itemId, new SimplePayload(ELEMENT, NAMESPACE, message));
+ Item item = new PayloadItem(itemId, new SimplePayload(ELEMENT, NAMESPACE, message));
return item;
}