powered by Jive Software

Need j2me sample code for connecting openfire

Hi

Anyone Please post the j2me sample code to connecting openfire server using user account created in openfire.

that is useful for reference to me

Thanks.

Hi to All,

how to create node in openfire and publish the info.

Please send the coding forcreating node and publish the info.

You could try a simple search of the site. At least attempt to find the information before asking.

I found node creation publish and subscribe code, but item not found error occurs while subscribing (getNode() ) in the subscribing program

Now i have posted both programs

Node creation and publishing code:

import java.util.List;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.pubsub.AccessModel;
import org.jivesoftware.smackx.pubsub.ConfigureForm;
import org.jivesoftware.smackx.pubsub.FormType;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;
import org.jivesoftware.smackx.pubsub.Subscription;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;

public class Se
{

public static void main(String[] args) throws XMPPException {

String itemId=“TestNode071”;
XMPPConnection connection = new XMPPConnection(“localhost”);
connection.connect();
connection.login(“knandha”, “knandha”);
System.out.println(“Connected”);
ConfigureForm form = new ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
PubSubManager manager = new PubSubManager(connection);
LeafNode myNode = (LeafNode) manager.createNode(itemId, form);
System.out.println(“Node Created”);

SimplePayload payload = new SimplePayload(“book”,“pubsub:test:book”, “Lord of the Rings”);
PayloadItem item = new PayloadItem(itemId, payload);
ItemEventListener myListener = new ItemEventListener() {
public void handlePublishedItems(ItemPublishEvent items) {
System.out.println(“result=”+items.getItems().toString());
}
};
myNode.addItemEventListener(myListener);
myNode.publish(item);
System.out.println(“Node Published”);
}
}

output:

Connected
Node Created
Node Published
result=[org.jivesoftware.smackx.pubsub.PayloadItem | Content [Lord of the Rings]]

Subscribing Program:

package org.jivesoftware.smackx;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.AccessModel;
import org.jivesoftware.smackx.pubsub.ConfigureForm;
import org.jivesoftware.smackx.pubsub.FormType;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;

public class TestSubscriber {

public static void main(String[] args) throws XMPPException{
XMPPConnection.DEBUG_ENABLED = false;
String itemId=“TestNode071”;
ConnectionConfiguration config = new ConnectionConfiguration(“localhost”, 5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login(“knandha”, “knandha”);
System.out.println(“Connected”);
PubSubManager manager = new PubSubManager(connection,“pubsub”);
LeafNode myNode = (LeafNode) manager.getNode(itemId); //Error occured in this line
System.out.println(“Node Received”);
ItemEventListener myListener = new ItemEventListener() {
public void handlePublishedItems(ItemPublishEvent items) {
System.out.println(“result=”+items.getItems().toString());
} };
myNode.addItemEventListener(myListener);
myNode.subscribe(“knandha@srinicomputer”);
System.out.println(“Node Subscriped”);

} }

Output:

Connected

Exception in thread “main” item-not-found(404)

at org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:53)

at org.jivesoftware.smackx.packet.SyncPacketSend.getReply(SyncPacketSend.java:61)

at org.jivesoftware.smackx.pubsub.PubSubManager.getNode(PubSubManager.java:161)

at org.jivesoftware.smackx.TestSubscriber.main(TestSubscriber.java:32)

Java Result: 1

BUILD SUCCESSFUL (total time: 1 second)

How to resolve this problem? Solution Please!..

This line…

PubSubManager manager = new PubSubManager(connection,“pubsub”);

Find out what is the exact name of the pubsub service. If you are using Openfire, the default is ‘pubsub.your_computer_name’. The best way to discover this name is to send a disco#item to your server using ServiceDiscoveryManager.

See my blog http://oneminutedistraction.wordpress.com/2010/07/26/discovering-services/