MobileFirst SAP Adapter http POST requests - sap

How do we pass header such as "content-type" in a SAP NW Adapter? I have to implement a $batch request from a MobileFirst hybrid app and for this need to set the content-type from the request.
How is that possible? I have searched through adapter documentation and nothing seems to help.

It's not possible to pass any headers to SAP NW adapters. If you're using v7.0, you might be able to make use of the RESTful Adapter Wizard along with Java adapters to pass the headers you're referring to: https://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.0.0/com.ibm.worklight.dev.doc/devref/t_impl_java_adapter_JAXRS.html

Related

invoking worklight adapter from external application

I am trying to invoke worklight adapter from external application. I also got the answer in Calling Worklight adapter from external app thread. However I dont want to send adapter name, procedure name and parameters as query params. Rather, I want to send them as payload inside request body. Pls suggest answers.
If you were using MFP v7.0+ you know that each MFP adapter is exposed as a REST API as well.
you just need to remove the security so external applications can access that REST API easily.
Not sure if its healthy to reduce security.
but you can mark the (via the adapter xml file) method as "wl_unprotected"

How to identify Worklight adapter calls in IBM HTTP Server logs?

Trying to identify worklight adapter requests from web server access logs, but all the requests look really generic. Any idea how to identify adapter requests?
The Request only contains "POST /Worklight/apps/services/api/MobileApp/android/query HTTP 1.1". I
can't see the adapter name nor procedure name.
while this query is indeed an adapter invocation , the adapter name, method and parameters are embedded into the POST HTTP message body. its not a big payload (less than 1KB).
I'm not an IHS log expert, but maybe there is a way to log also message body.
( I saw this un-answered: https://stackoverflow.com/questions/27354942)
However, if you upgrade to newer MFP version (v7.0+) then you can expose adapters as a RESTfull service. This will make the IHS logs much more clear which adapter was called (each one has different URL).

How to invoke Java adapter from HTTP adapter?

Is there any API to invoke a Java adapter from a HTTP adapter in IBM MobileFirst Platform Foundation 7.0?
I have tried with WL.Server.invokeHttp(input), but received a 404 response. What should be the value for 'path' in the input?
It is currently not possible to directly call a Java adapter from a JavaScript adapter.
You are encouraged to submit a feature request: https://developer.ibm.com/mobilefirstplatform/help
Alternatives:
Implement a JavaScript adapter that invokes Java code. See the tutorial Using Java in JavaScript adapters
Use another JavaScript adater - set the Java adapter as the backend it connects to and call it from the requesting JavaScript adapter
Rough steps to follow:
You have JavaScript adapter A
This adapter calls a procedure in another JavaScript adapter, adapter B (adapter mashup)
JavaScript adapter B will set in its XML the Java adapter properties as the backend (localhost, MFP server port)
Requests from this adapter should then be sent to /the-server-context-root/adapters/the-java-adapter/*
The Java adapter should have its security disabled, otherwise an access token would need to be forwarded in an header from the client in the request
As you can see the second option is less trivial to implement, and is less supported. I would investigate option 1...

MobileFirst - Use PHP / call RPG

i have two small questions about the mobilefirst- Server.
I found out, that the mobilefirst (or Worklight)-Server doesn't support PHP.
(IBM Worklight 6.0 - How to include a PHP file?)
Is that still so? Or is there any plan to include PHP?
Then I want to call RPG's with an Java-Adapter.
But I doesn't find any full example for calling a RPG.
Also I want to call RPG's with a Display File. Is that possible?
In the following article it sounds like it is easily possible:
http://www.it-zoom.de/dv-dialog/e/vom-greenscreen-zum-touchscreen-10865/
IBM MobileFirst server sits on top of a WebSphere Java EE based App Server. The MobileFirst Platform Adapter pattern is a server-side layer that provides abstraction to any generalized end-point; including PHP, SQL, SAP, whatever. So as long as your final endpoint is capable of acting as a "service", accepting HTTP requests, and producing JSON/XML responses, this pattern should work fine. The basic flow is:
mobile app client calls the MFP adapter
adapter calls the final endpoint (PHP/RPG in your case)
Endpoint responds with JSON/XML data
Adapter optionally converts response to JSON
Mobile client app receives and processes (displays) a consistent response from the adapter.
Hope this helps clarify the pattern for you.
PHP is a server-side HTML rendering technology. MobileFirst is (partly) for building hybrid mobile applications, which run on the client (mobile), so PHP wouldn't be relevant.
I'm not sure what an RPG is. Please can you specify the acronym in your question?

IBM Worklight Adapter requires OAuth

Here is my problem: I would like to create an application with IBM Worklight which will call via an adapter a service that requires OAuth (ie: Twitter).
Anyone have some thought for the best method to implement this using IBM Worklight?
For example, use one method to get the token, store the token in the session and then other methods to interact with the service?
Is there some out of the box functionality in IBM Worklight to handle the token acceptance in such case (ie: automatically open a browser to provide the authorization)?
Many thanks
Dominique
You can use the cordova inappbrowser plugin to get the access token and pass the token to the Worklight adapters. I am working on a devworks article now with an example so I will update this response with a link once it's live.
Here's the link to the article that might be helpful to you: http://www.ibm.com/developerworks/library/mo-worklight-linkedin/index.html