quarkus-screenshot

How To Debug Your Java Quarkus Microservices With Netbeans

As part of the quick tips series, I will show how you can debug Quarkus microservices using Netbeans. This quick tips work for any Java applications running either through Maven or in standalone.

Here is the commands to debug your application when running through Maven. The default debug port is 5005.

./mvnw compile quarkus:dev -Dagentlib:jdwp=transport=dt_socket,server=y,suspend=n

Here is the command to debug your application when executing through the jar command.

# start application in debug: example
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009 -jar <your-application.jar>

I hope this was helpful. Stay tune for more quick tips.

How to Take Screenshot of Websites Using Java and Firefox

Let’s set the scene why you would require to take a screenshot of website. A couple years ago, I was working for an intellectual property law firm who’s clients included some of the world largest software houses. I was working as a developer and my requirements was to scrap known website where the clients software were more likely to be distributed illegally, ie. torrents site.

This was back in ’09 and the initial PoC save the pages HTML which required to opened in a frame in order to be viewed. The application did not have a UI as the results was sent to Salesforce case management system. I recently came across a project trying to do the same thing but with illegal use of photos.

I decided to take a look at how this could be done but not only saving the HTML of the source page but to take a screenshot of what it looked at the time of crawling. There are many services now offers API to allow your application to take screenshots of website. But there is a simpler easier solution;

Introducing Firefox Headless Mode

Headless mode is a very useful way to run Firefox. Just as it might sound, Firefox is run as normal, minus any visible UI components visible. Though not so useful for surfing the web, it comes into its own with automated testing.

Firefox Headless mode allows to run Firefox as a background service. The headless mode as a

-screenshot
parameter which allows the browser to take a full page screenshot of a given URL. The following simple command would take a screenshot in Firefox:

/path/to/firefox -headless -screenshot https://developer.mozilla.com
You can omit the -headless flag when using the -screenshot flag as follow
/path/to/firefox -screenshot https://developer.mozilla.com
Please see Firefox Dev page for a list of all available options.

Take a screenshot from Java

A prerequisite is to make sure that Firefox is installed and accessible from your Java application.

The java code will execute the external Firefox process. I’m using Java 11 and the ProcessBuilder API but you can do the same with the Runtime API. The ProcessBuilder API gives you more control over the executed process.

It is important to remember that you can only have a single instance of Firefox running on your system. In a multi-threaded environment, you will control access to this process.

Here is a simple example of running Firefox in headless mode and taking a screenshot from Java; this is run from a MacOS.


package com.kiktronik.websitescreengraber;

import java.io.IOException;

/**
 *
 * @author Armel Nene
 */
public class Screenshot {
    
    public static void main(String[] args) throws IOException{
        Process p = new ProcessBuilder("/Applications/Firefox.app/Contents/MacOS/firefox", "--headless", "--screenshot", "armelnene.png", "https://www.armelnene.co.uk").start();
        System.out.println("Process ID: " + p.info());
    }
    
	}
	
I hope this would help you in your next project. Happy coding.

primefaces-mobile-weather-app1

Primefaces Mobile – Weather App Example

As a Java developer, I usually get requests of building mobile apps. I like building Java application; enterprise, web and mobile. The latest projects that I have been involved with make heavy use of JSF and Primefaces in particular.

I am quite confortable with JSF and therefore I decided to build a mobile application using JSF and Primefaces Mobile. Primefaces Mobile wraps JQuery as a JSF component so that you do not have to write any Javascript. This approach has huge benefits: JQuery is a well tested framework used by large companies such as Google and Microsoft.

I will make this post quite brief. I wanted to know how easy it would be to recreate the demo from the Primefaces Mobile labs page.

Here is a screenshot of the final application running in Firefox 11 (Windows 7 64 Bit).

This was a simple example taken directly from the website therefore I was expecting to a short exercise to make build and make it run. Well not so fast.

I created a Maven based Java EE 6 project using Netbeans IDE 7.1.1. After browsing Google for a bit, I spent a few minutes getting the right repository and dependency in place.

Once the dependency where in the place, I had to create the beans required for the actual JSF page to work. I found the Primefaces Mobile backing beans on Google Code. So now I had everything setup and running. At first glance, the application seemed to running fine and working. Then I tried the application on my iPad and the Android Emulator, and nothing was working. The user interface was displayed but the “get forecast” button was not making any Ajax calls.

So I started to debug the application everytime I had some spare time. I also noticed that, while running on a desktop browser, the application would be able to an Ajax called and updated the screen with the values (see screenshot above) but you wanted to make another to find out the temparature of let’s say London, the nothing would actually unless you refresh the page and try again. OK, so it’s not working as expected but the example on Primefaces Mobile labs worked fine on my iPad, emulator and desktop browser (IE 9 excluded).

So I ran the application using the NetBeans debugger and decided to look through Firebug. The first call goes through and stops at the breakpoint but subsquent calls do not even get to the managed bean. Firebug shows that the other code are being retrieve from the cache. I manually set all the HTTP headers so that it does not cache any content but this is still the same result NOT WORKING!

I have uploaded the code to GitHub click on the link to download it.

In conclusion, it’s not plug-and-play to make the examples on Primefaces.org labs work. The documentation for the examples are quite poor and I hope that the good folks from Primefaces can take look at my code and tell us what I am doing wrong.

A part from that, Primefaces is a good JSF framework that I use on a daily basis on multiple projects therefore I cannot really put them down but I wished the mobile examples work and tell us what is needed to make it work.

Please share your experience in the comments below or advice on how to fix it. Feel free to download the code from GitHub and have a look to.

Happy coding 🙂

20090420-oracle-buys-sun1

Will Oracle really make NetBeans the BEST IDE for Java

Not yet!!! But according to their webcast they want to make NetBeans the best Java IDE. This is a statement not to be taken lightly. Oracle are now investing in three IDEs which are all established in different ways. JDeveloper is Oracle’s IDE of choice, I am currently using it in my current project as I am developing for Oracle WebCenter. Oracle is also a strategic developer and board member of the Eclipse foundation. I do not understand what exactly is a strategic developer but I know that JDeveloper is their strategic IDE. Now, introducing NetBeans, Oracle has inherited NetBeans as part of Sun acquisitions (and a ton of products and services). Until now, Oracle has never made any plug-ins for the NetBeans platform but now they promise to make it the best IDE for Java, how will they make that happen?

I am a NetBeans evangelist and as the rest of the community, it was good news to actually know where it stands in the “Oracle” vision. So Oracle will never drop JDeveloper therefore the real fight is between Eclipse and NetBeans (as it always has been). In the first step of making NetBeans the best IDE, Oracle shold immediately start porting all their Eclipse plug-ins to NetBeans. Eclipse has strength in its alliance which also includes IBM (fierce rival to Oracle). Something has to give and Eclipse will not never close shop because Oracle has left them which is not as worse as lack of investment in the NetBeans community. It would also be a foolish decision to give NetBeans to the Apache Foundation (no disrespect here but it seems that public funds do not grow on trees).

There is something funny about Oracle “choice” statement. Did anybody tried to develop for WebCenter using NetBeans or Eclipse? That’s a nightmare!!! There is no choice given, they literally forced us to use JDeveloper (Do you require any Oracle support?) in our company which is the largest in its field in Europe (I am avoiding to mention the company name but you should get it from my twitter stream).

Eclipse and NetBeans are direct competitors with Eclipse being the de facto IDE for Java, dropping Eclipse support would close doors to millions of developers and dropping NetBeans will disaster for many paying customers (Sun’s partners).  I am not sure what is going to happen in the NetBeans/ Eclipse and JDeveloper saga but something has to give.

Let me know what you think.