Soap Adpter Isssue:Cannot read property "Body" from undefined: WORKLIGHT - javascript

I am making a adapter for HTTP soap based invocation, code for invocation is given below while invoking the adapter i am getting error like :"Cannot read property "Body" from undefined" .
SOAPAdapter.xml is:
<wl:adapter xmlns:wl="http://www.worklight.com/integration" xmlns:http="http://www.worklight.com/integration/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="SOAPAdapter">
<displayName>SOAPAdapter</displayName>
<description>SOAPAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>*.*.com</domain>
<port>80</port>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="2"/>
</connectivity>
<procedure name="get_soap_req_list"/>
SOAPAdapter-impl.js is:
function get_soap_req_list() {
var request =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+'<soap:Body>'
+'<AddList xmlns="http://schemas.microsoft.com/sharepoint/soap/">'
+'<listName>tiu</listName>'
+'<description>uyt</description>'
+'<templateID>6</templateID>'
+'</AddList>'
+'</soap:Body>'
+'</soap:Envelope>';
WL.Logger.debug("###"+request);
var input = {
method : 'post',
returnedContentType : 'xml',
path : '/_vti_bin/Lists.asmx',
body : {
content: request.toString(),
contentType: 'text/xml; charset=utf-8'
}
};
**27** var result = WL.Server.invokeHttp(input);
**28** return result;
}
console error is:
E: An error occurred while invoking procedure SOAPAdapter/get_soap_req_listFWLSE0100E: parameters:{
"arr": [
9
]
}
TypeError: Cannot read property "Body" from undefined (D%3A%5CWorklightworkSpace%5Cmodule_05_2_HTTP_Adapter%5Cadapters%5CSOAPAdapter/SOAPAdapter- impl.js#42)
FWLSE0101E: Caused by: null
result OutPut:
{
"errors": [
],
"info": [
],
"isSuccessful": true,
"responseHeaders": {
"Content-Length": "0",
"Date": "Thu, 20 Jun 2013 11:08:03 GMT",
"MicrosoftSharePointTeamServices": "14.0.0.6123",
"SPRequestGuid": "7a89adce-9ede-4197-bfc4-aff18e85e763",
"Server": "Microsoft-IIS/7.5",
"WWW-Authenticate": "NTLM",
"X-MS-InvokeApp": "1; RequireReadOnly",
"X-Powered-By": "ASP.NET"
},
"responseTime": 156,
"statusCode": 401,
"statusReason": "Unauthorized",
"text": "",
"totalTime": 172,
"warnings": [
]
}

Change to "return result;"
What is the output?

Related

How to get the value of one of the key-value pairs of JSON in JavaScript?

I want to get the value of gid in JavaScript
alert(JSON.stringify(data); √
alert(JSON.stringify(data['responseJSON']['gid'])); ×
I tried to use it like this but I got an error.
I found a lot of answers but still can't get the value I need.
{
"form": {},
"files": [{}],
"filenames": ["timg.jpg"],
"filescount": 1,
"extra": {},
"response": {
"success": true,
"msg": "image url after upload",
"gid": 81
},
"reader": {},
"jqXHR": {
"readyState": 4,
"responseText": "{\"success\":true,\"msg\":\"image url after upload\",\"gid\":81}",
"responseJSON": {
"success": true,
"msg": "image url after upload",
"gid": 81
},
"status": 200,
"statusText": "OK"
}
}
alert(JSON.stringify(data));
I want to get the value of gid (81),but it is not use.
ouhre! Welcome to Stackoverflow. Here is a way to get the value of 'gid'.
let json = {
form: {},
files: [{}],
filenames: ["timg.jpg"],
filescount: 1,
extra: {},
response: { success: true, msg: "image url after upload", gid: 81 },
reader: {},
jqXHR: {
readyState: 4,
responseText: '{"success":true,"msg":"image url after upload","gid":81}',
responseJSON: { success: true, msg: "image url after upload", gid: 81 },
status: 200,
statusText: "OK"
}
};
alert(json.jqXHR.responseJSON.gid)
You can check this out live at this Codesandbox, here, or read more about handling JSON and Objects in Javscript, here and here!

firebase "long link is not parsable"

I want to shorten a longLink with firebase and the REST API but I get the following response and I don't know what is wrong:
Response:
{
"error": {
"code": 400,
"message": "Long link is not parsable: https://www.google.de [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]",
"status": "INVALID_ARGUMENT"
}
}
And this is how I do it:
The Request: https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=(hereismyapikey)
the Body lookes like this:
{
"longDynamicLink": "https://www.google.de",
"suffix": {
"option": "SHORT"
}
}
I tried first with the real URL I want to shorten. Same error. Than with google and with and without the http(s). I'm out of options and hope somebody sees what I did wrong here.
EDIT: Full Postman request:
"item": [
{
"name": "shortLinks",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"longDynamicLink\": \"www.google.de\",\r\n \"suffix\": {\r\n \"option\": \"SHORT\"\r\n }\r\n}"
},
"url": {
"raw": "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=xxx",
"protocol": "https",
"host": [
"firebasedynamiclinks",
"googleapis",
"com"
],
"path": [
"v1",
"shortLinks"
],
"query": [
{
"key": "key",
"value": "xxx"
}
]
}
},
"response": []
}
]
You are using the simple method for creating dynamic link which is roughly equals to the manual creation of dynamic link : https://firebase.google.com/docs/dynamic-links/create-manually
In the docs if you see the link passed in example carefully you will see the pattern as below:
https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]
So you should format the input link according to this or create using the parameters which has very good breakdown of parameters in json:
https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters
Here is the api reference for firebase dynamic link creation from parameters:
https://firebase.google.com/docs/reference/dynamic-links/link-shortener#parameters
I find the JSON parameter method is easier.
var body = {
"dynamicLinkInfo": {
"dynamicLinkDomain": "yourcustom.page.link",
"link": fileUrl
},
"suffix": {
"option": "SHORT"
}
};
Then if you're using Node. The node-fetch package REST call would work like:
var fetchFileUrl = fetch(YOUR_SHORTLINK_URL, {
method: 'POST',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' },
}).then(function(response){
return response.json();
});

Is there any way in nodejs to print log4js output in JSON format?

I am trying to get output of log4js in JSON format so I can easily trace it.
Is there any way that we have to set in configuration.json so output produced by log4js will be in JSON format?
Currently I am using following config.
{
"appenders": [
{
"category": "XXXXX",
"type": "dateFile",
"filename": "XXXXXXXX",
"pattern": "-from-MM-dd",
"layout": {
"type": "messagePassThrough"
}
},
{
"category": "XXXXXXXXX",
"type": "dateFile",
"filename": "XXXXXXXX",
"pattern": "-from-MM-dd",
"layout": {
"type": "messagePassThrough"
}
}
],
"levels": {
"XXXXConfig": "INFO",
"XXXXXjectConfig" : "INFO"
}
}
and I got output is in following format :
DEBUG: 1458562784032 : 2016-03-21T12:19:44.4444+00:00 : Data in request: : {
"action": "XXXXXXX",
"user": {
"username": "XXXX",
"id" : XXXX,
"pos" : XXXX
},
"version": 111
}
instead I want it in (Something like following structure) :
{"id" : "1458562784032", "time" : "2016-03-21T12:19:44.4444+00:00", "message" : "Data in request:", "data" : "{
"action": "XXXXXXX",
"user": {
"username": "XXXX",
"id" : XXXX,
"pos: : XXXX
},
"version": 111
}" }
May be there is something I missing in config.
Thanks for helping.
There are two ways to implement this issue now, you can add your own layouts or pattern format.
Below is the sample code of adding your own layouts with JSON format
const log4js = require('log4js');
log4js.addLayout('json', function(config) {
return function(logEvent) { return JSON.stringify(logEvent) + config.separator; }
});
log4js.configure({
appenders: {
out: { type: 'stdout', layout: { type: 'json', separator: ',' } }
},
categories: {
default: { appenders: ['out'], level: 'info' }
}
});
const logger = log4js.getLogger('json-test');
logger.info('this is just a test');
We can use bunyan for same purpose which logs your console log in JSON format.
Here is the npm link for node : https://www.npmjs.com/package/bunyan.
Also even if you want to use log4js then create your own pattern and write log file into JSON format.
Thanks.

Problems using api auth with Google Calendar JS API

I'm working on a small website that can do stuff with the Google Calendar API. I've posted it over here: http://evansiroky.com/temp-gcal-question/tests/ Whenever I try to authorize, it doesn't seem to matter what clientId I use, it always says it is authorized. Also, it doesn't seem to matter if immediate is set to true or false. Here is the authorization code:
gapi.auth.authorize({
client_id: clientId,
scope: ['https://www.googleapis.com/auth/calendar'],
immediate: immediate
}, function(authResult) {
if(authResult && !authResult.error) {
isAuthorized = true;
} else {
isAuthorized = false;
}
if(callback) {
var out = isAuthorized ? null : authResult;
callback(out);
}
});
However, once I try to list events of a calendar, I get a dailyLimitExceededUnreg error. Here is the code for listing events:
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list(_.extend({
calendarId: 'primary',
orderBy: 'starttime',
singleEvents: true,
showDeleted: true,
}, options.data));
request.then(function(resp) {
options.success(resp);
}, function(reason) {
options.failure(reason);
});
});
And here is the error that is returned:
{
"result": {
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
},
"body": "{\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"usageLimits\",\n \"reason\": \"dailyLimitExceededUnreg\",\n \"message\": \"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.\",\n \"extendedHelp\": \"https://code.google.com/apis/console\"\n }\n ],\n \"code\": 403,\n \"message\": \"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.\"\n }\n}\n",
"headers": {
"date": "Fri, 02 Oct 2015 19:08:41 GMT",
"content-encoding": "gzip",
"server": "GSE",
"vary": "Origin, X-Origin",
"content-type": "application/json; charset=UTF-8",
"cache-control": "private, max-age=0",
"content-length": "215",
"expires": "Fri, 02 Oct 2015 19:08:41 GMT"
},
"status": 403,
"statusText": "OK"
}
What am I doing wrong?

Invalid JSON,Unexpected Token [duplicate]

This question already has an answer here:
AngularJS $http.post error Unexpected token F
(1 answer)
Closed 7 years ago.
I'm trying to send JSON data to server using angular, But getting JSON.parse error in firefox and Unexpected token in chrome.
It works sometime and throws error sometime.
I consider it is because of the timestamp I'm using to create some keys.
{
"genericformfieldId": "1",
"userId": "2",
"formData": {
"_1443551400000": [
{
"mValue": "HARYANA",
"type": "DropDown",
"name": "selectState"
}
],
"_1443637800000": [
{
"mValue": "CHHATTISGARH",
"type": "DropDown",
"name": "selectState"
}
],
"_1443810600000": [
{
"mValue": "sac",
"type": "SingleLineText",
"name": "departureFrom"
}
]
}
}
Please suggest.
Adding code for posting data
$http({
method: 'POST',
url: Url,
headers: { "Content-Type": "application/json" },
data: formData
})
.success( function( response, status, headers, config ) {
console.log( response );
if( response ) {
deferred.resolve( response );
}
})
.error( function( response, status, headers, config ) {
deferred.reject( null );
});
If you JSON.parse an object the "Unexpected token o" is thrown simply because you are trying to parse object.toString(), which is [object Object]. Try to JSON.parse('[object Object]'); ;)
This should work for you
var data = '{
"genericformfieldId": "1",
"userId": "2",
"formData": {
"_1443551400000": [
{
"mValue": "HARYANA",
"type": "DropDown",
"name": "selectState"
}
],
"_1443637800000": [
{
"mValue": "CHHATTISGARH",
"type": "DropDown",
"name": "selectState"
}
],
"_1443810600000": [
{
"mValue": "sac",
"type": "SingleLineText",
"name": "departureFrom"
}
]
}
}';
JSON.parse(data);
This answer https://stackoverflow.com/a/12719860/1868660 explains
Unexpected token ILLEGAL(…) issue
You must clean input json.
Check this:
https://jsfiddle.net/am190cv5/
Here's the source:
var s = '{"genericformfieldId": "1","userId": "2","formData": {"_1443551400000": [{"mValue": "HARYANA","type": "DropDown","name": "selectState"}],"_1443637800000": [{"mValue": "CHHATTISGARH","type": "DropDown","name": "selectState"}],"_1443810600000": [{"mValue": "sac","type": "SingleLineText","name": "departureFrom"}]}}';
var result = JSON.parse(s);
console.log(result);
Open the console and look the result.

Categories

Resources