Web app end-to-end demonstration
Overview
The purpose of this demonstration is to experience an end-to-end flow:
- A sample application that is pre-bundled with the PMF client SDK is registered and downloaded from the PMF Operations Console.
- A new or provided adapter is deployed to the PMF Operations Console.
- The application logic is changed to make a resource request.
End result:
- Successfully pinging the PMF.
- Successfully retrieving data using an adapter.
Prerequisites:
1. Starting the PMF
Make sure you have created a Persistent Mobile Foundation instance, or
If using the PMF Developer Kit, navigate to the server’s folder and run the command: ./run.sh
in Mac and Linux or run.cmd
in Windows.
2. Creating and registering an application
In a browser window, open the PMF Operations Console by loading the URL: http://your-server-host:server-port/mfpconsole
. If running locally, use: http://localhost:9080/mfpconsole. The username/password are admin/admin.
- Click the New button next to Applications
- Select the Web platform
- Enter com.sample.web as the application identifier
- Click on Register application
-
Click on the Get Starter Code tile and select to download the Web sample application.
3. Editing application logic
-
Open the project in your code editor of choice.
-
Select the client/js/index.js file and paste the following code snippet, replacing the existing
WLAuthorizationManager.obtainAccessToken()
function:WLAuthorizationManager.obtainAccessToken() .then( function(accessToken) { titleText.innerHTML = "Yay!"; statusText.innerHTML = "Connected to PMF"; var resourceRequest = new WLResourceRequest( "/adapters/javaAdapter/resource/greet/", WLResourceRequest.GET ); resourceRequest.setQueryParameter("name", "world"); resourceRequest.send().then( function(response) { // Will display "Hello world" in an alert dialog. alert("Success: " + response.responseText); }, function(response) { alert("Failure: " + JSON.stringify(response)); } ); }, function(error) { titleText.innerHTML = "Bummer..."; statusText.innerHTML = "Failed to connect to PMF"; } );
4. Deploy an adapter
Download this prepared adapter artifact and deploy it from the PMF Operations Console using the Actions → Deploy adapter action.
Alternatively, click the New button next to Adapters.
-
Select the Actions → Download sample option. Download the “Hello World” Java adapter sample.
If Maven and PMF CLI are not installed, follow the on-screen Set up your development environment instructions.
-
From a Command-line window, navigate to the adapter’s Maven project root folder and run the command:
pmfdev adapter build
-
When the build finishes, deploy it from the PMF Operations Console using the Actions → Deploy adapter action. The adapter can be found in the [adapter]/target folder.
5. Testing the application
- From a Command-line window, navigate to the [project root] → node-server folder.
- Open the [project root] → node-server → server.js file and edit the host and port variables with the correct values for your PMF.
- If using a local PMF, the values are typically http, localhost and 9080 For example:
var host = 'http://localhost'; // The Mobile Foundation server address var port = 9081; // The local port number to use var mfpURL = host + ':9080'; // The Mobile Foundation server port number
- Run the command:
npm start
to install required Node.js configuration and start the Node.js server. - In your browser, visit the URL: http://localhost:9081/home.
Secure Origins Policy
When using Chrome during development, the browser may not allow an application to load if using both HTTP and a host that is not “localhost”. This is due to the Secure Origins Policy implemented and used by default in this browser.
To overcome this, you can start the Chrome browser with the following flag:
--unsafely-treat-insecure-origin-as-secure="http://replace-with-ip-address-or-host:port-number" --user-data-dir=/test-to-new-user-profile/myprofile
- Replace “test-to-new-user-profile/myprofile” with the location of a folder that will act as a new Chrome user profile for the flag to work.
Results
- Clicking the Ping PMF button will display Connected to PMF.
- If the application was able to connect to the PMF, a resource request call using the deployed Java adapter will take place.
The adapter response is then displayed in an alert.
Next steps
Learn more on using adapters in applications, and how to integrate additional services such as Push Notifications, using the PMF security framework and more:
- Review the Application development tutorials
- Review the Adapters development tutorials
- Review the Authentication and security tutorials
- Review All Tutorials