what does opcode==0 signify? - javascript

I am using Kony studio for an app development. I have done the login validation using Eclipse to code for creating web services to connect to the oracle10g database. But on the front end I'm getting an error, when I'm trying to connect the front end to the web service.
The status==400 is getting validated but I'm not getting opcode as 0, instead its going in the else statement and giving an error alert. This is the Javascript code for connecting to the web service.
Please help. What does opstatus==0 signify?
function GetLogin()
{
var Userid =login.txtloginuname.text;
var Password = login.txtloginpass.text;
var inputParamsLogin={serviceID:"servicelogin",uname:Userid,pass:Password}
if (Userid!=null && Userid!="" && Password!="" && Password!=null)
{
appmiddlewareinvokerasync(inputParamsLogin,loginCallBackresponse);
}
else
{
var alert_seq5_act0 = kony.ui.Alert(
{
"message": "Please Enter User name and password",
"alertType": constants.ALERT_TYPE_ERROR,
"alertTitle": "",
"yesLabel": "OK",
"noLabel": "",
"alertIcon": "",
"alertHandler": null
}, {});
kony.application.dismissLoadingScreen();
}
function loginCallBackresponse(status,loginResults)
{
if(status==400)
{
alert("productResults");
if(loginResults.opstatus==0)
{
alert("inside opstatus");
else
{
var alert_seq5_act0 = kony.ui.Alert({"message": "Service Failed:"+loginResults.errmsg,
"alertType": constants.ALERT_TYPE_ERROR,
"alertTitle": "",
"yesLabel": "OK",
"noLabel": "",
"alertIcon": "",
"alertHandler": null}, {});
kony.application.dismissLoadingScreen();
}
}
}
}
I am getting the alert "product results" but unable to get the alert "inside opstatus".
Instead I'm getting "service failed alert.

If the opstatus is 0, it indicates that the service call is a success while a non-zero value indicates a failure.
Please read the following that gives you more info on network call in Kony
The following is the description of the parameters associated with network call in kony:
status - an integer value - indicating the status
The following are the various status returned:
100 - network call initiated successfully - resultset will not be available and it is nil.
200 - network is in progress (when you start receiving the 1st byte) - resultset will not be available and it is nil.
300 - network call canceled - resultset will not be available and it is nil.
400 - network call is finished (gets called in both success and failure scenarios - actual state can be queried using opstatus in the resultset.
Note: On Mobile Web, the callback function is always invoked with a status of 400. Other intermediate status codes are not applicable on Mobile Web.
resulttable - a Object with key-value pairs - follows the same structure (opstatus, errcode, errmsg along with the actual network returned data)
This represents the Object returned by the service. This Object contains three values:
opstatus
errcode
errmsg.
If the opstatus is 0, it indicates that the service call is a success while a non-zero value indicates a failure.
If the opstatus is a non-zero value, it is captured in errcode. The following are the possible error codes:
1000- Unknown Error while connecting (If the platform cannot differentiate between the various kinds of network errors, the platform reports this error code by default).
1011 - Device has no WIFI or mobile connectivity. Please try the operation after establishing connectivity.
1012 - Request Failed.
1013 - Middleware returned invalid JSON string.
1014 - Request timed out.
1015 - Cannot find host.
1016 - Cannot connect to host.
1200 - SSL - Certificate related error codes.
The error message corresponding to each error code is captured in the errmsg parameter.

Related

Paho MQTT JS client loses connection to Mosquitto broker when I publish or receive message (error AMQJS0005E)

Bottom line up front: The Paho MQTT client sucessfully connects to my Mosquitto broker, but immediately disconnects when I try to publish a message or when it receives a message from a topic it's subscribed to. I've tried changing Mosquitto's listening port and authentication settings, and using two different versions of Paho MQTT, and I still have the same problem.
Now let's get into detail.
Intro: I'm making a dashboard for some facial recognition devices that communicate through MQTT. I set up a Mosquitto broker and I've had no problems connecting to it and communicating with the devices using the Paho MQTT client for Python (I made a kind of server to sync the device's info to a database). Now I'm making the web interface, so I added a WebSockets listener to my mosquitto.conf and wrote a script using the Paho MQTT library for Javascript to connect to it, subscribe to topic sgdrf/out, send a simple JSON message to topic sgdrf/in to get the list of online devices, and process the response of the Python server once it arrives.
Problem and attempted solutions: I ran the Django server, loaded the web page and opened the JS console to find that the MQTT client successfully connected to the broker but immediately disconnected when it tried to publish the message to topic sgdrf/in. Here's each line of console output with their explanations:
The message produced by the onSuccess function, which indicates that the client successfully connected to the Mosquitto broker:
Conexión exitosa al broker MQTT.
In the onConnected function, I added console.log(uri) to see the URI used by the client to connect to the broker. I got:
ws://localhost:61613/
After printing uri to console, I made the client subscribe to sgdrf/out and then print 'subscribed' to console:
subscribed
Then I call get_online_devices(mqtt_client), a function which creates a simple JSON string and publishes it to the topic sgdrf/in. But first, it prints the strign to the console so that I can check it (just in case):
{"operator":"GetOnlineDevices","messageId":96792535859850080000,"info":{}}
Then, when the publish method is actually executed, is when I get this error (captured by the onConnectionLost function):
Pérdida de conexión con el broker MQTT: AMQJS0005E Internal error. Error Message: message is not defined, Stack trace: No Error Stack Available (código: 5)
I checked the Mosquitto log file and it only says when a new client was connected and then when it was disconnected because of a socket error (each time for every page reload). Tail of /var/log/mosquitto/mosquitto.log:
1614796149: New connection from 127.0.0.1 on port 61612.
1614796149: New client connected from 127.0.0.1 as mqttx_53195902 (p2, c1, k60, u'admin').
1614796182: Socket error on client sgdrf_dashboard_8499, disconnecting.
1614796325: New client connected from ::ffff:127.0.0.1 as sgdrf_dashboard_1597 (p2, c1, k60, u'admin').
1614796325: Socket error on client sgdrf_dashboard_1597, disconnecting.
1614796336: New client connected from ::ffff:127.0.0.1 as sgdrf_dashboard_6565 (p2, c1, k60, u'admin').
1614796336: Socket error on client sgdrf_dashboard_6565, disconnecting.
1614796931: New client connected from ::ffff:127.0.0.1 as sgdrf_dashboard_9773 (p2, c1, k60, u'admin').
1614796931: Socket error on client sgdrf_dashboard_9773, disconnecting.
1614797168: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
I tried changing the listening port in mosquitto.conf, and enabling and disabling authentication, but it changes nothing. And obviously I've had to restart Mosquito every time I changed the config file. I don't think the problem is Mosquitto.
I have the same problem whether I use Paho MQTT version 1.1.0 or 1.0.3.
As an experiment, I commented out the call to get_online_devices in my Javascript so that it doesn't try to publish anything, reloaded the page and there was no error, as expected. Then, I used MQTTX to send a JSON message to the sgdrf/out topic to which the MQTT JS client is subscribed to, and it immediately disconnected with the same error message.
Code: At the bottom of the page (index.html) I have the following code (the original code has Django template tags to fill in some values, so this is the actual code received by the browser):
<!-- Paho MQTT -->
<script src="/static/js/paho-mqtt-min.js"></script>
<!-- Scripts -->
<script src="/static/js/dashboard.js"></script>
<script>
function get_online_devices(mqtt_client) {
cmd = {
operator: "GetOnlineDevices",
messageId: generate_random_number_n_exp(20),
info: {}
};
payload_string = JSON.stringify(cmd);
console.log(payload_string)
mqtt_client.publish("sgdrf/in", payload_string);
}
function add_device_to_list(device) {
// Omitted for brevity. It's not being used yet.
}
let mqtt_client = make_mqtt_client("localhost", 61613);
let connection_options = make_connection_options(
"admin",
"CENSORED_PASSWORD"
);
mqtt_client.onConnected = function(reconnect, uri) {
console.log(uri)
mqtt_client.subscribe("sgdrf/out");
console.log('subscribed');
get_online_devices(mqtt_client);
};
mqtt_client.onConnectionLost = mqtt_client_on_connection_lost;
mqtt_client.onMessageDelivered = mqtt_client_on_message_delivered;
mqtt_client.onMessageArrived = function (msg) {
// Omitted for brevity. Checks if the payload is a
// JSON object with the right data and calls
// add_device_to_list for each item of a list in it.
};
$(document).ready(function() {
mqtt_client.connect(connection_options);
$("#reload-device-list-btn").click(function() {
get_online_devices(mqtt_client);
});
});
</script>
The dashboard.js files mentioned above just has some functions that I think will be useful for other pages, so I separated them to a file:
// dashboard.js
function generate_random_number_n_exp(n) {
return parseInt(Math.random() * Math.pow(10, n), 10)
}
function make_mqtt_client(host, port) {
let client_id = "sgdrf_dashboard_" + generate_random_number_n_exp(4);
return new Paho.Client(host, port, '/', client_id);
}
function make_connection_options(user, password) {
let connection_options = {
userName: user,
password: password,
onSuccess: mqtt_client_on_success,
onFailure: mqtt_client_on_failure,
};
return connection_options;
}
function mqtt_client_on_success() {
console.log('Conexión exitosa al broker MQTT.');
}
function mqtt_client_on_failure(error) {
console.log(
'Fallo de conexión con el broker MQTT: ' + error.errorMessage
+ ' (código: ' + error.errorCode + ')'
);
}
function mqtt_client_on_connection_lost (error) {
console.log('Pérdida de conexión con el broker MQTT: ' + error.errorMessage
+ ' (código: ' + error.errorCode + ')'
);
}
function mqtt_client_on_message_delivered(msg) {
let topic = message.destinationName;
let payload = message.payloadString;
console.log("Mensaje enviado a " + topic + ": " + payload);
}
function mqtt_client_on_message_arrived(msg) {
let topic = message.destinationName;
let payload = message.payloadString;
console.log("Mensaje recibido de " + topic + ": " + payload);
}
Here are the contents of my mosquitto.conf file:
per_listener_settings true
listener 61612
allow_anonymous false
password_file /home/s8a/Projects/sgdrf/config/pwdfile.txt
listener 61613
protocol websockets
allow_anonymous false
password_file /home/s8a/Projects/sgdrf/config/pwdfile.txt
It just sets up a TCP listener and a WebSockets listener, both disallow anonymous connections, and authenticate using a pwdfile. As I said before, I have enabled and disabled anonymous connections, and changed the port number to 9001 and back to 61613, and I still have the same error.
Conclusion: I don't know what to do and this project's deadline is next week.
I feel kinda stupid, because it was really a trivial typing mistake. The problem is that the onMessageDelivered and onMessageArrived functions have msg as argument, but I wrote messagein the function body for some reason. That's what the "message is not defined" error meant, message is literally not defined. Anyway I fixed that and now it sends and receives messages without problems.
...
More detailed story: What was not trivial is how I figured it out.
I decided to get my hands dirty and opened the non-minified version of paho-mqtt.js. I looked for "Invalid error" and found where the error constant is defined, and two places where it's used in a catch block. In both catch blocks I noticed that there was a ternary operator checking if (error.hasOwnProperty("stack") == "undefined") but the true and false clauses were inverted, which is why I was getting "No Error Stack Available".
So I inverted the clauses, and indeed I got a stack trace in the console (maybe I should file a bug report to the Paho dev team when I can). The stack trace had my mqtt_client_on_message_delivered function right at the top, so I read it again and suddenly everything made sense. Then I felt stupid for wasting an afternoon on this.

Firebase Auth sendEmailVerification() I'm getting an Error, but only with Safari browser

When a user signs up, I am requiring them to verify their email address.
It works fine in Firefox and Chrome, but not in Safari, where I get the following message:
Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred.
And no confirmation email is sent.
I’m sourcing this version:
firebasejs/6.4.0/firebase-auth.js
I've searched for similar problems. There were lots of Firebase Authentication errors, but I didn't find this one.
Using the Safari JavaScript debugger, filtering for all exceptions I receive the errors below.
And interestingly, after stepping through with the debugger on, setting Breakpoints at "All Exceptions" an email is sent. But not when running in real-time.
Hopefully that is a clue.
I send the email verification with this code.
if (current_user && !current_user.emailVerified) {
current_user.sendEmailVerification().then(function() {
const user_message = '<message to user>';
window.location = '/message?message=' + user_message;
}).catch((error) => {
console.log(error);
} );
}
The errors:
line 515 rpchandler.js
try {
response = JSON.parse(this.getResponseText()) || null;
It looks like the response is null.
line 183 promise.js Exception with thrown value: zi
try {
// Promise was rejected. Step up one call frame to see why.
if (reason instanceof Error) {
throw reason;
This happens a few times.
line 2190 authuser.js
// Cache the invalidation error.
self.userInvalidatedError_ = /** #type {!fireauth.AuthError} */ (error);
line 740 firebase-app.js
Exception with thrown value: TypeError: Argument to String.prototype.startsWith cannot be a RegExp
Any ideas?
I ended up rolling my own email verification workflow.
I'd be interested in reverting back to the Firebase Auth JavaScript email verification workflow, if there is a solution. But for now, I just have to move forward.

Cosmos DB Mongo API How to manage "Request Rate is Large" condition

I Have the following code..
async function bulkInsert(db, collectionName, documents) {
try {
const cosmosResults = await db.collection(collectionName).insertMany(documents);
console.log(cosmosResults);
return cosmosResults
} catch (e) {
console.log(e)
}
}
If I run it with a large array of documents I get ( not unexpectedly)
{ MongoError: Message: {"Errors":["Request rate is large"]}
ActivityId: b3c83c38-0000-0000-0000-000000000000,
Request URI: /apps/DocDbApp/services/DocDbServer24/partitions/a4cb4964-38c8-11e6-8106-8cdcd42c33be/replicas/1p/,
RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.19.102.5
at G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\pool.js:596:61
at authenticateStragglers (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\pool.js:514:16)
at Connection.messageHandler (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\pool.js:550:5)
at emitMessageHandler (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\connection.js:309:10)
at TLSSocket.<anonymous> (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\connection.js:452:17)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at TLSSocket.Readable.push (_stream_readable.js:208:10)
name: 'MongoError',
message: 'Message: {"Errors":["Request rate is large"]}\r\nActivityId: b3c83c38-0000-0000-0000-000000000000,
Request URI: /apps/DocDbApp/services/DocDbServer24/partitions/a4cb4964-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.19.102.5',
_t: 'OKMongoResponse',
ok: 0,
code: 16500,
errmsg: 'Message: {"Errors":["Request rate is large"]}\r\nActivityId: b3c83c38-0000-0000-0000-000000000000,
Request URI: /apps/DocDbApp/services/DocDbServer24/partitions/a4cb4964-38c8-11e6-8106-8cdcd42c33be/replicas/1p/,
RequestStats: ,
SDK: Microsoft.Azure.Documents.Common/1.19.102.5',
'$err': 'Message: {"Errors":["Request rate is large"]}\r\nActivityId: b3c83c38-0000-0000-0000-000000000000,
Request URI: /apps/DocDbApp/services/DocDbServer24/partitions/a4cb4964-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: ,
SDK: Microsoft.Azure.Documents.Common/1.19.102.5' }
It appears that some (approx. 165) of the 740 records I was processing have been loaded. All of them appear to have been assigned '_id' attributes.
Does anyone have any idea how to handle this (or at least tell which records were inserted and which were not processes)...
Requests with cosmosdb need to consume RUs. Obviously, your insert request exceeded the RU throughput and error code 16500 occurred.
Applications that exceed the provisioned request units for a
collection will be throttled until the rate drops below the reserved
level. When a throttle occurs, the backend will preemptively end the
request with a 16500 error code - Too Many Requests. By default, API
for MongoDB will automatically retry up to 10 times before returning a
Too Many Requests error code.
You could find more instructions from official document.
You could follow the ways as below to try to solve the issue:
Import your data in batches to reduce throughput.
Add your own retry logic in your application.
Increasing the reserved throughput for the collection. Of course, it increases your cost.
You could refer to this article.
Hope it helps you.
Update Answer:
It looks like your documents are not uniquely identifiable. So I think the "_id" attribute which automatically generated by Cosmos DB cannot determine which documents have been inserted and which documents have not been inserted.
I suggest you increasing throughput settings, empty the database and then bulk import the data.
Considering the cost , please refer to this document for setting the appropriate RU.
Or you could test bulk import operation locally via Cosmos DB Emulator.

Calling collection.find() causes an internal server error and times out afterwards

I've got an ExpressJS backend and added MongoDB to it. Previously with hardcoded data it worked perfectly but now that I've (tried) to add MongoDB to the pipeline, my request for the data times out. I've inserted a record in a collection using the command prompt:
> db
stackmailer
> db.sites.find()
{
"_id" : ObjectId("55ef5c1a7f6857848b7149b7"),
"title" : "Stack Overflow",
"icon" : "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png"
}
MongoDB is hosted at localhost:27017
2015-09-08T23:58:51.394+0200 I CONTROL [initandlisten] MongoDB starting : pid=6836 port=27017 dbpath=C:\data\db\ 64-bit host=JEROEN-LAPTOP
2015-09-08T23:58:51.422+0200 I NETWORK [initandlisten] waiting for connections on port 27017
2015-09-08T23:58:54.760+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:51658 #1 (1 connection now open)
I'm reading the data like this:
var db = require('mongoskin').db('localhost:27017/stackmailer');
router.get('/', function (req, res, next) {
db.collection('sites').find().toArray(function (err, result) {
if (err) {
console.log(err);
throw err;
}
console.log("found sites!");
console.log(result);
res.send(result);
});
}
Which is called from AngularJS like this:
StackExchangeService.getSites().then(function(data) {
$scope.data.sites = data;
});
angular.module('StackMailer.Services', [])
.factory('StackExchangeService', function($q, $http) {
var service = {
getSites: function() {
return getData('/sites');
}
};
function getData(url)
{
var d = $q.defer();
$http.get(url, ({ timeout: 10000 }))
.then(function(response, status) {
console.log("successfully retrieved data");
d.resolve(response.data);
}, function(response, status) {
console.log("couldn't retrieve data " + status);
d.reject(response);
});
return d.promise;
};
return service;
});
After the specified timeout span, "couldn't retrieve data 0" shows in the console. None of the console.log calls inside router.get() display output in the console.
This leads me to believe that I am somehow not connecting to MongoDB but as far as I can tell, I've got everything setup for that.
Looking at the ExpressJS output, I notice the following output (for 3 requests):
GET / 304 5.335 ms - -
GET /css/stackmailer.css 304 4.784 ms - -
GET /js/stackmailer.js 304 1.250 ms - -
GET /sites 500 479.902 ms - 1424
GET /tags 304 2.303 ms - -
GET /css/stackmailer.css 304 0.937 ms - -
GET / 304 1.028 ms - -
GET /css/stackmailer.css 304 1.231 ms - -
GET /js/stackmailer.js 304 1.608 ms - -
GET /tags 304 1.156 ms - -
GET /sites - - ms - -
GET / 304 2.988 ms - -
GET /css/stackmailer.css 304 4.508 ms - -
GET /js/stackmailer.js 304 2.022 ms - -
GET /tags 304 1.336 ms - -
GET /sites - - ms - -
Notice the first request to /sites which returns HTTP 500 and afterwards times out. This is reflected in the console log:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Curiously: when I wrap the db.collection() call in a try-catch block and try to log the error to the console, it doesn't cause the HTTP 500 anymore but I'm also not shown any output.
Any ideas on what could cause this?
Not sure why you are not seeing an error logged here, and it is possibly because of some other configuration present in your app not mentioned here.
However the error you "should" be seeing is this:
Error: URL must be in the format mongodb://user:pass#host:port/dbname
And that is because your connection string is not in a valid format accepted by the driver. It should instead be this:
var db = require('mongoskin').db('mongodb://localhost:27017/stackmailer');
Noting that the mongodb:// part is mandatory, and things like the port number ( which is the default ) are not.
I will also note that you appear to have this loading in your "route" module and presumably everywhere else that you intend to use a database connection. It is strongly advised to not do that, as database connections should be made once per application and the connection "shared" where it is needed to be used.

DHTMLX dhtmlxForm.send() Throws HTTP Status 400 - "The request sent by the client was syntactically incorrect."

This all started when we moved to DHTMLX v4.0.3. The dhtmlxForm.send() function now throws HTTP Status 400 - "The request sent by the client was syntactically incorrect." I don't see anything wrong with the POST. I did notice they are now including a randomly generated item "dhxr1422484613542" that does not have a value. Any idea why this is now throwing a HTTP 400? Thanks!
The Headers Tab:
The Preview Tab:
The JavaScript:
dhtmlxEvent(window,"load",function(){
var dhxLayout = new dhtmlXLayoutObject(document.body, '1C');
var f = dhxLayout.cells("a").attachForm([
{type:"settings", position:"label-left", labelAlign:"right", labelWidth:150, inputWidth:150},
{type:"hidden", name:"method", value:"getJson"},
{type:"hidden", name:"proc", value:"c3.chgpwd"},
{type:"password", name:"oldpwd", label:"Current Password", required:true},
{type:"password", id:"newpwd", name:"newpwd", label:"New Password", required:true},
{type:"password", name:"confirmpwd", label:"New Password (Again)", required:true},
{type:"button", name:"submit", width:50, offsetLeft:150, value:"Submit"}
]);
f.attachEvent("onButtonClick", function(name){
/* Here is the POST that used to work, but since v4.0.3 it throws a HTTP 400 */
f.send("lib.cfc?method=getJson&proc=c3.chgpwd","post",function(loader, response){
console.log(response); /*This is never reached, see attachments for the error reported during the POST*/
});
});
});
I've found that apache cannot handle url parameters when the equal symbol is missing after the name.
So a url such as:
http://domain.com?x=22&y
is not understandable by apache.
I guess the dhtmlx team does not use apache.

Categories

Resources