Hi,
I am using Smack-3.2.2.
What I am trying to do is add and implement some features and then by using xmlns, wanting to get them.
Main.java
publicclass Main { publicstaticvoid main(String args[]) throws Throwable { //create Connection and connect System.out.println(":::Adding Feature:::"); ServiceDiscoveryManager.getInstanceFor(connection).addFeature("http://jabber.org/protocol/disco#info"); ServiceDiscoveryManager.getInstanceFor(connection).addFeature("my:test:feature"); // create listener connection.addPacketListener( new MyCustomPacketListener(connection), new PacketFilter() { publicboolean accept(Packet packet) { if (packet.getXmlns().equals("my:test:feature")) { returntrue; } returnfalse; } }); // main method does not terminate while (true) { Thread.sleep(Long.MAX_VALUE); }
MyCustomPacketListener.java
publicclass MyCustomPacketListener implements PacketListener { // some code publicvoid processPacket(Packet packet) { IQ response = new IQ() { @Override public String getChildElementXML() { returnnew StringBuilder() .append("<query xmlns=\"my:test:feature\">") .append("<name>") .append("testApp") .append("</name>") .append("<type>") .append("someType") .append("</type>") .append("</query>") .toString(); } }; response.setTo("some@jid"); response.setType(IQ.Type.RESULT); response.setPacketID(packet.getPacketID()); connection.sendPacket(response); }}
From PSI, when I send:
<iq type="get" to="some@jid" id="info-1"><query xmlns='http://jabber.org/protocol/disco#info'/></iq>
I get the correct response, which have my added feature.
<iq from="some@jid/Smack" type="result" id="info-1" to="jid@some/PSI"> <query xmlns="http://jabber.org/protocol/disco#info"> <identity category="client" type="typeName" name="someName"/> <feature var="http://jabber.org/protocol/xhtml-im"/> <feature var="my:test:feature"/> <feature var="http://jabber.org/protocol/disco#info"/> </query></iq>
But when I send:
<iq type="get" to="some@jid" id="ded3"><query xmlns='my:test:feature'/></iq>
I get this error message that:
<iq from="some@jid/Smack" type="error" id="ded3" to="some@jid/Psi1"><error type="CANCEL" code="501"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
Please can anyone tell me, what I am doing wrong here?
Thanks.