Get PDF files from Worklight Server to the client - pdf

Based on the following reference:- Worklight Adapter getting pdf file from rest service, i got the PDF file from tomcat server through the worklight adapter. The server side code is:-
var input = {
method : 'get',
returnedContentType : 'plain',
path : '/PDF/example-abstract.pdf'
};
return WL.Server.invokeHttp(input);
When i invoke the invoke the procedure i am able to successfully retrieve the result. When i invoke the same procedure from client side like below:-
var invocationData = {
adapter: 'PdfReader',
procedure: 'readPDF',
parameters: []
};
I am unable to receive the response in the success handler. In logcat it showing the following error:-
07-03 13:07:05.330: E/pdf(4214): [http://Path-to-pdf:10080/pdf/apps/services/api/pdf/android/query] exception. SyntaxError: Unexpected token ILLEGAL
07-03 13:07:05.377: D/dalvikvm(4214): GC_FOR_ALLOC freed 347K, 10% free 8082K/8967K, paused 19ms
07-03 13:07:05.424: D/dalvikvm(4214): GC_CONCURRENT freed 155K, 7% free 8390K/8967K, paused 2ms+3ms
07-03 13:07:05.424: D/pdf(4214): response [http://Path-to-pdf:10080/pdf/apps/services/api/pdf/android/query] success: {"responseID":"2","statusCode":200,"text":"%PDF-1.4\n%????\n3 0 obj <<\n\/Length 2445 \n\/Filter \/FlateDecode\n>>\nstream\nx?X[??\n~?_?#?YQ?O?dw??M??3?4'\u000f0 \\Shorted
07-03 13:07:05.424: W/PluginManager(4214): THREAD WARNING: exec() call to Logger.DEBUG blocked the main thread for 45ms. Plugin should use CordovaInterface.getThreadPool().
07-03 13:07:05.455: E/pdf(4214): [http://Path-to-pdf:10080/pdf/apps/services/api/pdf/android/query] exception. TypeError: Cannot read property 'isSuccessful' of undefined
07-03 13:07:05.455: D/CordovaLog(4214): file:///data/data/com.pdf/files/www/default/worklight/worklight.js: Line 3320 : Uncaught SyntaxError: Unexpected token ILLEGAL
07-03 13:07:05.455: E/Web Console(4214): Uncaught SyntaxError: Unexpected token ILLEGAL at file:///data/data/com.pdf/files/www/default/worklight/worklight.js:3320
07-03 13:07:05.463: D/CordovaLog(4214): file:///data/data/com.pdf/files/www/default/worklight/worklight.js: Line 3320 : Uncaught TypeError: Cannot read property 'isSuccessful' of undefined
07-03 13:07:05.471: E/Web Console(4214): Uncaught TypeError: Cannot read property 'isSuccessful' of undefined at file:///data/data/com.pdf/files/www/default/worklight/worklight.js:3320
I need to know, how to make it reachable in the successHandler. Thanks in advance.

The problem is with parsing the JSON data, based on the following answer, I have converted the Json data to string using JSON.stringify(), so that the string can successfully reach the successHandler inside the handler i am using JSON.parse() to convert the string to JSON for use.

Related

How can I solve the error of Smart Contract?

I try to Call Smart Contract by NEAR Protocol for the first time.
Please tell me how can I solve the error as follows.
I have created Testnet NEAR Account.
I have compiled "Counter" Contract by using this example "https://github.com/near-examples/rust-counter/blob/master/contract/src/lib.rs".
I have deployed this contract to the testnet by using "near cli", and it has been succeed.
I call "veiw function" of near cli,Error Returned.
% near view Counter get_num '{}'
View call: Counter.get_num({})
An error occured
Error: [-32000] Server error: Account ID Counter is invalid
at /Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:322:31
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Object.exponentialBackoff [as default] (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24)
at async JsonRpcProvider.sendJsonRpc (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:297:24)
at async JsonRpcProvider.query (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:109:22)
at async Account.viewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:356:24)
at async exports.callViewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/index.js:75:48)
at async Object.handler (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9)
TypedError: [-32000] Server error: Account ID Counter is invalid
at /Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:322:31
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Object.exponentialBackoff [as default] (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24)
at async JsonRpcProvider.sendJsonRpc (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:297:24)
at async JsonRpcProvider.query (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:109:22)
at async Account.viewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:356:24)
at async exports.callViewFunction (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/index.js:75:48)
at async Object.handler (/Users/shin.takahashi/.nodebrew/node/v14.14.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
type: 'UntypedError',
context: undefined
}
Counter is not a valid account-id. Uppercase letters in accounts-id are not allowed). You need to pass the proper account-id.
I would expected your account-id to be something of the form takahashi.testnet or dev-1623565709996-68004511819798 (if contract was deployed using near dev-deploy command).
This is how you can deploy to testnet using dev-deploy, and call view function using near-cli:
❯ near --version
2.0.2
❯ near dev-deploy out/main.wasm
Starting deployment. Account id: dev-1623565709996-68004511819798, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: out/main.wasm
Transaction Id 5eTde2dUw5QTA8hbpWvAw4ABary64Tsnj9FzBCPS9Ne
Done deploying to dev-1623565709996-68004511819798
❯ near view dev-1623565709996-68004511819798 get_num '{}'
View call: dev-1623565709996-68004511819798.get_num({})
0
If you are using mainnet network (instead of testnet), you need to let near-cli knows about this, by setting the environment variable:
❯ export NEAR_ENV=mainnet

WebRTC Error - Session error description: Data channel type mismatch. Expected RTP, got SCTP

I am new to WebRTC and triyng to create my first app. I have found this article https://www.tutorialspoint.com/webrtc/webrtc_quick_guide.htm and did as it was said there. The resulted app works fine if I test it in the Chrome. But when I try to test this app in 2 browser (Chrome and Mozilla) it gives me this error:
Uncaught (in promise) DOMException: Failed to execute
'setRemoteDescription' on 'RTCPeerConnection': Session error code:
ERROR_CONTENT. Session error description: Data channel type mismatch.
Expected RTP, got SCTP..
This happens when I send an offer from Mozilla client and Chrome client tries to give an answer to this offer in this part of code:
myConnection.setRemoteDescription(new RTCSessionDescription(offer));
myConnection.createAnswer(function (answer) {
myConnection.setLocalDescription(answer);
send({
type: "answer",
answer: answer
});
}, function (error) {
alert("oops...error"); //<-- this alert fires all the time
});
I have googled this and all I have found is set new RTCPeerConnection(configuration, { optional: [{RtpDataChannels: false}] }) but if I do so then when I try to send a message it says that dataChannel.readyState is not openned.
What do I do wrong? Any help appriciated!
Thanks!
Remove optional: [{RtpDataChannels: true}] and then wait for the datachannel.onopen event to fire before attempting to send messages.

Intercept api errors

I'm using react-admin with standard crud options, I want to react to the RA/CRUD_GET_LIST_FAILURE (and all others in the future) to logout the user if the error is a 401 (like when the token timed out)
How am I supposed to do this ?
On custom requests I have my own sagas which handle this in the catch part and correctly do the job.
If I try to intercept the RA/CRUD_GET_LIST_FAILURE like this :
function * loadingErrorRA (action) {
var e = action.payload;
console.error('loadingError',action);
if(action.error === "Unauthorized"){
//I can't find a better way because I don't have access to the fetch response object in here
yield put(userLogout());
yield put(showNotification('Disconnected','warning'));
} else {
yield put(showNotification('Error '+action.error,'warning'));
}
}
function * errorLoadingSaga() {
yield takeLatest('RA/CRUD_GET_LIST_FAILURE', loadingErrorRA);
}
I have a blank screen and an error pops :
ListController.js:417 Uncaught TypeError: Cannot read property 'list' of undefined
at Function.mapStateToProps [as mapToProps] (ListController.js:417)
at mapToPropsProxy (wrapMapToProps.js:43)
at handleNewPropsAndNewState (selectorFactory.js:34)
at handleSubsequentCalls (selectorFactory.js:67)
at pureFinalPropsSelector (selectorFactory.js:74)
at Object.runComponentSelector [as run] (connectAdvanced.js:26)
at Connect.componentWillReceiveProps (connectAdvanced.js:150)
at callComponentWillReceiveProps (react-dom.development.js:11527)
....
index.js:2178 The above error occurred in the <Connect(TranslatedComponent(undefined))> component:
in Connect(TranslatedComponent(undefined)) (created by List)
in List (created by WithStyles(List))
in WithStyles(List) (at SalesByOrganismList.js:40)
in div (at SalesByOrganismList.js:39)
in SalesByOrganismList (created by WithPermissions)
in WithPermissions (created by Connect(WithPermissions))
in Connect(WithPermissions) (created by getContext(Connect(WithPermissions)))
...
And then saga catch it with :
index.js:2178 uncaught at loadingErrorRA TypeError: Cannot read property 'list' of undefined
at Function.mapStateToProps [as mapToProps]
...
Thanks for the help
https://marmelab.com/react-admin/DataProviders.html#error-format
When the API backend returns an error, the Data Provider should throw an Error object. This object should contain a status property with the HTTP response code (404, 500, etc.). React-admin inspects this error code, and uses it for authentication (in case of 401 or 403 errors). Besides, react-admin displays the error message on screen in a temporary notification.
And https://marmelab.com/react-admin/Authentication.html#catching-authentication-errors-on-the-api
Each time the API returns an error, the authProvider is called with the AUTH_ERROR type. Once again, it’s up to you to decide which HTTP status codes should let the user continue (by returning a resolved promise) or log them out (by returning a rejected promise).

freediameter - No remaining suitable candidate to route the message

Well, I've started a simple project with freediameter library. what I need to achieve in my project is to create a client diameter application that could send some CCR request to a diameter server.
for this matter, I tried to create a new extension for freediameter daemon.
So, the first thing I did was to setup the peer diameter server in config file:
ConnectPeer = "vm-pc.my.domain" { No_TLS; ConnectTo = "192.168.56.2"; Port=3868; };
and then initialize a request message in ta_entry function, in message body i specified the Destination-Host and Destination-Realm but still I receive this error:
01/10/17,01:55:24.980611 ERROR Routing error: 'No remaining suitable candidate to route the message to' for the following message:
01/10/17,01:55:24.980620 ERROR 'Credit-Control-Request'
01/10/17,01:55:24.980628 ERROR Version: 0x01
01/10/17,01:55:24.980635 ERROR Length: 20
01/10/17,01:55:24.980642 ERROR Flags: 0xC0 (RP--)
01/10/17,01:55:24.980649 ERROR Command Code: 272
01/10/17,01:55:24.980656 ERROR ApplicationId: 4
01/10/17,01:55:24.980664 ERROR Hop-by-Hop Identifier: 0x00000000
01/10/17,01:55:24.980671 ERROR End-to-End Identifier: 0xDCA05EF4
01/10/17,01:55:24.980678 ERROR {internal data}: src:(nil)(0) rwb:0x0 rt:0 cb:0x80523df30,0x0(0x803397da0) qry:0x0 asso:0 sess:0x0
01/10/17,01:55:24.981562 ERROR AVP: 'Session-Id'(263) l=8 f=-M val="hadi-pc.my.domain;1484000714;6"
01/10/17,01:55:24.981569 ERROR AVP: 'Origin-Host'(264) l=8 f=-M val="hadi-pc.my.domain"
01/10/17,01:55:24.981577 ERROR AVP: 'Origin-Realm'(296) l=8 f=-M val="my.domain"
01/10/17,01:55:24.981584 ERROR AVP: 'Destination-Host'(293) l=8 f=-M val="vm-pc.my.domain"
01/10/17,01:55:24.981591 ERROR AVP: 'Destination-Realm'(283) l=8 f=-M val="my.domain"
01/10/17,01:55:24.981599 ERROR AVP: 'Auth-Application-Id'(258) l=12 f=-M val=4 (0x4)
01/10/17,01:55:24.981606 ERROR AVP: 'CC-Request-Type'(416) l=12 f=-M val='EVENT_REQUEST' (4 (0x4))
01/10/17,01:55:24.981613 ERROR AVP: 'CC-Request-Number'(415) l=12 f=-M val=2 (0x2)
Can anybody help me on this ?
ps: as I see in the logs the CER/CEA are normal.
What Origin-Realm was signaled in the Capability-Exchange-Answer message when the connection was established?
The Diameter request routing process (as described in https://www.rfc-editor.org/rfc/rfc6733#section-6.1) relies on the realm, so if the Origin-Realm returned by the peer is not "my.domain", freeDiameter will not route to this peer, even if the Origin-Host matches.

changing privacy settings of video using vimeo api

i am trying to change the privacy settings of vimeo video using api class
below is my code
$vimeo = new phpVimeo('myconsumer_key', 'myconsumer_secret');
$info = $vimeo->call('vimeo.videos.setPrivacy', array('video_id' =>$videoid,'privacy'=>'nobody','users'=>$username,'password'=>""));
i provided the consumer key and consumer secret key which i generated from https://developer.vimeo.com/apps/new but when i call the function error occoured
Fatal error: Uncaught exception 'VimeoAPIException' with message 'Permission Denied' in D:\phpweb\Rohith\vimeo_video\vimeo.php:239 Stack trace: #0 D:\phpweb\Rohith\vimeo_video\vimeo.php(275): phpVimeo->_request('vimeo.videos.se...', Array, 'GET', 'http://vimeo.co...', true) #1 D:\phpweb\Rohith\vimeo_video\disablevideo.php(18): phpVimeo->call('vimeo.videos.se...', Array) #2 {main} thrown in D:\phpweb\Rohith\vimeo_video\vimeo.php on line 239