Posts

Showing posts from 2015

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 compi

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 applicati

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;       }       timeDiff = timeDiff / 60; // in hours       if (timeDiff < 24){             timeDiffStr = timeDiff + " hours ago" ;             return timeDiffStr;       }       timeDiff = timeD