Project

General

Profile

how to publish a message(item) by PubSub REST API?

peirong jiang
Added over 3 years ago

like the title :how to publish a message(item) by PubSub REST API?

I use the adhoc command:

show in the snapshot.

but publish failed.

the table: tig_pubsub_items has 0 record.

the other rest api: http://10.5.1.48:8080/rest/pubsub/pubsub.10.5.1.48/publish-item

I can get the command list (snapshot)

how can i send item successfuuly by PubSub REST API?

sendMsgItemByPubSubRestApi.png (73.6 KB) sendMsgItemByPubSubRestApi.png 1. send msg error
anotherAPI.png (64.5 KB) anotherAPI.png 2. send msg error
commandList.png (110 KB) commandList.png I can get the pubsub command List

Replies (7)

Added by peirong jiang over 3 years ago

I have resovled it.

the script is wrong.

the correct groovy like the snapshot.

   public PubSubActionsHandler() {
        regex = /\/(?:([^@\/]+)@){0,1}([^@\/]+)\/([^\/]+)/
        isAsync = true
        decodeContent = false;
        *requiredRole = "user"*

        execGet = { Service service, callback,*user,* localPart, domain, cmd ->
            execPost(service, callback,user, null, localPart, domain, cmd);
        }

        execPost = { Service service, callback, user,content, localPart, domain, cmd ->
            //if (localPart) {
            //  localPart = localPart.substring(0,localPart.length()-1);
            //}

            content = decodeContent(content ? content.getReader().getText() : null);

            def compJid = BareJID.bareJIDInstance(localPart, domain);

            Element iq = new Element("iq");
            iq.setXMLNS(Iq.CLIENT_XMLNS);
            *iq.setAttribute("from",user.toString());*
            iq.setAttribute("to", localPart ? "$localPart@$domain" : domain);
            iq.setAttribute("type", "set");
            iq.setAttribute("id", UUID.randomUUID().toString())

Added by István Tóth over 3 years ago

Please peirong jiang, can you send me what is the REST API end point you call, and what is the posted data exactly? I need this feature too...

(1)

Added by István Tóth over 3 years ago

Hi all

I tried out peirong jiang's script.

The item appear in the db in node_items table, but the item tag empty, even I filled out the entry field.

The result is something like this: '' - without the actual entry of pubsub item.

(1)

Added by Wojciech Kapcia TigaseTeam over 3 years ago

peirong jiang wrote:

like the title :how to publish a message(item) by PubSub REST API?

I use the adhoc command:

show in the snapshot.

Your command is wrong - please follow the guide in the wiki: Publish item to a node. Please note that content MUST be an XML.

Added by István Tóth over 3 years ago

Hi all

At me, now it's working,

Please note that content MUST be an XML.

This was the key.

(1)

Added by István Tóth over 3 years ago

I try out a CURL POST to publish an item in XML format.

In the attachment: Picture from the existing nodes, and an existing content of a node.

After I posting, i get this error Node pubsub.demo.v1 needs to be created before an item can be published.

ps0001.png (20.8 KB) ps0001.png existing nodes
ps0002.png (5.46 KB) ps0002.png node content
ps0003.png (5.02 KB) ps0003.png XML post
(1)

Added by Wojciech Kapcia TigaseTeam over 3 years ago

István Tóth wrote:

I try out a CURL POST to publish an item in XML format.

In the attachment: Picture from the existing nodes, and an existing content of a node.

After I posting, i get this error Node pubsub.demo.v1 needs to be created before an item can be published.

Please note, that the same node may exist for the different services! From the provided informations it's impossible to whether this is a bug or issue during posting.

Best way to investigate this would be to:

  • have all data, including REST URL;

  • check all pubsub tables (including services)

  • check the logs for processing of the request with --debug=server,pubsub,component2 options enabled.

    (1-7/7)