This question is related to - [How to invoke Java adapter from HTTP adapter? ][1]
I have 2 adapters in my MobileFirst 7.1 project :
A Java Adapter that is exposing Rest Endpoint.
A JavaScript adapter will call the Java Adapter via Rest Endpoint
To be exact, this is what I call in the JS adapter :
function JSAdapterCalltoJavaAdapter() {
var input = {
method : 'get',
returnedContentType : 'xml',
path : "adapter/JavaAdapterRestPath"
};
return WL.Server.invokeHttp(input);
}
We have run JMeter load test for 800 Threads on Java Adapter, there is no issue. However, when we run load Test on JS Adapter, the MobileFirst server stop responding, and does not accept incoming request from JS Adapter. The new requests timeout and the MobileFirst console become unresponsive. When we stop the load test, the server gradually recovered.
I have configured the following params adapter.xml :
<connectionTimeoutInMilliseconds>, <socketTimeoutInMilliseconds>, and <maxConcurrentConnectionsPerNode>
It seems like there is threading issue when using JS adapter to call Java adapter under load.
Sounds like you need to open a PMR (support ticket) if you are encountering a threading issue in the MobileFirst Server so that the support/dev team could help you. If you have an actual programming question, ask it.
Related
I'm looking to write a Ktor feature that should announce the service on a local network using DNS-SD/mDNS. I would like to be able to automatically start the announcing on ktor application start and stop it on ktor application stopped. I've written code that does this using ApplicationStarted and ApplicationStopped event. This code works.
However, I can find no way of getting what IP address/port from ktor other than reading the configuration.
Is there any way of listening for/listing the connectors that ktor is currently using?
You can access connectors through the BaseApplicationEngine instance:
val server = embeddedServer(Netty, 9091) {}
println(server.environment.connectors)
or by casting environment to ApplicationEngineEnvironment:
fun Application.module(testing: Boolean = false) {
(environment as ApplicationEngineEnvironment).connectors.forEach { connector ->
println("${connector.host}:${connector.port}")
}
}
My MFP Version is 8.0.0-2017012016.
When I am trying to call a Java Adapter from other Java Adapter, it is always throwing NullPointerException at the line:
HttpResponse response = adapterAPI.executeAdapterRequest(req);
What I have done is create the adapter named Producer, which contains method named sayHello which I am calling from Consumer Adapter.
Consumer Adapter contains method named getHello, which is consuming above mentioned sayHello method.
I have tested sayHello method alone and it is working fine.
I have tested the getHello method using WLResourceRequest and also with Swagger, but it is always throwing error.
Here is the link to download both the adapters. Both adapters are inside zip file.
Any help is greatly appreciated.
Thanks.
I am creating multiple applications which works the same. For every application I use an adapter which contains the same procedures, but perform the request to a different back end (same host, only different path).
The thing I would like is to add a configuration file (json / xml) to the adapters which I can load and fetch some information from such as the path so I know which back end I need to call. The configuration is now in top of the file, but in the future it would be lovely to be able to update the adapter without changing the configuration afterwards.
Is there a way to load a second file located in the same directory (as where the adapter xml and implementation file are)? I tried using XMLHttpRequest, but this doesn't work as it is unavailable. The code I tried, but couldn't test as the fifth line already breaks.
var config = null;
function loadConfiguration() {
var loader = new XMLHttpRequest();
loader.overrideMimeType('application/json');
loader.open('GET', 'config.json', false);
loader.onreadystatechange = function () {
// Only for async calls.
config = loader.responseText;
};
config = loader.send();
}
If there is a better way, I would love to hear it! We upgraded to MFPF 7.0 if there are any new possibilities.
You cannot do this with JavaScript adapters, however in MFPF 7.0 there is a new type of adapters: Java adapters. Using Java adapters you can achieve this.
The following blog post explains how you can provide a single adapter that will allow you to point to different hosts or differents paths in the same host, etc...
See here: Changing the adapter host at runtime
In Worklight 5.0.6, we have created an eventSource using the following:
WL.Server.createEventSource({
name: 'ReminderSource',
onUserSubscribe: 'userSubscribeFunc',
poll: {
interval: 86400,
onPoll: 'getReminders'
}
});
The getReminders procedure then calls other HTTP and SQL adapters to determine if we should send a Push Notification. When we deploy this to our Worklight server, we see the following error any time we try to call one of the procedures in another adapter:
The resource 'proc:tbl_member.getPreferences' should only be accessed
when authenticated in realm 'wl_antiXSRFRealm'.
We've tried using a mobileSecurityTest (which includes the wl_antiXSRFRealm) to protect the eventSource, but we get the same error. Is there a way to have our polling adapter procedure somehow "log in" to the antiXSRFRealm?
We can't make the other adapter procedures unprotected, because they do need to be protected.
antiXSRF is used for client-server cross scripting attack detection. It doesn't do too much for invocations between adapter procedures. Try creating a custom security test and adding only user realm there, no antiXSRF.
I've encountered a problem during development.
When the adapter is tested from within Eclipse ("Invoke Worklight procedure"), it does its job perfectly.
On the contrary, when the adapter is called from the app, it doesn't work. I receive the following error:
Error 405 HTTP method POST is not supported by this URL
I've noticed a strange thing. When the adapter is called from the test procedure the URL seems correct (/apps/services/api/...) In the other case, Worklight puts a worklight prefix (/worklight/apps/services/api/...) when it makes the call. Hence the URL cannot be reached.
Here Worklight Studio - error http 405 when connecting to mobile URL provided by Console I found a partial solution but it does not work.
Additional info
WL version is 5.0.6.
Application server is Tomcat 7.
Based on my experiments I found the problem.
Each worklight project has an application-descriptor.xml. Within it there is a tag that indicates the WL server root URL.
Since I've taken the project from another source, I've simply noticed that it was configured as
<worklightServerRootURL>http://sampleDomain/worklight</worklightServerRootURL>
where sampleDomain is only a placeholder for the real one.
Now it is configured like
<worklightServerRootURL>http://${local.IPAddress}:8080</worklightServerRootURL>
to perform internal local tests.
Hope it helps.