Frequently Asked Questions (FAQs)
Frequently Asked Questions (FAQs)
-
Question: What is the standard way of handling http status codes (401, and 404) from the VoltMX MobileFoundry Integration Service? Is this where the PreProcessor and PostProcessor logic comes into play?
Answer: a. In PostProcessor, Result object is available, in that user can use the below code snippet to find the httpStatus code.
Param statusCodeparam = result.findParam("httpStatusCode"); int httpStatusCode = Integer.parseInt(statusCodeparam.getValue());
b. By default, you pass the http status code in the resultset json to device, the below is the sample output string.
The user can use the below snippet inresultset = {"httpStatusCode":200,"marketIndex":[{"indName":"Dow Jones Ind.","indVal":"15618.22","symbol":"0DJIA","indValChg":" -20.90"},{"indName":"Nasdaq Comp.","indVal":"3939.86","symbol":"0NDQC","indValChg":"3.27"},{"indName":"NYSE Composite","indVal":" 10011.65","symbol":"0NYC","indValChg":"-52.46"},{"indName":"S & P 500","indVal":"1762.97","symbol":"0S&P5","indValChg":" -4.96"}],"opstatus":0}
.js
file to get the httpStatusCode from JSON resultset object.int statusCode = resultset["httpStatusCode "];
-
Question: How can one authenticate to this same RESTful api? I see options for Basic Authentication in the Application Properties menu and when working with service defs in VoltMX Studio but I really need to be able to dynamically assign those values in code i.e. User authenticates with Active Directory and then authenticates with REST endpoints.
Answer: Dynamically basic authentication, every request user can pass the username and password in request params with the following specified param names:
- userid
- pwd
If user has any domain and hostname, then use the following specified param names:
- domain
- hname
In middleware, first it checks in request parameters, if not available it checks in session, that is, session.getAttribute(userid), if not available in request and session, then it takes from service definition file.
in JS code level:
var inputParamTable={};
inputParamTable["appID"] = "ServicesApp";
inputParamTable["serviceID"] = "BasicAuthService"; inputParamTable["userid"] = "steve";
inputParamTable["pwd"] = "apple"; inputParamTable["domain"] = "kits";
inputParamTable["hname"] = "apple";If user wants to store userid and password in session, then you also consider from session, for this user need to write the below code in pre / post processor.
Session session = request.getSession(false); session.setAttribute("userid", "steve"); session.setAttribute("pwd", "******");
-
Question: if end server having proxy enabled authentication, then you need to configure the below -D parameters:
voltmx.http.proxyHost
voltmx.http.proxyPort
voltmx.http.proxyUser
voltmx.http.proxyPassword
-
Question: if end server is with NTLM enabled authentication then need to configure the additional below -D parameter:
voltmx.proxy.ntlm.domainName
-
Question: Adding Headers.
-
Add "Content-Type" and Set scope is session in IDE headers section, then write preprocessor for this service and use the below snippet in preprocessor.
Session session = request.getSession(); session.setAttribute("Content-Type"," application/json");
-
if user want to pass header values in request parameters,
Set scope is request in IDE headers section, then pass the header value with same key which is defined in Header section as request scope.
For example,
IDE header section Content-Type - request scope in input params of the service request
Content-Type=application/json
-
-
Question: Adding Custom Cookies in header
-
Create cookie object using http client 4.1 API, org.apache.http.cookie.Cookie
-
In pre or post processor, use the below snippet:
Session session = request.getSession(false); session.setAttribute("KCookie",cookie);
-
-
Question: If user want to change the url or user authentication details dynamically, implements URLProvider2 class and write user own logic to override the service def values.
-
Question: if Request is more than 1024 MB then linux default values will not allow to forward the request, so below setting need to be done in Linux OS.
Below changes are applied on QNBDEV server to resolve the BREservice issue.
Login to Linux shell with root privileges.
#vi /etc/sysctl.conf (Add the below values)
#increase TCP max buffer size settable using setsockopt()net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
#recommended for hosts with jumbo frames enabled net.ipv4.tcp_mtu_probing=1