Thursday, August 6, 2015

Use static resource folder in Tomcat

In this post I will explain how to use static resource folder in tomcat application server. Normally resources like Cascading Style Sheet (CSS) files, JavaScript files and images store inside the web application. That means when we deploy WAR file in to application server that WAR file contains resources inside it. It here I will explain how to access resources from static folder outside from WAR file.

Prerequisites 
  1. You should have install java(It requires to have JVM 6 or higher version ) in your PC and set path variable correctly (JAVA_HOME, PATH)
  2. You should have install Eclipse Java EE IDE in your PC
  3. You should have Apache Tomcat in your machine and it should be added to Run Time Environments in Eclipse
Step 1 Create Dynamic web project
As first step lets create simple Dynamic Web Project using Eclipse. Go to File->New->New Dynamic Web Project. Give prefered name to the project (Here I will user project name as SharedResourceWeb as Figure 1) Then click finish. 
Figure 1: Provide project name

Then click next and next interface also click next and last interface tick box "Generate Web.xml for deployment descriptor". Then Click Finish button.
Figure 2 : Folder structure of new project
Then right click on WEBContent folder under your project node and go to New->HTML File then provide file name as "index.html". Then add some content to index.html. I will add following content

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Shared Web</title>
</head>
<body>
My Test web project
</body>
</html>


Then lets check all the things work correctly by deploy this web app into tomcat. First right click project you create and go to Export->WAR file the next interface provide WAR file name and location you need to create file. I will use "webapps" folder inside the tomcat folder stucture as WAR file creation location. Then select appropriate  target run time. If you have the tomcat v6 or v7 select correct run time. I'm using tomcat v7 (Figure 3)
Figure 3: Create WAR file using Eclipse
Then click on Finish you can see generated WAR file inside the selected location. If you not generated inside the webapps folder in tomcat folder structure copy WAR file in to
"webapps" folder.
Then start the tomcat server and you will be able to access your web project according to following URL format.

http://localhost:[tomcat running port]/[ProjectName]/

for my project it's

http://localhost:8888/SharedResourceWeb/

You can see interface similar to figure 4.
Figure 4: Project I deployed to tomcat



Then go to conf folder inside the tomcat directory and open server.xml file. Then add following line in between <HOST></HOST>.
        <Context docBase="/SharedResource" path="/SharedResource" reloadable="true"/>
Then go to webapps folder and create SharedResource folder and create anther folder as css then add new styles.css file with following content.


b {
    font-size : 16 px ;
}
.div1 {
    background-color: yellow;
    font-size: large;
}
.div2 {
    background-color: lime;
    font-size: x-large;
}
i {
    color : red ;
}


Then restart the tomcat server and try to access the css file through following link.

http://localhost:[tomcat running port]/SharedResource/css/styles.css

for my project link will be http://localhost:8888/SharedResource/css/styles.css



Then lets add some content and styles in to index.html. I will add following content in to index.html.

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Shared Web</title>
<link rel="stylesheet" href="http://localhost:8888/SharedResource/css/styles.css">
</head>
<body>
<b>This is Title</b>
<div class="div1">
<p>This is first paragraph in the web page</p>
<p>This is second paragraph in the web page</p>
</div>
<div class="div2">
<p class="p3">This is last paragraph in the web page</p>
<i>EXIT</i>

</div>
</body>
</html>


Then create the new war file and placed it inside the webapps folder. Then restart tomcat after that refresh the web page (http://localhost:8888/SharedResourceWeb/) you created. It will show the content with styles. You can see similar page to Figure 5.


Figure 5: Web page with Styles


This kind of shared folder will help to change the styles of project without deploying project.

Saturday, July 25, 2015

BIRT reports 1: Install BIRT in Eclipse

BIRT sands for Business Intelligent and Reporting Tool which is an Open Source platform for data visualization and reporting. In this post I'm going to explain how to setup BIRT reports in windows Eclipse.

Prerequisites 
  1. You should have install java(It requires to have JVM 6 or higher version ) in your PC and set path variable correctly (JAVA_HOME, PATH)

To install you can choose either download All in one Eclipse or You can install BIRT as new plugin. Yo download All in one Eclipse go to BIRT download page and click on Download Now under All-in-One heading. (Figure 1)
Figure 1 : Download required BIRT

If you continue with All-in-One you can select preferred bit version with different operating systems. (Top right corner under Download Links heading) 

If you need to install it as plugin go to BIRT wiki update page and select your Eclipse version and copy URL then on you Eclipse go to Help->Install New Software.. You can see similar interface to Figure 2
Figure 2: Install New Software Interface
On this interface click on Add button (Top right corner) and provide name for the software and URL copied from BIRT wiki update page and then click OK button.
Then You can see similar interface to Figure 3 and on that interface Click on Select All button and click Next. Then continue the installation steps.
Figure 3: Click on Select All button
After successful installation you can go to File->New->Project then select Report Project under Business Intelligent and Reporting Tool. (Figure 4) After that click next and provide appropriate name for project then click Finish
Figure 4: Select Report Project

Then lets start to create new report in our new report project. To start go to File->New->Other then select report under Business Intelligent and Reporting Tool and click next.(Figure 5)  In next interface provide report name and click Finish.
Figure 5: Select report under Business Intelligent and Reporting Tool
Then Eclipse will prompt message asking to change the perspective in to Report Design click OK and then you can see interface similar to Figure 6.
Figure 5: Report design interface in Eclipse

On next post I will explain how to design report easily with data set and report designing techniques which can use to develop complex reports. 

Sunday, July 12, 2015

Performance load testing with JMeter 1



The Apache JMeter is pure java application that can use to perform functional testing and load testing on applications. This application will help to test on both static and dynamic resources.It can be used to simulate a heavy load on a server, group of servers, network or object to test its strength or to analyze overall performance under different load types. You can use it to make a graphical analysis of performance or to test your server/script/object behavior under heavy concurrent load.

It is supporting following servers and protocols to load and performance testing.
  • Web - HTTP, HTTPS
  • SOAP / REST
  • FTP
  • Database via JDBC
  • LDAP
  • Message-oriented middleware (MOM) via JMS
  • Mail - SMTP(S), POP3(S) and IMAP(S)
  • MongoDB (NoSQL)
  • Native commands or shell scripts
  • TCP
In this post I am going to explain how to test load and performance testing on web application in step by step approach.


Prerequisites 
  1. You should have install java(It requires to have JVM 6 or higher version ) in your PC and set path variable correctly (JAVA_HOME, JRE_HOME)
Step 1 Download and install JMeter
First you have to download JMeter from following location in Apache web site. (For this example I have downloaded apache-jmeter-2.13.zip file) Then extract the zip file and then run Jmeter.bat file in bin folder.


Figure 1: JMeter interface 
In the figure 1 you can see Test Plan icon in left side of the interface.  In this Test plan you can define the configurations where you start setting the testing configuration that are specific to your application. right click on it and go to Add. You can see different kind of features provided by the JMeter to perform testing.

Step 2 Create Thread Group in JMeter
Go to Test Plan and Right Click it then go to Add->Threads (Users)->Thread Group.
Then you can see similar interface to figure 2.


Figure 3: Thread Group view

Then click on the Thread Group and you can see similar interface to Figure 3. In that you can provide any preferred name. In Thread Properties section you can fill two main properties those are Number of Threads and Ramp Up Period. 
There is important section below the Thread Group name section it is "Action to be taken After sampler error". This will specify what kind of action should be taken when error occurred. For this example I put it as "Continue".
Under Thread Properties there are couple of important configurations.
Number of Threads - This specify number of concurrent users 
Ramp Up Period - This specify number of seconds JMeter to add concurrent users.

There is another option Thread properties it's Scheduler. You can specify start, end time, duration and start up delay. (These will only display when user ticked on Scheduler check box)

Step 3 Add request sampler in JMeter
To add request sampler in to JMeter right click on the Thread Group and go to Add -> Sampler  -> HTTP request as show in Figure 4. Then you can see similar interface to Figure 5. In that provide the server id/domain name in front of the Server Name or IP field. For this example I put www.google.com as server so my load testing will test Google site. Then save the request sampler witch added to the Thread group.

Figure 4: Add request sampler
Figure 5: Add HTTP request sampler

Step 3 Add summery report in JMeter
Actually summery report is one kind of listener available in JMeter. Other than the Summery report there are many listeners available in JMeter. (Figure 6)

Figure 6: Different kind of Listeners available in JMeter
To add summery report right click on Thread Group created and go to Add->Listener->Summery Report. Then you can see similar interface to Figure 7 and provide name for the summery report. Then save the summery report.

Figure 7: Summery report added to Thread Group
After save the summery report you can see that report under Thread Group you created.

Step 4 Start the load testing
To start load testing click on the Thread Group created and click green start icon on icon panel. Then in Right top left corner you can see number of Threads running on to your server and the success attempts.
Then you can go to summery report and you can find the result according to the Thread Group you have configured in step 1.(Figure 8)
Figure 8: Summery report for the load test

Hope this post help you to get basic idea about load testing using JMeter and I will add more advanced loaded testing mechanisms using JMeter in my future posts. 

Tuesday, June 30, 2015

Enable click event on disabled html element

This post will explain steps to trigger click event on disable html elements. Generally disable HTML elements will not fire any javascripts events but some times we needs to disable HTML elements initially and then in click event we may need to enable element. That kind of scenarios we can use following steps to archive it.

Whole example will be available in JSFiddle and you can try it your self. 
For this example I will use simple button to change a select field enable/disable function. Initially select field will be disabled and on the click event it will get enable. But actually user click on a another div placed in front of the select field but user will not have any idea about that. This div will be enable only when select field is disable.

<button id="enbDesBtn">Enable Passengers</button>
<div id="wrapper">
    <select id="passengers" disabled>
        <option value="1">Lakshan</option>
        <option value="2">Udara</option>
        <option value="3">Devmini</option>
        <option value="4">Nimasha</option>
    </select>
    <div id="overlay"></div>
</div>

Figure 1: HTML file view

Then we have to add following CSS and JavaScript in to HTML to archive our target. 

Javascript

var button = document.getElementById('enbDesBtn'),
    cars = document.getElementById('passengers'),
    overlay = document.getElementById('overlay');

button.addEventListener('click', function () {
    cars.disabled = !cars.disabled;
    var value="";
    if (cars.disabled) {
        button.textContent = 'Enable';
        value = 'Disable';
    } else {
        button.textContent = 'Disable';
        value = 'Enable';
    }
    alert(value);
}, true);

cars.addEventListener('change', function (evt) {
    console.log(evt.target.value);
}, true);

overlay.addEventListener('click', function () {
    alert('Disabled');
}, true);


CSS

#wrapper {
    display:inline-block;
    position:relative;
}
#overlay {
    display:none;
    width:100%;
    height:100%;
    position:absolute;
    top:0
    left:0;
    bottom:0;
    right:0;
}
#passengers:disabled + #overlay {
    display:block;
}

After adding above CSS and Javascripts in to HTML whole file will be similar to following.

<html>
<head>
<script>
window.onload=function(){
var button = document.getElementById('enbDesBtn'),
    cars = document.getElementById('passengers'),
    overlay = document.getElementById('overlay');

button.addEventListener('click', function () {
    cars.disabled = !cars.disabled;
    var value="";
    if (cars.disabled) {
        button.textContent = 'Enable';
        value = 'Disable';
    } else {
        button.textContent = 'Disable';
        value = 'Enable';
    }
    alert(value);
}, true);

cars.addEventListener('change', function (evt) {
    console.log(evt.target.value);
}, true);

overlay.addEventListener('click', function () {
    alert('Disabled');
}, true);
}
</script>
<style>
#wrapper {
    display:inline-block;
    position:relative;
}
#overlay {
    display:none;
    width:100%;
    height:100%;
    position:absolute;
    top:0
    left:0;
    bottom:0;
    right:0;
}
#passengers:disabled + #overlay {
    display:block;
}
</style>
</head>
<body>
<button id="enbDesBtn">Enable Passengers</button>
<div id="wrapper">
    <select id="passengers" disabled>
        <option value="1">Lakshan</option>
        <option value="2">Udara</option>
        <option value="3">Devmini</option>
        <option value="4">Nimasha</option>
    </select>
    <div id="overlay"></div>
</div>
</body>
</html>

As above example shows this functionality can be integrate with any other kind of HTML elements such as input fields, radio buttons etc.

Saturday, June 20, 2015

Create a war file using eclipse maven plugin

In this post I will explain how to set up eclipse to create war file from dynamic web project. Later it can be use to deploy web application on tomcat.

Prerequisites 
  1. You should have install java in your PC and set path variable correctly (JAVA_HOME, JRE_HOME)
  2. You should have Apache Tomcat in your machine.
  3. You should have install Eclips Java EE LUNA IDE in your PC.

Step 1 First create Dynamic web project 

As a first step we needs to have web project to create war file from it. So to create dynemic web project Go to New->Other and select dynamic web project then provide project name and select run time environment. In this post I'm using project name as SampleMavenProject and my run time environment as tomcat 7.

Then add new index.jsp file to webcontent directory in your project structure and add following content in to that.


<html>
    <head>
        <title>Index File Maven Project</title>
    </head>
    <body>
        <b>Maven test project running</b>
    </body>
</html>

Then we have to convert the Dynamic Web Project in to Maven Project to do that right click on project and go to Configure->Convert to Maven Project. (Figure 1)

Figure 1: Convert to Maven project

Then next interface you can provide details regarding the war file that you are going to create such as war file name and version etc and then click Finish. (Figure 2)

Figure 2: Provide details about project

After you click Finish you can see new pom.xml file is created on your project and in pom.xml you can see automatically added maven plugin details in to plugin section. (Figure 3)

Figure 3: New pom.xml created in project structure 

Then lets create war file from the project. Click right click on Run As->Maven Build and enter clean install in Goals and click run. (Figure 4)

Figure 4: Add clean install in Goals section

Then you can see similar out put in console in that you can see Build success notification and the war file generated location.(Figure 5)

Figure 5: Console out put

We have successfully created war file from our project. If you need to deploy it to Apache Tomcat then go to the war file generated location and copy that war and past it in webapps 
Apache Tomcat directory.
Then start the Apache Tomcat server and you can see your project folder will extracted in webapps folder. Then you can access you project on relevant project link. 


Setup Jenkins in Windows

In this post I'm going to explain step by step process to setup Jenkins in local machine.

Prerequisites 
  1. You should have install java in your PC and set path variable correctly (JAVA_HOME, JRE_HOME)
  2. You should have Apache Tomcat in your machine.
  3. You should have install Eclips Java EE LUNA IDE in your PC.

Step 1 Download Jenkins and setup

First we have to download Jenkins from Jenkins home page. You can download the Jenkins.war file in download Jenkins section. In this post I'm using version 1.617 Jenkins.

Figure 1: Download war file from Jenkins home page.
Then put Jenkins.war in to webapps folder in Apache Tomcat installation directory. (As show in Figure 2). Then start the  Apache Tomcat using startup.bat.

Figure 2: Place Jenkins.war in weapps folder on Apache Tomcat directory.

After successfully Tomcat started you can type http://localhost:8888/jenkins/ and access the Jenkins in your local machine. (Here 8888 is the port that use as http-apr)

Figure 3: Jenkins run in Tomcat

Saturday, June 13, 2015

Setup SVN server in local machine

As a developer it's really need to have understand on version controlling when work with project which contributed more developers development knowledge. In this post I will explain how to set up visual SVN server (https://www.visualsvn.com/) on local machine. 

Prerequisites 
  1. You should have install java in your PC and set path variable correctly (JAVA_HOME, JRE_HOME)
  2. You should have install Eclipse Java EE IDE in your PC

Step 1 Download and install virtual SVN server

First we have to download the visual SVN server (Version 3.3.1) from following location https://www.visualsvn.com/server/download/ select the correct bit version (Figure 1) and download the software.

Figure 1: Download appropriate version
Double click the downloaded file and install the server in to local machine. You can see interface similar to Figure 2.

Figure 2: Welcome screen of visual SVN server setup
Then click next, accept the terms and conditions then click next then you can see interface similar to Figure 3. Select visual SVN server and management console and make sure to check Add subversion command line tool to PATH environment variable then click next.

Figure 3: Select visualSVN server and management console

Then click on Standard edition (Figure 4)

Figure 4: Select standers edition
In next interface you have to provide installation directory for visualSVN server , the repository folder location and port to run visualSVN server. Figure 5

Figure 5: Provide basic details to install visualSVN
Then click next and from the next interface click on install button. After completion of installation you can see similar interface to Figure 6. Then Click finish.

Figure 6: Installation complete screen

Step 2 Configure visual SVN server

First run visualSVN program that you have installed in previous step. Then Right click on Repository and click on Create New Repository as show in Figure 7.

Figure 7: Select Create New Repository
On the pop up interface provide valid name for the repository you are going to create. (Figure 8) Then click new and on next interface select Single project repository and click Next.(Figure 9)

Figure 8: Provide valid name for repository

Figure 9: Select Singer Project Repository
On next interface select All subversion users have Read/Write access(Figure 10)then click on create.

Figure 10: Select All subversion user have Read/Write access option and click create
After successful installation you can see interface similar to Figure 11. In that interface you can see the repository URL witch use to access the repository.

Figure 11: Successfully created repository
Then click finish and now you can see your newly created repository under Repositories on visualSVN server. Then go in to your repository and expand it. Then right click on Trunk then select New->Folder and provide a folder name for a project that you going to setup in your repository. 

Figure 12: Click on New-> Folder
Then lets create new user for newly created repository for that right click on Users and Click create user. On the interface provide user name and password. (Figure 13)

Figure 13: Create user by providing user name and password

Step 3 Comit project into newly created SVN repository

Lets add new project in to newly created SVN repository. First lets create sample project on Eclipse (Any kind of project). Then we have to add SVN repository path in to Eclipse. Go to Window->Open perspective->Other 

Figure 14: Select other on Open perspective 
Select SVN repository Exploring and select Ok. Figure 15

Figure 15: Select SVN repository Exploring
Then right click on repository perspective and select New->Repository Location Then you can see similar interface to Figure 16. In that provide the repository URL that we have crated in second step.(https://Nadeesha-PC/svn/it.con.testSVN/) Then provide user credentials that you have created on creating user on visualSVN server then click finish

Figure 16: Provide repository details and Finish
Now we have added the repository URL in to eclipse and now we can add projects in to that repository. Now right click on the project that we created in previous step and select Team->Share Project then select the select SVN and select next. On next interface select existing repository location and click Finish. Now we have successfully added a project in to our repository. 

In project perspective you can see SVN path at the end of project name as show in figure 17. 

Figure 17: Successfully added a project
In visualSVN server also show the newly added project in to repository as show in Figure 18.

Figure 18: Newly added project in visualSVN server
We have successfully added a project in to visualSVN server. :)