Monthly Archives: December 2018

How to use JProfiler for Performance testing

If you are a developer, some point of time you will have to use JProfiler for measuring the performance of your application. Many times, this is left to specialized performance teams or developers who know the tools well, but don’t know much about the code that they are trying to measure the performance. This approach, despite might be working, can have its flaws. Especially since performance team members are not writing the code. So as part of this past, I want to debunk few myths around this and why a developer should equally focus on a tool like JProfiler to check the performance.

What will you need

  • JProfiler (standalone or plugin in IntelliJ)
  • IntelliJ
  • A web application that you can profile

Understanding JProfiler

First JProfiler is a tool to understand what is going on inside a running JVM. Before we run the test, we should understand the basic functionality of JProfiler and how it will help us in performance improvement.

There are three aspects to JProfiler:

Time Profiling – This measures the execution paths of your application on the method level.

Memory Profiling – This provides the in-depth understand of heap usage by the application.

Thread Profiling – This analyses the thread synchronization issues.

JProfiler combines time, memory and thread profilers in a single application.

Performance Test

In this test, we will be profiling java code of the application. You can download JProfiler as a standalone tool to run or download a plugin with IntelliJ which is what I have done in my case.

Once you start IntelliJ for your web application either locally or remotely, you will see an icon on top right to start the JProfiler. If you are running the application locally, JProfiler will launch and will ask user to find the directory where JProfiler.exe is located, once you click OK, it will start the application server (from intelliJ RUN configuration).

JProfiler from IntelliJ

In Filter Settings , you can select the option Edit and it will launch another window where you can provide other application related settings. You can also run JProfiler for a remote application. For that you can provide the application’s host and port address in this application settings.

Application Settings

In my case, I am running the application locally, so I will skip these settings for right now.

Once the OK button is clicked, it will launch the tomcat webserver that I am using in this Spring based web application. I will launch my application in another browser window and do the necessary testing with application. JProfiler should profile my activity. Once you do that, we can verify CPU view for hot spots that Profiler found in our application. This will look like below:

Hot Spots

One good thing about this feature is that it shows where the application is taking more time and it is arranged in descending order. So most of the time that my code is taking in the libraries that I am using. If you expand each node, you will find in detail about each method that is getting called.

Conclusion

In this post, I showed how to use JProfiler. This was an introductory post as I have not talked about the different views that JProfiler offers for profiling the application.

Migrate Android Project from Eclipse to Android Studio

I remember downloading Android Studio back in 2013 to work on an Android project. But after playing around for an hour or two, I got frustrated. I had to delete Android Studio and go back to Eclipse. One reason why Eclipse was never successful with android because of patchy user interface for building Android applications, unfortunately that’s still the case in 2018.

Well, at least Google has made significant changes with Android Studio from 2015. It is almost compulsory to use Android Studio to build any new android applications. But there are few eclipse devotes like me who were still using eclipse to build android applications.

In this post, I will show how to migrate an android project from Eclipse to Android Studio. Warning: Even though the post looks very simple, it took me sizable efforts to figure out this migration. Hope it will be easier for readers.

Steps to migrate from Eclipse to Android Studio

  1. Download Android Studio from here. I had downloaded Android Studio version 3.3 RC2, but for it kept giving me syncing error when I imported the project. So I downgraded Android Studio version 3.2.1. Install Android Studio on your environment.
  2. On starting screen of Android Studio, you will see an option to import existing ADT project. Here you choose your eclipse based android project.
    1. Other option in this scenario, is to export android project from eclipse as gradle based project and it will also make life easier to import that project in Android Studio.
  3. Once you import the project in Android Studio, it will take some time to sync. In sync, Android Studio is basically creating gradle build file for your project. Converting all your library jars into dependencies. Other task it will be doing is to merge all your AndroidManifest.xml files. If there are any errors, it will show those errors during sync. Easiest way to fix AndroidManifest.xml errors are to go to this screen:

 4. Once the sync is successful, you can still face some issue to build the project. One major change with android studio gradle build is that in dependencies compile has been replaced by implementation project OR implementation files. Also to pull most of your dependencies, you will have to add google() as maven URL. minSdkVersion and targetSdkVersion should be moved to build file now and you can remove that from AndroidManifest.xml . Most of this should let you build your project successfully.

Conclusion

In this post, I showed how to migrate from eclipse to android studio for your android project. It is straight forward, but definitely depending on the project, you will run into few issues that you will have to resolve while building the project. Send me email or comment on this post if you have any questions.

 

 

Supporting FORMS authentication for ADFS in Android applications

Scenario with ADFS Authentication

Recently I came across this scenario where an application was using ADFS for authentication. The administrator had configured Windows Integrated Authentication as well as Forms Authentication as authentication policies. But when the user accessed the Android application, passive authentication through the Android webview browser fails because it redirects to the Windows Integrated Authentication URL instead of Forms Authentication. As the webview browser does not support WIA.

Android Phone

A solution to configure ADFS

Most organizations when using Active  Directory Federation Services (ADFS), use windows integrated authentication for their intranet. This helps users in their networks to enter credentials only once. Most browser-based applications provide a seamless experience to users without asking them to enter credentials again.

However, in this scenario, a user was trying to access an android application that equally needs passive authentication with an android webview browser. But android webview browser does not support WIA that results in authentication failure.

In such a scenario, ADFS should fall back to FORMS authentication and redirect the user to the login form. ADFS for windows server provides a simple configuration trick for authentication to fall back to FORMS.

  1. WIASupportedUserAgentString property of Set-ADFSProperties command
  2. WindowsIntegratedFallbackEnabled property of Set-AdfsGlobalAuthenticationPolicy command

Set-AdfsGlobalAuthenticationPolicy -WindowsIntegratedFallbackEnabled $true

WIASupportedUserAgentString gives the user agents that support WIA. If the component of the user agent string does not match any of the components of the user agent strings that are configured in WIASupportedUserAgentString property, ADFS will fall back to providing forms-based authentication, provided WindowsIntegratedFallbackEnabled flag is set to true.

Get-AdfsProperties | Select -ExpandProperty WIASupportedUserAgents

MSIE 6.0

MSIE 7.0; Windows NT

MSIE 8.0

MSIE 9.0

MSIE 10.0; Windows NT 6

MSIE 11.0; Windows NT 10

Windows NT 6.3; Trident/7.0

Windows NT 6.3; Win64; x64; Trident/7.0

Windows NT 6.3; WOW64; Trident/7.0

Windows NT 6.2; Trident/7.0

Windows NT 6.2; Win64; x64; Trident/7.0

Windows NT 6.2; WOW64; Trident/7.0

Windows NT 6.1; Trident/7.0

Windows NT 6.1; Win64; x64; Trident/7.0

Windows NT 6.1; WOW64; Trident/7.0

Windows NT 10.0; Trident/7.0

Windows NT 10.0; Win64; x64; Trident/7.0

Windows NT 10.0; WOW64; Trident/7.0

MSIPC

In this particular case, we removed Safari and Chrome from the list of user-agent strings, that’s when the authentication for application worked through passive authentication.

Conclusion

In conclusion, I showed in this post how to use FORMS authentication with ADFS for an android application. If you enjoyed this post, subscribe to my blog.

References

  1. Configuring Forms based authentication
  2. Forms based authentication