Elasticsearch does not return jsonp - json

im trying to connect my polymer element to my own elasticsearch-server.
My first problem was, that they are on two different ports, so it had to choose JSONP because of Cross-Domain problems.
So I found out, that I just have to add
http.jsonp.enable: true
in the elasticsearch.yml.
Im starting the server simply by executing the "elasticsearch.bat".
I've indexed data.
If I try to load the API via iron-jsonp-library, im always getting an unexpected token error.
<iron-jsonp-library id="libraryLoader"
library-url="http://127.0.0.1:9200/data/_search?pretty%%callback%%"
notify-event="api-load"
callbackName="jsonpCallback">
</iron-jsonp-library>
In Google Chrome, I'm getting following result from elasticsearch
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":5,"max_score":1.0,"hits":[{"_index":"data","_type":"data","_id":"5","_score":1.0,"_source":{"id":5,"name":"Meyr","manufacturer":"Meyr","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Meyr"}},{"_index":"data","_type":"data","_id":"2","_score":1.0,"_source":{"id":2,"name":"Meier","manufacturer":"Meier","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Meier"}},{"_index":"data","_type":"data","_id":"4","_score":1.0,"_source":{"id":4,"name":"Mair","manufacturer":"Mair","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Mair"}},{"_index":"data","_type":"data","_id":"1","_score":1.0,"_source":{"id":1,"name":"Maier","manufacturer":"Maier","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Maier"}},{"_index":"data","_type":"data","_id":"3","_score":1.0,"_source":{"id":3,"name":"Mayr","manufacturer":"Mayr","weight":1.0,"price":1.0000,"popularity":1,"instock":true,"includes":"Mayr"}}]}}
Due to some internet knowledge of JSONP, its not jsonp.
Why is my elasticsearch server, not formatting right?

Are you prior to v2.0? Looks like they removed jsonp in 2.0 (elastic.co/guide/en/elasticsearch/reference/2.2/…).
Alsopretty%%callback%% doesn't look right, the %%callback%% macro usually needs to be the value of name (like onload=%%callback%%). The element replaces %%callback%% with the name of a global function that is generated for you.

Related

Data Studio Connector can't get access token for BigQuery Service Account: Access not granted or expired

I'm trying to make a community connector to connect my database in BigQuery to data studio with the service account that I hooked up as the Owner/DataViewer/JobUser of the BigQuery project. I know that the service account works when connecting to BigQuery because I've tested it elsewhere. I copied from the connector code from this tutorial (https://developers.google.com/datastudio/solution/blocks/using-service-accounts) almost exactly, replacing the SQL string with my query and adding some different query parameters. I also stored the service account's credentials in my script properties by pasting the json object and storing it like:
var service_account_creds_obj = {
"type": "service_account",
"project_id": ...
...
}
scriptProperties.setProperty('SERVICE_ACCOUNT_CREDS', JSON.stringify(service_account_creds_obj));
However, I always get stuck in the flow when my getData function calls getOauthService().getAccessToken(), which doesn't ever successfully return. When I create a report using the connector, I get this error: "Access not granted or expired." I can't find the documentation for getAccessToken and I'm having trouble understanding why it won't terminate. I can see that it doesn't return because a console.log immediately before that line displays but it never gets to the log on the next line. Then my try-catch block catches the error that I'm seeing. Note that my getOauthService function is exactly the same as the one from the documentation/tutorial example, except that I've played around with the input text in the call to createService. That input text shouldn't really matter though right?
Please, I've been trying to debug this for hours, but the documentation on this is pretty horrible, and it's really hard to debug since the flow of the code is handled in the background and stackdriver logging is really buggy.
I figured out my problem. The documentation posted above said to set the OAuth2 scope to https://www.googleapis.com/auth/bigquery.readonly. However, I naively included
"oauthScopes": ["https://www.googleapis.com/auth/bigquery.readonly"]
in my manifest file. Meanwhile, the code I copied over from the documentation already included this line:
.setScope(['https://www.googleapis.com/auth/bigquery.readonly']);
So I'm not sure exactly why this caused a problem. But it must have prevented the OAuth2.createService function from properly getting set.

Laravel - Json Encode Works Fine But Returns Malformed UTF-8 Error Regardless

Problem
The JSON is returned correctly encoded but json_last_error equates to 5 thus Laravel throws this exception on response creation in JsonResponse->setData().
Related References
A resolved bug report for symfony and PHP 7.3: https://github.com/symfony/symfony/issues/31447 mentions this exact issue. That is:
If a json_encode()/json_decode() without JSON_THROW_ON_ERROR encoding option set throws an error, any subsequent call to the same with that flag set will not reset the error of the previous call.
The JSON_THROW_ON_ERROR RFC mentions this behavior as by design: https://wiki.php.net/rfc/json_throw_on_error
Unfortunately Laravel's code uses the flag but does not cater for this behavior and throws exception if json_last_error() returns a non zero value. Which in this case should have been ignored as it will always reference the previous error. Perhaps a version check should be added.
Investigation
I have also searched the bowls of my application and haven't found the misbehaving json_encode/json_decode without JSON_THROW_ON_ERROR set so I am sure it is internal to Laravel before Middleware calls.
Additional Context
This suddenly started happening today in our server. It happens when users connect to the server through the web app from select systems. Even though system kind should not affect server side response generation but still web app always generates this error for specific PCs/Mobiles.
Proposed Hack
After sifting through the Symfony bug report, the easiest workaround I have found is to just clear the error through an inconsequential json_encode('1') call. Which effectively resets the error code to 0 and the later JSON methods work fine.
Fortunately we have our own response generation class so just adding this before the hand-off to Laravel works fine.
Still this is a hack. I am more interested in a better solution or any bug fix available.

Bottlenose 400 - How To Parse HTTPError

I'm getting a 400 error when testing the examples provided by Bottleneck.
I double checked that I'm using the correct Associate Tag with the right region (do I include the '-20' in the AWS_ASSOCIATE_TAG?), I tried setting my Ubuntu's timezone (running on a VM) to GMT to follow the api_url builder (below) but that didn't help.
I checked the credentials using AWS-Cli and I was able to pull all EC2 instances without a permission error.
I tried reading the HTTPError using e.read, but I'm getting a class bytes object which I can't further investigate.
Is there a way to parse the error into XML or a simple string so that I could understand what the error actually is? Did anyone else encounter this problem and can think of a solution?
AWS Error codes
query = {
'Operation': self.Operation,
'Service': "AWSECommerceService",
'Timestamp': time.strftime(
"%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
'Version': self.Version,
}
I was skimming the docs and so I missed a crucial element - I was using AWS' API credentials, while the ones required belong to Amazon Product API.
To access those, please use this link.

Wirecloud FI-Ware Testbed compatibility

I was wondering if Wirecloud offers complete support for object storage with FI-WARE Testbed instead of Fi-lab. I have successfully integrated Wirecloud with Testbed and have developed a set of widgets that are able to upload/download files to specific containers in Fi-lab with success. However, the same widgets do not seem to work in Fi-lab, as i get an error 500 when trying to retrieve the auth tokens (also with the well known object-storage-test widget) containing the following response:
SyntaxError: Unexpected token
at Object.parse (native)
at create (/home/fiware/fi-ware-keystone-proxy/controllers/Token.js:343:25)
at callbacks (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:164:37)
at param (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:138:11)
at pass (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:173:5)
at Object.router (/home/fiware/fi-ware-keystone-proxy/node_modules/express/lib/router/index.js:33:10)
at next (/home/fiware/fi-ware-keystone-proxy/node_modules/express/node_modules/connect/lib/proto.js:195:15)
at Object.handle (/home/fiware/fi-ware-keystone-proxy/server.js:31:5)
at next (/home/fiware/fi-ware-keystone-proxy/node_modules/express/node_modules/connect/lib/proto.js:195:15)
I noticed that the token provided in the beggining (to start the transaction) is
token: Object
id: "%fiware_token%"
Any idea regarding what might have gone wrong?
The WireCloud instance available at FI-WARE's testbed is always the latest stable version while the FI-LAB instance is currently outdated, we're working on updating it as soon as possible. One of the things that changes between those versions is the Object Storage API, so sorry for the inconvenience as you will not be able to use widgets/operators using the Object Storage in both environments.
Anyway, the response you were obtaining seems to indicate the object storage instance you are accessing is not working properly, so you will need to send an email to one of the available mail lists for getting help (fiware-testbed-help or fiware-lab-help) telling what is happening to you (remember to include your account information as there are several object storage nodes and ones can be up and the others down).
Regarding the strange request body:
"token": {
id: "%fiware_token%"
}
This behaviour is normal, as the WireCloud client code has no direct access to the IdM token of the user. It's the WireCloud's proxy which replaces the %fiware_token% pattern with the correct value.

JSONP to HTML Table using PLUGIN

I want to convert the JSON-P exposed by WCF service to a HTML Table.
For this i am using a plugin:
http://ajaxstack.com/jsonreport/
(THis is a excellent plugin because it handles date very well..)
It has a function:
_.jsonreport(jop);
where jop shoule be a JSON data.
To get the json data i am using jquery get:
To use this:
$.get('http://localhost:1256......', function (jop) {
alert(jop);
var test = _.jsonreport(jop);
alert(test);
});
But i started getting PERMISSION DENIED ERRORS in almost every browser except IE
(Might be because of cross domain restrictions....).
Can i get complete json using ajax. Actually ajax returns objects not complete JSON
How can i tackle this.
Any help is appreciated
I think you can us typical jsonp for this. Have you used it at all successfully in not IE browsers (IE being a microsoft prod, allows ur localhost to access xDomain if you've visited and deemed the other domain safe).
If u cannot use regular jsonp, I suggest using flyJSONP/YQL, jankyPOST/jankyPOST techniques.
reg jsonp:
script src="somedomain.com/somepage.json?myCallbackFunction=jsonp" /script
function myCallbackFunction(data){
return data
}
Hope this helps...
I am using two different projects one for service and one for application in asp.net both application run on localhost with differnet port number and IE does not support cross domain so it throws an error.
So to fixed this i need to combine both projects.