Error FWLSE0013E: Unable to call JSONObject procedure due to incompatible casting to JSONArray

I have implemented a client-side function called login in my IBM MobileFirst application, which I found on this informative link.

login: function (username,password){    
            //promise
            var logindef = $q.defer();
            //tempuser
            tempUser = {username:username, password:password};
            userObj.username = username;
            checkOnline().then(function (onl){
                if (onl){ //online
                    console.log("attempting online login");
                    var parameters={
                            'username':'username',
                            'password':'password'
                        };
                    var options = {
                        parameters:parameters,  
                        adapter:"realmAuth",
                        procedure:"submitLogin"
                    };
                    ch.submitAdapterAuthentication(options,{
                        onSuccess: function(){
                            console.log("-> submitAdapterAuthentication onSuccess!");
                            //update user info, as somehow isUserAuthenticated returns false without it
                            WL.Client.updateUserInfo({onSuccess: function(){    
                                //return promise
                                logindef.resolve(true);
                            }});
                        }
                    });
                } else { //offline
                    console.log("attempting offline login");
                    logindef.resolve(offlineLogin());
                }
            });
            return logindef.promise;
        },

I am trying to invoke an adapter function named submitLogin

function submitLogin(parameters){
        if (!parameters)
        return { 'isSuccessful': false, 'errorMsg' : 'parameters is ' + parameters};
        var role="";
        if (parameters.username=='admin') 
            role='admin';
        else
            role='customer';
        var input = {
                method : 'post',
                returnedContentType : 'plain',
                path : 'rest/default/V1/integration/' + role + '/token'+
                            '?username='+parameters.username+
                            '&password='+parameters.password,
                headers: {"Accept":"application\/json"} 
            };
            var response = WL.Server.invokeHttp(input);
            var token=response.text;
            token = token.replace("\"", "");            //delete the ""
            token = token.replace("\"", "");//*/
            //token exp: l9ea4tv62mbfy7kmt0ekv6vdxmb23gjp
            if (token!=null) 
            { 
                var userIdentity = {
                        userId: parameters.username,
                        displayName: parameters.username, 
                        attributes: {
                            foo: "bar"
                        }
                };
                WL.Server.setActiveUser("AdapterAuthRealm", userIdentity); 
                
                return { 
                    authRequired: true 
                };
            }

    return onAuthRequired(null, "Invalid login credentials");
}

When attempting to execute my application in a browser, I encounter the following error:

[ERROR ] FWLSE0013E: Cannot invoke procedure realmAuth/submitLogin [project Eticket] com.ibm.json.java.JSONObject cannot be cast to com.ibm.json.java.JSONArray

Answer №1

The format of your parameters array is incorrect.

Here is the code you provided:

var parameters={
                'username':'username',
                'password':'password'
                };

Javascript adapters require an ordered list of parameters without names, not a JSON object.

The correct format should be:

var parameters = ['myUsername','myPassword']

Make sure to update your adapter signature from function submitLogin(parameters) to

function submitLogin(username,password)
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am receiving a high volume of row data from the server. What is the best way to present this information on a redirected page?

There is a scenario where Page 1 receives a substantial amount of row data in JSON format from the server. The goal is to present this information on Page 2, which will be accessed by clicking on Page 1. To accomplish this task, JavaScript/jQuery and PHP ...

Is there a more efficient method for streamlining the Express-Validator middleware in a separate file

In my current project, there is a lot of validation required using Express-Validator. In each file, I find myself repeating the same validation code: //Validation and Sanitizing Rules const validationRules = [ param('tab').isString().isLength({ ...

Identifying the category of a value through a conditional check on another value

I am looking for my code editor to automatically determine the type of extraData based on the value of error, which is being narrowed down by an if statement: export enum ErrorCodes { Unknown = 'UNKWN', BadRequest = 'BDREQ', } int ...

Ways to change a value into int8, int16, int32, uint8, uint16, or uint32

In TypeScript, the number variable is floating point by default. However, there are situations where it's necessary to restrict the variable to a specific size or type similar to other programming languages. For instance, types like int8, int16, int32 ...

Updating URL on tab selection in Angular Bootstrap Tabs

I am incorporating Bootstrap's Tabs into my project and I want the URL to change when a tab is clicked. For example: /home/first /home/second Unfortunately, I am struggling to make this work properly. Here is the code snippet from my $routeProvider: ...

Acquiring MySQL information and storing it in a variable array

Currently, I am retrieving data from MySQL with $username and $chance. The data contains two usernames but only the first one is being loaded. var data = [ { "name" : "<?php echo $username; ?>", "hvalue" : <?php echo $chan ...

Node Js Error: morgan causing TypeError - app.use is not a valid function

Just diving into the world of node js and decided to follow a tutorial on scotch.io. I added morgan for logging requests, but when I hit run, I encountered an error saying TypeError: app.use is not a function. Here's the snippet from my app.js; const ...

transferring background-image in html between elements

Imagine having a three-level hierarchy HTML code structured like this: <section> <div id="outer"> <div id="inner"> </div> </div> </section> If we set background-image:someImage.jpg to the section, and backg ...

Refreshing a Vue JS component

As a beginner in VueJs, I am facing an issue with reloading a component and table when a refresh button is clicked. I have tried using the forceUpdate method and changing keys, but it has not been successful so far. If anyone has any suggestions on how to ...

I'm having trouble understanding why I'm getting an error when trying to link CSS or SCSS

<link rel="stylesheet" type="text/css" href="scss/styles.scss"> <link rel="stylesheet" type="text/css" href="css/styles.css"> /*webpackconfig.js*/ var path = require("pat ...

JavaScript's includes method fails to verify input against the array

Just starting out with Javascript and striving to write clean code! To test my app, I aim to have a user's name input via prompt checked against an array for validation purposes. When I hardcode the value of a variable, the includes function filters ...

Removing a hyperlink and adding a class to a unordered list generated in JavaScript - here's how!

In my JavaScript code, I have the following implementation: init: function() { var html = []; $.each(levels, function(nr) { html.push('<li><a href="#">'); html.push(nr+1); ...

Using Jquery to iterate through a JSON array

After receiving data from a webservice, this JSON string is retrieved: [{"TITLE":"asdasdasd","DESCRIPTION":"asdasd","PORTFOLIOID":1}, {"TITLE":"sss","DESCRIPTION":"sss","PORTFOLIOID":2}, {"TITLE":"sdfsdf","DESCRIPTION":"sdfsfsdf","PORTFOLIOID":3}] Is i ...

Is there a way to verify if a user is currently in a voice channel using DiscordJS V13?

I am attempting to verify if the user who initiated a command is currently in a voice channel. After running my bot, I receive the correct voice channel information. However, if I leave the channel and try the command again, I still get back the same cache ...

Encountered difficulties implementing Chart.js with Angular2

Greetings! I am currently attempting to utilize one of the Charts provided by http://www.chartjs.org, however, I seem to be encountering difficulties in getting it to function properly. I have followed the documentation by installing 'npm install char ...

What is the best way to calculate the combined total of radio button values using jQuery or JavaScript?

I recently came across a tutorial on how to sum radio button values using JavaScript or jQuery, and I decided to implement it in my code. However, I encountered some issues as it didn't work as expected. My goal was to offer users the option to downlo ...

Search for objects in the array that have the same name, and then combine the values of those matching

I've done some research on various platforms, but haven't come across a solution to my specific issue. I'm looking to extract objects from an array and group them by their names in order to calculate the total hours for each matching object. ...

Transform the array into JSON with correct formatting

I am currently working on converting my array to JSON format. The JSON data is being stored in the database and will later be decoded for permission validation purposes. For example: This is how I want the JSON data to be stored in the database: { "adm ...

Is it feasible to trigger a modal to open from a source external to the Vue

How can a component be made reusable by calling a method from outside the component? Currently, I include a button to open the modal in a template slot: index.php <modal> <template slot="button"> <button class="btn">Open mo ...

Error: Module not located in Custom NPM UI Library catalog

I have recently developed an NPM package to store all of my UI components that I have created over the past few years. After uploading the package onto NPM, I encountered an issue when trying to use a button in another project. The error message "Module no ...