How to extract data from xml on ejabberd server? - ejabberd

I am using custom module to view data of every coming packet on the ejabberd server. My log print on the terminal is given below:
18:30:06.370 [info] mod_stanza_ack a presence has been sent coming from: {jid,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<"2923451306214954478930">>,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<"2923451306214954478930">>}
18:30:06.371 [info] mod_stanza_ack a presence has been sent to: {jid,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<>>,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<>>}
18:30:06.372 [info] mod_stanza_ack a presence has been sent with the following packet:
{presence,<<"IaOQN-29">>,unavailable,<<"en">>,{jid,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<"2923451306214954478930">>,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<"2923451306214954478930">>},{jid,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<>>,<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,<<"faiqkhan-virtualbox">>,<<>>},undefined,[],undefined,[],#{ip => {0,0,0,0,0,65535,49320,422}}}
how can I extract data from xml format using specific tags like:
from first and second line: jid.

Using https://github.com/processone/xmpp#stanzas
There's plenty of example code in... ejabberd source code :P

Related

Jmeter - when there are number of threads are running, the variable from JSON extractor is not working sometimes

I am now using Jmeter to run the test of APIs.
The situation is that I have a login Api which will return a token inside response. I use a JSON extractor to save the token as a variable. Then, I use the ${token} is the header of other requests.
However, I found that when I was trying to run 40-50 threads, the ${token} in some threads would be empty, and caused a high error rate.
Therefore, may I ask is there any method to solve it and why?
Thanks very much.
Try saving full response from the Login API, most probably your server gets overloaded and cannot return the token and returning some error message instead.
There are following options:
If you're running JMeter in command-line non-GUI mode you can amend JMeter's Results File Configuration to store the results in XML form and include the response data, add the next lines to user.properties file:
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
and when you run your test next time the .jtl results file will contain response bodies for all the requests.
Another option is using a Listener like Simple Data Writer configured like:
and when you run the test the responses.xml file will contain the response data
Both .jtl results file and responses.xml can be inspected using View Results Tree listener
More information: How to Save Response Data in JMeter

Not able to send message using strophe.js and ejabberd

I am using strophe.js and ejabberd for implementing a chat in my site. But I couldn't successfully send a message or retrieve messages using mam. The log is printing the SENT: and RECV: strings. The code I am using to send a message is
var m = $msg({to: 'admin#ks111', from: 'admin#ks111', type: 'chat'}).c("body").t('body');
connection.send(m);
and the SENT string obtained is
SENT: <body rid='3431080199' xmlns='http://jabber.org/protocol/httpbind'><enable xmlns='urn:xmpp:sm:3' resume='false'/><message to='user1#server' from='user2#server' type='chat' xmlns='jabber:client'><body>body</body></message></body>
I tried with the gajim client for no response. But if I am removing the 'body' tag like...
<message to='user1#server' from='user2#server' type='chat' xmlns='jabber:client'><body>body</body></message>
the chat is received properly. The 'body' tag is added with all the requests by default. What could be the issue. Please provide a solution.
body should only be added by library implementing XMPP over BOSH. They are part of the BOSH control structure and signalling. I presume your Strophe client use BOSH so having a BOSH wrappers is expected. I also supposed that your are connecting using standard XMPP using Gajim, so you need to use standard XMPP without BOSH wrapper. Otherwise, it is not understood as an XMPP packet (a body tag is not a valid XMPP packet).
All seems normal and expected.

How can I display an XML page instead of JSON, for a dataset

I am using the pycsw extension to produce a CSW file. I have harvested data from one CKAN instance [1], into another [2], and am now looking to run the pycsw 'paster load' command:
paster ckan-pycsw load -p /etc/ckan/default/pycsw.cfg -u [CKAN INSTANCE]
I get the error:
Could not pass xml doc from [ID], Error: Start tag expected, '<' not found, line 1, column 1
I think it is because when I visit this url:
[CKAN INSTANCE 2]/harvest/object/[ID]
It comes up with a JSON file as opposed to an XML (which it is expecting)
I have run the pycsw load command on other ckan instances and have had no problems with them. They also display an XML file at the url stated above, so I wanted to know how to get CKAN to serve an XML file instead of JSON?
Thanks in advance for any help!
As you've worked out, your datasets need to be in ISO(XML) format to load into a CSW server. A CKAN only has a copy of the dataset in ISO(XML) format if it harvested them from a CSW.
If you use the CKAN(-to-CKAN) harvester in the chain then the ISO(XML) record doesn't get transferred with it. So you'd either need to add this functionality to the CKAN(-to-CKAN) harvester, or get rid of the CKAN-to-CKAN harvest step.
Alternatively if the record originated in a CKAN, then it has no ISO(XML) version anyway, and you'd need to create that somehow.

SQL Server Service Broker system error -9616, when can it happen?

I have a scenario in one of my Service Broker conversation configurations, which looks like this:
one message type, which is sent by initiator only (VALIDATION = WELL_FORMED_XML, no XSD)
one contract with this message type
both deployed on the initiator and target side (remote machines)
Occasionally I find Service Broker system error messages in the target queue like this:
<Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-9616</Code><Description>A message of type 'here_is_the_name' was received and failed XML validation. XML parsing: line 1, character 547, illegal xml character This occurred in the message with Conversation ID 'here_is_the_guid', Initiator: 1, and Message sequence number: 0.</Description</Error>
I looked at Remus Rusanu's blog post and he states that:
This system error is sent to a conversation that has sent a message type marked as conforming to a certain XML schema but the payload has failed to pass the XML validation for the said schema
In my case there is no XML schema involved and I was trying to reproduce this case in my dev env using the same SQL Server versions and I was unable to do it.
I would like to know is it possible to receive this system error message although I'm not using XSD schema ? If so, when can it happen, what is the scenario where Service Broker generates error like above?
The message clearly says "XML parsing: line 1, character 547, illegal xml character" so in my opinion it has nothing to do with the schema validation.
Can it be that the transport level is encountering some problems (TCP errors) and that is why Service Broker is generating this error message ?
Message validation occurs on enqueue the message in the target queue, not on SEND. Message type validation (NONE, XML, XDS) is provided to protect your application. Validating during SEND is not enough, as a malicious application can send a message w/o using Service Broker ( a wire protocol simulator). Since validation during enqueue is mandatory, adding validation during SEND would add CPU burden for little value.
So what that means is the your SEND side application is sending invalid XML, and this gets caught on the target side. The wording on my blog is poorly chosen, I should had been more explicit that the validation can fail a schema (if specified) or it can fail the well formed XML test.
Can you post the message body you're sending?

Assistance with a simple WSO2 ESB project

I'm very very new to this and need some help writing an ESB script to take an event posted via HTTPS on Port 9090 in WSO2 and transform it into a message to be apended to an XML file on the server:
The HTTPS data will contain : “ID=Servername|Severity=sevtype” (Where Servername is a device name and Sevtype can either be "WARNING" or "OK" depending on whether the server is down or up)
This then needs to be transformed and appended to an existing XML file in the following format:
<event>
<componentID>Servername</componentID>
<timestamp>2012-04-27 01:37:10</timestamp> ***(Date and time the event was received)***
<severity>NORMAL</severity> ***(If original is WARNING then severity = SEVERE else it = NORMAL)***
<eti>NodeStatus</eti><etivalue>Up</etivalue> ***(If original is WARNING then severity = Down else it = Up)***
<\event>
Please could someone assist me i'm really floundering with what seems to be a simple thing
Many Many Thanks
Simon
You can write a simple task to poll your data into the server and can do a xslt transformation to construct that particular xml format message.
Some references to write a task;
http://wso2.org/project/esb/java/4.0.3/docs/configuration_language.html#TaskConcept
http://docs.wso2.org/wiki/display/ESB403/Writing+Tasks
http://wso2.org/library/2900
How do you get the ID and Severity? are they http headers?
Generally you can use payload factory mediator[1] to build the payload messages with some input parameter data.
[1] http://wso2.org/project/esb/java/4.0.3/docs/samples/message_mediation_samples.html#Sample17