PrivacyListManager returning null

PrivacyListManager.getInstanceFor(CONNECTION) is returning null.

When I look at PrivacyListManager class,

I can see getInstanceFor returns a connection which is got from a addConnectionCreationListener.

How is this addConnectionCreationListener working ? Am I meant to init. the PrivacyListManager first somehow ?

thanks

Hi,

the PrivacyListManager as well as some other managers are available once you are connected to an XMPP server.

XMPPConnection connection = new XMPPConnection("localhost");
connection.connect();
connection.login("user1", "user1"); PrivacyListManager privacyListManager = PrivacyListManager.getInstanceFor(connection); ...

This is because changes made via the PrivacyListManager result in XMPP packets sent to the XMPP server. So using a PrivacyListManager without an established connection makes no sense.

Also everytime you want to get an instance of the PrivacyListManager you have to use the same connected XMPPConnection instance.

Best regards,

Henning

Hi Henning

Thanks for your reply. Yes I understand what you are saying, but it doesnt work for me, or look right.

I have tried your code, and it returns null on the listmanager.

The PrivacyListManager class starts a listener (ConnectionCreationListener) to listen for connections ON CREATION, and this is what is returned on the method ``getInstanceFor.


BUT, if the connection has already been created(as per your code), then how is the listener, which listens for connections
when CREATED, grabs the connection.

So, in summary should this be the logic ??? :

1) Start ConnectionCreationListener in privacylistmanager
2) Connect to XMPP server
3) ConnectionCreationListener gets the connection
4) getInstanceFor returns the connection

But it seems this is happening, and this is what your asking me to do:

1) Connect to XMPP server
2) Start ConnectionCreationListener in privacylistmanager
3) getInstanceFor returns null - (as listener only listens for created connections)

Am I being daft here ?

Best

Johnny

Hi,

then probably the problem is that Smack can’t load the smack-config.xml on startup. The initialization is as follows:

The first access to XMPPConnection class executes the static code block in the XMPPConnection class (Connection class in current trunk).

In this block the SmackConfigration class is initialized. SmackConfiguration class then executes a static code block that reads the “META-INF/smack-config.xml”. This config file contains a list of classes that should be loaded on Smack startup. Among these classes is the PrivacyListManager class which is then loaded and in its static code block it registers the ConnectionCreationListener. Now if a new connections logs into an XMPP server the listener is called and an instance of the PrivacyListManager is created and stored in the instances map. (btw: the name ConnectionCreationListener is actually wrong and it will hopefully one day be renamed to ConnectionEstablishedListener).

To test if the smack-config.xml couldn’t be loaded or doesn’t contain the entry for the PrivacyListManager you can try the following code:

// load the PrivacyListManager class before creating the connection
Class clazz = PrivacyListManager.class; // this statement initializes the XMPPConnection class which leads to loading the classes in smack-confix.xml
XMPPConnection connection = new XMPPConnection("localhost");
connection.connect();
connection.login("user1", "user1"); PrivacyListManager privacyListManager = PrivacyListManager.getInstanceFor(connection);

Normally the smack-config.xml is located within the smack.jar file.

Hope that helps.

Best regards,

Henning

FYI

You can try to add

PrivacyListManager.getInstanceFor(connection);

before

connection.connect();

Hi henning, I face the same problem . I use the following step as told by you but i not succeed .

PrivacyListManager privacyListManager = PrivacyListManager.getInstanceFor(connection);

this line return null for privaceListManager. Can you help me.