Posts

Get application status from Tomcat

The project in which I'm working on right now has a feature named "Check Component Status". In our case, we've a large project that consists many microservices. We've deployed these microservices in different servers. Now, we are interested to check which microservice is up and which is down. Also we're interested to know which service has not been deployed yet. So, we created a tiny application that would check the status of the microservices. Some of our microservices were deployed in tomcat and some were in Wildfly. In this post I'm going to explain how we checked the component/microservice status from tomcat. Tomcat already has a management application which is installed by default in the 'management' context path. If we're running tomcat locally on port 8080, we can access the default tomcat application page here: http://localhost:8080/ . Clicking on the "Manager App" link or going to the http://localhost:8080/manager/html wil...

AngularJS Tutorial: Part 2

Image
In the previous part , we developed a web application that actually does nothing. Following is a brief description of what we've done so far: - Created a HTML template for our application - Added AngularJS and twitter-bootstrap libraries and integrated with our application - Tested AngularJS integration by writing an Angular expression In this post, we are going to modify the left navigation table so that clicking on an item keeps it in selected state i.e add blue background to mark as selected. In order to do so, we are going to use Directives. So, first question is what is a directive? Here is a high level description from AngularJS documentation At a high level, directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS's  HTML compiler  ( $compile ) to attach a specified behavior to that DOM element or even transform the DOM element and its children. As you probably know, AngularJS has a HTML comp...

AngularJS Tutorial - Part 1

Image
In this part, we'll download the required libraries and write a hello world application using AngularJS. As we are going to develop a web application, we'll need to write HTML, Javascript and CSS. Let's create a directory named 'js' and another named 'css' in the project root directory. We'll use twitter-bootstrap for the front-end. Let's download the following css files and put them in the css directory that we previously created. - bootstrap.min.css - styles.css bootstrap.min.css is the css library and styles.css contains some custom rules for the template being used in our project. We'll write any other custom css rules in this file. We are done with css files and it's time to download the required Javascript libraries. Let's download AngularJS library from their website  https://angularjs.org/  and put it in the js directory of our project. Now, we need to write down the HTML file that'll be used as our base template. ...

AngularJS Tutorial - Part 0

I'm learning AngularJS and have decided to write down my experience with the journey so that it can help others like me who are new to AngularJS. The project we are going to develop is a simple API documentation based on JSON. It'll have the following features - A two pane layout based on Twitter Bootstrap  . I'm going to use this example layout found on the getting started section.  http://getbootstrap.com/examples/dashboard/ - On the left side, there will be API names e.g Get Users, Update User etc - On the right side, there will be API description including API url, parameters etc - Clicking on a API name from left side will open the API details on the right side - JSON files that will contain API names. Each API details will be stored in seperate JSON files. Here is the Github link to the final project we are going to develop  https://github.com/rafiqnayan/api-browser Requirements before following the series: - Familiar with HTML, CSS and how web applica...

Getting time diff from timestamp in Java

You have a timestamp and you want to get the difference in string like the folowing: 10 sec ago 3 minute ago 7 days ago  and so on. The following function does it. private String getTimeDiff( long timestamp){     String timeDiffStr = "" ;       Calendar cal = Calendar.getInstance();       long currentTimeInMillis = cal.getTimeInMillis();       long timeDiff = (currentTimeInMillis - timestamp) / 1000;       if (timeDiff < 60){             timeDiffStr = timeDiff + " seconds ago" ;             return timeDiffStr;       }       timeDiff = timeDiff / 60;       if (timeDiff < 60){             timeDiffStr = timeDiff + " minutes ago" ;             return timeDiffStr;     ...

Road to AngularJS

AngularJS is a great framework for developing single page responsive web applications. If you are a web application developer and work with front end, you should learn AngularJS. As there are too many ways to do a particular job, learning angular may seem difficult at the very beginning. If you read the tutorials that are available in internet, you might get confused seeing that same task is done in different ways by different people. I've been studying on AngularJS for last few months and trying to get a clear concept on how this works and what I should do to use AngularJS in my projects. In this post, I'll note down my experience of learning AngularJS so that I can follow in later. I hope this will also help others who want to learn AngularJS. Step 1: Follow the tutorial that is available in the  https://docs.angularjs.org/tutorial . There are 13 steps in this tutorial. Complete all of them. As they use Git for the codebase and node.js for server, it would be better if...

JKS to PEM conversion

Situation: I've generated a private key using keytool. I've created a CSR file with this private key and signed it with a CA. I'm using this successfully in my java projects and with Tomcat. Now, I need to use this SSL certificate with Nginx server. To do so, I need to provide the private key and certificate file to Nginx. I've got the CRT files from CA. But the question is, how to use the keytool generated private key with Nginx or other servers?   Solution: We need to extract the private key from the keystore file and save it in a format so that other servers can recognize it. Extract the private key from keystore using this tool  https://code.google.com/p/java-exportpriv/wiki/Usage Use the following command to extract the private key in PKCS#8 format java ExportPriv .keystore mykey test123 You can use this private key with Nginx or Apache who does not support keytool generated private key.