This chapter includes the following sections:
To test or debug your MAF application, deploy it in debug mode to a device on one of the platforms (Android, iOS, or Universal Windows Platform) that MAF supports. MAF and respective platform provides tools that let you connect the JDeveloper development environment with the MAF application executing on a device or a virtual device. For example, if you want to test your MAF application on an Android device, you deploy your MAF application in debug mode from JDeveloper to an Android device or to an Android Virtual Device (AVD). The Universal Windows Platform and iOS provide similar tools.
The high-level steps to debug a MAF application include the following tasks:
Configure the deployment profile that you use to deploy the MAF application to the test environment so that it deploys the MAF application in debug mode.
Configure the MAF application’s maf.properties
file to enable debugging.
Deploy the MAF application to the test environment.
Use the appropriate tools for the debugging task that you want to complete. If, for example, you want to debug Java code in your MAF application, use the tools that JDeveloper provides. If you want to debug the code that renders the user interface (HTML, CSS, or JavaScript) of your MAF application, use the tools that each platform provides for this task.
MAF provides other features to assist testing your application. These include the ability to monitor your application’s performance, plus send analytics and diagnostic information to Oracle Mobile Cloud service (if your application accesses resources from that service).
There are two approaches to testing a MAF application:
Testing on a mobile device: this method always provides the most accurate behavior, and is also necessary to gauge the performance of your application. However, you may not have access to all the devices on which you want to test, making device testing inconclusive.
Testing on a mobile device emulator or simulator: this method usually offers better performance and faster deployment, as well as convenience. However, even though a device emulator or simulator closely approximates the corresponding physical device, there might be differences in behavior and limitations on the capabilities that can be emulated.
Typically, a combination of both approaches yields the best results.
You should use a combination of the following methods to test the accessibility of your MAF application developed for iOS-powered devices:
Testing with the Accessibility Inspector on an iOS-powered device simulator.
For detailed information, see the "Test Accessibility on Your Device with VoiceOver" section in the Accessibility Programming Guide for iOS available through the iOS Developer Library.
Testing with the VoiceOver on an iOS-powered device.
For more information, see the "Using VoiceOver to Test Your Application" section in the Accessibility Programming Guide for iOS available through the iOS Developer Library.
JDeveloper is equipped with debugging mechanisms that allow you to execute a Java program in debug mode and use standard breakpoints to monitor and control execution of an application. For more information, see the section on debugging applications in Developing Applications with Oracle JDeveloper.
Since a MAF application cannot be run inside JDeveloper, the debugging approach is different: you can use the JDeveloper debugger to connect to a Java Virtual Machine instance on a mobile device or simulator and control the Java portions of your deployed MAF application.
MAF automatically configures the project properties for debugging (see What You May Need to Know About the Debugging Configuration). The following are the steps you need to take to use JDeveloper to debug the Java code in your MAF application:
To test or debug an application:
From JDeveloper's main menu, click Run > Choose Active Run Configuration to select an active run configuration.
In the Applications window, right-click on any file that you want to test and choose Run.
Alternatively, choose Debug if you want to run the application with debugging enabled.
Tip:
You can also open any file in the MAF application in Source view, right-click on it, and then select Run or Debug.
Note:
If you are using an existing application that does not have the predefined set of run configurations, you can create new run configurations (see What You May Need to Know About the Debugging Configuration).
For additional information, see the following:
When a new MAF application is created, the creation wizard automatically configures the application properties for debugging. This includes the creation of default run configurations that may be used to run or debug the MAF application on an iOS simulator or Android emulator or device. These run configurations allow you to build, deploy, run, or debug a MAF application by clicking the JDeveloper Run or Debug buttons. When you click the Run or Debug button in JDeveloper and select a MAF run configuration, the deployment profile associated with the run configuration is executed to build and deploy the application to the targeted device. Once the application has been deployed, it automatically starts. If the Debug button was selected, the application will start with the debugger.
For information on how to create and edit run configurations, see Creating and Configuring a Run Configuration.
To create a new configuration or to modify an existing one, complete the Edit Run Configuration dialog (see Figure 29-1) as follows:
A maf.properties
file allows you to specify startup parameters for the JVM and web views of MAF to enable debugging of the Java code and JavaScript. The maf.properties
file is automatically created and placed in the Descriptors/META-INF
directory under the Application Resources (see Using and Configuring Logging), which corresponds to the <application_name>
/src/META-INF
location in your application file system.
When you execute a MAF run configuration, the following debugging properties are automatically set in the maf.properties
file:
java.debug.enabled
: Set to true
if doing a debug session; set to false
if doing a run session.
Caution:
When java.debug.enabled
is set to true
, the JVM waits for a debugger to establish a connection to it. Failure of the debugger to connect will result in the failure of the MAF AMX application feature to load.
java.debug.port
: Set to the port number configured in the MAF run configuration being executed.
javascript.debug.enabled
: Set to true
if doing a debug session; set to false
if doing a run session. Applies to Android only.
Note:
The javascript.debug.enabled
property is not required for enabling JavaScript debugging when the MAF application is running on an iOS-powered simulator or iOS-powered device.
The contents of the maf.properties
file may be similar to the following:
java.debug.enabled=true java.debug.port=8000 javascript.debug.enabled=true
For information on how to use JDeveloper to debug the Java code, see Debugging MAF Applications.
If your MAF application includes the MAF AMX content, after you configure the device or emulator, you can set breakpoints, view the contents of variables, and inspect the method call stack just as you would when debugging other types of applications in JDeveloper.
Note:
You can only debug your Java code and JavaScript (see How to Enable Debugging of Java Code and JavaScript). Debugging of EL expressions or other declarative elements is not supported.
Describes how to debug the Java and UI code of MAF applications that you deploy to Android.
To debug Java code, you configure the maf.properties
file in your application and create a run configuration in JDeveloper. For more information about these tasks, see How to Enable Debugging of Java Code and JavaScript and Configuring JDeveloper and MAF Applications to Debug Code. Once you complete these tasks, you can deploy your MAF application in debug mode to debug your Java code, as described in How to Debug Java Code on the Android Platform.
To debug UI code (JavaScript, HTML, and CSS), you configure the maf.properties
file in your application (javascript.debug.enabled=true
). Once you complete this task, you can debug your UI code, as described in How to Debug UI Code on the Android Platform.
To debug a MAF application’s Java code on the Android platform using JDeveloper, follow the debugging procedure described in Debugging MAF Applications.
For information on how to configure an Android-powered device or emulator and how to deploy a MAF application for debugging, see How to Deploy an Android Application to an Android Emulator.
To allow debugging of a MAF application running on an Android-powered device or its emulator, verify that the Network Information plugin is enabled, as described in Introduction to Using Plugins in MAF Applications
When developing a MAF application, you may need to debug code that renders the user interface (UI) of your application on an Android device. The code that renders the UI can include JavaScript, HTML, and CSS. You can debug this code using Google’s Chrome DevTools when you deploy the MAF application from your development machine to the Android device. Figure 29-2 shows the Chrome DevTools inspecting an AMX page from a MAF application.
Figure 29-2 Chrome DevTools Inspecting an AMX Page from a MAF application
For more information on the Chrome DevTools, including the requirements to use it, see Remote Debugging on Android with Chrome DevTools on the Google Developers’ site.
See also the “Debugging HTML in Oracle MAF Applications on Android” video on the Oracle Mobile Platform YouTube channel for an overview of how to debug UI code on Android. Note that the latter video makes reference to a cvm.properties
file. This file has been renamed to maf.properties
in the current release.
Configure the maf.properties
file to include the following entry: javascript.debug.enabled=true
maf.properties
file, see How to Enable Debugging of Java Code and JavaScript.Deploy in debug mode. For more information, see Deploying MAF Applications .
Describes how to debug the Java and UI code of MAF applications that you deploy to iOS.
Before you can debug Java code, you configure the maf.properties
file in your application and create a run configuration in JDeveloper. For more information about these tasks, see How to Enable Debugging of Java Code and JavaScript and Configuring JDeveloper and MAF Applications to Debug Code. Once you complete these tasks, you can deploy your application in debug mode to the iOS device and debug your Java code. For more information about how to deploy in debug mode, see How to Debug Java Code on the iOS Platform.
To debug UI code (JavaScript, HTML, and CSS), you configure the maf.properties
file in your application (javascript.debug.enabled=true
). Once you complete this task, you can debug your UI code, as described in How to Debug UI Code on the iOS Platform.
To debug a MAF application’s Java code on the iOS platform using JDeveloper, follow the debugging procedure described in Debugging MAF Applications.
For information on how to configure an iOS-powered device or simulator and how to deploy a MAF application for debugging, see the following:
If you are working with the iOS platform, you can use the Safari browser to debug JavaScript. To do so, open the Safari preferences, select Advanced, and then enable the Develop menu in the browser by selecting Show Develop menu in menu bar.
When the Develop menu is enabled, select either iPhone Simulator or iPad Simulator, as Figure 29-3 and Figure 29-4 show, and then select a UIWebView that you are planning to debug, as Figure 29-5 shows.
Note:
Whether the Develop menu displays an iPhone Simulator or iPad Simulator option depends on which device simulator is launched.
Use the featureContentDelay
additional build argument to record log messages and errors from your custom JavaScript before the first page from your application loads. This argument specifies a delay before the WebView is populated with content. Set the additional build argument -featureContentDelay
to 20
. For more information about setting additional build arguments, see Defining the iOS Build Options.
Figure 29-3 Using Develop Menu on Safari Browser for Debugging on iPhone Simulator
Figure 29-4 Using Develop Menu on Safari Browser for Debugging on iPad Simulator
Figure 29-5 Using Develop Menu on Safari Browser to Select UIWebView
Figure 29-6 and Figure 29-7 show the CSS, DOM, and HTML Safari Remote Web Inspector in action.
Figure 29-6 Remote Web Inspector
Figure 29-7 AMX Page Analyzed by Remote Web Inspector at Runtime
Figure 29-8 and Figure 29-9 show JavaScript debugging using breakpoints inside the Safari browser.
Figure 29-8 JavaScript Debugging in Safari Browser
Figure 29-9 AMX Page Debugged at Runtime
Describes how to debug the Java and UI code of MAF applications that you deploy to the UWP.
You can debug the Java code in MAF applications that you deploy to the UWP using JDeveloper’s debugging tools. For more information, see How to Debug Java Code on the Universal Windows Platform.
Use Visual Studio to debug the JavaScript, HTML, and CSS code in your MAF application, as described in How to Debug UI Code on the Universal Windows Platform.
Describes how to debug Java code in a MAF application that you deploy to the Universal Windows Platform (UWP).
Perform the following steps so that you can debug Java code in a MAF application that you deploy to the UWP:
Configure the MAF application’s maf.properties
file entries to enable debugging. Ensure that the following values appear in the maf.properties
file.
java.debug.enabled=true java.debug.port=8000 java.debug.mode=client java.debug.host=localhost
For more information about the maf.properties
file, see How to Enable Debugging of Java Code and JavaScript.
Configure the Windows deployment profile for the MAF application to use Debug mode, as shown in Figure 29-10. Click to access this dialog.
Figure 29-10 Enabling Debug Mode for the MAF Application
Add a custom project to your MAF application so that it can access the standard JDeveloper application run/debug configuration dialogs. Once you add this custom project to your MAF application, enable the Remote Debugging option with a connection that listens for the JPDA protocol. Start a debug listener in the custom project. For more information about these tasks, see How to Enable Remote Debugging of a MAF Application on the Universal Windows Platform.
Deploy the MAF application using the local Windows machine option. For more information, see Deploying a MAF Application to the Universal Windows Platform.
Once you deploy the MAF application using the Windows Local Machine deployment option, the application starts and establishes a debug session with JDeveloper.
Add a custom project to your MAF application to expose the Run/Debug configuration panels that the MAF application creation template does not display when you create a MAF application.
When developing a MAF application on the Universal Windows Platform (UWP), you may need to debug code that renders the user interface (UI) of your application. The code that renders the UI can include JavaScript, HTML, and CSS. You debug this code using Visual Studio.
For information about installing Visual Studio for use in MAF application development, see the Setting Up Development Tools for the Universal Windows Platform section in Installing Oracle Mobile Application Framework.
Before debugging your MAF application, you need to develop and deploy the application. For information on developing and deploying application, see Getting Started with MAF Application Development and Deploying MAF Applications .
To debug UI code in MAF applications deployed on the UWP:
For your MAF application, you can enable logging on all supported platforms through JavaScript (see How to Use JavaScript Logging) and embedded code (see How to Use Embedded Logging) using a single configuration with the log output directed to a single file. This log output includes the output produced by System.out.println
and System.err.println
statements.
The default MAF's logging process is as follows:
The logging begins at application startup.
The existing log file from the previous application run is deleted, so only the contents of the current run are available.
When you are running your application on an iOS-powered device simulator, you can only access the Java logging output through a file of whose name and location you are notified as soon as the output redirection occurs and the file is generated. One of the typical locations for this file is /Users/
<userid>
/Library/Developer/CoreSimulator/Devices/
<device_id>
/data/Containers/Data/Application/
<container_id>
/application.log
, where <device_id>
and <container_id>
references represent long UUID strings created by iOS during the installation of the application. The values of these references cannot be predicted and when multiple simulators or applications are installed, it is difficult to determine which folder corresponds with the simulator used during deployment. When using JDeveloper for deployment, the -consoleRedirect
option is automatically set to direct the log output to a known location. If you set it on a MAF run configuration for iOS using the Edit Run Configuration > Mobile Run Configuration dialog and that run configuration is used to deploy or run the MAF application on an iOS-powered device simulator, the log file is created at the configured location and its contents is displayed on a console in JDeveloper. If you do not set the value using the Edit Run Configuration > Mobile Run Configuration dialog or you choose to perform a regular deployment (for example, such that it does not use a MAF run configuration for iOS), the log file is created in the <appRoot>/<deployRoot>/<iOSProfileName>/
log
<appName>
.log
file and its contents is displayed on a console in JDeveloper. For more information, see Creating and Configuring a Run Configuration.
Note:
The path must be an absolute path to receive the log file and the location must be writable for the current user.
When you are running your application on an iOS-powered device, the console output is redirected to an application.log
file that is placed in the Documents/logs
directory of your application. You can access this directory as follows on your iOS-powered device:
*.xcappdata
file and select Show Package Contents.application.log
file.On Android, the output is forwarded to a text file with the same name as the application. The output file location is /sdcard
. If this location is not present or is configured as read-only, the log output is rerouted to the application's writable data directory. The contents of the log file is replicated in the Android Logcat utility (see http://developer.android.com/tools/debugging/debugging-log.html
). JDeveloper displays the logging output from the Logcat when you use JDeveloper to deploy your MAF application to an Android-powered device or emulator.
For both iOS and Android, the logging output appears in JDeveloper’s run or debug Log page immediately after the deployment. In case of a regular deployment, the deployment log is displayed in the Deployment Log page, whereas the application log is displayed in a separate Log page. If you use a Run/Debug run configuration to build, deploy, and launch the MAF application, the Terminate option in the Processes tab of the Applications window terminates the MAF application along with the process that performs the log redirection. The View Log option enables you to see the log page, as the following illustration shows.
If your use a deployment profile to build, deploy, and launch the MAF application, the Terminate option in the Processes tab terminates only the log redirection process, whereas the MAF application remains running.
The logging.properties
file is automatically created and placed in the Descriptors/META-INF
directory under the Application Resources (see Using and Configuring Logging), which corresponds to the <application_name>
/src/META-INF
location in your application file system. In this file, it is defined that all loggers use the java.util.logging.ConsoleHandler
and SimpleFormatter
, and the log level is set to SEVERE
. You can edit this file to specify different logging behavior (see How to Configure Logging Using the Properties File).
Note:
In your MAF application, you cannot use loggers from the java.util.logging
package.
MAF loggers are declared in the oracle.adfmf.util.Utility
class as follows:
public static final String APP_LOGNAME = "oracle.adfmf.application"; public static final Logger ApplicationLogger = Logger.getLogger(APP_LOGNAME); public static final String FRAMEWORK_LOGNAME = "oracle.adfmf.framework"; public static final Logger FrameworkLogger = Logger.getLogger(FRAMEWORK_LOGNAME);
The logger that you are to use in your MAF application is the ApplicationLogger
.
You can also use methods of the oracle.adfmf.util.logging.Trace
class.
For more information, see Java API Reference for Oracle Mobile Application Framework.
The following example shows the logging.properties
file that you use to configure logging.
# default - all loggers to use the ConsoleHandler .handlers=java.util.logging.ConsoleHandler # default - all loggers to use the SimpleFormatter .formatter=java.util.logging.SimpleFormatter oracle.adfmf.util.logging.ConsoleHandler.formatter= oracle.adfmf.util.logging.PatternFormatter oracle.adfmf.util.logging.PatternFormatter.pattern= [%LEVEL%-%LOGGER%-%CLASS%-%METHOD%]%MESSAGE% #configure the framework logger to only use the adfmf ConsoleHandler oracle.adfmf.framework.useParentHandlers=false oracle.adfmf.framework.handlers=oracle.adfmf.util.logging.ConsoleHandler oracle.adfmf.framework.level=SEVERE #configure the application logger to only use the adfmf ConsoleHandler oracle.adfmf.application.useParentHandlers=false oracle.adfmf.application.handlers=oracle.adfmf.util.logging.ConsoleHandler oracle.adfmf.application.level=SEVERE
The oracle.adfmf.util.logging.ConsoleHandler
plays the role of the receiver of the custom formatter.
The oracle.adfmf.util.logging.PatternFormatter
allows the following advanced formatting tokens that enable log messages to be printed:
%LEVEL%
—the logging level.
%LOGGER%
—the name of the logger to which the output is being written.
%CLASS%
—the class that is being logged.
%METHOD%
—the method that is being logged.
%TIME%
—the time the logging message was sent.
%MESSAGE%
—the actual message.
The following logging levels are available:
SEVERE
: this is a message level indicating a serious failure.
WARNING
: this is a message level indicating a potential problem.
INFO
: this is a message level for informational messages.
FINE
: this is a message level providing tracing information.
FINER
: this level indicates a fairly detailed tracing message.
FINEST
: this level indicates a highly detailed tracing message.
Caution:
When selecting the amount of verbosity for a logging level, keep in mind that by increasing the verbosity of the output at the SEVERE
, WARNING
, and INFO
level negatively affects performance of your application.
The logger defined in the logging.properties
file matches the logger obtained from the oracle.adfmf.util.Utility
class (see Using and Configuring Logging). The logging levels also match. If you decide to use the logging level that is more fine-grained than INFO
, you must change the ConsoleHandler
's logging level to the same level, as the following example shows.
oracle.adfmf.util.logging.ConsoleHandler.formatter= oracle.adfmf.util.logging.PatternFormatter oracle.adfmf.util.logging.ConsoleHandler.level=FINEST oracle.adfmf.util.logging.PatternFormatter.pattern= [%LEVEL%-%LOGGER%-%CLASS%-%METHOD%]%MESSAGE%
JavaScript writes the output to the console.log
or.error/.warn/.info
. This output is redirected into the file through the System.out
utility.
You customize the log output by supplying a message. The following JavaScript code produces "Message from JavaScript"
output:
<script type="text/javascript" charset="utf-8"> function test_function() { console.log("Message from JavaScript"); } </script>
To make use of the properties defined in the logging file, you need to use the adf.mf.log
package and the Application
logger that it provides.
The following logging levels are available:
adf.mf.log.level.SEVERE
adf.mf.log.level.WARNING
adf.mf.log.level.INFO
adf.mf.log.level.CONFIG
adf.mf.log.level.FINE
adf.mf.log.level.FINER
adf.mf.log.level.FINEST
To trigger logging, use the adf.mf.log.Application
logger's logp
method and specify the following through the method's parameters:
the logging level
the current class name as a String
the current method as a String
the message string as a String
The following example shows how to use the logp
method in a MAF application.
adf.mf.log.Application.logp(adf.mf.log.level.WARNING, "myClass", "myMethod", "My Message");
Upon execution of the logp
method, the following output is produced:
[WARNING - oracle.adfmf.application - myClass - myMethod] My Message
For more information, see JSDoc Reference for Oracle Mobile Application Framework.
Embedded logging uses the java.util.logging.Logger
, as illustrated in the following example. The EmbeddedClass
represents a Java class defined in the project.
import java.util.logging.Level; import java.util.logging.Logger; import oracle.adfmf.util.logging.*; ... Utility.ApplicationLogger.logp(Level.WARNING, EmbeddedClass.class.getName(), "onTestMessage", "embedded warning message 1"); Logger.getLogger(Utility.APP_LOGNAME).logp(Level.WARNING, this.getClass().getName(), "onTestMessage", "embedded warning message 2"); Logger.getLogger("oracle.adfmf.application").logp(Level.WARNING, this.getClass().getName(), "onTestMessage", "embedded warning message 3");
The preceding code produces the following output:
[WARNING - oracle.adfmf.application - EmbeddedClass - onTestMessage] embedded warning message 1 [WARNING - oracle.adfmf.application - EmbeddedClass - onTestMessage] embedded warning message 2 [WARNING - oracle.adfmf.application - EmbeddedClass - onTestMessage] embedded warning message 3
Even though it is not recommended to manipulate your MAF projects with Xcode because you can lose some or all of your changes during the next deployment with JDeveloper, you may choose to do so in exceptional circumstances.
Before you begin:
Deploy the application to the iOS simulator from JDeveloper.
To open the generated project directly in Xcode:
Navigate to the workspace_directory
\deploy\
deployment profile name
\temporary_xcode_project\
.
Open the Xcode project called Oracle_ADFmc_Container_Template.xcodeproj
.
If you are debugging your MAF application using Xcode, you cannot see the Java output in the IDE (on neither JDeveloper console nor Xcode console). Instead, the output is redirected to a file (see Using and Configuring Logging). By adding the following argument to your application's schema, you can disable this behavior and enable access to the Java, JavaScript, and Objective-C log output in Xcode in real time when debugging on either an iOS-powered device or simulator:
-consoleRedirect=FALSE
Using the following APIs, you can access the application log information:
oracle.adfmf.framework.api.PerfMon
oracle.adfmf.framework.api.LogEntry
oracle.adfmf.util.HOTS
For more information, see Java API Reference for Oracle Mobile Application Framework.
You can prevent the logging output from being directed to the application log file, in which case the log file either remains blank or is not created in the first place. When logging is disabled, trace statements are absent from the application log and any output directed to stderr
and stdout
is redirected to either a null
location or other location that is not accessible to the end user.
To disable all logging, set the disableLogging
property to true
in the application's adf-config.xml
file, as follows:
<adf-property name="disableLogging" value="true"/>
By default, logging is enabled in MAF applications and the disableLogging
property is set to false
.
For information on the adf-config.xml
file, see Introduction to MAF Application and Project Files.
MAF assists you in monitoring and measuring the performance of your MAF application. You can, for example, measure the time it takes for the following events in your application to complete:
An action that a button invokes to complete
A page to load
A REST call to return a response
In addition, you can print statistics that show the mean and standard deviation time of operations that you monitor in your MAF application.
logging.properties
file. The values assigned to the loggers in the following example are for illustrative purposes. See Table 29-1 for descriptions of all possible values.
oracle.adfmf.amx.useParentHandlers=false oracle.adfmf.amx.handlers=oracle.adfmf.util.logging.ConsoleHandler oracle.adfmf.amx.level=SEVERE # used to control what monitors are captured in the list of monitors oracle.maf.performance.monitor.captured.level = FINEST # used to control what monitors are reported in the dumpStatistics oracle.maf.performance.monitor.reported.useParentHandlers=false oracle.maf.performance.monitor.reported.handlers=oracle.adfmf.util.logging.ConsoleHandler oracle.maf.performance.monitor.reported.level = FINEST # used to control what monitor observations (start/stop times) are logged. oracle.maf.performance.monitor.observations.reported=false oracle.maf.performance.monitor.observations.reported.handlers=oracle.adfmf.util.logging.ConsoleHandler oracle.maf.performance.monitor.observations.reported.level = FINEST
Once performance measurement completes, you can review the data that MAF collected while it measured the performance of your application. The following example shows an extract of the output that MAF produces after it monitors performance. In the example, the monitor observed 5 occurrences of a Process AMX event
that had a mean completion time of 1435.5
milliseconds with a standard deviation of 1990.567….
[INFO - oracle.maf.performance.monitor.reported - MonitorFactory - dumpStatistics] PERFMON-JAVA STATS: Monitor 'com.company.WorkBetter.**Perf_Monitor**.Springboard.Container.Process AMX event' description: 'Time to process event' observations: 5 mean: 1435.4 standard deviation: 1990.5674567821106
Table 29-1describes the available performance monitor levels that you can set in the logging.properties
file.
Table 29-1 Performance Monitor Levels
Level | Description |
---|---|
Level.INFO |
This is the coarsest monitor level. It monitors events and actions. Using this level, you can, for example, monitor the loading of a page or the completion of an end user action, such as a button click. Use of this monitor level has minimal impact on performance. |
Level.FINE |
This level monitors more performance indicators that it orders into the following categories:
Use of this monitor level impacts the performance of your application and should not be enabled by default. Consider using this level to gain insight into how your code executes with a view to restructuring or refining your application. |
Level.FINER |
Use to monitor significant performance issues, such as how it long it takes to process nodes in an AMX page, data change events or EL expressions. |
Level.FINEST |
Use this monitor level to debug the performance of your application. |
logging.properites
takes effect when you first start the application.
Note:
MAF provides a number ofsetPerformanceMonitor
methods in the oracle.adfmf.framework.api
package’s PerfMon
class that enable you to change the performance monitor level at runtime. For more information, see the Java API Reference for Oracle Mobile Application Framework.In addition to specifying a monitor level in the logging.properties
file, you can add monitors to your application to collect the performance data. MAF uses the Java class, oracle.adfmf.performance.Monitor
(monitor), to collect performance data. A monitor is a stop watch that can be started, stopped and can add observations. By adding observations, you can use monitors to gain insights, such as the standard deviation for a given measurement. Each monitor has a unique ID and an optional description.
Monitor exposes a number of addObservation()
methods that enable a monitor to measure the duration of an event or the number of occurrences of an event. When measuring duration, start the monitor before the event. After the event occurs, invoke an addObservation()
method from the monitor. This stops the monitor. Duration is the time between the start()
and the addObservation()
method. You can restart a monitor that was never stopped. As you might expect, you cannot stop a monitor that was never started. An attempt to stop such a monitor logs an error.
A monitor that measures the number of occurrences of an event does not need to be started or stopped. Use the addObservation(double duration)
method that does not stop the monitor, as demonstrated in the following example that counts the number of occurrences of JSON serialization in the application where you monitor performance. The duration
parameter specifies the time since the monitor last added an observation.
The following example demonstrates how you create a monitor to measure the duration of an event. The example also shows a sample of the statistical information that this monitor produces.
import oracle.adfmf.performance.Monitor; .... public void measurePerformance() { Monitor monitor = null; try { //// Check that the appropriate monitor level is set before you create the monitor if (Utility.PerformanceMonitorCaptured.isLoggable(Level.INFO)) { monitor = MonitorFactory.getInstance().getMonitor("REST call", Level.INFO, "REST call timing"); monitor.start(); } // // Perform your custom logic here: // } finally { if (monitor != null) { monitor.addObservation(); } } } public void countCalls() { Monitor monitor = null; try { if (Utility.PerformanceMonitorCaptured.isLoggable(Level.FINE)) { monitor = MonitorFactory.getInstance().getMonitor("Call count", Level.FINE, "Count number of calls"); monitor.start(); } // // Perform your custom logic here: // } finally { if (monitor != null) { monitor.addObservation(1); } } }
To create a monitor that collects performance data in your application, you configure the logging.properties
file to enable the performance monitor capture level to collect the data. In the example aboves, MAF will not collect performance data for the monitor if the application’s logging.properties
file does not contain the following entry:
# used to control what monitors are captured in the list of monitors oracle.maf.performance.monitor.captured.level = FINEST
For more information about monitor (oracle.adfmf.performance.Monitor
), see Java API Reference for Oracle Mobile Application Framework.
In addition to monitor, MAF also provides oracle.adfmf.performance.Story
(story). A story allows you to start and end the collection of performance data. Once you end collection of the performance data for a story, MAF presents a hierarchical view of the collected performance data using a story ID that you assigned when you started the story. The hierarchical view shows the individual timing measurements for events that took place during the story. In addition, MAF performs a health of the system (HOTS) checkpoint at the end of the story. As part of this HOTS checkpoint, standard deviations for all of the monitor data collected during the story will be computed, so you can gain insight into how individual story events measure up statistically. All monitor data will then be cleared from the MonitorFactory
.
Note:
You can perform a HOTS checkpoint independently of a story by invoking theoracle.adfmf.util.HOTS.checkpoint()
method. This determines information for your application, such as total memory used by the JVM, free memory, used memory (total minus free), and the number of active features. The following shows a sample of the data returned by checkpoint()
:
HOTS.memory.used (N/A) count: 1.0335056E7 HOTS.memory.free (N/A) count: 1.365112E7 HOTS.memory.total (N/A) count: 2.3986176E7 HOTS.memory.max (N/A) count: 4.9152E7 HOTS.threads.active (N/A) count: 20.0 HOTS.features.active (N/A) count: 6.0
The following example shows a managed bean that exposes methods to start a story with a story ID (**Perf_Monitor**
) and stop the story. This story could be started and ended from a button in the UI of the application that you want to measure the performance. For example, you may want to measure the loading of a page, so you expose a UI button that enables you to start the story prior to navigating to the page and another button that ends the story once the page loads.
package mobile; import oracle.adfmf.amx.event.ActionEvent; import oracle.adfmf.performance.Story; public class PerfBean { public PerfBean() { super(); } public void startStory(ActionEvent ae) { Story.startStory("**Perf_Monitor**"); } public void endStory(ActionEvent ae) { Story.endStory(); } }
The performance monitor level that you specify in the logging.properties
file determines how much data the story captures. That is, a logging.properties
file entry of oracle.maf.performance.monitor.reported.level = FINEST
produces a more verbose story than an entry of INFO
. When the story ends, all performance data captured during a story is sorted based on timing. This sorting presents monitor observations corresponding to JavaScript events at a correct time, since the time when these observations were recorded might be different from the time when the measured events took place. MAF then iterates through the sorted records and produces indented output, as demonstrated in the following example.
MAF writes the story into the application log file. A sample output for an application that navigates from one AMX page to another AMX page might look like the following:
Example 29-1 MAF Performance Monitor Data Generated using Story
[INFO - oracle.maf.performance.monitor.observations.reported - Monitor - start] PERFMON-JAVA START: **Perf_Monitor**.Navigation.Embedded.Story **Perf_Monitor** (Story Book) at 1452728427473 [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - start] PERFMON-JAVA START: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view1.amx event of type action on node cb2 (Time to process event) at 1452728427416 [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - stop] PERFMON-JAVA STOP: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view1.amx event of type action on node cb2 (Time to process event) took: 14897.0ms (started at 1452728427416) [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - start] PERFMON-JAVA START: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view1.amx event of type action on node cb1 (Time to process event) at 1452728442323 [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - stop] PERFMON-JAVA STOP: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view1.amx event of type action on node cb1 (Time to process event) took: 586.0ms (started at 1452728442323) [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - start] PERFMON-JAVA START: **Perf_Monitor**.Navigation.Container.Load page /view2.amx (Time to fully render the page) at 1452728442441 [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - stop] PERFMON-JAVA STOP: **Perf_Monitor**.Navigation.Container.Load page /view2.amx (Time to fully render the page) took: 468.0ms (started at 1452728442441) [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - start] PERFMON-JAVA START: **Perf_Monitor**.Navigation.Embedded.Evaluate method expression #{myBean2.endStory} (UserSpace) at 1452728450665 [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - stop] PERFMON-JAVA STOP: **Perf_Monitor**.Navigation.Embedded.Evaluate method expression #{myBean2.endStory} (UserSpace) took: 78.0ms (started at 1452728450665) [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - start] PERFMON-JAVA START: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view2.amx event of type action on node cb2 (Time to process event) at 1452728450626 [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - stop] PERFMON-JAVA STOP: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view2.amx event of type action on node cb2 (Time to process event) took: 85.0ms (started at 1452728450626) [INFO - oracle.maf.performance.monitor.observations.reported - Monitor - stop] PERFMON-JAVA STOP: **Perf_Monitor**.Navigation.Embedded.Story **Perf_Monitor** (Story Book) took: 23367.0ms (started at 1452728427473) [INFO - oracle.maf.performance.monitor.reported - MonitorFactory - dumpStatistics] PERFMON-JAVA STATS: Monitor 'com.company.aPerfMonDocApp.**Perf_Monitor**.Navigation.Container.Process AMX event' description: 'Time to process event' observations: 3 mean: 5189.333333333333 standard deviation: 8410.817102596711 [INFO - oracle.maf.performance.monitor.reported - MonitorFactory - dumpStatistics] PERFMON-JAVA STATS: Monitor 'com.company.aPerfMonDocApp.**Perf_Monitor**.Navigation.Container.Load page' description: 'Time to fully render the page' observations: 1 mean: 468.0 standard deviation: NaN [INFO - oracle.maf.performance.monitor.reported - MonitorFactory - dumpStatistics] PERFMON-JAVA STATS: Monitor 'com.company.aPerfMonDocApp.**Perf_Monitor**.Navigation.Embedded.Evaluate method expression' description: 'UserSpace' observations: 1 mean: 78.0 standard deviation: NaN [INFO - oracle.maf.performance.monitor.reported - MonitorFactory - dumpStatistics] PERFMON-JAVA STATS: Monitor 'com.company.aPerfMonDocApp.**Perf_Monitor**.Navigation.Embedded.Story' description: 'Story Book' observations: 1 mean: 23367.0 standard deviation: NaN 1452728427473 0001.0001 [0000] Start: **Perf_Monitor**.Navigation.Embedded.Story **Perf_Monitor** (INFO) 1452728442323 0002.0002 [0001] Start: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view1.amx event of type action on node cb1 (INFO) 1452728442441 0003.0003 [0002] Start: **Perf_Monitor**.Navigation.Container.Load page /view2.amx (INFO) 1452728442909 0003.0003 [0002] Stop: **Perf_Monitor**.Navigation.Container.Load page /view2.amx (took = 468.0) started at 1452728442441 (INFO) 1452728442909 0002.0002 [0001] Stop: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view1.amx event of type action on node cb1 (took = 586.0) started at 1452728442323 (INFO) 1452728450626 0004.0002 [0001] Start: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view2.amx event of type action on node cb2 (INFO) 1452728450665 0005.0003 [0004] Start: **Perf_Monitor**.Navigation.Embedded.Evaluate method expression #{myBean2.endStory} (INFO) 1452728450711 0004.0002 [0001] Stop: **Perf_Monitor**.Navigation.Container.Process AMX event Page: /view2.amx event of type action on node cb2 (took = 85.0) started at 1452728450626 (INFO) 1452728450743 0005.0003 [0004] Stop: **Perf_Monitor**.Navigation.Embedded.Evaluate method expression #{myBean2.endStory} (took = 78.0) started at 1452728450665 (INFO) 1452728450840 0001.0001 [0000] Stop: **Perf_Monitor**.Navigation.Embedded.Story **Perf_Monitor** (took = 23367.0) started at 1452728427473 (INFO)
Describes how to insert diagnostic information from MAF applications that access REST web services hosted by Oracle Mobile Cloud service (MCS).
MAF applications that access REST web services use RestServiceAdapter
to access these services. If your application accesses REST services hosted by MCS and you want to use MCS Diagnostics to monitor and/or debug your application’s calls to REST services hosted by MCS, create a McsRestServiceAdapter
to send the following information to MCS:
Mobile diagnostic session ID.
This attribute maps an application session on a specific device. The application sends this information through the Oracle-Mobile-DIAGNOSTIC-SESSION-ID
HTTP request header.
Mobile device ID
Correlates the REST API requests sent to MCS with the physical device that makes the request. The mobile application supplies this information through the Oracle-Mobile-Device-ID
HTTP request header.
Client request time,
Indicates the API call time stamp that is captured on the client side immediately before the application submits the request. The mobile application supplies this information using the HTTP request header Oracle-Mobile-CLIENT-REQUEST-TIME
attribute.
Oracle-Mobile-Diagnostic-Session-ID: 19975 Oracle-Mobile-Device-ID: d09379504b0a3247 Oracle-Mobile-Client-Request-Time: 2016-02-09T09:03:17.777Z
The following example shows how you create the McsRestServiceAdapter
:
... import oracle.maf.api.dc.ws.rest.RestServiceAdapterFactory; import oracle.maf.api.dc.ws.rest.RestServiceAdapter; ... RestServiceAdapterFactory factory = RestServiceAdapterFactory.newFactory(); RestServiceAdapter mcsRestServiceAdapter = factory.createMcsRestServiceAdapter();
For more information about creating an adapter, see Creating a Rest Service Adapter to Access Web Services.
A MAF application with one or more mobile backends (MBE) hosted on MCS can send analytics information about application usage to MCS Analytics.
Analytics information that MAF generates to send to MCS provides information about the application lifecycle and an end user’s interaction with the MAF application. MAF categorizes analytics events into MAF Framework events and business events. You send information captured in response to MAF Framework events to MCS by configuring properties in your application’s logging.properties
file. Examples of MAF framework events includes application start, feature events like activate and feature navigation, and user authentication events. MAF logs these events by default when you configure your application to send analytics information to MCS.
The following example shows the payload that MAF generates and transfers to MCS for a FeatureNavigation
MAF framework event that occurs when an end user is redirected to a login application feature (LF1
) before navigating to secured application features (secure-feature-1
, and secure-feature-2
). MAF logs all MAF framework events within a session that starts when a MAF application that is configured to send analytics information activates. The session ends when the MAF application deactivates. In the following example, the sessionID
property identifies the session.
JDeveloper’s Log window displays this payload when you deploy your MAF application to a device in debug mode.
"name":"FeatureNavigation", "properties":{"SourceId":"null","DestinationId":"LF1"}, "type":"custom", "timestamp":"2015-11-06T20:35:27.384Z", "sessionID":"com.company.MafAnalytics_736ad3d4-3443-4f65-8378-4e653ade2d30_160121114922" "name":"FeatureNavigation", "properties":{"SourceId":"LF1","DestinationId":"secure-feature-1"}, "type":"custom", "timestamp":"2015-11-06T20:35:27.384Z", "sessionID":"com.company.MafAnalytics_736ad3d4-3443-4f65-8378-4e653ade2d30_160121114922" "name":"FeatureNavigation", "properties":{"SourceId":"secure-feature-1","DestinationId":"secure-feature-2"}, "type":"custom", "timestamp":"2015-11-06T20:35:27.384Z", "sessionID":"com.company.MafAnalytics_736ad3d4-3443-4f65-8378-4e653ade2d30_160121114922"
Business events are events that you (the application developer) define in your application. You capture the analytics information for the event using the APIs that MAF provides in oracle.maf.api.analytics.AnalyticsUtilities
. MAF also exposes a data control method (fireEventListener
) on the ApplicationFeatures data control. Drag and drop this data control method to an AMX page where you can configure it to listen for the event that you define. These APIs can also be used to send analytics from MAF Framework events to MCS.
MAF also enables you to send context event information (device model, country, time zone, and so on) to MCS or to another repository that you choose.
You can also send analytics to repositories other than MCS.
For more information, see:
How to Configure the Transfer of Analytics to Oracle Mobile Cloud Service
How to Programmatically Send Analytics to Oracle Mobile Cloud Service
MAF Framework Events that Capture Analytics Information (Describes the MAF Framework events that MAF provides.)
For information about the classes in the oracle.maf.api.analytics
package that you can extend and customize, see Java API Reference for Oracle Mobile Application Framework.
MAF populates the logging.properties
file in a new MAF application with the properties that you need to configure to send analytics information from your MAF application to MCS Analytics.
The following example shows the ready-to-use entries that the logging.properties
file contains when you create a new MAF application.
# Configure the analytics logger # Analytics events are logged only if oracle.maf.api.analytics.level=ALL # Set to OFF or any level other than ALL to disable analytics oracle.maf.api.analytics.level=ALL oracle.maf.api.analytics.handlers=oracle.maf.api.analytics.LoggerAnalyticsHandler, oracle.maf.api.analytics.McsAnalyticsHandler oracle.maf.api.analytics.custom.level=INFO oracle.maf.api.analytics.LoggerAnalyticsHandler.level=INFO # Configure MCSHandler oracle.maf.api.analytics.McsAnalyticsHandler.level=INFO oracle.maf.api.analytics.McsAnalyticsHandler.connectionId=Mcs_Connection_Id oracle.maf.api.analytics.McsAnalyticsHandler.batchSize=25 oracle.maf.api.analytics.McsAnalyticsHandler.offlineWrite=false oracle.maf.api.analytics.McsAnalyticsHandler.recordUsername=false oracle.maf.api.analytics.McsAnalyticsHandler.contextProviderClassName=oracle.maf.api.analytics.McsContextProvider
Of the properties listed in the previous example, only connectionId
is mandatory. Table 29-2 describes the optional properties. The connectionId
property is where you define a valid connection to a MCS MBE. Use the connectionId
defined in your application’s connection.xml
as the value for this property. If you do not specify a valid connectionId
, MAF does not send events to MCS. Instead, MAF appends these events on disk until the maximum number of events allowed by the device is reached.
A valid connectionId
in your application’s connection.xml
file uses the ID of the MBE (oracle-mobile-backend-id
) and the application key (oracle-mobile-application-key
) that is generated when the MAF application registers with the MBE. MAF adds these two values to the HTTP header that creates a connection to MCS. These values identify the MBE to which the MAF application sends analytic events and identify the application from which the analytics events originate.
Note:
You do not need to register your MAF application as a client on MCS for all 3 platforms (Android, iOS, and Universal Windows Platform). Register the MAF application for one platform and use the generated application key as a value fororacle-mobile-application-key
.If the connection to the MCS MBE uses HTTP basic authentication type, associate oracle/wss_http_token_client_policy
with the connection. For connections that use Oauth, associate oracle/http_oauth2_token_mobile_client_policy
with the connection. If you do not associate the correct policy with the connection, MAF does not flush analytics events to MCS. For more information about associating a security policy with a connection, see Accessing Secure Web Services.
The following example shows extracts of an application connections.xml
file with values for the properties just discussed.
<References xmlns="http://xmlns.oracle.com/adf/jndi"> <Reference name="Mcs_Connection_Id" className="oracle.adf.model.connection.url.HttpURLConnection" adfCredentialStoreKey="McsLoginConn" xmlns=""> ... <RefAddresses> <XmlRefAddr addrType="Mcs_Connection_Id"> <Contents> <urlconnection name="Mcs_Connection_Id" url="http://mcs_instance.oracle.com:7201"/> ... </Reference> <Reference name="McsLoginConn" className="oracle.adf.model.connection.adfmf.LoginConnection" adfCredentialStoreKey="McsLoginConn" partial="false" manageInOracleEnterpriseManager="true" deployable="true" xmlns=""> <Factory className="oracle.adf.model.connection.adfmf.LoginConnectionFactory"/> <RefAddresses> <XmlRefAddr addrType="adfmfLogin"> <Contents> <login url="http://mcs_instance.oracle.com:7201/mobile/platform/users/login"/> <logout url="http://mcs_instance.oracle.com:7201/mobile/platform/users/logout"/> <customAuthHeaders> <header name="oracle-mobile-backend-id" value="0e4a9dfa-046a-4aaa-b8dd-331044ad81f4"/> <header name="oracle-mobile-application-key" value="be53201a-8674-48d7-96d0-bb02f4cd06c5"/> </customAuthHeaders> ... </References>
Configure the following optional entries in the logging.properties
file to implement the described functionality.
Table 29-2 Optional Properties to Manage the Transfer of Analytics from a MAF Application
Property | Description |
---|---|
batchSize | An optional property that determines the number of events saved locally before the MAF application sends them to an associated MCS instance. Events will be uploaded in batches to MCS. There is a limit on maximum batch size (65). If batchSize is not provided or exceeds the maximum limit of 65, a default batchSize of 25 applies. |
offlineWrite | An optional property that determines if offline buffering of events should be enabled or not. It is possible that events get generated while a device is offline or the client is not able to establish a connection with MCS. Configure the offlineWrite property if you do not want to lose these events. Once the connection is re-established, MAF flushes these saved events to MCS. The offlineWrite property ensures that those events get cached to disk to enable their buffering while offline. MAF provides support for up to 250 events. Events will be saved on a rolling basis. That is, MAF saves the last 250 events. This ensures offline buffering of the latest events. MAF also flushes events to MCS when the application deactivates, irrespective of whether batchSize has been reached or not. By default, offlineWrite is disabled. Set it to True to enable it. |
recordUsername | An optional property that determines if username should be captured or not. Set to True so that MAF captures the username when a user logs into a secured feature. If an application does not contain any secured feature or if the user has not yet logged into the secured feature then username remains null. If the application contains several secured features, then username will be updated based upon the credentials (username) used to log into that feature. The username captured will be sent as one of the fields in the context event. Therefore, if you intend to capture username, configure logging.properties so that the recordUsername property is True and contextProviderClassName has a valid class name for generating the context event. For example, oracle.maf.api.analytics.McsAnalyticsHandler.recordUsername=true . |
contextProviderClassName | Optional. Provide a value for this property when the context event is generated. The value you specify determines the class that generates the context event for MCS. The context event contains information like timezone offset, geolocation and device information. It can also contain username if recordUsername is set to True . The contextProviderClassName property is disabled by default. The following example shows how you enable it: oracle.maf.api.analytics.McsAnalyticsHandler.contextProviderClassName=oracle.maf.api.analytics.McsContextProvider |
MAF provides an API in oracle.maf.api.analytics.AnalyticsUtilities
that you can use to send events to MCS.
The AnalyticsUtilities
class provides the following API:
public static void fireEvent(Level level, String category, String eventName) // Send an event without a payload public static void fireEvent(Level level, String category, String eventName, JSONObject payload) // Send an event with a JSON payload level: The logging level of the event. Set to any standard level supported by Java logging. category: The category of the event. Set to 'custom' for all events except context, sessionStart(MAF Framework event) and sessionEnd(MAF Framework event). Set the latter events to 'system'. eventName: Provide your own event name if you do not use an event provided in the AnalyticsUtilities class. Throws an exception if null. payload: A JSONObject that contains key-value pairs for custom events. The JSONObject must be of type String. No other data type is supported.
Configure your application’s logging.properties
file with the values necessary to transfer analytics to MCS before you use this API. Specify, for example, the MCS connectionID
.
The following example demonstrates how to use this API to send analytics from a MAF application to MCS.
// Sending events from your application. // The following logs event when there is no payload to register for an event. AnalyticsUtilities.fireEvent(Level.WARNING, AnalyticsUtilities.CATEGORY_CUSTOM, "EVENT_VIDEO_ACTIONS"); // The following logs event when there is a JSON payload to send for a custom event. try { JSONObject payload = new JSONObject(); payload.put("PAYLOAD_VIDEONAME", getFileName()); payload.put("PAYLOAD_ACTION", getAction()); // Creating a custom event 'EVENT_VIDEO_ACTIONS' of level INFO AnalyticsUtilities.fireEvent(Level.INFO, AnalyticsUtilities.CATEGORY_CUSTOM, "EVENT_VIDEO_ACTIONS" , payload); } catch(Throwable t) { // log the error }
You can set different log levels to capture events based on user interaction. For example, the EVENT_VIDEO_ACTIONS
event in the previous example could be of INFO
level when your end user performs a play action. Alternatively, it could be set to WARNING
level to capture events in case of failure. You manage the logging level in the logging.properties
file. For example, to manage the logging of EVENT_VIDEO_ACTIONS
events, configure the logging.properties
file as follows:
// Set to WARNING to log events for the play action. Set to INFO (or a lower level) // to log events for the play action plus failure events oracle.maf.api.analytics.custom.EVENT_VIDEO_ACTIONS.level=WARNING // Disable logging of EVENT_VIDEO_ACTIONS oracle.maf.api.analytics.custom.EVENT_VIDEO_ACTIONS.level=OFF
MAF applications can capture context events and send the collected information to MCS or to a repository other than MCS.
A context event defines the context of subsequent events until another context event is logged. An event can be logged from a MAF Framework event or from events that you define in your application.
Table 29-3 lists key names that MCS accepts in the key-value pairs of the JSON object(s) that transmit context events from the MAF application. MCS requires that all properties be of type String. All properties in the following table are optional.
Note:
MCS translates latitude and longitude information to city, state, country, and postal code. Provide latitude and longitude information or locality, region, postalCode and country, but not both.
Table 29-3 Valid Key Names to Send Context Event Information to MCS
Key Name | Description |
---|---|
userName | The user of the device who was logged in to the secured feature when the context events were logged. |
timezone | Device's offset from UTC in seconds |
model | Device's model name |
osName | Device operating system name |
osVersion | Device operating system version |
latitude | Device's GPS latitude |
longitude | Device's GPS longitude |
locality | Device's locality |
region | Device's region |
postalCode | Device's postal code |
country | Device's country |
To send context event information from your MAF application to MCS, configure the following entry in your logging.properties
file:
oracle.maf.api.analytics.McsAnalyticsHandler.contextProviderClassName= oracle.maf.api.analytics.McsContextProvider
With this entry configured in your logging.properties
file, MAF sends the context event information listed in Table 29-3 to MCS. You also need to set recordUsername
to True
in the logging.properties
file if you want the MAF application to send the user name to MCS.
If you want to generate context events that contain fields you define, configure the following entry in your logging.properties
file:
oracle.maf.api.analytics.McsAnalyticsHandler.contextProviderClassName=oracle.maf.demo.CustomContextProvider
Where oracle.maf.demo.CustomContextProvider
is a class that implements oracle.maf.api.analytics.ContextProvider
, as shown in Example 29-2. The generated context event contains the timezone, carrier, and manufacturer information.
Example 29-2 Custom Context Provider to Send Context Information
package oracle.maf.demo; import java.util.Date; import java.util.TimeZone; import oracle.maf.api.analytics.ContextProvider; import oracle.adfmf.json.JSONObject; public class CustomContextProvider implements ContextProvider { public CustomContextProvider() { super(); } public JSONObject generateContext() { JSONObject myCustomCtx = new JSONObject(); // // TimeZone - Mobile device's offset from UTC in seconds // Date date = new Date(); int offset = TimeZone.getDefault().getOffset(date.getTime()) / 1000; try { myCustomCtx.put("timezone", new Integer(offset).toString()); myCustomCtx.put("carrier", "AT&T"); myCustomCtx.put("manufacturer", "Apple"); } catch(Exception ex) { ex.printStackTrace(); } return myCustomCtx; } }
MAF applications can send analytics to repositories other than MCS.
To achieve this, you write a custom class that extends oracle.maf.api.analytics.McsAnalyticsHandler
and overrides processEvent()
method, as shown in the following example.
package oracle.maf.demo; import java.io.IOException; import oracle.adfmf.framework.exception.AdfException; import oracle.adfmf.json.JSONArray; import oracle.adfmf.resource.CDCErrorBundle; import oracle.adfmf.util.ResourceBundleHelper; import oracle.maf.api.analytics.McsAnalyticsHandler; import oracle.maf.api.dc.ws.rest.RestServiceAdapter; import oracle.maf.api.dc.ws.rest.RestServiceAdapterFactory; public class CustomHandler extends McsAnalyticsHandler { public CustomHandler() { super(); } // // Establish the connection to a different repository and flush the events. // protected void processEvents() throws AdfException { // Extract the events to be flushed _events = super.getEvents(); RestServiceAdapter restAdapter = RestServiceAdapterFactory.newFactory().createRestServiceAdapter(); restAdapter.clearRequestProperties(); // Get valid connectionId of the repository. restAdapter.setConnectionName(getConnectionId()); restAdapter.setRequestMethod(RestServiceAdapter.REQUEST_TYPE_POST); restAdapter.addRequestProperty("Content-Type", "application/json"); restAdapter.setRequestURI(_ANOTHER_REPOSITORY_URI); restAdapter.setGenerateAnalyticsEvents(false); // make REST call to send events try { String responseMessage = restAdapter.send(_events.toString()); } catch (IOException ex) { throw new AdfException(AdfException.ERROR, ResourceBundleHelper.CDC_ERROR_BUNDLE, CDCErrorBundle.ERR_ANALYTICS_FLUSH_EVENTS, new Object[] { ex }); } } private JSONArray _events = new JSONArray(); private static final String _ANOTHER_REPOSITORY_URI = "_repository_uri"; }
You also need register the custom class in the logging.properties
file. For example, to register CustomHandler
, configure logging.properties
as shown in the following example:
# Configure the analytics logger oracle.maf.api.analytics.level=ALL oracle.maf.api.analytics.handlers=oracle.maf.demo.CustomHandler oracle.maf.api.analytics.custom.level=INFO # Configure CustomHandler oracle.maf.demo.CustomHandler.level=INFO oracle.maf.demo.CustomHandler.connectionId=RepositoryConn oracle.maf.demo.CustomHandler.batchSize=7 oracle.maf.demo.CustomHandler.offlineWrite=true oracle.maf.demo.CustomHandler.recordUsername=false oracle.maf.demo.CustomHandler.contextProviderClassName=oracle.maf.api.analytics.McsContextProvider
MAF provides a range of MAF Framework events that capture analytics information.
These events are grouped into two categories (custom and system). Configure your application’s logging.properties
file so that the application sends these events to MCS. First, configure your application’s logging.properties
file to enable the sending of analytics information by, among other things, specifying the MCS connectionID
. You then specify the events that you want to send. Use the information in the following tables for this latter task.
Table 29-4 lists the MAF Framework events (custom category) that you can configure in the logging.properties
file to send analytics information to MCS from your application. You can disable each event by setting it to OFF or to a higher logging level than the level that enables logging of the event.
Table 29-4 MAF Framework Events (Custom Category)
Event Name | Logging Level | Enable or Disable Logging |
---|---|---|
UpdateAuthenticationStatus |
FINE |
|
FeatureNavigation |
INFO |
|
Login |
INFO |
|
LoginCallback |
FINER |
|
Timer |
INFO for Operations: Warning and Expired FINE for Operation: Adjust |
|
Logout |
INFO |
|
LogoutCallback |
FINER |
|
PageNavigation |
INFO |
|
FeatureTransition |
INFO |
|
ApplicationTransition |
INFO |
|
RESTWebService |
INFO |
|
Table 29-5 lists the MAF Framework events (system category) that you can configure in the logging.properties
file to send analytics information to MCS from your application
Table 29-5 MAF Framework Events (System Category)
Event Name | Logging Level | Description |
---|---|---|
sessionStart |
INFO | MAF reserves the use of this event name to identify the session that it starts when a MAF application activates and starts to log analytics information. Do not define events in your MAF application that use this event name. |
sessionEnd |
INFO | MAF reserves the use of this event name to identify the session that it stops when a MAF application deactivates and stops logging analytics information. Do not define events in your MAF application that use this event name.
MAF flushes events to MCS when |
context |
INFO | Sends context event information (for example, the timezone, carrier, and manufacturer of the device). Enable this event as follows:
oracle.maf.api.analytics.McsAnalyticsHandler .contextProviderClassName=oracle.maf.api .analytics.McsContextProvider For more information about the context event information, see How to Send Context Events to Oracle Mobile Cloud Service |