asmack pubsub getItems error - android

I'm trying to publish some information to server using the Pubsub nodes.unfortunately,I failed to retrieve the node that published before.Just very similar as the problem in the following link:
http://community.igniterealtime.org/message/199690#199690
to be specific, the code snippets like following :
try {
LeafNode node = mPubsub.getPEPNode(USEINFONODE,mFrom);
if(null != node){
List<Item> items = node.getItems();
Log.i("items",items.toString());
}
} catch (XMPPException e) {
Log.e("userInfoExtension","error : and the error is " + e.toString());
}
and the output error is no resposne from server.
the output of the debug is just like this:
<iq id="B9tI0-4" to="pubsub.mymachine" type="get"><query xmlns="http://jabber.org/protocol/disco#info" node="theNode"></query></iq>
<iq id="B9tI0-5" to="pubsub.mymachine" type="get"><pubsub xmlns="http://jabber.org/protocol/pubsub"><items node='theNode'/></pubsub></iq>
However according to the link mentioned above, the expected iq stanza shall be like this:
<iq type='get'
from='notifyserver#mymachine'
to='pubsub.mymachine'
id='items1'>
<query xmlns='http://jabber.org/protocol/disco#items'
node='theNode'/>
</iq>
so It shows that I miss the from field in the iq stanza,I'm wondering how can I put the from ='client#server' into the iq stanza. I have tried asmack libraries including :
asmack-android-7.jar , asmack-android-7-beem.jar asmack-android-16-beem.jar,all failed.
Can anyone help with this? Thanks very much.
I have found that it has something to do with receiving the packet. actually I have received the packet that I needed, the trouble is that the packet may can not be processed by smack in somewhere, and it will throw no response from sever exception.
so I think the problem is actually not receiving incoming packet correctly .
so does in my other question:
http://stackoverflow.com/questions/14357707/how-to-send-and-listen-to-custom-xmpp-presence-packet-with-asmack-the-library

I'm sorry to mislead you ! the error is caused by my extension provider which lead the parsing
packet into an endless loop, thus ,caused the no response from server exception.

Related

Smack Push Notification not working

I am using Smack library to get XMPP pubsub requests in my Android App.
I want to send alert from 1 phone which is received on another phone as push notification popup.
On debugging, control returns null due to this code in Smack 4.2.0 library's ChatManager.java class.
EntityJid userJID = from.asEntityJidIfPossible();
if (userJID == null) {
LOGGER.warning("Message from JID without localpart: '" + message.toXML() + "'");
return null;
}
My from isnt null,ofc... but, my asEntityjidIfPossibe is null.
My Iq is as follows:
<iq
to="pubsub.foo"
from="notifier#foo"
type="set"
id="1523272621323">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish xmlns="http://jabber.org/protocol/pubsub"
node="/home/foo/notifier/c7215880-a36e-4cb9-bdd3-441cf9c29c31/pqr">
<item id="item11523272621323">
<json xmlns="urn:xmpp:json:0">
{"id":"b7da305d-77c2-422a-9c95-7ec8a347192e",
"orgId":"c7215880-a36e-4cb9-bdd3-441cf9c29c31",
"user_id":"f0622ed6-860f-4f4e-9b11-c4ab6cb8cd66",
"username":"xyz",
"subject":"Message",
"body":"hello all",
"priority":"NORMAL",
"ack_required":false,
"users":["pqr"],
"replyTo":["/home/foo/notifier/c7215880-a36e-4cb9-bdd3-441cf9c29c31/xyz",
"/home/foo/notifier"]}
</json>
</item>
</publish>
</pubsub>
</iq>
All I want is to see if message sent is recieved or not? And how to get data to process it...Data is sent perfectly on the server from the sending phone.
On recieving device,
I get this message TWICE,
Message from JID without localpart: '<message to='xyz#foo/5301412210663914056363834' from='pubsub.foo'><event xmlns='http://jabber.org/protocol/pubsub#event'><items node='/home/foo/notifier/c7215880-a36e-4cb9-bdd3-441cf9c29c31/xyz'><retract id='item11523351450156'/></items></event></message>'

How to know message sending has failed in asmack

I am trying to send a message using asmack and I am getting an error like this in log cat:
07-23 13:44:45.759: D/SMACK(20581): RCV (0): <message from='139#192.168.10.241' to='143#192.168.10.241/false' type='error' id='7DOua-233'><body>dgvvvcvcvhcbfbfvgchcbgbhgbhvnhbnvbvbhgbbbbhvbcnvbvbvbvvvcbvcbv hvvvbcvbbhnhjbnnvjbbnnnvnhbnbbbnnn</body><error code='500' type='wait'><resource-constraint xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Your contact offline message queue is full. The message has been discarded.</text></error></message>
This is the code:
if(mConnection!=null)
{
Message msg = new Message(params[0], Message.Type.chat);
msg.setBody(params[1]);
try
{
System.out.println("sending..");
mConnection.sendPacket(msg);
System.out.println("sent!"+msg.getBody());
System.out.println("sent!"+msg.getTo());
flag=true;
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
How can I catch the above log cat error in my own try catch block? In the current case it is returning true even if message sending has failed. How can I know whether the message sending has failed due to the error like above.
Add a packet listner and check the type of packet received. If its an error your message is not delivered.
In your xmpp server go to offline messages settings and set a very high limit for storing offline messages such as 1024 KB and also check always store messages even if the maximum size has been reached.
Hope this works!

Setting Avatar using asmack

I am making a chat application for android and i am using asmack. My question is how do i set v-card avatar using asmack. what i am doing is as follows but the avatar is not getting saved. when i retrive avatar i got null
public static void setAvatarInVCard(){
urldefault=new URL("https://s3.amazonaws.com/ksr/avatars/3075521/Avatar.small.jpg");
java.io.InputStream stream = urldefault.openStream();
byte[] avatar1 = IOUtils.toByteArray(stream);
System.out.println("avatar length "+avatar1.length);
VCard vCard = new VCard();
vCard.setAvatar(avatar1, "avatar1/jpg");
vCard.save(MyService.getConnection());
}
when i logcat result using asmack what stanza it was sending is as follows and the ending tags were not present either.
PM SENT (1090972696): <iq id="7hY4J-7" from="111#192.168.1.7/Smack" type="set"><vCard xmlns='vcard-temp'><PHOTO><BINVAL>/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAICAgICAQICAgIDAgIDAwYEAwMDAwcFBQQGCAcJCAgHCAgJCg0LCQoMCggICw8LDA0ODg8OCQsQERAOEQ0ODg7/2wBDAQIDAwMDAwcEBAcOCQgJDg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg7/wAARCABQAFADASIAAhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAABwgFBgMECQECAP/EAEIQAAEEAQMCBAMEBQcNAAAAAAECAwQFBgcREgAhCBMiMQkUQSMyUWEVFhhCkSQzNFNnccEXUmJyc4GDkqGisbXw/8QAGgEAAwADAQAAAAAAAAAAAAAABQYHAgQIA//EAC8RAAEDAgQEBAcAAwAAAAAAAAECAxEABAUhMUEGElGhExRhgSIjMnGx0fAHkfH/2gAMAwEAAhEDEQA/AGL8xe331f8AN0r3ioznKsU0VgwMYta6BJu5JiOoekrTPkN7buIjAIUlACdyt5RHBPZPqUD0z3SIeMS+xl3JsKxBcGvk5LwXayZC2kKltxWifJYQo+pKXHQpZA2BDXfseqdibhaslkGDUA4fYD
i also try sending the URL directly like this
vCard.setAvatar(urldefault);
but still avatar not getting saved the log-cat result is as follows.
03-14 18:06:37.199: D/SMACK(3210): 06:06:37 PM SENT (1090973048): <iq id="5SfDm-9" from="111#192.168.1.7/Smack" type="set"><vCard xmlns='vcard-temp'/>
03-14 18:06:37.289: D/SMACK(3210): 06:06:37 PM RCV (1090973048): <iq type="result" id="5SfDm-9" to="111#192.168.1.7/Smack"/>
Thanks for the help in advance.
How big is the size of this image , i think its supposed be well within a range of 1 mb (Guess approx) or less, because i face the same issue and i get XML Stanza is too big as a response and the connection breaks , im looking at options to minimize the bitmap size

Unable to get Joined Chat Rooms using asmack

My problem is i am not been able to receive joined chat rooms. I am using the openfire server 3.8.2 and asmack library asmack-android-16.jar. I receive item-not-found error when i call getJoinedRooms function. though i can see the user is joined in the room from the admin console. Is it the server problem or the client problem or some issue with asmack? Please tell me if someone is able to get joined chat rooms using openfire and asmack for android.
here is how i am call the function:
Iterator RoomsIterator=MultiUserChat.getJoinedRooms(MyService.getConnection(),"user#192.168.1.3");
i also tried this but it gives no response form server:
Iterator RoomsIterator=MultiUserChat.getJoinedRooms(MyService.getConnection(),"user#192.168.1.3/Smack");
Please help me with my problem
Thanks in advance.
I solved my problem by adding a packet listener after call get joined rooms function.. as i was getting an empty list but when i debug i check that the rooms was getting returned in the resultant xml stanze that was sent by the server therefore i run the getjoinedroom function of asmack and then i manually add ha packet listener like this:
public void AddPacketListener(){
PacketFilter filter = new IQTypeFilter(IQ.Type.RESULT);
MyService.getConnection().addPacketListener(new PacketListener()
{
public void processPacket(Packet paramPacket) {
if(paramPacket.getFrom().equals(MyService.getConnection().getUser())){
String xml=paramPacket.toXML();
String from[];
System.out.println(xml);
from=paramPacket.getFrom().split("/");
Pattern pattern = Pattern.compile("<item jid=\"(.*?)/>");
Matcher matcher = pattern.matcher(xml);
String parts[];
Roomlist.clear();
while (matcher.find()) {
parts=matcher.group(1).split("#");
Roomlist.add(parts[0]);
}
return;
}
}
},filter);
}

Message id issue connecting chat between iOS and Android in Quickblox

I'm having an issue connecting an iOS and Android device with their corresponding QBChat libraries, with the message ID's.
Message objects in Quickblox's iOS library are defined as QBChatMessage objects, that doesn't exist in Quickblox's Android library (which delegates them to a Message class in SMACK library).
The problem is that QBChatMessage class manages message id's as integers, while Message class manages them as Strings. Every message sent from my Android device has a 7-character unique string + a number with the message's position in SMACK chat. When my iPhone receives the message, its ID is a number with the ID from SMACK parsed as much as it could, as in this communication sample (taken from the Android device):
SENT <message id="D64u5-4" to="102521-1799#chat.quickblox.com" from="132505-1799#chat.quickblox.com/Smack" type="chat"><body>{"content":{"text":"hello"},"type":1}</body><thread>7J9230</thread></message>
SENT <message id="D64u5-5" to="102521-1799#chat.quickblox.com" from="132505-1799#chat.quickblox.com/Smack" type="chat"><body>{"content":{"text":"yeah"},"type":1}</body><thread>7J9230</thread></message>
SENT <message id="D64u5-6" to="102521-1799#chat.quickblox.com" from="132505-1799#chat.quickblox.com/Smack" type="chat"><body>{"content":{"text":"test"},"type":1}</body><thread>7J9230</thread></message>
RCV <message id="0" from="102521-1799#chat.quickblox.com" type="chat" xmlns="jabber:client" to="132505-1799#chat.quickblox.com"><body>{"content":{"text":"hello"},"type":1}</body></message>
RCV <message id="1" from="102521-1799#chat.quickblox.com" type="chat" xmlns="jabber:client" to="132505-1799#chat.quickblox.com"><body>{"content":{"text":"yeah?"},"type":1}</body></message>
RCV <message id="2" from="102521-1799#chat.quickblox.com" type="chat" xmlns="jabber:client" to="132505-1799#chat.quickblox.com"><body>{"content":{"text":"yeah!"},"type":1}</body></message>
Message's ID is important for me, in order of database storage. How is this possible? What should I do to solve this issue?
Thanks, kind regards! :)
Daniel, sounds good.
Is changing type of QBChatMessages.ID to NSString will solve your issue?
Will do that in next release. If you haven't time to wait - just write with your request to assist#quickblox.com, will make special build of SDK for you
Below is my Android code for group chat:
/* Sends messages */
public void sendChatMessage(String text)
{
Message message = muc.createMessage();
message.setBody(text);
message.setPacketID("ABC_1");
muc.sendMessage(message);
}
/* Listens for messages */
public void receiveMessage()
{
muc.addMessageListener(new PacketListener() {
public void processPacket(Packet packet)
{
final Message message = (Message) packet;
log.i("packed id: ", packet.getPacketID());
log.i("message id: ", message.getPacketID());
}
});
}
The output I see in logcat is
packet id: null
message id: null
Could you please tell me why the IDs are null? Am I missing something here?

Categories

Resources