How to invoke Java adapter from HTTP adapter? - ibm-mobilefirst

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...

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"

Accessing Soap service using java adapter in mobilefirst

I have written a SOAP WSDL application using mobilefirst by:
1) Using the Discover backend services option
2) Writing my own JavaScript adapter code to follow the documentation provided by IBM.
Now my final R&D is to consume this soap service using a java adapter.
I have gone through many StackOverflow topics and samples but I haven't been able to find anything related. Can anyone explain the steps to invoke a SOAP-based webservice request using java adapter?
The following video blog post details the following about Java adapers: https://www.youtube.com/watch?v=cKM5480-6wI
Creating Java Adapter
Understanding Java Adapter structure
Implementing simple sayHello procedure for HTTP GET method
Implementing several procedures for different HTTP methods
Working with various types of request parameters
Using Java code to access MobileFirst server functionality and Java servlet functionality
Debugging Java Adapters
Communicating with a simple backend using using Apache HTTP Client
Leveraging WSDL files and communicating with a SOAP based webservice
Using WLResourceRequest in client applications to communicate with Java Adapters
Using Postman REST client for communicating with Java Adapters
Create HTTP Adapter
In xml add WebService Host and Port in Domain/Port elements
Assemble soapXMLRequest
Use HTTP Invoke to call server
ex.
var input = {
method : 'post',
returnedContentType : 'xml',
headers : {
SOAPAction : SOAP_FULL_URL
},
path : WEBSERVICE_PATH,
body : {
content : soapXMLRequest,
contentType : 'text/xml; charset=utf-8'
}
};
var response = WL.Server.invokeHttp(input);

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 procedure from JS adapter procedure in MobileFirst Platform 7.0?

Our team is migrating to MobileFirst Platform 7.0 because of Java adapters introduced in this version. And after having a quick look I haven't found how to invoke procedures in Java adapter from procedures in JavaScript adapters. Looks like Java adapter doesn't define procedures and has only REST endpoints. How to access them from JS adapter?
In general the new RESTful JAX-RS (Java-based) adapters in version 7.0 operate independently of the old JavaScript-style adapters. I'm not aware of an in-process API to call them, so you would have to call them like any other RESTful service using WL.Server.invokeHttp (i.e. like how you might typically do this using the HTTP adapter).
However, don't confuse the new RESTful JAX-RS (Java-based) adapters with using custom Java code in older-style JavaScript adapters, which you can also do (and were able to do prior to 7.0). See this tutorial for more information on the latter.

Use of third parameter in the WL.Client.InvokeProcedure

I am using the client side API WL.Client.InvokeProcedure(invocationData, options, UseSendInvoke) in worklight 6. But I could not find a description for the parameter UseSendInvoke in the API. Do you guys know what it is?
This parameter is used internally by WL authentication framework. Technically there should not be a reason for developer to use it.
There are several ways to invoke adapters.
(1) First one is via client application. This is where you use WL.Client.invokeProcedure(invocationData, options) API.
(2) Second is by using adapter invocation service - http://pic.dhe.ibm.com/infocenter/wrklight/v6r0m0/index.jsp?topic=%2Fcom.ibm.worklight.help.doc%2Fdevref%2Fc_adapter_invocation_service.html. Basically issuing an http request to WL server and getting a response from adapter. RPC style.
When you're doing it via (1) - you have two authentication layers - first is security test defined for application, second is security test defined for adapter procedure.
When you're doing it via (2) - there is only one security layer - security test defined for adapter procedure.
UseSendInvoke param (which is, once again, for internal usage) means that your application will go via path (2) instead of regular path (1).
There's no UseSendInvoke argument that WL.Client.invokeProcedure takes, at least not in the public API defined in the documentation. You can look at the documentation for Worklight v6.0.0, Worklight v5.0.6, Worklight v5.0.5 to learn more about that particular API.