Project

General

Profile

Tigase plugins to send and receive custom IQ stanzas

Razor Ra
Added about 5 years ago

Hi,

I have created a custom IQ provider in Smack xmpp.

Now what I am trying to do is create tigase plugins to send an IQ stanza and receive the response from that IQ provider.

So far I have:

Created a tigase plugin, which only purpose is to send an IQ stanza, and it is working fine.

I have also created another plugin which suppose to get the result of that stanza send by that IQ provider.

public class TestClass extends XMPPProcessor implements XMPPProcessorIfc
{

  private static final String ID = "mytestID";
  private static final String XMLNS = "test:iq:type";
  private static final String[] ELEMENTS = {"query"};
  private static final String[] XMLNSS = {XMLNS};

  @Override
  public String id() {
    return ID;
  }

  @Override
  public String[] supElements() {
    return ELEMENTS;
  }

  @Override
  public String[] supNamespaces() {
    return XMLNSS;
  }  

  @Override
  public void process(
          final Packet packet,
          final XMPPResourceConnection session,
          final NonAuthUserRepository repo,
          final Queue queue,
          final Map settings) throws XMPPException 
  {
    // code... 
  }

So, when my first plugin sends the following IQ stanza

<iq type="get" to="test@my-tigase-server" id="dsfsdaf43">
 <query xmlns='test:iq:type'/>
</iq>

It is caught by my second plugin because of the XMLNS (test:iq:type).

That stanza is never sent to that IQ provider. I have tried implementing preProcess method but still it never reaches to my custom IQ provider.

Can you please tell me, how to fix this problem.

Thanks


Replies (5)

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam about 5 years ago

Could you please describe in more details what it is you want to accomplish? What is the exact workflow in your use case?

I am asking because the Tigase plugin is not for "just sending" stanza. The plugin is for processing stanzas received from a user. During the stanza processing the plugin may generate a response, one or multiple, it can send a result back to the user or forward the packet to a different designation or both.

If you have multiple plugins for the same stanza type all of them receive the packet for processing.

Added by Razor Ra about 5 years ago

I have multiple plugins which trigger other plugins.

In this particular case,

  1. I have one plugin which after performing some particular task sends a stanza of following type:
<iq type="get" to="test@my-tigase-server" id="1qaz2">
 <query xmlns='test:iq:type'/>
</iq>
  1. and I have a second plugin which suppose to get the response of that stanza, which is of following type.
<iq type="result" from="test@my-tigase-server" id="1qaz2">
 <query xmlns='test:iq:type'/>
    <utc>20020910T17:58:35</utc>
    <tz>MDT</tz>
    <display>Tue Sep 10 12:58:35 2002</display>
  </query>
</iq>

But my second plugin (which also suppose to get the response) also gets the stanza of type "GET" and never forwards it to the user.

Hope, I explained myself well this time.

Thanks

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam about 5 years ago

I am sorry, but I am not sure if I understand you correctly. As I understand you explained what is happening now but I want you to also explain what you want to happen. What is your correct behavior or what you want it to do? Do you have some description for your data flow or a description of the workflow, some drawings? Before we understand what you want it to do, we cannot help you too much.

Any plugin which defines the same supported elements and namespaces should receive all stanzas of that kind (element name, namespace). This is how it is designed to do. If it does not work for you for some reason, then you might have a mistake in your code. Without showing us your code and the exact data you send from a client and exact data you receive in the client it is impossible for us to help you too much.

Added by Razor Ra about 5 years ago

Sorry, I don't have any description of the workflow or any drawings.

Let me try to explain again :)

First let me tell you what I want to do:

  1. First plugin - it sends multiple IQ stanzas, but for now it sends an IQ stanza to the user with "test:iq:type" namespace.

  2. Second plugin - it is to receive an IQ stanza with only "test:iq:type" namespace.

So my First plugin sends this

Element sendDiscoInfo = createIqQuery("admin@my-tigase", "testuser@my-tigase", StanzaType.get, UUID.randomUUID().toString(), test:iq:type");
Packet p = Packet.packetInstance(sendDiscoInfo);
queue.offer(p);

   *---------*

public static Element createIqQuery(
          final String from,
          final String to,
          final StanzaType type,
          final String id,
          final String xmlns) 
  {
    Element iq = new Element("iq",
            new String[]{"from", "to", "type", "id"},
            new String[]{from, to, type.toString(), id});

    Element query = new Element("query");

    query.setXMLNS(xmlns);

    iq.addChild(query);

    return iq;

  }

-----------------------------------------
Which is:
<iq type="get" from="admin@my-tigase" to="testuser@my-tigase" id="1qaz2">
 <query xmlns='test:iq:type'/>
</iq>

It is working fine, stanza is created and sent to the user.

But after that, comes my Second plugin.

Because my Second plugin is only interested in "test:iq:type" namespace, so the Iq stanza created by my First plugin comes directly to my Second plugin +and never goes to the user+.

I know that every namespace of type "test:iq:type" have to come to the Second plugin, but after that I want it to go to the user.

How can I send it to the user after reaching Second plugin.

Thanks for bearing with me.

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam about 5 years ago

Have a look at the Message plugin code. It sends Message stanza to a user and there is plenty of inline comments for explanation.

    (1-5/5)