Friday, August 22, 2014

Oracle MAF - Issues, Tips and Tricks

Hi All,

I have built a mobile application using Mobile Application Framework released in July 2014.
In the mobile app I have done integration using REST services with JSON output. And the user will fill some forms and will send attachments from camera and library. The user can see history and I have used a pie chart as well for historical data.

Here is some of the issues, tricks which I learnt and I am sharing the same:

*********************************************************************************

ISSUES, TIPS & TRICKS:

*********************************************************************************
1.

[11:29:47 AM] Checking state of Android Debug Bridge server...
[11:29:47 AM] Android Debug Bridge server already running.
[11:29:55 AM] Command-line executed: ["C:\Program Files\Android\android-sdk\platform-tools\adb", start-server]
[11:29:55 AM] ADB server didn't ACK
[11:29:55 AM] * failed to start daemon *
[11:29:55 AM] * daemon not running. starting it now on port 5037 *
[11:29:55 AM] Command-line execution failed (Return code: -1)
[11:29:55 AM] Deployment cancelled.

Solution:
Go to platform-tools and kill adb server, it might be running because you would have done some debugging.
cd C:\Program Files\Android\android-sdk\platform-tools
adb kill-server


*********************************************************************************
2.

Error while deploying MAF app to android:
[12:11:31 PM] Cannot run program "xxx\adt-bundle-windows-x86_64-20140321\sdk\tools\zipalign"": CreateProcess error=2, The system cannot find the file specified
[12:11:31 PM] CreateProcess error=2, The system cannot find the file specified

In case, if you hit the above error while deploying MAF application to android device, here is the reason:

When generating an deployable artifact(apk), JDeveloper uses zipalign.exe that comes with ADT. This used to be located in /sdk/tools, but (with latest ADT release) it is now located in /sdk/build-tools/ folder. A quick work around (till the fix is available in Jdev) for the above issue is to copy the appropriate  zipalign.exe to /sdk/tools folder.

If zipalign is not available, that means you have upgraded your tools but you have not upgraded your build-tools, do that from SDK Manager.

*********************************************************************************
3. ( MAF Application Hangs / Stuck at Splash screen showing Oracle logo )
The application is hanging after successful deployment and you are only seeing the splash screen.
a. Welll check cvm.properties, if you missed changing back java.debug to false
b. You are calling webservices and you missed selecting the checkbox for "Network" in maf-applications.xml -> Permissions
c. MAF only supports XML encoded in the ASCII, UTF-8 or UTF-16 character sets.  JDeveloper might default this based on your machine`s setting and uses it to encode the XML files in your MAF application.
Change the character encoding option in Project Properties for your project:

d. If the above don`t resolve your issue then deploy your application in debug mode and open monitor.bat(location -> tools directory under android folder) and see what exception is coming.

*********************************************************************************
4.
When seeing the logs in monitor I am getting the following message multiple times and because of that its diffcult to find the required logs:
07-23 05:43:50.796: W/Trace(3095): Unexpected value from nativeGetEnabledTags: 0

Goto your Logcat
As a workaround I'm filtering the LogCat output with the following expression on the by Log Message field of the filter:

^(?!.*(nativeGetEnabledTags)).*$ 

*********************************************************************************
5. ( Webservice Certification Error )

When calling a secured webservice I am getting the following error:
Certificate was issued by an unrecognized entity

Download certificate using firefox, available in details tab when we access the site.

ADF Mobile will only recognize certificates from a few popular CA signing authorities.

Following the below link and register your certificate with JVM:
http://docs.oracle.com/cd/E35521_01/doc.111230/e24475/security.htm#CDDCCDFF

First copy cacerts file from your project to the bin directory, then run the below command and then copy back the cacerts file:
cacerts file location - \MobileApp\resources\security

cd C:\Program Files\Java\jdk1.7.0_60\bin
keytool -importcert -keystore cacerts -file adpc_cert -storepass changeit -noprompt

*********************************************************************************
6.

07-23 16:00:16.784: D/CVM(1243): [SEVERE - oracle.adfmf.framework - RestTransportLayer - readResponse] ERROR: REST Transport - read - ERROR [oracle.adfmf.framework.exception.AdfInvocationRuntimeException] - HTTP Status Code 500 Internal Server Error: The server encountered an unexpected condition which prevented it from fulfilling the request.
07-23 16:00:16.818: D/CVM(1243): ERROR [oracle.adfmf.framework.exception.AdfInvocationRuntimeException] - HTTP Status Code 500 Internal Server Error: The server encountered an unexpected condition which prevented it from fulfilling the request.
07-23 16:00:16.824: D/CVM(1243):  at oracle.adfmf.dc.ws.rest.RestTransportLayer.getInputStream(Unknown Source)
07-23 16:00:16.824: D/CVM(1243):  at oracle.adfmf.dc.ws.rest.RestTransportLayer.readResponse(Unknown Source)
07-23 16:00:16.844: D/CVM(1243):  at oracle.adfmf.dc.ws.rest.RestTransportLayer.sendReceiveBytes(Unknown Source)
07-23 16:00:16.844: D/CVM(1243):  at oracle.adfmf.dc.ws.rest.RestTransportLayer.sendReceive(Unknown Source)


07-23 16:00:17.274: D/CVM(1243):         <title>Request format is unrecognized for URL unexpectedly ending in '/'.</title>

Make sure the REST URL which you are setting in your code doesn`t have / in the end.
*********************************************************************************
7. ( Invalid Request Format when calling REST service )
Getting the below error while calling a REST service with json output using RESTServiceAdapter:
 System.InvalidOperationException: Request format is invalid: .
Can be multiple reasons. Make sure you specify the correct content-type and accept parameters:
        // Specify the type of request
        restServiceAdapter.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        restServiceAdapter.addRequestProperty("Accept", "application/json; charset=UTF-8");


*********************************************************************************
8. 
The most important property for displaying an image is max-width:100%
Using this the image is fully displayed properly in specified or calculated region based on the screen size of the mobile.
*********************************************************************************
9. ( Display multiple line in list view )
If you want to display multiline output text inside a listview use below attribute in inline style for outputText:
 white-space:pre-wrap
*********************************************************************************
10.

 Use severe logs during testing and your logs will be generated even in release mode.            Trace.log(Utility.ApplicationLogger, Level.SEVERE, LoginBean.class, "Calling Authentication Service",
                      "##############Payload:  " + payload);
This way you don`t need to deploy in debug mode for seeing the logs. But make sure to change back to INFO during production deployment.
Note: Release mode runs much faster than debug mode.
*********************************************************************************
11. ( Open a URL programatically through Javascript )

You have a requirement to open a url from your mobile app in mobile browser programmatically. In that case you can call a javascript function and use the below code:
if(device.platform == 'Android') {
  navigator.app.loadUrl(url, {openExternal:true});
  } else {
  window.open(url, '_system');
  }


*********************************************************************************
12. Setting and Getting EL Value Programmatically

AdfmfJavaUtilities.setELValue("#{pageFlowScope.msg}", "Welcome");
String msg = (String)AdfmfJavaUtilities.evaluateELExpression("#{pageFlowScope.msg}");

*********************************************************************************


13. Getting size of the iterator (estimatedrowcount or rowcount)

As suggested by Steven Davelaar in one of the discussion threa:
The AmxIteratorBinding class has a method getIterator which returns an instance of BasicIterator. This class has a method getTotalRowCount, so you can use the following expression:

#{bindings.yourIteratorName.iterator.totalRowCount}

See the javadoc for more info BasicIterator (Oracle Fusion Middleware Java API Reference for Oracle Mobile Application Framework http://docs.oracle.com/middleware/mobile200/mobile/api-ref/oracle/adfmf/bindings/iterator/BasicIterator.html#getTotalRowCount())
*********************************************************************************
I will keep on updating this blog.

Regards,
Deepak

11 comments:

  1. How to navigate between 2 AMX pages with parameter and without parameter

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hey I am nerd in oracle MAF.
    Can you please tell me ,Is it possible to call feature from feature...and feature can contain whatever amx ,pageflow...etc.
    if yes can you please tell me the steps...

    ReplyDelete
  4. Hi,
    I am new to Oracle MAF and trying to build myown applications. Could you please tell me how to create a hamgurger menu in MAF?

    ReplyDelete
  5. Hi there, I'm running a mobile hybrid MAF application and in android/iOS i keep getting an issue where randomly page will load, show white screen and loading logo, but then never complete loading.

    Whenever I press the blank screen again though it will again start loading and complete loading. Do you know why this would occur?

    ReplyDelete
  6. Hi there, i am new to MAF, I am building application which detects users current location i used StartLocationMonitor
    FOLLOWED STEPS:-
    https://blogs.oracle.com/imc/using-startlocationmonitor-to-enable-geolocation-in-maf-applications


    I AM GETTING ERROR:-
    Target unreachable base expression 'locationBean' resolved to null

    please guide me on this issue

    thanks in advance

    ReplyDelete