Mobilefirst 7.1 Adapter - CLI - ibm-mobilefirst

I am using MobileFirst CLI 7.1. I am following the tutorial (https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/hello-world/integrating-mfpf-sdk-in-cordova-applications/) and almost everything works fine. I am using the RSSAdapter and I keep getting the following error when I deploy the app to the phone:
status : 500
responseHeaders {5}
X-Powered-By : Servlet/3.0
Content-Type : application/json
Content-Length : 430
Connection : Close
Date : Mon, 24 Aug 2015 09:55:41 GMT
responseText : {\"statusCode\":404,\"errors\":[\"White spaces are required between publicId and systemId.\",\"Failed to parse the payload from backend (procedure: HttpRequest)\"],\"isSuccessful\":false,\"statusReason\":\"Not Found\",\"responseHeaders\":{\"Date\":\"Mon, 24 Aug 2015 09:55:41 GMT\",\"Content-Length\":\"149\",\"Content-Type\":\"text/html;charset=UTF-8\",\"Connection\":\"close\",\"Server\":\"FeedsPortal\"},\"warnings\":[],\"totalTime\":276,\"responseTime\":244,\"info\":[]}
responseJSON {9}
statusCode : 404
errors [2]
0 : White spaces are required between publicId and systemId.
1 : Failed to parse the payload from backend (procedure: HttpRequest)
isSuccessful : false
statusReason : Not Found
responseHeaders {5}
warnings [0]
totalTime : 276
responseTime : 244
info [0]
invocationContext : null
This is how my code looks like:
--- RSSAdapter.xml ----
<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="RSSAdapter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>RSSAdapter</displayName>
<description>RSSAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>rss.cnn.com</domain>
<port>80</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store
<sslCertificateAlias></sslCertificateAlias>
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
</connectivity>
<procedure name="getStories"/>
<procedure name="getStoriesFiltered"/>
</wl:adapter>
----- RSSAdapter-impl.js ---
function getStories(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path
};
return WL.Server.invokeHttp(input);
}
function getStoriesFiltered(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path,
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);
}
function getPath(interest) {
if (interest == undefined || interest == '') {
interest = '';
}else {
interest = '_' + interest;
}
return 'rss/edition' + interest + '.rss';
}
--- JS ---
function invokeAdapter() {
var resourceRequest = new WLResourceRequest(
"/adapters/RSSAdapter/getStories",
WLResourceRequest.GET);
resourceRequest.send().then(success,error);
}
function success(res) {
console.log('Success');
console.log('res ', res);
/*console.log('Text ', res.responseJSON.rss.channel.item.length);*/
console.log('Text ', res.responseJSON);
alert("Total RSS Feed items received:"+res.responseJSON);
}
function error(error) {
console.log('Nei');
console.log('error ', JSON.stringify(error));
alert("Response error"+ JSON.stringify(error));
}

Update: in recent iFixes, the default adapter was changed to no longer point to CNN. If you haven't, please upgrade.
There is nothing wrong with your project. For whatever reason it appears that the default adapter created has stopped working with the CNN website; it is being investigated.
In the meanwhile you can either use an adapter from a different project (that is working with the engadget website), or create your own.
See for example the adapter that is provided as part of the Starter Application sample (you can copy the adapter folder to your MobileFirst project and use "mfp push" to deploy it to the server; make sure to update the adapter and procedure names in your applicative code).

Related

Mobilefirst 8.0 cordova apps not able to connect server

POC for MobileFirst 8.0 version apps and I created sample apps and maven based adapter. Finally I invoked that adapter index.js file to call the adapter its working fine when I used browser simulator but its not working while I installed android device I got below that error in android LOGCAT,
[ERROR:xwalk_autofill_client.cc(121)] Not implemented reached in virtual void xwalk::XWalkAutofillClient::OnFirstUserGestureObserved()
How to resolve this issue.
please find the implementation below.
adapter
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed Materials - Property of IBM
5725-I43 (C) Copyright IBM Corp. 2011, 2013. All Rights Reserved.
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-->
<mfp:adapter name="HttpAdapter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mfp="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>HttpAdapter</displayName>
<description>HttpAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>https</protocol>
<domain>mobilefirstplatform.ibmcloud.com</domain>
<port>443</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
</connectionPolicy>
</connectivity>
<procedure name="getFeed" secured="false"/>
<procedure name="unprotected" secured="false"/>
</mfp:adapter>
adapter implementation
function getFeed(tag) {
var input = {
method : 'get',
returnedContentType : 'xml',
path : getPath(tag)
};
return MFP.Server.invokeHttp(input);
}
/**
* Helper function to build the URL path.
*/
function getPath(tag){
if(tag === undefined || tag === ''){
return 'feed.xml';
} else {
return 'blog/atom/' + tag + '.xml';
}
}
/**
* #returns ok
*/
function unprotected(param) {
return {result : "Hello from unprotected resource"};
}
apps implementation
function myFunction(){
console.log('==================== inside calling ==================');
var resourceRequest = new WLResourceRequest(
"/adapters/HttpAdapter/getFeed",
WLResourceRequest.GET,3000
);
resourceRequest.setQueryParameter("params", "['']");
resourceRequest.send().then(
function(response) {
alert("------- success " +JSON.stringify(response));
},
function() {
alert("----------- >>> errror ------");
}
)
}
Please use mata tag in your HTML file it will resolve your issues for android.
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />

How To Retrieve Data From Rest API In Appcelerator

I have the misfortune of further developing an existing mobile application in Appcelerator. The app uses a Rest API on a remote server to read and write data. The API works well in test environments and in production. I need to post data to the API and read the output. Here is an example of what the output of the API looks like after a POST command:
{
"equipment":
{
"result": "create",
"id": 419213
},
"_meta":
{
"offset": 0,
"limit": -1,
"total_results": 1,
"url": "http://localhost:8080/api/v1/equipment",
"utc_start_time": 1459449461115,
"nano_total_time": 74771
}
}
I am able to successfully post the data in Appcelerator. I have verified this in the database that the CRUD operation is acting on. However, I am unable to get the aforementioned data from the httpClient object that makes the call, despite following the directions in the outdated Titanium documentation.
Here is my Appcelerator code:
var payload = "name=atad&asset_number=adtasd&department_id=185080&property_id=10086&designator_id=379828&is_leased=N&is_assignable_asset=N&status=A";
var url = "http://localhost:8080/api/v1/equipment";
var client = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info(e); // {}
Ti.API.info(e.source); // []
Ti.API.info(JSON.stringify(e.source)); // {}
Ti.API.info(JSON.stringify(e.source.reponseText)); // null
Ti.API.info(JSON.stringify(e.source.reponseData)); // null
Ti.API.info(this); // []
console.log(JSON.stringify(this)); // {}
Ti.API.info(JSON.stringify(this.reponseText)); // null
Ti.API.info(this.reponseData); // null
}
,onerror : function(e){
Ti.API.info(e);
alert("error");
}
});
var auth = 'Basic ' + Ti.App.Properties.getString('auth');
client.open("POST", apiUrl);
client.setRequestHeader('Authorization', auth);
client.setRequestHeader('Content-Type', 'text/plain');
client.send(payload);
Here is the console output:
[INFO] : {
[INFO] : code = 0;
[INFO] : source = "[object TiNetworkHTTPClient]";
[INFO] : success = 1;
[INFO] : type = load;
[INFO] : }
[INFO] : [object TiNetworkHTTPClient]
[INFO] : {"method":"POST","url":"http://localhost:8080/api/v1/equipment"}
[INFO] : <null>
[INFO] : <null>
[INFO] : [object TiNetworkHTTPClient]
[INFO] : {"method":"POST","url":"http://localhost:8080/api/v1/equipment"}
[INFO] : <null>
[INFO] : <null>
The documentation here http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient explicitly says to use this.responseText, but that is clearly not giving me the results I need. I need that "id" that is being returned from the server.
How do I read the data that is returned from the server after a post API call?
There is just a typo in this.responseText
Have a look at this module: https://github.com/jasonkneen/RESTe
It makes your life easier and gives you a great way to the same syntax for future projects!
If you want to keep your syntax (which is fine too):
have a look at this example: https://github.com/m1ga/titanium-libraries/blob/master/api.js#L49
and the following lines. It shows you how to read the JSON. Basically you have to wait for if (this.readyState === 4) {} inside the onload and then read the this.responseText or JSON.parse() it.
It looks like the apiUrl variable is not defined?
Which could explain a lot or your current frustration.

how to invoke adapters hybrid application MobileFirst Platform 6.3

i have some error
Caused by: FWLSE0099E: An error occurred while invoking procedure [project EMoney]InquiryAdapters/HttpRequestFWLSE0100E: parameters: [project EMoney]
Http request failed: org.apache.http.conn.HttpHostConnectException: Connect to rss.cnn.com:80 [rss.cnn.com/74.125.200.121] failed: Connection timed out: connect
FWLSE0101E: Caused by: [project EMoney]org.apache.http.conn.HttpHostConnectException: Connect to rss.cnn.com:80 [rss.cnn.com/74.125.200.121] failed: Connection timed out: connectjava.lang.RuntimeException: Http request failed: org.apache.http.conn.HttpHostConnectException: Connect to rss.cnn.com:80 [rss.cnn.com/74.125.200.121] failed: Connection timed out: connect
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to rss.cnn.com:80 [rss.cnn.com/74.125.200.121] failed: Connection timed out: connect
Caused by: java.net.ConnectException: Connection timed out: connect
inquiryAdapters.xml
<wl:adapter name="InquiryAdapters"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>InquiryAdapters</displayName>
<description>InquiryAdapters</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>rss.cnn.com</domain>
<port>80</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store
<sslCertificateAlias></sslCertificateAlias>
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
</connectivity>
<procedure name="getStories"/>
<procedure name="getStoriesFiltered"/>
<procedure name="getFeedsFiltered"/>
</wl:adapter>
inquiryAdapters.impl
function getStories(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path
};
return WL.Server.invokeHttp(input);}
function getStoriesFiltered(interest) {
path = getPath(interest);
var input = {
method : 'get',
returnedContentType : 'xml',
path : path,
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);}
function getFeedsFiltered() {
var input = {
method : 'get',
returnedContentType : 'xml',
path : "rss.xml",
transformation : {
type : 'xslFile',
xslFile : 'filtered.xsl'
}
};
return WL.Server.invokeHttp(input);}
function getPath(interest) {
if (interest == undefined || interest == '') {
interest = '';
}else {
interest = '_' + interest;
}
return 'rss/edition' + interest + '.rss';}
when i want to invoke the adapters (http adapters).
If you have followed the next steps yet you get a "Connection timed out" error, you likely have a network issue unrelated to MobileFirst Platform 6.3: check for any firewalls that prevent your connection to arrive to CNN.com
Created a new project
Create a new HTTP adapter
Right-click on adapter folder > Deploy MobileFirst Adapter
Right-click on adapter folder > Call MobileFirst Adapter
Now a browser window with the response should've opened.

IBM Worklight Adapters and OAuth -- header values in adapter

I'm currently working on an adapter call that takes an OAuth token in the Authorization header. The request works just fine in a FireFox RestClient AND an xhr get... but is failing from the Worklight adapter with an error saying the user needs to login. Which is the same error that the user would see if they didn't pass in the authorization header.
wl adapter:
function getFriends(accessToken) {
var authtok = 'Bearer ' + accessToken;
var input = {
method : 'get',
headers: {Authorization: authtok},
path : '/connections/opensocial/rest/people/#me/#self'
};
return WL.Server.invokeHttp(input);
}
Anyone else seeing an error like this? Is there a way to trace the worklight adapter invocation to inspect that the headers sent into the request are as expected?
Looks like your server was also expecting the hostname in the headers. Try changing your input to this:
var input = {
method : 'get',
returnedContentType : 'json',
path : '/connections/opensocial/rest/people/#me/#self',
headers: {
'Authorization': authtok,
Host: "HOSTNAME THAT IS USED IN THE .XML FILE"
}
};
So if your adapter's xml file looks like this:
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>https</protocol>
<domain>jeremy.server.whatever.com</domain>
<port>443</port>
-->
</connectionPolicy>
Then your headers should look like this:
headers: {
'Authorization': authtok,
Host: "jeremy.server.whatever.com"
}

worklight adapter

I am getting a problem in worklight adapter , In the following http adapter method
,it is showing The mandatory parameter 'action' is missing, returning statusCode as
500 and statusReason as "Internal Server Error". I had given all the user credentials
correctly in adapter xml file, but I don't know why I'm getting this error.
Code:
function actionOnProcessInstance()
{
var param = "/rest/bpm/bfm/v1/process/_PI:9003013d.4387342e.1efe573f.7c20307?action=resume";
var input =
{
method : 'put',
returnedContentType : 'json',
path : param,
};
var response = WL.Server.invokeHttp(input);
return response;
}
In 5.0.5.x, invokeHttp will take any params provided on the path for put and post and place them inside the http body instead of having them remain on the path as query params (as the developer probably intended). This behavior will be updated in an upcoming version but for now there's no way to force these to stay as query params.