Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Dan_vL
Product and Topic Expert
Product and Topic Expert

Appendix F:  Tips

Where to Get Help with Cordova Questions
Adding the WTP HTML and JavaScript Editors to Eclipse
Monitoring HTTP and HTTPS Requests
Customizing and Reducing the Project Size
Setting the Session Timeout for the Management Cockpit
Accelerating the Android Emulator
Proxy Settings on Android
iOS 7 Status Bar Overlays the App
Enabling Landscape Orientation
Simple Customizations
Opening URL's
Miscellaneous Tips

Where to Get Help with Cordova Questions

There is an active forum on PhoneGap/Cordova at PhoneGap Forum.

The list of known Cordova issues can be searched at Apache Cordova Issue Tracker.

The Cordova mailing lists can be searched at Apache Cordova Mailing Lists.

The Apache Cordova News section often lists bug fixes that are in a particular release.

Adding the WTP HTML and JavaScript Editors to Eclipse

By default the Android ADT Eclipse bundle does not contain the Web Tools editors.  These can be added by choosing Help > Install New Software... > Juno >  Web, XML, Java EE and OSGi Enterprise Development > JavaScript Development Tools and Web Page Editor.

After restarting Eclipse, right click on an HTML or JavaScript file and open it with the appropriate editor.

The default editor for a certain file type can be set under Window > Preferences > General > Editors > File Associations

Monitoring HTTP and HTTPS Requests

It can be useful to examine the REST calls made between an application and the SMP 3.0 server and the SMP server and a backend.  The following shows some different tools to do that although there are many others that can also be used.

TcpTrace
SMP 3.0 Server Trace
SMP 3.0 Server Trace with Fiddler
Device Trace with Fiddler

TcpTrace

The following steps demonstrate the TcpTracewhich also shows cookies.

  • Download and run TcpTrace.

  • Specify the port TcpTrace will use to listen for requests and the host and port it should forward the request to.


  • Modify the application to use the port TcpTrace is listening on and make some requests.


SMP 3.0 Server Trace

The SMP 3.0 server can also log all requests.  There are a couple of different ways to do this.

  • To enable this feature, modify C:\SAP\MobilePlatform3\Server\config_master\org.eclipse.gemini.web.tomcat\default-server.xml and uncomment the entry <Valve className="org.apache.catalina.valves.AccessLogValve".

  • Restart the SMP 3.0 server.

  • After making some requests to the SMP 3.0 server examine the log file at C:\SAP\MobilePlatform3\Server\log\localhost_http_access_2014-04-29.log.
    10.7.171.196 - - [29/Apr/2014:16:58:28 -0400] "OPTIONS /odata/applications/latest/com.mycompany.timing/Connections HTTP/1.1" 200 - 146
    10.7.171.196 - i826567 [29/Apr/2014:16:58:28 -0400] "POST /odata/applications/latest/com.mycompany.timing/Connections HTTP/1.1" 201 1704 453
    10.7.171.196 - - [29/Apr/2014:16:58:30 -0400] "OPTIONS /com.mycompany.timing/FlightCollection HTTP/1.1" 200 - 3
    10.7.171.196 - i826567 [29/Apr/2014:16:58:33 -0400] "GET /com.mycompany.timing/FlightCollection HTTP/1.1" 200 582225 3038
    The second last entry indicates the response size and the last entry indicates the duration in milliseconds that the operation took.  The last operation returned 569KB and took approximately 3 seconds to complete.

  • Modify the following file.
    C:\SAP\MobilePlatform3\Server\config_master\com.sap.js.logging\logging.cfg
    Add the following line.
    system.logger.org.apache.http.wire=trace
    Restart the SMP server and execute a read operation and then examine the following log file.
    C:\SAP\MobilePlatform3\Server\log\machine_name-smp-server.log
    "GET http://services.odata.org/V2/OData/OData.svc/Products HTTP/1.1[\r][\n]"
    "accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1[\r][\n]"
    "maxdataserviceversion: 3.0[\r][\n]"
    "accept-encoding: gzip,deflate[\r][\n]"
    "accept-language: en-US[\r][\n]"
    "cookie: X-SMP-SESSID=1624561118350E68CDB6424A2804FEDE0DC8430295B095C2470ED2CF7409B793; X-SMP-SESSIDSSO=DD1BE16B2AC24AA77D88FB57B3DD2458; X-SMP-APPCID=8852b007-feba-49d6-907a-3df0413d66cb; X-SUP-APPCID=8852b007-feba-49d6-907a-3df0413d66cb[\r][\n]"
    "x-requested-with: com.mycompany.offline[\r][\n]" "Cookie: [\r][\n]"
    "Host: services.odata.org[\r][\n]"
    "Proxy-Connection: Keep-Alive[\r][\n]"
    "User-Agent: Apache-HttpClient/4.2.5 (java 1.5)[\r][\n]"
    "[\r][\n]" "HTTP/1.1 200 OK[\r][\n]"
    "Cache-Control: no-cache[\r][\n]"
    "Content-Length: 1028[\r][\n]"
    "Content-Type: application/json;charset=utf-8[\r][\n]"
    "Vary: Accept-Encoding[\r][\n]"
    "Server: Microsoft-IIS/8.0[\r][\n]"
    "DataServiceVersion: 2.0;[\r][\n]"
    "X-AspNet-Version: 4.0.30319[\r][\n]"
    "X-Powered-By: ASP.NET[\r][\n]"
    "Date: Wed, 25 Feb 2015 19:28:02 GMT[\r][\n]"
    "Proxy-Connection: Keep-Alive[\r][\n]"
    "Connection: Keep-Alive[\r][\n]"
    "Content-Encoding: gzip[\r][\n]"
    "Set-Cookie: ARRAffinity=4a346cc2ba936a87116efc1bc94884e8ba98aac9ef2852df21b6678b3bdb51e0;Path=/;Domain=services.odata.org[\r][\n]" "[\r][\n]"

SMP 3.0 Server Trace with Fiddler

Another way to examine the requests made by the SMP server to an endpoint that has the option Use System Proxy checked is to configure the SMP Server to use Fiddler as the proxy.  In this way requests made by the SMP server that go through the proxy can be examined.  To see this in action run the example from the Offlinesection.

  • Ensure that the option Use System Proxy is checked.


  • Configure the SMP Server to use Fiddler as its proxy.


  • Check the port that Fiddler is listening on.  Fiddler > Tools > Fiddler Options > Connections >
    If your network requires a proxy, check Act as system proxy on startup. After making changes, restart fiddler.



  • Uncheck the option to Capture Traffic via File > Uncheck Capture Traffic.  This means only the requests made using Fiddler as a proxy will be captured.


  • The following is the captured requests from performing a register, Read, Open Store.  Note it is only the Read (1st request) and the Open Store requests (4 requests) are captured as register in this case is not using the proxy.


  • If the endpoint is accessed over HTTPS, in Fiddler choose Tools > Fiddler Options > Capture HTTPS Connects > Decrypt HTTPS traffic > from all processes.


    The Fiddler generated certificate for the specific backend will need to be imported into the SMP keystore.  It does not appear to be sufficient to simply import the Fiddler Root certificate.
    For example, if the endpoint is
    https://sapes1.sapdevcenter.com/sap/opu/odata/IWFND/RMTSAMPLEFLIGHT
    after trying to capture the traffic with Fiddler, open certmgr.msc, and  export the certificate generated by Fiddler for this endpoint.
    Note, you may need to refresh the view to see the certificate.
    Choose Copy to File > No, do not export the private key > Base-64 encoded X.509.


    Import the Fiddler Root cert and this generated cert into the SMP keystore.
    keytool -import -v -alias fiddlersapes -keystore smp_keystore.jks -storepass changeit -file c:\certs\fiddlerSapes.cer
  • Here is an example of a Read request being made from the SMP server to the backend using HTTPS being viewed in Fiddler.


Device Trace with Fiddler

  • It is also possible to use Fiddler to capture the traffic between the mobile device and the SMP server.  This would include the calls that are made during the registration process which is not shown above.  To do so, set the proxy on the mobile device to use Fiddler.  Settings > Wi-Fi > Long Press on the network connection > Modify Network > Show Advanced Options > Proxy Manual, specify the proxy hostname and port.


    The following is the trace from performing a Register, Read and Open Offline Store. 


    Notice that this time the registration calls are included in the trace.  Also note that the calls from the offline store (MobiLink) are shown but are not readable as they are encrypted.

  • It is also possible to examine HTTPS traffic.  In Fiddler choose Tools > Fiddler Options > Capture HTTPS Connects > Decrypt HTTPS traffic > from all processes.
    In a browser on the device open the following URL and click on the link You can download the FiddlerRoot certificate.
    http://ip_of_machine_with_fiddler_running:8888

    Here is an example of viewing HTTPS traffic with Fiddler.


  • Note, that in order for Fiddler to view HTTPS traffic from an iOS device or simulator, the following instructions need to be followed.  Note that replacing makecert with the CertMaker for iOS and Android causes the endpoint specific cert not to be generated in the Windows cert store and hence will cause the SMP Server trace with Fiddler for HTTPS backends to fail.

    FAQ - Certificates in Fiddler
    Capture Traffic from iOS Device

Customizing and Reducing the Project Size

The default project created by running

cordova create ...

is copied from

C:\Users\user_name\.cordova\lib\www\cordova\3.x\www
or
/Users/user_name/.cordova/lib/www/cordova/3.x/www

As such if there are files that you always wish to include in new Kapsel projects such as datajs-1.1.2.min.js they can be included here.  Alternatively if you wish to not include certain files, they can be removed.
Note that in Cordova 3.4, the create command supports a --src parameter which specifies the location to get the contents for the assets folder of the newly created project.  See CB-4153

Note, on iOS .folders are hidden by default.  They can be made viewable by

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

Setting the Session Timeout for the Management Cockpit

The duration after which the Management Cockpit by default times out and requests the user to log in again is 20 minutes from the last use.  This value can be changed by modifying the session-timeout setting in the following file and restarting the SMP 3.0 server.

C:\SAP\MobilePlatform3\Server\config_master\org.eclipse.gemini.web.tomcat\web.xml

Note that if the same browser that is hosting the Management Cockpit is also used to say invoke a REST call against the SMP 3.0 server and uses a different security profile, the Management Cockpit is logged out.  An example of this is using the Chrome Advanced Rest Client to send a push notification as described in the section Push.

Accelerating the Android Emulator

There are two ways that the Android emulator can be configured to run faster.  The first way uses graphics acceleration to increase the redraw rate of the emulator.  It can be enabled by checking Use Host GPU

Note you may run into screen redraw issues after enabling this option.

The second way is to use virtual machine acceleration.  This requires the download of the Intel Hardware Accelerated Execution Manager. 

It then needs to be installed.

C:\Android\adt-bundle-windows-x86_64-20130729\sdk\extras\intel\Hardware_Accelerated_Execution_Manager\IntelHaxm.exe

An Android X86 based image, Intel Atom (x86) must be selected.

Note that after starting the emulator; the following message appears indicating that it is working correctly. 

For additional details see Using Hardware Acceleration.

Proxy Setting for Android

If you use a proxy server, the Android emulator can be configured under Settings > More > Mobile Networks > Access Point Names.

To set the proxy settings for an Android device that is using WIFI, go to Settings > Wireless and Network > Wi-Fi Settings > Long press on the Wi-Fi network > Check the Show Advanced Options.
A quick way to test if the proxy settings are working is to open the browser and attempt to access a web site such as http://www.google.com.

iOS 7 Status Bar Overlays the App

If your app runs on iOS 7 you may need to add a 20 pixel top margin so that the status bar does not overlay the main screen of the application.  The Status Bar Issue describes the problem in more detail and contains the following solution.

document.addEventListener('deviceready', onDeviceReady, false);

function init() {
    if (parseFloat(window.device.version) >= 7.0) {
          document.body.style.marginTop = "20px";
    }
}
 

A SAPUI5 specific solution is shown below.

html[data-sap-ui-os^="iOS7"] .sapMBar {
  border-top-color:#F2F2F2;
  border-top-style:solid;
  border-top-width:20px;
}

Perhaps a better way to address this is to use the org.apache.cordova.statusbarplugin.

cordova plugin add org.apache.cordova.statusbar

Then modify the config.xml file and set the StatusBarOverlaysWebView to false.

Enabling Landscape Orientation

If you rotate an iPhone device or simulator, the HTML page does not rotate to support the new orientation.  To add this ability, in Xcode, under Info > Custom iOS Target Properties > Supported interface orientations, add the missing interface orientations such as Landscape (left home button).

On an Android device, check the following setting on 5.x devices. Settings > Display > When device is rotated > Rotate the contents of the screen.

Simple Customizations

There are a few easy ways to quickly customize your app including adding a gradient, removing the default Cordova splash screen and changing the app icon.  Additional information on app icons and splashscreens can be seen at Splashscreen.

  • To add a gradient use a tool like Ultimate CSS Gradient Generatorto generate a line of CSS that can be added to the top of your index.html.
    <head>
        <style>
            body {background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#feffff), color-stop(35%,#ddf1f9), color-stop(100%,#a0d8ef));}
        </style>
  • To change the splash screen on iOS, left-click on the Project > Target > scroll to Launch Images, right-click on the image that matches the device type being used and choose open with Finder.    Replace that image with a new image that has the appropriate resolution.  The same approach can be followed to change the app icon.
  • To change the app icon on Android, replace the icon image with a new image that has the appropriate resolution.  The icon images are located in the following folder.
    project_name\platforms\android\res\drawable-xxxx.

Note that cleaning the project may be necessary after changing the icon or splash screen.

Opening URL's

To open an external URL from index.html, the Cordova InAppBrowser plugin can be used.

<script>
    function showURL(url) {
        var URLToOpen = encodeURI(url);  //may be needed if URL contains parameters
        var ref = window.open(URLToOpen, '_blank', 'location=yes,toolbar=yes,toolbarposition=top'); //toolbar options are iOS only

//Note on Android, some attachment types such as PDF, XLS, DOCX can be opened by changing '_blank' to '_system'


  //The appropriate viewer would need to be installed and it may help to have a file manager program like ES File Explorer installed













    }
</script>
<a href="javascript:void(0);" onclick="showURL('http://www.google.com')">www.google.com</a>

This will open a new window showing the web site www.google.com. ; When the window is closed, the Kapsel app will regain focus.

Note that local HTML files can simply be opened using

<a href="accounts.html">Open Accounts</a>

Note that on Android, if the resource does not exist and the link is clicked on the app will close.  To instead shown an error screen, modify the config.xml file under the res/xml folder to include a preference setting indicating an error page to open.

<preference name="errorUrl" value="file:///android_asset/www/error.html" />

See Android Configuration for additional details.

Miscellaneous Tips

  • Sometimes in Xcode it is necessary to perform a more complete clean of a project.  This can be performed by holding the Alt key when selecting the Product menu.  The Clean menu item changes to Clean Build Folder...

  • The iOS simulator can be reset to a clean state.  This can be performed by choosing iOS Simulator > Reset Content and Settings...

  • To delete an app on iOS, long press on the app icon.

  • An iOS app can be removed from memory by pressing the home button twice quickly.  On iOS 7 swipe the app up to remove it.

  • See Interacting with iOS Simulator for details on things such as how to rotate, drag and pinch.

  • A linker error may occur if the Deployment Target is changed from 6.0 to 7 or 8 on an Xcode project that contains the Logon plugin. This can be corrected by adding the library "libstdc++.6.0.9.dylib". Under the General tab for the project, click on the + sign in the Linked Frameworks and Libraries section and add "libstdc++.6.0.9.dylib".

  • An Android app can be uninstalled or reset to a newly deployed state via Settings > Apps > App > Uninstall or Clear Data.  A quicker way to do this is to long press on the app and then drag the icon to Uninstall or App Info.

  • If the application running in an Android emulator takes a while to load it may be necessary to increase the loadUrlTimeout value.  This can be set in the Java class for the plugin.
    public class LogonDemo extends DroidGap
    {
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.setIntegerProperty("loadUrlTimeoutValue", 60000);   //add this line.

            super.onCreate(savedInstanceState);
            // Set by <content src="index.html" /> in config.xml
            super.loadUrl(Config.getStartUrl());
            //super.loadUrl("file:///android_asset/www/index.html")
        }
    }
    See also Android Configuration.

  • Occasionally the logcat view stops displaying messages from the attached Android or simulator.  Sometimes, switching to the DDMS perspective and clicking on a few entries in the Devices view corrects this.  Also make sure that no filters or regular expressions are being accidentally applied.

  • If the SMP 3.0 Management Cockpit fails to open, one reason may be that another process is using port 8083.  To view which process is using port 8083 enter
    netstat -ano | findstr 8083
    TCP    [::]:8083              [::]:0                 LISTENING       8092
    Using the above information we can see that a process with the process ID of 8092 is using port 8083.  Open the task manager on windows and add the PID column and check Show processes from all users to find the process that is using port 8083.  The SMP 3.0 server should appear as a java.exe process and a description of SAP Java VM Runtime binary.

  • In the Xcode All Output view you may see the following message.
    Started backup to iCloud!  Please be careful.
    Your application be might rejected by Apple if you store too much data.
    This setting is controlled by the preference setting BackupWebStorage which is set by default to cloud in the config.xml file.
    See also iOS Configuration.

  • If you are doing Android development on iOS and wish to create a new Android emulator running android for me opens the Android SDK Manager without any menus.  If instead it is opened with
    nohup android &
    the terminal window can be closed and then the Android SDK Manager menu appears.

  • If you need to enter text on an Android device and wish to use your computers keyboard try the following.
    adb shell input text some_text_to_enter
  • If you have a tip that isn't listed here that others would benefit from please mention it in the comments section below.

Back to Getting Started With Kapsel

2 Comments