<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5956132650471213105</atom:id><lastBuildDate>Fri, 13 Aug 2021 19:11:36 +0000</lastBuildDate><category>screencast</category><category>Java</category><category>Java EE 6</category><category>JSF 2.0</category><category>Tomcat</category><category>multiple_instances</category><category>CDI</category><category>JSF</category><category>load balancer</category><category>mod_jk</category><category>tomcat clustering</category><category>JSF 2.2</category><category>JasperReports</category><category>Java EE 7</category><category>Linux</category><category>javaEE</category><category>session replication</category><category>iReport</category><category>IoT</category><category>Java SE</category><category>Pi4j</category><category>Raspberry Pi</category><category>charts</category><category>mqtt</category><category>nginx</category><category>virtual hosting</category><category>Kernel</category><category>SSH</category><category>SSH Tunneling</category><category>apache</category><category>attack</category><category>bootloader</category><category>docker</category><category>grub</category><category>javaSE</category><category>javaSE7</category><category>security</category><category>sqlinjection</category><category>themes</category><category>vulnerability</category><title>Ramki Technical Blog</title><description></description><link>http://www.ramkitech.com/</link><managingEditor>noreply@blogger.com (Ramakrishnan)</managingEditor><generator>Blogger</generator><openSearch:totalResults>37</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4974605726429371669</guid><pubDate>Fri, 13 Aug 2021 19:10:00 +0000</pubDate><atom:updated>2021-08-14T00:40:48.234+05:30</atom:updated><title>Kubernetes multi node on prem installation with k0s distribution</title><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/ZxDK2AKUzR8&quot; width=&quot;630&quot; youtube-src-id=&quot;ZxDK2AKUzR8&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description><link>http://www.ramkitech.com/2021/08/kubernetes-multi-node-on-prem.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/ZxDK2AKUzR8/default.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-1492602292250807796</guid><pubDate>Fri, 12 Feb 2016 05:50:00 +0000</pubDate><atom:updated>2016-02-18T15:17:40.706+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">IoT</category><category domain="http://www.blogger.com/atom/ns#">Java EE 7</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.2</category><category domain="http://www.blogger.com/atom/ns#">mqtt</category><category domain="http://www.blogger.com/atom/ns#">Pi4j</category><category domain="http://www.blogger.com/atom/ns#">Raspberry Pi</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>IoT: Monitor Home Temperature using Raspberry Pi 2 via MQTT Protocol</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;h3 class=&quot;post-title entry-title&quot; style=&quot;font-stretch: normal; margin: 0px; position: relative;&quot;&gt;&lt;/h3&gt;&lt;div class=&quot;post-header&quot; style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 1.6; margin: 0px 0px 1.5em;&quot;&gt;&lt;div class=&quot;post-header-line-1&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;post-body entry-content&quot; id=&quot;post-body-4022130907826083868&quot; style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 25.2px; width: 800px;&quot;&gt;&lt;div id=&quot;aim14022130907826083868&quot;&gt;&lt;/div&gt;&lt;div id=&quot;aim24022130907826083868&quot;&gt;&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;In this post I am going to demonstrate that remotely monitor the Temperature using Raspberry Pi and MQTT protocol. This work is done &amp;nbsp;using Java code.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;ScreenCast&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/arPvuqaC6I4&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2016/02/iot-monitor-home-temperature-using.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/arPvuqaC6I4/default.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4022130907826083868</guid><pubDate>Mon, 02 Nov 2015 06:36:00 +0000</pubDate><atom:updated>2016-05-03T09:57:39.306+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">IoT</category><category domain="http://www.blogger.com/atom/ns#">Java EE 7</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.2</category><category domain="http://www.blogger.com/atom/ns#">mqtt</category><category domain="http://www.blogger.com/atom/ns#">Pi4j</category><category domain="http://www.blogger.com/atom/ns#">Raspberry Pi</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>IoT : Remotely Control the LED in Raspberry Pi 2 using Java (pi4j) and MQTT Protocol </title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In this post I am going to demonstrate that how remotely control LED and how it can be connected to Raspberry Pi using MQTT protocol and control GPIO pins using pi4j library. This work is done &amp;nbsp;using Java code.&lt;br /&gt;&lt;br /&gt;Recently I bought Raspberry Pi 2, so I just wanted to do some learning stuff, basically how to blink (on/off) &amp;nbsp;LED remotely.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;I have performed extensive survey about Raspberry Pi on internet I found lots of stuff about connect LED with Raspberry Pi via GPIO pins. This created a lots of interest. So I m searched Java library to control gpio pins and I got &lt;a href=&quot;http://pi4j.com/index.html&quot; target=&quot;_blank&quot;&gt;pi4j library&lt;/a&gt;.&amp;nbsp;&amp;nbsp; Actually pi4j library easy to learn and provide bunch of examples. Details of its are mentioned below:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;pi4j Library&lt;/span&gt;&lt;/b&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Its provides a friendly object-oriented I/O API and implementation libraries for Java programmers to access the full I/O capabilities of the Raspberry Pi platform. This project abstracts the low-level native integration and interrupt monitoring to enable Java programmers to focus on implementing their application business logic. For more details, refer this website :&amp;nbsp;&lt;a href=&quot;http://pi4j.com/index.html&quot;&gt;http://pi4j.com/index.html&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;GPIO pins layout are differ from each iteration of Raspberry pi. I have used Raspberry Pi2&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;GPIO Pins Layout for Raspberry Pi 2&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://pi4j.com/images/j8header-2b-large.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Raspberry Pi 2 GPIO Layout&quot; border=&quot;0&quot; src=&quot;http://pi4j.com/images/j8header-2b-large.png&quot; height=&quot;320&quot; title=&quot;Raspberry Pi 2 GPIO Layout&quot; width=&quot;176&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Raspberry Pi 2 GPIO Layout&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;I have wired gpio pin no 15 and 16 to 2 LED&#39;s. Diagrammatic represent is shown below:&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-WAXmJqtMP7o/Vjb_Trk75kI/AAAAAAAAJ_M/xg-qc9u4t1I/s1600/led_blink_bb.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;318&quot; src=&quot;https://1.bp.blogspot.com/-WAXmJqtMP7o/Vjb_Trk75kI/AAAAAAAAJ_M/xg-qc9u4t1I/s400/led_blink_bb.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Some important key steps:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;To control LED via Java I used pi4j lib code.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;Sample Code for turn on LED and turn off via GPIO 15 pin, is mentioned below:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ import com.pi4j.io.gpio.GpioController; import com.pi4j.io.gpio.GpioFactory; import com.pi4j.io.gpio.GpioPinDigitalOutput; import com.pi4j.io.gpio.PinState; import com.pi4j.io.gpio.RaspiPin;  public class ControlGpioExample { // create gpio controller         final GpioController gpio = GpioFactory.getInstance();                         final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_15, &quot;MyLED&quot;);         pin.setShutdownOptions(true, PinState.LOW);          pin.high();         Thread.sleep(5000);         pin.low();          gpio.shutdown();     } } ]]&gt;&lt;/script&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;After this steps, we can &amp;nbsp;control LED &amp;nbsp;remotely by &amp;nbsp;performing network protocols, For this performance I got&amp;nbsp;&lt;a href=&quot;https://dzone.com/refcardz/getting-started-with-mqtt&quot; target=&quot;_blank&quot;&gt;Dzone Refcard about MQTT protocols&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;MQTT Protocol&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;MQTT (formerly MQ Telemetry Transport) is a &lt;b&gt;publish-subscribe&lt;/b&gt; based &quot;light weight&quot; messaging protocol for use on top of the TCP/IP protocol. It is designed for connections with remote locations where a &quot;small code footprint&quot; is required or the network bandwidth is limited. The publish-subscribe messaging pattern requires a message broker. The broker is responsible for distributing messages to interested clients based on the topic of a message &amp;nbsp; &lt;b&gt;&lt;i&gt;--Wikipedia&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Basically it is client server model. We need server, its called &quot;message broker&quot;. First we need to install server. So here we use &quot;Mosquitto&amp;nbsp;server&quot;. &lt;a href=&quot;http://mosquitto.org/&quot; target=&quot;_blank&quot;&gt;Mosquitto&lt;/a&gt; is an open source (BSD licensed) message broker that implements the MQ&amp;nbsp;Telemetry Transport protocol versions 3.1. Download and install from &lt;a href=&quot;http://mosquitto.org/download/&quot;&gt;http://mosquitto.org/download/&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So we need client to connect message broker(server). There are many mqtt clients available. Generally, one of the popular client is &lt;a href=&quot;http://www.eclipse.org/paho/&quot; target=&quot;_blank&quot;&gt;Eclipse Paho&lt;/a&gt;. Secondle we need to add Paho client to our java project for communicate to message broker (mosquitto server).&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;I have used Amazon Ec2 instances (free tier). I installed&amp;nbsp;&lt;a href=&quot;http://mosquitto.org/&quot; target=&quot;_blank&quot;&gt;Mosquitto&lt;/a&gt;&amp;nbsp;server and WildFly JavaEE7 server. Then deploy my war file into wildfly server. Here&amp;nbsp;&lt;a href=&quot;http://mosquitto.org/&quot; target=&quot;_blank&quot;&gt;Mosquitto&lt;/a&gt;&amp;nbsp;is message broker and wildfly provide webpage for control LED. (I used JSF and Primefaces Lib for quick prototype)&lt;br /&gt;&lt;br /&gt;In Raspberry Pi, our code is to going &amp;nbsp;connect the&amp;nbsp;&lt;a href=&quot;http://mosquitto.org/&quot; target=&quot;_blank&quot;&gt;Mosquitto&lt;/a&gt;&amp;nbsp;message broker with the help of paho library in port 1883. It is default port for MQTT and &amp;nbsp;this subscribe the topic &amp;nbsp;and waiting for any message to receive. If any message is received, then it process the message based on we are turn on LED using pi4j library. Check the code &lt;a href=&quot;https://github.com/ramkicse/PiLED/blob/master/LEDPiControl/src/main/java/com/ramki/led/LEDCount.java&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In Wildfly server, based on JSF page any button triggered which directly connect to&amp;nbsp;&lt;a href=&quot;http://mosquitto.org/&quot; target=&quot;_blank&quot;&gt;Mosquitto&lt;/a&gt;&amp;nbsp;server using same paho library and publish the message in same topic which raspberry pi subscribed. &amp;nbsp;That&#39;s it. &amp;nbsp;Check the server code &lt;a href=&quot;https://github.com/ramkicse/PiLED/blob/master/LEDWebapp/src/main/java/com/ramki/led/piled/LedToggle.java&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;My web page&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-afT8Tqk7GE0/Vjb7KlRiBYI/AAAAAAAAJ_A/U_5O8sqlt2E/s1600/raspled.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;187&quot; src=&quot;https://2.bp.blogspot.com/-afT8Tqk7GE0/Vjb7KlRiBYI/AAAAAAAAJ_A/U_5O8sqlt2E/s400/raspled.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;All codes in my github repo &lt;a href=&quot;https://github.com/ramkicse/PiLED&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b style=&quot;color: #990000; font-size: x-large;&quot;&gt;Screencast:&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/qUj0cjGREJ8&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2015/11/iot-remotely-control-led-in-raspberry.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://1.bp.blogspot.com/-WAXmJqtMP7o/Vjb_Trk75kI/AAAAAAAAJ_M/xg-qc9u4t1I/s72-c/led_blink_bb.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-7073790236553324741</guid><pubDate>Thu, 15 Oct 2015 05:51:00 +0000</pubDate><atom:updated>2016-02-18T15:17:58.592+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">docker</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">nginx</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">session replication</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><title>Docker : Tomcat Clustering with Load Balancer (Tomcat and Nginx)</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;In this post i will show Tomcat Clustering in Docker Container. In&lt;a href=&quot;http://www.ramkitech.com/2013/01/tomcat-clustering-series-part-5-nginx.html&quot; target=&quot;_blank&quot;&gt;&amp;nbsp;my previous post i discussed how to achieve tomcat clustering with Nginx Front end&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Its almost same scenario, but this time we will achieve via docker container.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Docker&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;b style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;Docker&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;is an&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;mw-redirect&quot; href=&quot;https://en.wikipedia.org/wiki/Open-source&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Open-source&quot;&gt;open-source&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;project that automates the deployment of&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Application_software&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Application software&quot;&gt;applications&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;inside&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;mw-redirect&quot; href=&quot;https://en.wikipedia.org/wiki/Software_container&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Software container&quot;&gt;software containers&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;, by providing an additional layer of abstraction and automation of&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Operating-system-level_virtualization&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Operating-system-level virtualization&quot;&gt;operating-system-level virtualization&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;on&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Linux&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Linux&quot;&gt;Linux&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;.&lt;/span&gt;&lt;sup class=&quot;reference&quot; id=&quot;cite_ref-SYS-CON_Media_5-0&quot; style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 11.2px; line-height: 1; unicode-bidi: -webkit-isolate;&quot;&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Docker_(software)#cite_note-SYS-CON_Media-5&quot; style=&quot;background: none; color: #0b0080; text-decoration: none; white-space: nowrap;&quot;&gt;[4]&lt;/a&gt;&lt;/sup&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;Docker uses resource isolation features of the&lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Linux_kernel&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Linux kernel&quot;&gt;Linux kernel&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;such as&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Cgroups&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Cgroups&quot;&gt;cgroups&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;and kernel&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;mw-redirect&quot; href=&quot;https://en.wikipedia.org/wiki/Linux_namespaces&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Linux namespaces&quot;&gt;namespaces&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;&quot;&gt;&amp;nbsp;to allow independent &quot;containers&quot; to run within a single Linux instance, avoiding the overhead of starting and maintaining&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Virtual_machine&quot; style=&quot;background: none rgb(255, 255, 255); color: #0b0080; font-family: sans-serif; font-size: 14px; line-height: 22.4px; text-decoration: none;&quot; title=&quot;Virtual machine&quot;&gt;virtual machine&lt;/a&gt;&amp;nbsp; --Wikipedia&lt;br /&gt;&lt;br /&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;we need 4 docker container (3 tomcat containers + 1 Nginx container).&lt;br /&gt;i used official &lt;a href=&quot;https://hub.docker.com/_/tomcat/&quot; target=&quot;_blank&quot;&gt;tomcat&lt;/a&gt; and &lt;a href=&quot;https://hub.docker.com/_/nginx/&quot; target=&quot;_blank&quot;&gt;nginx&lt;/a&gt; images. official tomcat container not enable the cluster aware feature. so we will take official image and deploy our code and change the server.xml file and run the image as container.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s1600/session-repicate1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;371&quot; src=&quot;https://3.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s640/session-repicate1.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;we need to do some steps like deploy the our code and change server.xml file in all 3 tomcat container. so i used here &lt;a href=&quot;https://docs.docker.com/compose/&quot; target=&quot;_blank&quot;&gt;docker-compose&lt;/a&gt; tool.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Docker Compose&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;Compose is a tool for defining and running multi-container applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.&lt;br /&gt;&lt;br /&gt;In docker compose we need to define in single file called yaml file.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000;&quot;&gt;&lt;b&gt;compose.yaml&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;script src=&quot;https://gist.github.com/ramkicse/4f0c7303876d25b3a5e3.js&quot;&gt;&lt;/script&gt; &lt;br /&gt;&lt;br /&gt;In that file define all 3 tomcat container entries and change the server.xml file and tomcat-users.xml and deploy our app to ROOT location in tomcat.&lt;br /&gt;&lt;br /&gt;check my &lt;a href=&quot;https://github.com/ramkicse/docker-cluster&quot; target=&quot;_blank&quot;&gt;github repo&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Once we defined the yaml file then use single command like &lt;b&gt;&lt;i&gt;docker-compose up&lt;/i&gt;&lt;/b&gt; for start all 4 container up and running.&lt;br /&gt;we can also use&amp;nbsp;&lt;b style=&quot;font-style: italic;&quot;&gt;docker-compose -d up &lt;/b&gt;for run in background.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;margin: 0px; position: relative;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: #660000; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif;&quot;&gt;Screencast&lt;/span&gt;&lt;span style=&quot;color: #660000; font-family: &amp;quot;arial&amp;quot; , &amp;quot;tahoma&amp;quot; , &amp;quot;helvetica&amp;quot; , &amp;quot;freesans&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;:&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;color: #660000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;https://www.youtube.com/embed/Z3MWoPbV02s&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2015/10/docker-tomcat-clustering.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://3.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s72-c/session-repicate1.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-8332665984667285715</guid><pubDate>Mon, 12 Aug 2013 11:44:00 +0000</pubDate><atom:updated>2017-10-01T11:16:05.170+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CDI</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Java EE 7</category><category domain="http://www.blogger.com/atom/ns#">javaEE</category><category domain="http://www.blogger.com/atom/ns#">JSF</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.2</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>HTML5 support in JSF 2.2 with Bean Validation 1.1 (JavaEE 7)</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In this post i will show the HTML5 Support given by JSF 2.2, Which is part of Java EE 7 Spec. Also how to integrate the Bean Validation 1.1 feature with help of CDI (Contexts and Dependency Injection) 1.1 spec.&lt;br /&gt;&lt;br /&gt;Before going the HTML5 support, my earlier posts on JSF, i used&amp;nbsp;@ManagedBean annotation, because its part of Managed Bean Specification (Java EE 6). Another Reason i used Tomcat as a primary container, if i used Managed Bean Spec then its part of Mojjara implementation, so no need to add more CDI specific (Jboss Weld lib) lib to class-path.&lt;br /&gt;&lt;br /&gt;But from Java EE 7 on-wards, JCP community expand the CDI capabilities and make CDI as important spec in Java EE 7 and Managed Bean spec is deprecated&amp;nbsp;in favor of CDI . so they recommend to use CDI wherever its possible. so our future all post to target the CDI. next post i will show how add the CDI capability to tomcat container.&lt;br /&gt;&lt;br /&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So as part of CDI we need to use&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;@Named&lt;/b&gt; annotation. Its equal to&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;@ManagedBean&lt;/b&gt; annotation, but its CDI Specific and all life cycle of the beans takes care by CDI container.&lt;br /&gt;&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[ import java.io.Serializable; import javax.enterprise.context.SessionScoped; import javax.inject.Named;  @Named @SessionScoped public class DemoBean implements Serializable{      } ]]&gt;&lt;/script&gt; &lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;HTML5&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; HTML5 is future of web standard, its provide lots of capability to browser like Full multimedia (audio and video playback), access the local resources like camera, microphone, Geolocation.&lt;br /&gt;for more information check these resources&lt;br /&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&amp;nbsp;&lt;a href=&quot;http://webplatform.org/&quot;&gt;Webplatform.org&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;color: #0000ee;&quot;&gt;&lt;u&gt;&lt;a href=&quot;https://digital.com/tools/html-cheatsheet/&quot; target=&quot;_blank&quot;&gt;HTML CHEAT SHEET&lt;/a&gt;&lt;/u&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;HTML5 Form elements are part of this features. This feature enable to the website without any 3rd party JavaScript framework to get fields/widgets like date picker, color picker, Check the &lt;a href=&quot;http://html5-demos.appspot.com/&quot; target=&quot;_blank&quot;&gt;sample page here&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;HTML5 Support in JSF2.2&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;In JSF 2.0/2.1, its not supporting HTML5 form elements, the reason is HTML render-kit, which is part of JSF Implementation is not aware the HTML 5 elements or attributes. so even we put these attributes like placeholder, type=date, these Render-kit it just ignore while generating the HTML for client request. In that case there is 3rd party plugin called &lt;a href=&quot;http://code.google.com/p/omnifaces/%E2%80%8E&quot; target=&quot;_blank&quot;&gt;OmniFaces&lt;/a&gt; provides the Render-kit to support the HTML5 in JSF 2.0/2.1.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In JSF 2.2 onward&#39;s, HTML5 support internally as part of the Framework. The big issue is HTML5 attributes are we can&#39;t count or categorized. for example any input tag we add the data-* as attribute like data-theme, data-highlight, etc.. &amp;nbsp;so we need to do some way to classify these attribute. That way is called &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&quot;Pass through&quot;&lt;/b&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For eample i want to add one HTML5 input tag like this&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;input type=&quot;text&quot; placeholder=&quot;Enter your Name&quot; /&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here i want to convert this tag to JSF tags, because i want to bind this tag to my backing bean then&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;h:&lt;/span&gt;inputText &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;p:&lt;/span&gt;placeholder=&quot;Enter your Name&quot; /&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;here &lt;b&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;h:&lt;/span&gt; &lt;/b&gt;is prefix for normal HTML components, but&lt;b&gt; &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;p:&lt;/span&gt;&lt;/b&gt; is prefix for pass through.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;Like we can add the HTML5 Date picker componet&lt;br /&gt;&lt;br /&gt;Original HTML5 Code : &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;input type=&quot;date&quot; /&amp;gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;JSF2.2 Code :&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;h:inputText &amp;nbsp;p:type=&quot;date&quot; /&amp;gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Check the Video below, for more information and step - by step&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Add Validation&lt;/span&gt;&lt;/h3&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Now we got HTML5 Form elements in our projects, we need to validate what user entered, for this purpose either we used client side validation or server side validation.&lt;br /&gt;&lt;br /&gt;Client side validation is faster and good. but if somebody disable the JavaScript and submit the form then big problem. so we need server side validation also important. In server side we manually validate these fields.&lt;br /&gt;&lt;br /&gt;Java EE 7 gives updated Bean Validation 1.1 spec for this purpose. These Bean validations are declarative way we can specify and validate by the system. so its very cool feature.&lt;br /&gt;&lt;br /&gt;For example i asked user name to client, now client entered some value, now i need to validate its should not be null and its satisfy my other requirements like at-least 5 char for name like this&lt;br /&gt;&lt;br /&gt;so usually what we do we put if condition like this&lt;br /&gt;&lt;br /&gt;&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[ if(name !=null &amp;amp;&amp;amp; &quot;&quot;.equals(name.trim())  &amp;amp;&amp;amp; name.length&amp;gt;5) {           // some logic } ]]&gt;&lt;/script&gt; these kind of statements needed for all fields. But if we using Bean Validation then its simple.&lt;br /&gt;&lt;br /&gt;open the backing bean and mark the fields with constraint annotation&lt;br /&gt;&lt;br /&gt;&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[ public class DemoBean {      @NotEmpty      private String name;       @NotNull      @Past      private Date dob;        @Email          private String email;       // Getter and Setters } ]]&gt;&lt;/script&gt; When the the form is submit, then CDI called the bean validation features in transparent manner. If any validation is failed then its add those messages into faces context. so we can see those messages in that page.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Bean Validation applicable not only bean fields, Its have capability to validate the method arguments and its return type. This is grate features of bean validation.&lt;br /&gt;&lt;br /&gt;&lt;script class=&quot;brush: java&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[     @NotNull     public String method1( @NotNull String name, @Size(min=5) String lastName)      {           //logic            return somevalue;      } ]]&gt;&lt;/script&gt; Now when we call this method through CDI, these validation are applied.&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Twitter BootStrap Theme&lt;/span&gt;&lt;/h3&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I make one small example of HTML5 support and Bean validation, i used some free template based on Twitter bootstrap. &amp;nbsp;these are the refernce&lt;br /&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://getbootstrap.com/&quot;&gt;http://getbootstrap.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://bootswatch.com/&quot;&gt;http://bootswatch.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://bootsnipp.com/&quot;&gt;http://bootsnipp.com/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.creativitytuts.org/index.php/tutorialcontroller/listVideos/PL7029EEFC21D2DC58&quot;&gt;http://www.creativitytuts.org/index.php/tutorialcontroller/listVideos/PL7029EEFC21D2DC58&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;In last link we can learn the twitter bootstrap in depth.&lt;br /&gt;&lt;br /&gt;Check the video for small demo code combine HTML5 Support&amp;nbsp;+ Bean Validation&amp;nbsp;+ Twitter Bootstrap Theme. (Watch it in HD mode)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Demo Code is available in my &lt;a href=&quot;https://github.com/ramkicse/HTML5-JSF2.2-BeanValidation1.1&quot; target=&quot;_blank&quot;&gt;Github&lt;/a&gt; or u can download &lt;a href=&quot;https://github.com/ramkicse/HTML5-JSF2.2-BeanValidation1.1/archive/master.zip&quot; target=&quot;_blank&quot;&gt;zip from here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Screen Cast :&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;//www.youtube.com/embed/anochWfg4sc&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/h3&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2013/08/html5-support-in-jsf-22-with-bean.html</link><author>noreply@blogger.com (Ramakrishnan)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-3875608015387787096</guid><pubDate>Tue, 04 Jun 2013 12:27:00 +0000</pubDate><atom:updated>2016-05-03T10:34:11.272+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java EE 7</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.2</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><title>File Upload is Easy in JSF2.2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;To bring the File Upload feature in Java based web application is one of the difficult and complex job, we need to&amp;nbsp;dependent&amp;nbsp;on 3rd party&amp;nbsp;libraries&amp;nbsp;like&lt;b style=&quot;background-color: #fff2cc;&quot;&gt; Apache Commons FileUpload&lt;/b&gt;&amp;nbsp;Libraries. These&amp;nbsp;libraries&amp;nbsp;codes are complex and most of them boilerplate code.&lt;br /&gt;&lt;br /&gt;If we are using Java Server Faces (JSF), we have the page with some fields and file upload menu the its add more complexity,&amp;nbsp;fields&amp;nbsp;are binded to backing bean but these file uploads components are need to tie up with some 3rd party file upload&amp;nbsp;libraries.&lt;br /&gt;&lt;br /&gt;In Primefaces provide easy way to do the file upload in JSF web application,&amp;nbsp;even though&amp;nbsp;primefaces internally used the same Apache Commons FileUpload&amp;nbsp;Libraries, but provide simple JSF tags. We need configure &amp;nbsp;some listeners.&lt;br /&gt;&lt;br /&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In Servlet 3.0 they introduced the &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/http/Part.html&quot;&gt;&lt;b&gt;Part&lt;/b&gt;&lt;/a&gt; Interfaces and &lt;b&gt;@MultiPartConfig&lt;/b&gt; annotations for easy way to do the file upload without any 3rd party libs, Servlet 3.0 is part of Java EE 6 specification. so any servlet 3.0 implementation servers &amp;nbsp;like Tomcat 7, Jboss 6, GlassFish 3 they can get benefit of servlet 3.0. but this feature is not&amp;nbsp;available&amp;nbsp;in JSF 2.1. so again still&amp;nbsp;it&#39;s&amp;nbsp;complex to use file upload in JSF, because we need to mix servlet and JSF backing bean.&lt;br /&gt;&lt;br /&gt;Recently JSF 2.2 is&amp;nbsp;released&amp;nbsp;as part of Java EE 7 specification. Now this specs are final and its going to&amp;nbsp;release&amp;nbsp;Q2 of 2013.&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;Check my post about &lt;a href=&quot;http://www.ramkitech.com/2013/06/an-introduction-to-jsf-22.html&quot; target=&quot;_blank&quot;&gt;An introduction to JSF 2.2&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;in this post i going to show the File Upload feature with a demo&lt;br /&gt;&lt;br /&gt;At last JSF 2.2 is added the File Upload component, so we just use &amp;lt;h:inputFile&amp;gt; tag to make the file upload web application so easily, and this component use the Part interface, which its introduced its part of Servlet 3.0. so this JSF2.2&amp;nbsp;libraries&amp;nbsp;is working perfectly with Tomcat 7 (because tomcat 7 is implemented the Servlet 3.0 spec).&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;To bring the File Upload feature we need to follow 3 step process&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Add &amp;lt;h:inputFile&amp;gt; tag in JSF page&lt;/li&gt;&lt;li&gt;Add&amp;nbsp;enctype=&quot;multipart/form-data&quot; attribute in enclosing &amp;lt;h:form&amp;gt; tag&lt;/li&gt;&lt;li&gt;Create the field in Backing bean with Part data type.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Setup the Environment&lt;/span&gt;&lt;/h3&gt;JSF 2.2 lib are part of Java EE 7, but we can include as a&amp;nbsp;libraries&amp;nbsp;into existing Java EE 6 platform without upgrading the server.&lt;br /&gt;we can get the JSF 2.2&amp;nbsp;libraries (&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;Mojarra&lt;/b&gt; implementation) from here&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://repo1.maven.org/maven2/com/sun/faces/jsf-api/2.2.0/jsf-api-2.2.0.jar&quot;&gt;jsf-api-2.2.0.jar&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://repo1.maven.org/maven2/com/sun/faces/jsf-impl/2.2.0/jsf-impl-2.2.0.jar&quot;&gt;jsf-impl-2.20.jar&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Step 1: &amp;nbsp;Add &amp;lt;h:inputFile&amp;gt; tag in JSF page&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In JSF page add the &amp;lt;h:inputFile&amp;gt; tag where we need file upload component&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; white-space: pre;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;nt&quot; style=&quot;background-color: white; border: 0px; color: navy; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;&amp;lt;h:inputFile&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot; style=&quot;background-color: white; border: 0px; color: teal; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;background-color: white; border: 0px; color: #dd1144; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;&quot;#{demoBean.file1}&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot; style=&quot;background-color: white; border: 0px; color: navy; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;here i bind the value property to file1 field, which data type is Part, check the third step&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Step 2: &amp;nbsp;Add&amp;nbsp;enctype=&quot;multipart/form-data&quot; attribute in enclosing &amp;lt;h:form&amp;gt; tag&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;When u want file upload feature then we need to inform the browser that form may contain&amp;nbsp;multiple normal text input field&amp;nbsp;&amp;nbsp;and some file upload&amp;nbsp;component, so prepare the POST&amp;nbsp;request in special form, like parts by part with special delimiter boundary.&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; white-space: pre;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;nt&quot; style=&quot;background-color: white; border: 0px; color: navy; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;&amp;lt;h:form&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;na&quot; style=&quot;background-color: white; border: 0px; color: teal; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;enctype=&lt;/span&gt;&lt;span class=&quot;s&quot; style=&quot;background-color: white; border: 0px; color: #dd1144; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;&quot;multipart/form-data&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot; style=&quot;background-color: white; border: 0px; color: navy; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; margin: 0px; padding: 0px; white-space: pre;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: navy; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;liberation mono&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 12px; line-height: 18px; white-space: pre;&quot;&gt; &amp;lt;/h:form&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;so index.xhtml file looks like&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xhtml&quot;&gt;&lt;![CDATA[ &lt;html xmlns:h=&quot;http://java.sun.com/jsf/html&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;    &lt;h:head&gt;        &lt;title&gt;Facelet Title&lt;/title&gt;    &lt;/h:head&gt;    &lt;h:body&gt;        Hello from Facelets                  &lt;h:form enctype=&quot;multipart/form-data&quot;&gt;            &lt;h:inputfile value=&quot;#{demoBean.file1}&quot;&gt;&lt;/h:inputfile&gt;                          &lt;h:inputfile value=&quot;#{demoBean.file2}&quot;&gt; &lt;/h:inputfile&gt;             &lt;h:commandbutton action=&quot;#{demoBean.upload()}&quot; value=&quot;Upload&quot;&gt;        &lt;/h:commandbutton&gt;&lt;/h:form&gt;    &lt;/h:body&gt;&lt;/html&gt;]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Step 2: &amp;nbsp;Create Backing Bean&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;now create the backing bean for this page. we need to create the fields for input File component with Part type. Part interface is&amp;nbsp;introduced&amp;nbsp;in servlet 3.0 for represent the file chunks&amp;nbsp;sent&amp;nbsp;by browser, JSF 2.2 use this &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/http/Part.html&quot;&gt;Part&lt;/a&gt; interface, Using the Part interface we can get the header information of each file chunk sent by browser, these header contain the file name and other meta information about the file.&lt;br /&gt;&lt;br /&gt;Part interface also contain write() method to write the file contents into specified server location, or u can get the InputStream then we can process it.&lt;br /&gt;&lt;br /&gt;DemoBean.java&lt;br /&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ import java.io.IOException; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.servlet.http.Part;   /**  *  * @author ramki  */ @ManagedBean @SessionScoped public class DemoBean {      private Part file1;     private Part file2;      // getters and setters for file1 and file2      public String upload() throws IOException {          InputStream inputStream = file1.getInputStream();                 FileOutputStream outputStream = new FileOutputStream(getFilename(file1));                  byte[] buffer = new byte[4096];                 int bytesRead = 0;         while(true) {                                     bytesRead = inputStream.read(buffer);             if(bytesRead &amp;gt; 0) {                 outputStream.write(buffer, 0, bytesRead);             }else {                 break;             }                                }         outputStream.close();         inputStream.close();                 return &quot;success&quot;;     }      private static String getFilename(Part part) {         for (String cd : part.getHeader(&quot;content-disposition&quot;).split(&quot;;&quot;)) {             if (cd.trim().startsWith(&quot;filename&quot;)) {                 String filename = cd.substring(cd.indexOf(&#39;=&#39;) + 1).trim().replace(&quot;\&quot;&quot;, &quot;&quot;);                 return filename.substring(filename.lastIndexOf(&#39;/&#39;) + 1).substring(filename.lastIndexOf(&#39;\\&#39;) + 1); // MSIE fix.             }         }         return null;     } } ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;here we need get the file name from the Header of the chunk, so there is&amp;nbsp;boilerplate&amp;nbsp;code can do, here&amp;nbsp;i don&#39;t&amp;nbsp;like this method :-( &lt;br /&gt;&lt;br /&gt;there is no direct method to&amp;nbsp;retrieve&amp;nbsp;the file name. so use this code we can get the name of the file is uploaded by client, then using write method we can store into server.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Get my sample project from my &lt;a href=&quot;https://github.com/ramkicse/jsf2.2-FileUpload&quot;&gt;&lt;b&gt;Github&lt;/b&gt;&lt;/a&gt; or download from &lt;b&gt;&lt;a href=&quot;https://github.com/ramkicse/jsf2.2-FileUpload/archive/master.zip&quot;&gt;here&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;For more information (step by step) see the screencast&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Screencast&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;http://www.youtube.com/embed/8KzoSfkMMXM&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2013/06/file-upload-is-easy-in-jsf22.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/8KzoSfkMMXM/default.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4916298030846639307</guid><pubDate>Tue, 04 Jun 2013 09:59:00 +0000</pubDate><atom:updated>2016-02-18T15:18:46.964+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java EE 7</category><category domain="http://www.blogger.com/atom/ns#">JSF</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.2</category><title>An Introduction to JSF 2.2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Recently Java EE 7 specification goes into final. Next week (June 12) oracle going to release the Java EE 7 specification and Glass Fish 4 as reference implementation to general&amp;nbsp;availability.&lt;br /&gt;&lt;br /&gt;Java EE 7 adds more features like JSF 2.2, Servlet 3.1, Json Processing,&amp;nbsp;websocket&amp;nbsp;support, etc..&lt;br /&gt;&lt;a href=&quot;https://wikis.oracle.com/display/GlassFish/PlanForGlassFish4.0&quot; target=&quot;_blank&quot;&gt;click here&lt;/a&gt; about the spec.&lt;br /&gt;&lt;br /&gt;In this post&amp;nbsp;i&#39;m&amp;nbsp;going walk through in JSF 2.2&lt;br /&gt;&lt;br /&gt;JSF 2.2 is added more features, and JSF as &amp;nbsp;a main presentation layer of Java EE platform. compare to JSP, jsp is not getting more feature, they just add&amp;nbsp;maintenance&amp;nbsp;release.&lt;br /&gt;&lt;b style=&quot;color: #990000;&quot;&gt;&lt;/b&gt;&lt;br /&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;b style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;b style=&quot;color: #990000;&quot;&gt;Features of JSF 2.2&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;File Upload Component&lt;/li&gt;&lt;li&gt;Faces Flow&lt;/li&gt;&lt;li&gt;HTML5&amp;nbsp;Support&lt;/li&gt;&lt;li&gt;Cross Site Request&amp;nbsp;Forgery Protection&amp;nbsp;(CSRF)&lt;/li&gt;&lt;li&gt;Multi-Templating&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;File Upload Component&lt;/span&gt;&lt;/h4&gt;&lt;br /&gt;This is most awaited feature in JSF, now we can build the file upload feature in web application without any 3rd party&amp;nbsp;libraries.&lt;br /&gt;&lt;br /&gt;i am going to cover this topic in&lt;a href=&quot;http://www.ramkitech.com/2013/06/file-upload-is-easy-in-jsf22.html&quot; target=&quot;_blank&quot;&gt;&amp;nbsp;another&amp;nbsp;post.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Faces Flows&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;&lt;br /&gt;Faces flows&amp;nbsp;provides&amp;nbsp;to create the JSF web application in modular way, each module is self contained pages , own backing beans and entry and exit points. Its make the module more reusable.&lt;br /&gt;&lt;br /&gt;Faces flows are&amp;nbsp;inspired&amp;nbsp;from Spring Web Flows and Oracle Task Flows&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogs.oracle.com/arungupta/entry/jsf_2_2_faces_flow&quot; target=&quot;_blank&quot;&gt;Arun Gupta&amp;nbsp;&lt;/a&gt;described his post&amp;nbsp;about Faces Flows&lt;br /&gt;&lt;br /&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;HTML5 Support&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;&lt;br /&gt;HTML5 is future of the web, old JSF&amp;nbsp;libraries&amp;nbsp;are doesn&#39;t support HTML5 tags and attributes like&amp;nbsp;placeholder&amp;nbsp;attribute in input field tag, etc.&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;lt;h:inputText &amp;nbsp; value=&quot;#{backingBean.field}&quot; &amp;nbsp; p:placeholder=&quot;Enter text&quot; &amp;nbsp;/&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Cross Site Request&amp;nbsp;Forgery Protection (CSRF)&lt;/span&gt;&lt;/b&gt;&lt;/h4&gt;&lt;br /&gt;CSRF is one kind of security attack, Its make the request on existing session.&lt;br /&gt;&lt;br /&gt;For example i opened the Tomcat Manager web application and i logged in, now i try to open another web site in different tab, now that website try to execute the code like&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace; font-size: 11px; white-space: pre-wrap;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;http://localhost:8080/manager/html/stop?path=/app1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace; font-size: 11px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;then browser make the request to that server (localhost:8080), browser already have session, so that server stop the application.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;so we need to add CSRF protection token for every request, if token is not found or invalid then that request is not &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;proceed&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt; further, server ignores the request&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;tomcat 7 uses own CSRF token&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace; font-size: 11px; white-space: pre-wrap;&quot;&gt;http://&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace; font-size: 11px; white-space: pre-wrap;&quot;&gt;localhost&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace; font-size: 11px; white-space: pre-wrap;&quot;&gt;:8080/manager/html/stop?path=/app1&amp;amp;org.apache.catalina.filters.CSRF_NONCE=CEF9F082EF983140038CF804CA81F29E&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace; font-size: 11px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;here tomcat 7 adds the CSRF &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;token&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;now JSF 2.2 we can declaratively add the CSRF token to protecting the&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;resources &lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;from CSRF attacks&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-family: inherit;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;Multi - Templating&lt;/span&gt;&lt;/span&gt;&lt;/h4&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;Multi Templating&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt; is another feature to add more templates (Layout, skins), to web applications.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;so we can change the template in run time like wordpress we can change the themes,&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;just put the theme jar file in &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;classpath&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;, Java platform discovered and apply the templates.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;If u have any comments welcomed&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2013/06/an-introduction-to-jsf-22.html</link><author>noreply@blogger.com (Ramakrishnan)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-2570542160608564795</guid><pubDate>Mon, 28 Jan 2013 15:06:00 +0000</pubDate><atom:updated>2013-04-12T11:16:22.882+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">nginx</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">session replication</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><title>Tomcat Clustering Series Part 5 : NginX as Load Balancer</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Hi this is&amp;nbsp;my fifth part of the&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/search/label/tomcat%20clustering&quot; target=&quot;_blank&quot;&gt;Tomcat Clustering Series&lt;/a&gt;.&amp;nbsp;In this&amp;nbsp;post we are going to discuss how to replace Apache httpd load balancer to Nginx as a load balancer.&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc; color: #660000;&quot;&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Hi i finished &lt;a href=&quot;http://www.ramkitech.com/search/label/tomcat%20clustering&quot; target=&quot;_blank&quot;&gt;Tomcat Clustering Series&lt;/a&gt;. In these series we have 2 big setups needed for Tomcat Clustering&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Setup and configure the Load Balancer&lt;/li&gt;&lt;li&gt;Configure the Session Replication in Tomcat.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s1600/tomcat_simple_load_balancer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;205&quot; src=&quot;http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s400/tomcat_simple_load_balancer.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;In first setup, we configure the Load Balancer using Apache httpd web server. Its open source and widely used.&lt;br /&gt;&lt;div&gt;Second setup is session replication in Tomcat through modify/add &amp;lt;cluster&amp;gt; tag in server.xml file. These tomcat instance may&lt;a href=&quot;http://www.ramkitech.com/2011/07/running-multiple-tomcat-instances-on.html&quot; target=&quot;_blank&quot;&gt; run on&amp;nbsp;single&amp;nbsp;machine&lt;/a&gt; or different machine.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In our &lt;a href=&quot;http://www.ramkitech.com/search/label/tomcat%20clustering&quot; target=&quot;_blank&quot;&gt;Tomcat Clustering Series&lt;/a&gt;, the big part is configure the Load balancer (Apache httpd web server). Because&amp;nbsp;there&amp;nbsp;are lots of steps are involved&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Install the Apache httpd web server from either source or repo&lt;/li&gt;&lt;li&gt;Compile and install the mod_jk connector&lt;/li&gt;&lt;li&gt;Create the workers.properties file (add tomcat IP and ajp port information )&lt;/li&gt;&lt;li&gt;Configure into httpd.conf file (Add mod_jk related settings)&lt;/li&gt;&lt;/ol&gt;these&amp;nbsp;setups&amp;nbsp;are take &lt;b&gt;&lt;u&gt;more time and very difficult to debug.&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Is there is any alternative to load balancer?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; Yes, Nginx its emerging web server. this post we are going to discuss how to setup nginx as a load&amp;nbsp;balancer&amp;nbsp;in our tomcat cluster.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;What is Nginx?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://en.wikipedia.org/wiki/Nginx&quot; target=&quot;_blank&quot;&gt;Nginx&lt;/a&gt; is open source and alternative to Apache httpd web server. Its provide more performance and little memory foot print.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Install Nginx&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; we can install nginx through either repository (apt-get,yum) or from source. here i m build nginx from source from &lt;a href=&quot;http://nginx.org/en/download.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. then extract the compressed file.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;./configure --help &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;above command shows possible command line options available for compile&lt;/div&gt;&lt;div&gt;for install use this command&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;./configure &amp;nbsp; --prefix=/home/ramki/nginx &amp;nbsp; --with-http_ssl_module &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;here&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;--prefix&lt;/span&gt; used to specify where nginx server want to install, here i m using my home folder (like /usr/local/nginx)&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: blue;&quot;&gt;--with-http_ssl_module&lt;/span&gt; here i&amp;nbsp;specified&amp;nbsp;install SSL module (https), its not necessary. If we want secure webpage then this module is needed.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;then compile the source&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;&lt;b&gt;make&lt;/b&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;install the nginx based on our configuration&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;sudo make install &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;now installation is done, To &lt;u&gt;start the nginx&lt;/u&gt;,&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;cd&amp;nbsp;/home/ramki/nginx/sbin &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;sudo ./nginx &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;now open browser and go to http://localhost to get nginx default page.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To &lt;u&gt;stop the nginx&lt;/u&gt;, we need to pass stop signal via -s option&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;sudo ./nginx &amp;nbsp;-s stop &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Configure as a Load Balancer&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Nginx&amp;nbsp;configurations&amp;nbsp;are stored in nginx.con file in conf/ folder. &amp;nbsp;We need to perform 2 steps to make nginx as load balancer.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;First define Upstream&amp;nbsp;block&amp;nbsp;in nginx.conf file&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Upstream&amp;nbsp;block&amp;nbsp;provides simple load-balancing across upstream (backend) servers. In upstream block have unique name (here &amp;nbsp;tomcatcluster), later we need to point out from other block.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;upstream tomcatcluster &amp;nbsp;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;server&amp;nbsp;&lt;a href=&quot;http://127.0.0.1:8181/&quot; style=&quot;color: #1155cc;&quot; target=&quot;_blank&quot;&gt;127.0.0.1:8181&lt;/a&gt;;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href=&quot;http://127.0.0.1:8282/&quot; style=&quot;color: #1155cc;&quot; target=&quot;_blank&quot;&gt;127.0.0.1:8282&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href=&quot;http://127.0.0.1:8383/&quot; style=&quot;color: #1155cc;&quot; target=&quot;_blank&quot;&gt;127.0.0.1:8383&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc; font-size: 12.727272033691406px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here we define the&amp;nbsp;back-end&amp;nbsp;servers (Tomcat instances) via server directive.&lt;/div&gt;&lt;div&gt;In each server directive we mention IP address of server and&amp;nbsp;HTTP&amp;nbsp;port number(&lt;b&gt;Not AJP port number&lt;/b&gt;).&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;Second forward (proxy) the request to&amp;nbsp;back-end&amp;nbsp;servers&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This step is forward the request to upstream blocks, where we&amp;nbsp;define&amp;nbsp;the back end servers.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;location / {&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;proxy_pass&amp;nbsp;&lt;a href=&quot;http://tomcatcluster/&quot; style=&quot;color: #1155cc;&quot; target=&quot;_blank&quot;&gt;http://tomcatcluster&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here if location / is already present, then remove and add this new one.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here proxy_pass directive,&amp;nbsp;proxifier(forward)&amp;nbsp;the requests to upstream servers. here tomcatcluster is name of the upstream block and we used http protocol to forward the request.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;that&#39;s&amp;nbsp;it. Load balancer is ready.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;now start the tomcat instances based on my previous post (session replication). then start nginx.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;now access http://localhost.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;now nginx forward the request in round robin fashion to&amp;nbsp;back-end&amp;nbsp;servers. all servers have the session, so it can able to process the request&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;This is same as non-sticky&amp;nbsp;session method we used in my previous posts.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;If we want sticky session, then nginx&amp;nbsp;directly&amp;nbsp;not provide, but some 3rd party patches are&amp;nbsp;available. but nginx provide ip_hash directive. Its forward all request from&amp;nbsp;single&amp;nbsp;IP to same tomcat like sticky session. But sticky session works based on cookie (session). but ip_hash is based on IP address of client.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;If u want to configure ip_hash, then modify the upstream block, add ip_hash&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;upstream tomcatcluster &amp;nbsp;{&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ip_hash;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;b style=&quot;font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;server&amp;nbsp;&lt;a href=&quot;http://127.0.0.1:8181/&quot; style=&quot;color: #1155cc;&quot; target=&quot;_blank&quot;&gt;127.0.0.1:8181&lt;/a&gt;;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href=&quot;http://127.0.0.1:8282/&quot; style=&quot;color: #1155cc;&quot; target=&quot;_blank&quot;&gt;127.0.0.1:8282&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;                &lt;/span&gt;server&amp;nbsp;&lt;a href=&quot;http://127.0.0.1:8383/&quot; style=&quot;color: #1155cc;&quot; target=&quot;_blank&quot;&gt;127.0.0.1:8383&lt;/a&gt;;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: arial, sans-serif; font-size: 12.727272033691406px;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc; font-size: 12.727272033691406px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;just restart the server, u feel like sticky session concept.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;when we compare the Nginx to Apache httpd web server, nginx is provide simple&amp;nbsp;configuration, and can handle huge amount of traffic, consume little memory foot print and its take little CPU load.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;search &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Nginx vs Apache&lt;/span&gt; we get some&amp;nbsp;amazing&amp;nbsp;benchmark results.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Screen Cast :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/zRPJ_U2MruU&quot; width=&quot;700&quot;&gt;&lt;/iframe&gt; &lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2013/01/tomcat-clustering-series-part-5-nginx.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s72-c/tomcat_simple_load_balancer.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4326698037755275470</guid><pubDate>Wed, 05 Dec 2012 13:54:00 +0000</pubDate><atom:updated>2013-04-12T11:17:20.967+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">session replication</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><title>Tomcat Clustering Series Part 4 : Session Replication using Backup Manager</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Hi this is&amp;nbsp;my fourth part of the&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/search/label/tomcat%20clustering&quot; target=&quot;_blank&quot;&gt;Tomcat Clustering Series&lt;/a&gt;.&amp;nbsp;In this&amp;nbsp;post we are going to discuss the how to setup session replication using Backup Manager in tomcat clustering environment. Session replication makes High availability and full fail-over capability to our clustering environment.&lt;b style=&quot;background-color: #fff2cc; color: #660000;&quot;&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc; color: #660000;&quot;&gt;&lt;br /&gt;&lt;/b&gt;Its continuation of the &lt;a href=&quot;http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html&quot; target=&quot;_blank&quot;&gt;last post (session replication using Delta Manager)&lt;/a&gt;. In delta manager each tomcat instance need to replicate the session information to all other tomcat instances. Its take more time and replication if our cluster size is increased. so there is alternative manager is there. Its Backup Manager.&lt;br /&gt;&lt;br /&gt;Backup Manager is&amp;nbsp;replicate&amp;nbsp;the copy of session data to &lt;b&gt;&lt;u&gt;exactly one&lt;/u&gt;&lt;/b&gt; other tomcat instances. This big difference between both managers. here which tomcat creates that is &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;primary copy&lt;/b&gt;&lt;/span&gt; of the session. and another tomcat whose hold the replicate session is &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;backup copy&lt;/b&gt;&lt;/span&gt;. If any one of the tomcat is down. back up tomcat serve the session. Its&amp;nbsp;achieve&amp;nbsp;the&amp;nbsp;fail over&amp;nbsp;capability.&lt;br /&gt;&lt;br /&gt;The setup process of backup manager is same as Delta manager. except we need to mention the Manager as BacupManager (&lt;span style=&quot;background-color: white; color: #dd1144; font-family: Consolas, &#39;Liberation Mono&#39;, Courier, monospace; font-size: 12px; line-height: 16px; white-space: pre;&quot;&gt;org.apache.catalina.ha.session.DeltaManager&lt;/span&gt;) &amp;nbsp;inside &amp;lt;Cluster&amp;gt; element.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Suppose we have 3 tomcat instances like &lt;a href=&quot;http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt;. and i&amp;nbsp;configured&amp;nbsp;into backup manager.&lt;br /&gt;&lt;br /&gt;now user try access the page. User request comes to load balancer, and load balancer redirect the rquest to suppose tomcat1. Now tomcat one create the session, now tomcat1 is&amp;nbsp;responsible&amp;nbsp;to&amp;nbsp;replicate&amp;nbsp;exactly one copy to any one of the tomcat. so&amp;nbsp;tomcat1&amp;nbsp;picks any tomcat which is part of the cluster (multicast). here tomcat1 picks tomcat3 as a backup. so tomcat3 hold the backup copy of the session.&lt;br /&gt;&lt;br /&gt;we are run the load balancer in sticky session mode. so all further request from that particular user &amp;nbsp;is&amp;nbsp;redirect&amp;nbsp;to tomcat1 only. all modification in tomcat1 is replicate to tomcat3.&lt;br /&gt;&lt;br /&gt;now tomcat1 is&amp;nbsp;crashed/shutdown for some reason&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-D3AA9gQBYpk/UL9Ls6hChHI/AAAAAAAACr0/LgO94l_udaY/s1600/session-replicate_backup_manager.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; src=&quot;http://1.bp.blogspot.com/-D3AA9gQBYpk/UL9Ls6hChHI/AAAAAAAACr0/LgO94l_udaY/s400/session-replicate_backup_manager.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;now same user try to&amp;nbsp;access&amp;nbsp;the page. this time load balancer try to redirect to tomcat1. but tomcat1 is down. so&amp;nbsp;load-balancer&amp;nbsp;pick one tomcat from the remaining tomcats. here&amp;nbsp;interestingly&amp;nbsp;2 case are there.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Case 1:&lt;/span&gt;&lt;/h3&gt;&amp;nbsp; Suppose Load balancer pick the tomcat3 then tomcat3 receive the request and tomcat3 itself hold the backup copy of the session. so tomcat3 make that session as primary copy and tomcat3 pick any one tomcat as backup copy. so here remaining only one tomcat is there. so tomcat3 replicate the session to tomcat2. so now tomcat3 hold primary copy and tomcat2 hold the backup copy. now tomcat3 give the response to user. all further request is handled by tomcat3 (sticky session).&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;case 2:&lt;/span&gt;&lt;/h3&gt;&amp;nbsp;Suppose Load balancer pick the tomcat2 then tomcat2 receive the request and tomcat2 don&#39;t have the session. so tomcat2 session manager (Backup Manager) ask to all other tomcat manager &quot;hi anybody hold the session for this user (based on session id [cookie])&quot;. Actually tomcat3 have the backup session. so tomcat3 inform to tomcat2. and replicate the&amp;nbsp;session&amp;nbsp;to tomcat2. now &amp;nbsp;tomcat2 make that session as primary copy and tomcat3 whose already have copy of session as&amp;nbsp;remains&amp;nbsp;as a backup copy of that session. so now tomcat2 hold primary copy and tomcat3 hold the backup copy. now tomcat2 give the response to user. all further request is handled by tomcat2 (sticky session).&lt;br /&gt;&lt;br /&gt;so in either case our session is replicate and maintained by backup manager. Its good for large cluster.&lt;br /&gt;check the&amp;nbsp;video&amp;nbsp;below&lt;br /&gt;&lt;br /&gt;check my configuration in &lt;a href=&quot;https://github.com/ramkicse/tomcat-clustering-session-replication-&quot; target=&quot;_blank&quot;&gt;my github repo&lt;/a&gt; or get as &lt;a href=&quot;https://github.com/ramkicse/tomcat-clustering-session-replication-/archive/master.zip&quot; target=&quot;_blank&quot;&gt;ZIP&lt;/a&gt;&amp;nbsp;file&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;a name=&quot;loadbalancerfail&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Note:&lt;/span&gt;&lt;/h3&gt;&lt;/a&gt;&lt;br /&gt;Load balancer also faces &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;single point failure&lt;/b&gt;&lt;/span&gt;. to resolve this we need to put another load balancer with public address and update the new IP to DNS server with same URL. so our URL like example.com query resolves the 2 IP address for 2 load balancer.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;How its work:-&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;-&amp;gt; If browser want to access http://example.com then it first ask DNS server.&lt;br /&gt;-&amp;gt; DNS server gives 2 IP address to browser&lt;br /&gt;-&amp;gt; Browser take the first IP address and try to connect.&lt;br /&gt;-&amp;gt; If in the case that server is failed to respond then browser side make timeout&lt;br /&gt;-&amp;gt; then browser contact second IP address, now second load balancer is works fine.&lt;br /&gt;&lt;br /&gt;This kind of adding more load balancer makes to our website more&amp;nbsp;scalable&amp;nbsp;and reliable in case of tragedy.&lt;br /&gt;&lt;br /&gt;check in ur terminal&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;gt; &amp;nbsp; &amp;nbsp; nslookup google.com &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;its gives 11 IP address. these all are google&amp;nbsp;load balancer&#39;s located in various&amp;nbsp;geographic&amp;nbsp;locations&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Another thing this DNS servers not return same order of IP list to browser. each an every time its rotate(round robin) the IP list. so in 2 different machine ask google.com get different order of IP list. so these 2 differnt machine connect different google load balancer. so here DNS server also play little role for distribute the requests(loads).&lt;br /&gt;&lt;br /&gt;to verify use same command twice. and verify the IP order.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Screen Cast:&lt;/span&gt;&lt;/h2&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/vgbUKiNg6lU&quot; width=&quot;700&quot;&gt;&lt;/iframe&gt; &lt;/div&gt;</description><link>http://www.ramkitech.com/2012/12/tomcat-clustering-series-part-4-session.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-D3AA9gQBYpk/UL9Ls6hChHI/AAAAAAAACr0/LgO94l_udaY/s72-c/session-replicate_backup_manager.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5838067658082292351</guid><pubDate>Tue, 20 Nov 2012 06:28:00 +0000</pubDate><atom:updated>2013-04-12T11:17:28.154+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">session replication</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><title>Tomcat Clustering Series Part 3 : Session Replication</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Hi this is&amp;nbsp;my third part of the&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/search/label/tomcat%20clustering&quot; target=&quot;_blank&quot;&gt;Tomcat Clustering Series&lt;/a&gt;.&amp;nbsp;In this&amp;nbsp;post we are going to discuss the how to setup session replication in tomcat clustering environment. Session replication makes High availability and full fail-over capability to our clustering environment.&lt;b style=&quot;background-color: #fff2cc; color: #660000;&quot;&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;In my previous post we&amp;nbsp;discussed about setup &lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html&quot; target=&quot;_blank&quot;&gt;simple load balancer&lt;/a&gt; and how to make &lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html&quot; target=&quot;_blank&quot;&gt;session affinity&lt;/a&gt; concepts.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;&lt;b&gt;How to setup Session Replication in tomcat&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;before going to session replication we need to understand 2 important concepts&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Multicast&lt;/li&gt;&lt;li&gt;Session Manager in Tomcat&lt;/li&gt;&lt;/ul&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Multicast&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Multicast&quot; target=&quot;_blank&quot;&gt;Multicast&lt;/a&gt; is To transmit a single message to a select group of recipients. here&amp;nbsp;multicast&amp;nbsp;used by tomcat cluster to identify the instances those part of cluster.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;There is&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt; 2 types of cluster&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Static Tomcat Cluster&lt;/li&gt;&lt;li&gt;Dynamic&amp;nbsp;Tomcat Cluster&lt;/li&gt;&lt;/ul&gt;In&lt;span style=&quot;background-color: #d9ead3;&quot;&gt; &lt;b&gt;static cluster&lt;/b&gt;&lt;/span&gt; there is no need multicast, because each tomcat we statically defined/configured the other instances. But &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;dynamic Cluster&lt;/b&gt;&lt;/span&gt; we are not&amp;nbsp;defined&amp;nbsp;anything. so each tomcat in that cluster some how to identify the other tomcat instances.&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;so here&amp;nbsp;multicast&amp;nbsp;concepts is used. each and every tomcat first&amp;nbsp;joining&amp;nbsp;to &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;single&amp;nbsp;multicast&amp;nbsp;group&lt;/b&gt;. and send the heartbeat signals in periodic interval. so other tomcat instances&amp;nbsp;received&amp;nbsp;these signal and add the member to the cluster.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Session Manager in Tomcat&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Session Manager is used to create and manage the session behalf the application. In Servlet Specification&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: #e06666;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;request.getSession();&lt;/span&gt;&lt;/b&gt; line is mention that container (tomcat) is responsible for create the session. here tomcat use the Session Manager for this purpose.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;there is &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;4 types of Session Manager&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Standard Manager&lt;/li&gt;&lt;li&gt;Persistent Manager&lt;/li&gt;&lt;li&gt;Delta Manager&lt;/li&gt;&lt;li&gt;Backup Manager&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Standard Manager&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Its is the default manager used by tomcat. Even though we are not mention in our web application tomcat use this manager for managing our session. If u want to customize the this&amp;nbsp;standard&amp;nbsp;manager then add &amp;lt;Manager&amp;gt; tag in context.xml file.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;lt;Manager className=“org.apache.catalina.session.StandardManager” /&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here&amp;nbsp;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;org.apache.catalina.session.StandardManager &lt;/span&gt;is fully qualified class name of the Standard Manager.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Persistent Manger&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;This mnager is to sote the session information into persistent place after some interval. here two types of store is available.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;File Store&lt;/li&gt;&lt;li&gt;JDBC Store&lt;/li&gt;&lt;/ul&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;File Store&lt;/b&gt;&lt;/span&gt; helps to store all session information in&amp;nbsp;separate&amp;nbsp;files in&amp;nbsp;underlying&amp;nbsp;file system (local HDD or shared&amp;nbsp;file-system&amp;nbsp;like NFS,..)&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JDBC Store&lt;/b&gt; helps to store the session information to&amp;nbsp;relational&amp;nbsp;database.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;so using the Persistent&amp;nbsp;Manager we can&amp;nbsp;achieve&amp;nbsp;the tomcat cluster. but its not&amp;nbsp;swapped&amp;nbsp;out in real time. its pushes the information after certain interval. so if anything badly happen(crash) before that interval then in-memory session data is gone.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Delta Manger&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;In this post we are going to use this manager. Its replicate the session to all other instances. so this manager&amp;nbsp;usually&amp;nbsp;used&amp;nbsp;clustered&amp;nbsp;environment. but not good for large cluster.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Backup Manager&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;this manager&amp;nbsp;usually&amp;nbsp;used&amp;nbsp;clustered&amp;nbsp;environment. Its like delta manger. but it will &amp;nbsp;replicate to exactly one other instance(backup instance). Its acted like one instance is Primary &amp;nbsp;and another instance as backup &amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;b style=&quot;color: #660000; font-size: x-large;&quot;&gt;Steps to make Session Replication in Tomcat Clustering&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;color: #660000; font-size: x-large;&quot;&gt;&lt;br /&gt;&lt;/b&gt;here i will continue from exactly where i left in last &lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html&quot; target=&quot;_blank&quot;&gt;session affinity post&lt;/a&gt;. so check that &lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; and make sure jumRoute all are set properly. so&amp;nbsp;steps&amp;nbsp;are&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Enable Multicast routing&lt;/li&gt;&lt;li&gt;Add &amp;lt;Cluster&amp;gt; Entries in conf/server.xml file&amp;nbsp;for all instances.&lt;/li&gt;&lt;li&gt;Enable the Web Application as distributable&lt;/li&gt;&lt;/ol&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;/ul&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;1. Enable Multicast routing&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;In Linux Environment most of the system kernel is capable to process the multicast address. but we need to add route entry in kernel routing table.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;here eth0 is my&amp;nbsp;Ethernet&amp;nbsp;interface. so change&amp;nbsp;according&amp;nbsp;to your &amp;nbsp;interface&lt;br /&gt;&lt;div&gt;In&amp;nbsp;multicast&amp;nbsp;address is belong to Class D address Range&lt;span style=&quot;background-color: #d9ead3;&quot;&gt; (224.0.0.0 to 239.255.255.255).&lt;/span&gt; so we inform to kernel if any one&amp;nbsp;access&amp;nbsp;these address then it goes through eth0 interface.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;2. Add &amp;lt;Cluster&amp;gt; Entries in conf/server.xml file&amp;nbsp;for all instances.&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;This very important part for tomcat clustering. We need to Add &amp;lt;Cluster&amp;gt; tag in &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;conf/server.xml &lt;/b&gt;&lt;/span&gt;file in all tomcat instances.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&amp;lt;Cluster className=&lt;span style=&quot;color: magenta;&quot;&gt;&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;&lt;/span&gt;/&amp;gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;we can add this &amp;lt;Cluster&amp;gt; tag in either inside the&amp;lt;Engine&amp;gt; tag or &amp;lt;Host&amp;gt; tag.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here SimpleTcpCluster is Tomcat&amp;nbsp;Cluster&amp;nbsp;implementation&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This tag is looks like simple but its has many inner tags. if we&amp;nbsp;omitted&amp;nbsp;then its takes the default&amp;nbsp;values. if we want do any cutomization (like change multicat address, receving address port) we need to use complete &amp;lt;Cluster&amp;gt; tag&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;this is complete &amp;lt;Cluster&amp;gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;lt;Cluster className=&quot;org.apache.catalina.ha.tcp.SimpleTcpCluster&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; channelSendOptions=&quot;8&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt;&amp;lt;Manager className=&quot;org.apache.catalina.ha.session.DeltaManager&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                            &lt;/span&gt;expireSessionsOnShutdown=&quot;false&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                            &lt;/span&gt;notifyListenersOnReplication=&quot;true&quot;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt;&amp;lt;Channel className=&quot;org.apache.catalina.tribes.group.GroupChannel&quot;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                     &lt;/span&gt;&amp;lt;Membership className=&quot;org.apache.catalina.tribes.membership.McastService&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #20124d; white-space: pre;&quot;&gt;                                            &lt;/span&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;address=&quot;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;228.0.0.4&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #20124d; white-space: pre;&quot;&gt;                                            &lt;/span&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;port=&quot;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;45564&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                            &lt;/span&gt;frequency=&quot;500&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                            &lt;/span&gt;dropTime=&quot;3000&quot;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                     &lt;/span&gt;&amp;lt;Sender className=&quot;org.apache.catalina.tribes.transport.ReplicationTransmitter&quot;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                       &lt;/span&gt;&amp;lt;Transport className=&quot;org.apache.catalina.tribes.transport.nio.PooledParallelSender&quot;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                     &lt;/span&gt;&amp;lt;/Sender&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                      &lt;/span&gt;&amp;lt;Receiver className=&quot;org.apache.catalina.tribes.transport.nio.NioReceiver&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                       &lt;/span&gt;address=&quot;auto&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                       &lt;/span&gt;port=&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #4c1130;&quot;&gt;&lt;b&gt;4000&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                       &lt;/span&gt;autoBind=&quot;100&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                      &lt;/span&gt;selectorTimeout=&quot;5000&quot;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                      &lt;/span&gt;maxThreads=&quot;6&quot;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;     &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                   &lt;/span&gt;&amp;lt;Interceptor &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; className=&quot;org.apache.catalina.tribes.group.interceptors.TcpFailureDetector&quot;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                   &lt;/span&gt;&amp;lt;Interceptor&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; className=&quot;org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor&quot;/&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;          &lt;/span&gt;&amp;lt;/Channel&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&amp;lt;Valve className=&quot;org.apache.catalina.ha.tcp.ReplicationValve&quot; filter=&quot;&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&amp;lt;Valve className=&quot;org.apache.catalina.ha.session.JvmRouteBinderValve&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;&amp;lt;ClusterListener className=&quot;org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&amp;lt;ClusterListener className=&quot;org.apache.catalina.ha.session.ClusterSessionListener&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;background-color: #fff2cc; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #20124d;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;lt;/Cluster&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #d0e0e3;&quot;&gt;&lt;b&gt;Check my sample &lt;a href=&quot;https://github.com/ramkicse/tomcat-clustering-session-replication-/blob/master/instance-1/conf/server.xml&quot; target=&quot;_blank&quot;&gt;conf/server.xml&lt;/a&gt; file (for reference)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;here most of the code are &amp;nbsp;boiler plate code. just copy and paste. if we need we can customize. for example we can change the multicat address and port number.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;lt;Manager className=&quot;org.apache.catalina.ha.session.DeltaManager&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;here&amp;nbsp;Manager tag define the delta manager. Delta manager means&amp;nbsp;replicate&amp;nbsp;to all instances.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #20124d; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;lt;Channel className=&quot;org.apache.catalina.tribes.group.GroupChannel&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;Tomcat Clustering use the &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;Apache Tribes communication framework&lt;/span&gt;. &amp;nbsp;This group commnication&amp;nbsp;framework&amp;nbsp;is responsible for dynamic&amp;nbsp;membership&amp;nbsp;(using&amp;nbsp;multicast) , send and&amp;nbsp;receive&amp;nbsp;the session delta information using&amp;nbsp;uni-cast&amp;nbsp;(normal TCP connection).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;lt;Membership className=&quot;org.apache.catalina.tribes.membership.McastService&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #20124d; white-space: pre;&quot;&gt;                                            &lt;/span&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;address=&quot;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;228.0.0.4&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #20124d; white-space: pre;&quot;&gt;                                            &lt;/span&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;port=&quot;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;45564&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                            &lt;/span&gt;frequency=&quot;500&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                            &lt;/span&gt;dropTime=&quot;3000&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;This is Membership definition. here address is multicast address. we can pick any address from Class D address range (224.0.0.0 to 239.255.255.255)and any port number.&lt;br /&gt;&lt;br /&gt;Each and every tomcat send the heart beat signal to multicast address in&amp;nbsp;periodic&amp;nbsp;(&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;frequency&lt;/b&gt;&lt;/span&gt;) interval. all other tomcat whose joined the multicast address they can&amp;nbsp;receive&amp;nbsp;these signals and add the membership to the cluster. if heat beat signal is not&amp;nbsp;revive&amp;nbsp;some&amp;nbsp;particular&amp;nbsp;interval&amp;nbsp;(&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;dropTime&lt;/b&gt;&lt;/span&gt;) from any one of the tomcat, then we need to consider that tomcat is failed.&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fce5cd;&quot;&gt;Note:-&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;All tomcat instances which is part of the clustering, &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;should have same&amp;nbsp;multicast&amp;nbsp;address and port number.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;lt;Sender className=&quot;org.apache.catalina.tribes.transport.ReplicationTransmitter&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                       &lt;/span&gt;&amp;lt;Transport className=&quot;org.apache.catalina.tribes.transport.nio.PooledParallelSender&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                     &lt;/span&gt;&amp;lt;/Sender&amp;gt;&lt;/span&gt;&lt;br /&gt;here sender use the PooledParallelSender have pooled connections to use the send the session information&amp;nbsp;concurrently. so its speedup the session replication process.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #20124d; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&amp;lt;Receiver className=&quot;org.apache.catalina.tribes.transport.nio.NioReceiver&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                       &lt;/span&gt;address=&quot;auto&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                       &lt;/span&gt;port=&quot;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #4c1130;&quot;&gt;&lt;b&gt;4000&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                       &lt;/span&gt;autoBind=&quot;100&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                      &lt;/span&gt;selectorTimeout=&quot;5000&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;                                      &lt;/span&gt;maxThreads=&quot;6&quot;/&amp;gt;&lt;/span&gt;&lt;br /&gt;here we define which port Receiver can bind and used for receiving the session replicate information. here two properties are important. address and port. here address is ur system IP address and port is any unused port. here&lt;span style=&quot;background-color: #fce5cd;&quot;&gt; address=&quot;auto&quot;&lt;/span&gt; its automatically pick the system IP address.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;we have some interceptor&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;TcpFailureDetector&amp;nbsp;&lt;/span&gt;-Its ensure that instance are dead. In some case&amp;nbsp;multicast&amp;nbsp;messages are delayed, all tomcat instances are think about that tomcat is dead. but this interceptor to make tcp unicast to failed tomcat and ensure that instances is actually failed or not&lt;br /&gt;&lt;br /&gt;another important&amp;nbsp;listener&amp;nbsp;is&amp;nbsp;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;JvmRouteSessionIDBinderListener,&lt;/span&gt;&amp;nbsp;we talk&amp;nbsp;about&amp;nbsp;later&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;3. Enable the Web Application as distributable&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&amp;nbsp; &amp;nbsp;We need to&amp;nbsp;make&amp;nbsp;the our web application distribuable. its simple add&amp;nbsp;&amp;lt;distributable/&amp;gt; tag in web.xml file. In according to servlet specification&amp;nbsp;&amp;nbsp;&lt;b style=&quot;background-color: #d9ead3;&quot;&gt;&amp;lt;distributable/&amp;gt; &lt;/b&gt;tag in web.xml mention that any container to consider this application can work in&amp;nbsp;distributed&amp;nbsp;environment.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;&lt;b&gt;Note:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;All session in our web&amp;nbsp;application&amp;nbsp;must me serializable.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Do these steps to all tomcat instances and start the tomcat and httpd server. check my configuration in my &lt;a href=&quot;https://github.com/ramkicse/tomcat-clustering-session-replication-&quot; target=&quot;_blank&quot;&gt;github repo&lt;/a&gt;&amp;nbsp;or get as &lt;a href=&quot;https://github.com/ramkicse/tomcat-clustering-session-replication-/archive/master.zip&quot; target=&quot;_blank&quot;&gt;ZIP&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s1600/session-repicate1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;231&quot; src=&quot;http://1.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s400/session-repicate1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;This is my configuration. all 3 tomcat instances are&amp;nbsp;configured&amp;nbsp;in delta manager and i deployed the distributed web&amp;nbsp;application. all tomcat use the&amp;nbsp;multicast&amp;nbsp;to maintain the membership.&lt;br /&gt;&lt;br /&gt;now client make the request and first tomcat process and create the session, then looks like this&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-H8t6z1PlfJk/UKsf4WH8oLI/AAAAAAAACrA/Ti25yR5i5Fw/s1600/session-replicate2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;227&quot; src=&quot;http://4.bp.blogspot.com/-H8t6z1PlfJk/UKsf4WH8oLI/AAAAAAAACrA/Ti25yR5i5Fw/s400/session-replicate2.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;then tomcat 1 is responsible to replicate the session using&amp;nbsp;Apache&amp;nbsp;tribes group&amp;nbsp;communication&amp;nbsp;framework to replicate the session to all instances.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-lnVwldNtunU/UKsf5lA6mRI/AAAAAAAACrI/GcnN5qFlHaA/s1600/session-replicate3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; src=&quot;http://3.bp.blogspot.com/-lnVwldNtunU/UKsf5lA6mRI/AAAAAAAACrI/GcnN5qFlHaA/s400/session-replicate3.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;now all tomcat instance have exact copy of the session. so if tomcat 1 crashed or shutdown, then any other tomcat still can&amp;nbsp;process&amp;nbsp;the request [see the video below]&lt;br /&gt;&lt;br /&gt;We used session&amp;nbsp;affinity&amp;nbsp;like&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html&quot; target=&quot;_blank&quot;&gt;previous&amp;nbsp;post&lt;/a&gt;. based on that cookie id&amp;nbsp;contain&amp;nbsp;the tomcat name (worker name). so when first tomcat1 return the session id end with tomcat1. but when tomcat 1 is failed and tomcat 2 take the responsible for all further request. but session id still contain the tomcat1. so its makes the load balancer&amp;nbsp;difficult.&amp;nbsp;because&amp;nbsp;tomcat1 is down. and load balancer pick any other tomcat. but&amp;nbsp;actually&amp;nbsp;tomcat2 takes the&amp;nbsp;responsible. so we need to reflect these changes in session id. &lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc; color: #20124d;&quot;&gt;JvmRouteSessionIDBinderListener&lt;/span&gt;&amp;nbsp; take care to change the client session id to tomcat2 when&amp;nbsp;failure&amp;nbsp;is&amp;nbsp;occurred&amp;nbsp; so load balancer redirect to tomcat2 without confusing.&lt;br /&gt;&lt;br /&gt;Check&amp;nbsp;the &lt;a href=&quot;https://github.com/ramkicse/tomcat-clustering-session-replication-&quot; target=&quot;_blank&quot;&gt;git hub&lt;/a&gt; for all configuration files and tomcat clustering setup is available. or u can download as &lt;a href=&quot;https://github.com/ramkicse/tomcat-clustering-session-replication-/archive/master.zip&quot; target=&quot;_blank&quot;&gt;ZIP&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Reference:&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html&quot; target=&quot;_blank&quot;&gt;Apache Tomcat Cluster Documentation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-family: Times, Times New Roman, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #660000; font-family: Times, Times New Roman, serif;&quot;&gt;Screen&amp;nbsp;Cast:&lt;/span&gt;&lt;/h2&gt;&lt;br /&gt;&lt;/div&gt;&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;http://www.youtube.com/embed/cYBdaeNeXbY&quot; width=&quot;700&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-ZfR6DhJ_vpg/UKsf-Dgx5CI/AAAAAAAACrQ/ly1ToOlibr0/s72-c/session-repicate1.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-1342436239924206221</guid><pubDate>Tue, 30 Oct 2012 08:48:00 +0000</pubDate><atom:updated>2016-02-18T18:00:03.871+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><title>Tomcat Clustering Series Part 2 : Session Affinity Load Balancer</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Hi this second part of the&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/search/label/tomcat%20clustering&quot; target=&quot;_blank&quot;&gt;Tomcat Clustering Series&lt;/a&gt;. In my&lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html&quot; target=&quot;_blank&quot;&gt; first part&lt;/a&gt; we discuss about how to setup simple load balancer. and we seen how load balancer distribute the request to tomcat instance in round robin fashion.&lt;span style=&quot;color: #660000;&quot;&gt; &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;[Check the video below for better understanding]&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In this post we discuss about what is the problem is occur in simple load balancer when we introduce sessions in our web application. and we will see how to resolve this issue.&lt;br /&gt;&lt;br /&gt;Its&amp;nbsp;continuation&amp;nbsp;of my &lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html&quot; target=&quot;_blank&quot;&gt;first part&lt;/a&gt; of this series. so kindly go read my &lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html&quot; target=&quot;_blank&quot;&gt;first part&lt;/a&gt; then continue here.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;How Session works in Servlet/Tomcat?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Before going into problem, let see the &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;session management in Tomcat&lt;/b&gt;&lt;/span&gt;.&lt;br /&gt;If any if the page/servlet&amp;nbsp;create the session&amp;nbsp;then Tomcat create the Session Object and&amp;nbsp;attached&amp;nbsp;into group of session (HashMap kind structure) and that session can identify using session-id, its just random number generated through any one of the hash algorithm. then respond to client with cookie header field. That cookie header field are key value pair. so tomcat create jsessioid is the key and random session-id is the value.&lt;br /&gt;&lt;br /&gt;Once response reached to client (Web Browser) its update the cookie value. If already exist, then its overrides the cookie value. Then all further communication browser send the cookie attached with&amp;nbsp;request&amp;nbsp;to that server.&lt;br /&gt;&lt;br /&gt;HTTP is stateless protocol. so server can&#39;t find the client session usual way. so server reads the header of the request and extract the cookie value and server got the Random session-id. then it search through group of session maintained by the tomcat. (It&amp;nbsp;usually&amp;nbsp;hash-map). then tomcat got perfect Session of that particular client (Web Browser).&lt;br /&gt;&lt;br /&gt;If client cookie value doesn&#39;t match with group of sessions then tomcat create the completely new session and send the new cookie to browser. then browser update it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;this &lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;index.jsp&lt;/span&gt;&lt;/b&gt; code to deploy all tomcat instances&lt;br /&gt;&lt;pre class=&quot;brush: java; ruler: true;&quot;&gt;&amp;lt;%@page import=&quot;java.util.ArrayList&quot;%&amp;gt;&lt;br /&gt;&amp;lt;%@page import=&quot;java.util.Date&quot;%&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;%@page import=&quot;java.util.List&quot;%&amp;gt;&lt;br /&gt;&amp;lt;%@page contentType=&quot;text/html&quot; pageEncoding=&quot;UTF-8&quot;%&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;br /&gt;    &lt;head&gt;&lt;br /&gt;        &lt;br /&gt;        &lt;title&gt;JSP Page&lt;/title&gt;&lt;br /&gt;    &lt;/head&gt;&lt;br /&gt;    &lt;body&gt;&lt;br /&gt;&lt;span style=&quot;color: blue; font-size: xx-small;&quot;&gt;&lt;br /&gt;        Instance 1 &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;br /&gt;       &lt;br /&gt;        &lt;hr /&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: #cc0000; font-size: xx-small;&quot;&gt;&lt;br /&gt;         &lt;br /&gt;&lt;br /&gt;        Session Id : &amp;lt;%=request.getSession().getId()%&amp;gt; &lt;br /&gt;&lt;br /&gt;        Is it New Session : &amp;lt;%=request.getSession().isNew()%&amp;gt;&lt;br /&gt;&lt;br /&gt;        Session Creation Date : &amp;lt;%=new Date(request.getSession().getCreationTime())%&amp;gt;&lt;br /&gt;&lt;br /&gt;        Session Access Date : &amp;lt;%=new Date(request.getSession().getLastAccessedTime())%&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        &lt;/span&gt;&lt;br /&gt;        &lt;b&gt;Cart List &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;        &lt;hr /&gt;&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        &lt;ul&gt;&lt;br /&gt;        &amp;lt;%&lt;br /&gt;&lt;br /&gt;                String bookName = request.getParameter(&quot;bookName&quot;);&lt;br /&gt;                List&lt;string&gt; listOfBooks = (List&lt;string&gt;) request.getSession().getAttribute(&quot;Books&quot;);&lt;br /&gt;&lt;br /&gt;                if (listOfBooks == null) {&lt;br /&gt;                    listOfBooks = new ArrayList&lt;string&gt;();&lt;br /&gt;                    request.getSession().setAttribute(&quot;Books&quot;, listOfBooks);&lt;br /&gt;                }&lt;br /&gt;                if (bookName != null) {&lt;br /&gt;                    listOfBooks.add(bookName);&lt;br /&gt;                    request.getSession().setAttribute(&quot;Books&quot;, listOfBooks);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                for (String book : listOfBooks) {&lt;br /&gt;                    out.println(&quot;&lt;br /&gt;&lt;li&gt;&quot;+book + &quot;&lt;/li&gt;&lt;br /&gt;&quot;);&lt;br /&gt;                }&lt;br /&gt;            &lt;br /&gt;        %&amp;gt;&lt;br /&gt;        &lt;/string&gt;&lt;/string&gt;&lt;/string&gt;&lt;/ul&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;        &lt;form action=&quot;index.jsp&quot; method=&quot;post&quot;&gt;&lt;br /&gt;            Book Name &lt;input name=&quot;bookName&quot; type=&quot;text&quot; /&gt;&lt;br /&gt;&lt;br /&gt;            &lt;input type=&quot;submit&quot; value=&quot;Add to Cart&quot; /&gt;&lt;br /&gt;        &lt;/form&gt;&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;    &lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;What is the Problem In Simple Load Balancer?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;If we deploy the web application, in which its used the session then actual problem is&amp;nbsp;occurred.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s1600/tomcat_simple_load_balancer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;328&quot; src=&quot;https://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s640/tomcat_simple_load_balancer.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;I&amp;nbsp;describe with sequence&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;1. User request one web page, in that web page its used sessions (like shopping cart).&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;2. Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. suppose this time its send to tomcat1.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;3. tomcat1 create the session and respond with cookie header to client.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;4. load balancer just act as relay. its send back to client.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;5. next time user request again the shopping cart to server. this time user send the cookie header also&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;6.Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. this time its send to tomcat2.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;7. Tomcat 2 receive the request and extract the session-id. and this session id is doesn&#39;t match with their managed session. because this session is&amp;nbsp;available&amp;nbsp;only in tomcat1. so tomcat 2 is create the new session &amp;nbsp;and send new cookie to client&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;8. Client&amp;nbsp;receive&amp;nbsp;the response and update the cookie(Its overwrite the old cookie).&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;9. Client send one more time to request that page and send the cookie to server.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;10.&amp;nbsp;Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. this time its send to tomcat3.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;11.&amp;nbsp;Tomcat 3 receive the request and extract the session-id. and this session id is doesn&#39;t match with their managed session. because this session is&amp;nbsp;available&amp;nbsp;only in tomcat2. so tomcat3 is create the new session &amp;nbsp;and send new cookie to client&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;12. Client&amp;nbsp;receive&amp;nbsp;the response and update the cookie.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;(Its overwrite the old cookie).&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;13. Client send one more time to request that page and send the cookie to server.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;14.&amp;nbsp;Load balancer intercept the request and use the round robin fashion its send to one of the tomcat. this time its send to tomcat1.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;15.&amp;nbsp;Tomcat 1 receive the request and extract the session-id. and this session id is doesn&#39;t match with their managed session. because client session id is updated by tomcat 3 last time. so even though tomcat 1 have one session object created by this client. but client session id is wrong.so tomcat1 is create the new session &amp;nbsp;and send new cookie to client (for more info watch the video below)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;16. Client&amp;nbsp;receive&amp;nbsp;the response and update the cookie.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;this&amp;nbsp;sequence&amp;nbsp;is&amp;nbsp;continue ...&lt;br /&gt;&lt;br /&gt;as the result every request one session is created. instead of&amp;nbsp;continue&amp;nbsp;with old one.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;root cause is Load&amp;nbsp;balancer&lt;/b&gt;&lt;/span&gt;. If load balancer redirect the request&amp;nbsp;correctly&amp;nbsp;then this problem is fixed. but how load balancer know in advance about this client before is processed by particular tomcat.&lt;br /&gt;HTTP is stateless protocol. so HTTP&amp;nbsp;doesn&#39;t&amp;nbsp;help this situation. and other information is jsessionid cookie. its good but its just random value. so we can&#39;t take decision based on this random value.&lt;br /&gt;ex:&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;header-name&quot; style=&quot;box-sizing: border-box; display: inline-block; font-family: &#39;Lucida Grande&#39;, sans-serif; font-size: 11px; margin-right: 0.5em; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;Cookie: &lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace;&quot;&gt;JSESSIONID=40025608F7B50E42DFA2785329079227&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 id=&quot;dqx7lbg_sessionaffinity&quot;&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;Session affinity/Sticky Session&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Session affinity overrides the load-balancing algorithm by directing all requests in a session to a specific tomcat server. so when we setup the session affinity our problem is solved. but how to setup because session values are random value. so we need to generate the session value some how identify the which tomcat generate response.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white; color: #990000; font-size: large;&quot;&gt;&lt;b&gt;jvmRoute&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Tomcat configuration file (server.xml) caontain &amp;nbsp;&amp;lt;Engine&amp;gt; tag have jvmRoute property for this purpose. so edit the config file and update the &amp;lt;Engine &amp;gt; tag like this&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&amp;lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost“ &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;jvmRoute=“tomcat1”&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt; &amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;here we mention &lt;/span&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;jvmRoute=&quot;tomcat1&quot;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt; here tomcat1 is worker name of this tomcat. check the workers.properties file in&lt;/span&gt;&lt;a href=&quot;http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html&quot; style=&quot;background-color: white;&quot; target=&quot;_blank&quot;&gt; last post&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Add this line to all tomcat&amp;nbsp;instances&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;conf/server.xml&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt; file and change the jvmRoute value according to workers name and restart the tomcat instances.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Now all tomcat generate the session-id pattern like this&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;lt;Random Value like before&amp;gt;.&amp;lt;jvmRoute value&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex: tomcat1 generate the session id &amp;nbsp;like&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;lucida grande&amp;quot; , sans-serif; font-size: 11px; text-align: center; white-space: pre-wrap;&quot;&gt;Cookie:&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;dejavu sans mono&amp;quot; , monospace; font-size: 11px; text-align: center; white-space: pre-wrap;&quot;&gt;JSESSIONID=40025608F7B50E42DFA2785329079227.tomcat1&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ol class=&quot;children expanded&quot; style=&quot;-webkit-padding-start: 12px; background-color: white; box-sizing: border-box; cursor: default; font-family: &#39;Lucida Grande&#39;, sans-serif; font-size: 11px; list-style-type: none; margin: 0px; min-width: 100%; padding: 2px 6px !important; position: relative; text-align: center;&quot;&gt;&lt;li style=&quot;box-sizing: border-box; margin-bottom: 1px; margin-left: -2px; margin-top: 1px; padding: 0px 0px 0px 14px; text-align: center; white-space: nowrap; word-wrap: break-word;&quot; title=&quot;&quot;&gt;&lt;/li&gt;&lt;li&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;here tail have which tomcat generate the session. so load balancer easily find out to where we need to&amp;nbsp;delegate&amp;nbsp;the request. in this case its tomcat1.&lt;br /&gt;&lt;br /&gt;so update all tomcat instances conf/server.xml file to add the jvmRoute property to appropriate worker name values. and restart the instances. all problem is fixed and entire load balance works fine even session based application.&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;but there is still one drawback&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;if 5 user acessing the website. In session affinity is setup. here&lt;br /&gt;&lt;br /&gt;tomcat 1 serves 2 user,&lt;br /&gt;&lt;div&gt;tomcat 2 serves 2 user,&amp;nbsp;&lt;/div&gt;&lt;div&gt;tomcat 3 serves 1 user, &amp;nbsp;then suddenly one of instance is failed, then what happen?&lt;br /&gt;&lt;br /&gt;suppose instance 1 (tomcat1) is failed, then those 2 users lost their session. but their request are redirect to one of the remaining tomcat instances (tomcat2,tomcat3). so they still access the web page. but they lost&amp;nbsp;previous&amp;nbsp;sessions. this is one of the draw back. but its compare to last post load balancer. its works in session based web application also.&lt;br /&gt;&lt;br /&gt;next post we will see how to set up the session replication in load balancer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #0c343d;&quot;&gt;please share ur thoughts through comments.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;Update :&amp;nbsp;Check&amp;nbsp;the Session Replication Process in&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/2012/11/tomcat-clustering-series-part-3-session.html&quot; target=&quot;_blank&quot;&gt;Third&amp;nbsp;Part&lt;/a&gt; of this Series&lt;/h4&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Screen Cast:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;http://www.youtube.com/embed/-9C2ZtdAAFY?theme=light&quot; width=&quot;640&quot;&gt;&lt;/iframe&gt; &lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/10/tomcat-clustering-series-part-2-session.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s72-c/tomcat_simple_load_balancer.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-9158320692799127009</guid><pubDate>Wed, 10 Oct 2012 07:57:00 +0000</pubDate><atom:updated>2016-05-03T10:38:24.575+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">load balancer</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">tomcat clustering</category><title>Tomcat Clustering Series Part 1 : Simple Load Balancer</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;I am going to start new series of posts about &lt;a href=&quot;http://www.ramkitech.com/search/label/tomcat%20clustering&quot; target=&quot;_blank&quot;&gt;Tomcat clustering&lt;/a&gt;. In this first post we will see what is problem in normal deployment in only single machine, what is clustering and why is necessary and how to setup the simple load balancer with Apache httpd web server + Tomcat server cluster.&lt;b style=&quot;background-color: #fff2cc; color: #660000;&quot;&gt;[Check the video for better understanding]&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Why need Clustering? (Tomcat Clustering)&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In normal production servers are running in single machine. If&amp;nbsp;that&#39;s&amp;nbsp;machine may be failed due to crashed or hardware&amp;nbsp;defects or OutOfMemory&amp;nbsp;exception then&amp;nbsp;&amp;nbsp;our site can&#39;t access by anybody.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-GUoJCzHlkWE/UHUH8hMT85I/AAAAAAAAClw/td_6l_JLh0E/s1600/normal_deployment.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;205&quot; src=&quot;http://1.bp.blogspot.com/-GUoJCzHlkWE/UHUH8hMT85I/AAAAAAAAClw/td_6l_JLh0E/s400/normal_deployment.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;so &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;how to solve this problem?&lt;/b&gt;&lt;/span&gt;. to add more tomcat machine to collectively (group/cluster) run as a production server. (oppose&amp;nbsp;of single machine). Each tomcat has deployed the same web application. so any tomcat can process the client request. If one tomcat is failed, then other tomcat in the cluster to&amp;nbsp;proceeds&amp;nbsp;the request.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-pQLAYmjpO68/UHUKwW1g-bI/AAAAAAAACmE/FcRbf0PsSHY/s1600/tomcat_clustering.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;209&quot; src=&quot;http://3.bp.blogspot.com/-pQLAYmjpO68/UHUKwW1g-bI/AAAAAAAACmE/FcRbf0PsSHY/s320/tomcat_clustering.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;Here one big problem is arrive. each tomcat instances are running in dedicated physical machine or many tomcat instances are running in single machine(Check my post about&lt;a href=&quot;http://www.ramkitech.com/2011/07/running-multiple-tomcat-instances-on.html&quot; target=&quot;_blank&quot;&gt; Running multiple tomcat instances in single machine&lt;/a&gt;). so each tomcat running on different port and may be in&amp;nbsp;&amp;nbsp;different IP.&lt;br /&gt;&lt;br /&gt;the problem is in client perspective, to which tomcat we need to make the request? because there are lots of tomcat part of clustering is running. each tomcat we need to make IP and Port combination. like&lt;br /&gt;http://192.168.56.190:8080/ or&amp;nbsp;http://192.168.56.191:8181/&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-h8yCwF7-w1Q/UHUKyo8DLsI/AAAAAAAACmQ/CfsOnomRSSc/s1600/tomcat_how_to_access.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;176&quot; src=&quot;http://1.bp.blogspot.com/-h8yCwF7-w1Q/UHUKyo8DLsI/AAAAAAAACmQ/CfsOnomRSSc/s640/tomcat_how_to_access.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;so how to solve this problem?&lt;br /&gt;To add one server&amp;nbsp;in-front&amp;nbsp;of all tomcat clusters. to accept all the request and distribute to the cluster. so this server acts as a load balancer. There is lots of server is&amp;nbsp;available&amp;nbsp;with load balancing capability. here we are going to use&amp;nbsp;Apache&amp;nbsp;httpd web server as a load balancer. with mod_jk module.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-YoAJypnbcOs/UHUKzjI5GuI/AAAAAAAACmc/8oV7yfG7GN4/s1600/tomcat_load_balancer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;272&quot; src=&quot;http://1.bp.blogspot.com/-YoAJypnbcOs/UHUKzjI5GuI/AAAAAAAACmc/8oV7yfG7GN4/s640/tomcat_load_balancer.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;so now all clients to access the load balancer (Apache httpd web server) and don&#39;t bother about tomcat instances. so now ur URL is http://ramkitech.com/ (Apache&amp;nbsp;runs on port 80).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;Apache httpd Web Server&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Here we are going to use Apache httpd web server as a Load Balancer. To provide the load balancing capability to Apache httpd server we need to include the either mod_proxy module or mod_jk module. here we are using mod_jk module.&lt;br /&gt;&lt;br /&gt;Before continuing this post check my &lt;a href=&quot;http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html&quot; target=&quot;_blank&quot;&gt;old post (Virtual Host Apache httpd server)&lt;/a&gt; about How to install the Apache httpd server and mod_jk module. and how to configure the mod_jk.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;How to setup the Simple Load Balancer&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;For simplicity purpose i going to run 3 tomcat instances in single machine(we can run on dedicated machine also) with Apache httpd web server. and single web application is deployed in all tomcat instances.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s1600/tomcat_simple_load_balancer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;328&quot; src=&quot;http://2.bp.blogspot.com/-9nG82vXSuFw/UHUS9R5_9pI/AAAAAAAACmw/QMlhCCwySiw/s640/tomcat_simple_load_balancer.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;here we use mod_jk module as the load balancer. by default its use the round robin algorithm to&amp;nbsp;distribute&amp;nbsp;the requests. now we need to configure the workers.properties file like &lt;a href=&quot;http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html&quot; target=&quot;_blank&quot;&gt;virtual host concept in Apache httpd server.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.list=tomcat1,tomcat2,tomcat3&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat1.type=ajp13&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat1.port=8009&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat1.host=localhost&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat2.type=ajp13&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat2.port=8010&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat2.host=localhost&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat3.type=ajp13&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat3.port=8011&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;worker.tomcat3.host=localhost&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;here i configure the 3 tomcat instances in&lt;span style=&quot;background-color: #d9ead3;&quot;&gt; &lt;b&gt;workers.properties&lt;/b&gt;&lt;/span&gt; file. here type is ajp13 and port is ajp port (not http connector port) and host is IP address of tomcat instance machine.&lt;br /&gt;&lt;br /&gt;there are couple of special&amp;nbsp;workers&amp;nbsp;we need add into workers.properties file.&lt;br /&gt;&lt;br /&gt;First one is add load balancer worker, here the name is &amp;nbsp;balancer (u can put any name).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;worker.balancer.type=lb&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;worker.balancer.balance_workers=tomcat1,tomcat2,tomcat3&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;here this worker &lt;i&gt;&lt;b&gt;type&lt;/b&gt;&lt;/i&gt; is lb, ie load balancer. its special type provide by load&amp;nbsp;balancer. and another property is&amp;nbsp;&lt;i&gt;&lt;b&gt;balance_workers&lt;/b&gt;&lt;/i&gt; to specify all tomcat instances like&amp;nbsp;tomcat1,tomcat2,tomcat3 (comma&amp;nbsp;separated)&lt;br /&gt;&lt;br /&gt;Second one, add the status worker, Its optional. but from this worker we can get&amp;nbsp;statistical&amp;nbsp;of load balancer.&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;worker.stat.type=status&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;here we use special type status.&lt;br /&gt;&lt;br /&gt;now we modify the&amp;nbsp;worker.list property.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;worker.list=balancer,stat&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;so from outside there are 2 workers are visible (balancer and stat). so all request comes to balancer. then balancer worker manage all tomcat instances.&lt;br /&gt;&lt;br /&gt;complete&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #990000;&quot;&gt; workers.properties&lt;/span&gt;&lt;/u&gt;&lt;/b&gt; file&lt;br /&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[  worker.list=balancer,stat  worker.tomcat1.type=ajp13 worker.tomcat1.port=8009 worker.tomcat1.host=localhost  worker.tomcat2.type=ajp13 worker.tomcat2.port=8010 worker.tomcat2.host=localhost  worker.tomcat3.type=ajp13 worker.tomcat3.port=8011 worker.tomcat3.host=localhost   worker.balancer.type=lb worker.balancer.balance_workers=tomcat1,tomcat2,tomcat3  worker.stat.type=status ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;Now workers.properties confiuration is finished. now we need to send the all request to balancer worker.&lt;br /&gt;so modify the httpd.conf file of Apache httpd server&lt;br /&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ LoadModule    jk_module  modules/mod_jk.so  JkWorkersFile conf/workers.properties  JkLogFile     logs/mod_jk.log JkLogLevel    emerg JkLogStampFormat &quot;[%a %b %d %H:%M:%S %Y] &quot; JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories JkRequestLogFormat     &quot;%w %V %T&quot;  JkMount  /status  stat JkMount  /*  balancer ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;div&gt;the above code is just boiler plate code. 1st line load the mod_jk module, 2nd line to&amp;nbsp;specified&amp;nbsp;the worker file (workers.properties file). all others are just logging purpose.&lt;br /&gt;&lt;br /&gt;The last 2 lines are important.&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkMount &amp;nbsp;/status &amp;nbsp;stat&lt;/b&gt; &amp;nbsp; means any request to match the /status then that request forward to stat worker. Its status type worker. so its shows status of load balancer.&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkMount &amp;nbsp;/* &amp;nbsp;balancer&lt;/b&gt; this line matches all the request, so all request is forward to balancer worker. In balancer worker is uses the round robin algorithm to distribute the request to other tomcat instances.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That&#39;s&amp;nbsp;it.&lt;br /&gt;now access the load balancer from the browser. each and every request is&amp;nbsp;distribute&amp;nbsp;to 3 tomcat&amp;nbsp;instances. If one of the tomcat instances are failed then load balancer&amp;nbsp;dynamically&amp;nbsp;understand and stop to forward the request to&amp;nbsp;that&amp;nbsp;failed tomcat instances. Other tomcat instances are&amp;nbsp;continue&amp;nbsp;to work. If that failed tomcat is recovered from failed state to normal state then load balancer add to cluster and forward the request to that tomcat. (check the video)&lt;br /&gt;&lt;br /&gt;Here &lt;b style=&quot;background-color: #d9ead3;&quot;&gt;&lt;span style=&quot;color: #660000;&quot;&gt;big question is How Load balancer knows when one tomcat instance is failed or tomcat is just recovered&amp;nbsp;from failed state?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Ans : &lt;/b&gt;when one tomcat instance is failed, load balancer don&#39;t know about&amp;nbsp;that&amp;nbsp;instances is failed. so its try to forward the request to all tomcat instances. If load balancer try to forward the request to failed tomcat instance, its will not respond. so load balancer understand and marked the state as a failed and forward the same request to another tomcat instances. so client&amp;nbsp;perspective&amp;nbsp;we not feel one tomcat instances are failed. &lt;br /&gt;&lt;br /&gt;when tomcat instances recovered from failed state. that time also load balancer don&#39;t know that tomcat is ready for processing. Its still marked the state is failed. In&amp;nbsp;periodic&amp;nbsp;interval&amp;nbsp;load balancer checks the health status of all tomcat instances. (by default 60 sec). after checking health status then only load balancer came to know that tomcat&amp;nbsp;instance&amp;nbsp;is ready. and its update the status is OK.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;please share ur thoughts through comments.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;u&gt;&lt;b&gt;Video :&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/9gtpyqhd-NI&quot; width=&quot;700&quot;&gt;&lt;/iframe&gt; &lt;/div&gt;</description><link>http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-GUoJCzHlkWE/UHUH8hMT85I/AAAAAAAAClw/td_6l_JLh0E/s72-c/normal_deployment.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-113471435826741420</guid><pubDate>Wed, 12 Sep 2012 08:06:00 +0000</pubDate><atom:updated>2016-05-03T10:39:48.065+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">charts</category><category domain="http://www.blogger.com/atom/ns#">iReport</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>Integrate Chart Image into Jasper Report Part - 2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In my previous post we discussed &lt;a href=&quot;http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html&quot; target=&quot;_blank&quot;&gt;how to&amp;nbsp;Integrate&amp;nbsp;the Charts into Jasper Reports&lt;/a&gt;&amp;nbsp;using JFreeChart API in Jasper Report. In this post there is another way to&amp;nbsp;embeds&amp;nbsp;the charts into Jasper Reports. This method, we need to generate/create the chart using any 3rd party Java Lib and convert into Image Object or stored into&amp;nbsp;File-system, then just insert the Image into Jasper Report. here no need to use chart&amp;nbsp;functionality&amp;nbsp;in Jasper Report. because these chart are&amp;nbsp;limited&amp;nbsp;functionality.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Steps:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Create the chart using any Java libraries&lt;/li&gt;&lt;li&gt;Convert the Chart into BufferedImage or Stored into files&lt;/li&gt;&lt;li&gt;pass the Image into Jasper Report.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;1. Create the chart using any Java libraries&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;In this step we going to create the chart. here i m using &lt;a href=&quot;http://jopenchart.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;jopenchart&lt;/a&gt; Java library to create the chart. In their website &lt;a href=&quot;http://jopenchart.sourceforge.net/tutorial.html&quot; target=&quot;_blank&quot;&gt;tutorial section&lt;/a&gt; contain some sample codes. so i used these codes. and download the jopenchart lib from &lt;a href=&quot;http://prdownloads.sourceforge.net/jopenchart/charting-0.94.jar&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;2. Convert the chart into&amp;nbsp;BufferedImage or Stored into files&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; In jopenchart have the&amp;nbsp;in-build&amp;nbsp;function for store chart into the file.&lt;br /&gt;ChartEncoder.createPNG(new FileOutputStream(System.getProperty(&quot;user.home&quot;) + &quot;/chat.png&quot;), c);&lt;br /&gt;and if u want into in-memory Image object then use render() method.&lt;br /&gt;  &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); DefaultChart chart = ....; Graphics2D gd=bi.createGraphics(); chart.render(gd); ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;In above code we create empty BufferedImage object. the get the Graphics2D object from the BufferedImage and pass the&amp;nbsp;Graphics2D into chart render() method. so when render() method is called, the chart is write into BufferedImage object.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;3. Pass the Image into Jasper Report&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; We need to create the Jasper Report. this time we are not using chart function in Jasper reports. we using Image component of jasperreport. We have 2 options are there, pass the Image Object or Pass the Path String object where image is stored in File-system. here first i m using Image object.&lt;br /&gt;&lt;br /&gt;we use parameter to pass into jasper report. so first create the new Parameter in Jasper Report and&amp;nbsp;named &quot;chartImage&quot; and Parameter Class &quot;java.lang.Object&quot;.&amp;nbsp; drag the Image Component and set the properties. Image Expression and Expression Class like&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Image Expression == &amp;gt; &amp;nbsp;$P{chartImage}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Expression Class &amp;nbsp;== &amp;gt;&amp;nbsp;java.awt.Image&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-blQh4fe8Yzo/UFA91t8YnUI/AAAAAAAAClY/CeigA9_RD1A/s1600/image_property.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;85&quot; src=&quot;http://2.bp.blogspot.com/-blQh4fe8Yzo/UFA91t8YnUI/AAAAAAAAClY/CeigA9_RD1A/s400/image_property.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;If we use stored Image File then change the Parameter class to&amp;nbsp;java.lang.String and Image Expression Class to&amp;nbsp;java.lang.String.&lt;br /&gt;&lt;br /&gt;here Image Expression class is decided the Jasper Report. how we add the Image. If u put &quot;java.awt.Image&quot; as a Expression class then we are passing the Image object. and jasper report can understand. If u mention &quot;java.lang.String&quot; then we pass as String that pointing to Image file. (png,jpg,gif,..).&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;u&gt;DemoBean.java&lt;/u&gt;&lt;br /&gt;  &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[  @ManagedBean @SessionScoped public class DemoBean {      int width = 640;     int height = 480;     BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);      public DemoBean() {         int[] quadr = {0, 1, 4, 9, 16, 25, 36};         int[] exp = {1, 2, 4, 8, 16, 32, 64};         double[] columns = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};          // Creating a data set array         DefaultDataSet[] ds = new DefaultDataSet[3];          // Filling all DataSets         ds[0] = new DefaultDataSet(ChartUtilities.transformArray(new int[]{0, 6}),                 ChartUtilities.transformArray(new double[]{0.0, 6.0}),                 CoordSystem.FIRST_YAXIS,                 &quot;Linear Growth&quot;);          ds[1] = new DefaultDataSet(ChartUtilities.transformArray(quadr),                 ChartUtilities.transformArray(columns),                 CoordSystem.FIRST_YAXIS,                 &quot;Quadratic Growth&quot;);          ds[2] = new DefaultDataSet(ChartUtilities.transformArray(exp),                 ChartUtilities.transformArray(columns),                 CoordSystem.FIRST_YAXIS,                 &quot;Exponential Growth&quot;);          String title = &quot;Growth Factor Comparison&quot;;            DefaultChartDataModel data = new DefaultChartDataModel(ds);          data.setAutoScale(true);          DefaultChart c = new DefaultChart(data, title, DefaultChart.LINEAR_X_LINEAR_Y);            c.addChartRenderer(new LineChartRenderer(c.getCoordSystem(),data), 1);          c.setBounds(new Rectangle(0, 0, width, height));         Graphics2D gd=bi.createGraphics();         c.render(gd);  //      /*  if ur using Image file then use these code */ //        try { //            ChartEncoder.createPNG(new FileOutputStream(System.getProperty(&quot;user.home&quot;) + &quot;/chart.png&quot;), c); //        } catch (Exception e) { //            e.printStackTrace(); //        }       }      public String pdf() throws JRException, IOException {                  String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath(&quot;/reports/Charts.jasper&quot;);          Map parameter = new HashMap();         parameter.put(&quot;chartImage&quot;, bi);          JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, parameter, new JREmptyDataSource(1));         HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();         httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.pdf&quot;);         ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();         JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);         FacesContext.getCurrentInstance().responseComplete();          return null;     } } ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fb5e53; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 25px;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; font-size: medium;&quot;&gt;Download the Sample Project from my &amp;nbsp;&lt;a href=&quot;https://github.com/ramkicse/ChartImageJasperReport&quot; style=&quot;color: #4e40d6; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;GitHub&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fb5e53; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 25px;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;b style=&quot;background-color: #fb5e53; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 18px; line-height: 25px;&quot;&gt;&lt;br /&gt;&lt;/b&gt;Check the&amp;nbsp;screen-cast&amp;nbsp;for better understanding.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;Screen cast:&lt;/span&gt;&lt;/b&gt;&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/DaxMHyJ-haY&quot; width=&quot;700&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/09/integrate-chart-image-into-jasper.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-blQh4fe8Yzo/UFA91t8YnUI/AAAAAAAAClY/CeigA9_RD1A/s72-c/image_property.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-6364888110286960545</guid><pubDate>Wed, 05 Sep 2012 10:01:00 +0000</pubDate><atom:updated>2016-05-03T10:41:12.649+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">charts</category><category domain="http://www.blogger.com/atom/ns#">iReport</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><title>Integrate Charts in Jasper Reports +JSF 2.0</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In this post we will walk through how to integrate Charts (JFreeChart) into Jasper Report framework.&amp;nbsp;JasperReports is the world&#39;s most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Xlsx, Docx, Pptx, Odf&lt;br /&gt;&lt;br /&gt;Check my&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html&quot; target=&quot;_blank&quot;&gt;Introduction&amp;nbsp;to Jasper Reports&lt;/a&gt; and&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html&quot; target=&quot;_blank&quot;&gt;Sub-report&amp;nbsp;with jasper Report &lt;/a&gt;posts.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;2-ways to Integrate the Charts/Graphs into Jasper Reports&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Use JFreeChart API inside Jasper Report to generate the Charts while generating reports&lt;/li&gt;&lt;li&gt;Use any 3rd party Java Libraries to create the chart and stored in In-memory Image object (or) stored in file. then pass the Image/file to&amp;nbsp;Jasper Report. then&amp;nbsp;embed&amp;nbsp;the Image into Report. (check &lt;a href=&quot;http://www.ramkitech.com/2012/09/integrate-chart-image-into-jasper.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ol&gt;In this post we going to use 1st option. In Jasper Report use JFreeChart Components to make charts. In my&lt;a href=&quot;http://www.ramkitech.com/2012/09/integrate-chart-image-into-jasper.html&quot; target=&quot;_blank&quot;&gt; next post &lt;/a&gt;we will see the 2nd way to&amp;nbsp;generate&amp;nbsp;the charts in reports.&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;I ll create one sample application (Progress Report) to&amp;nbsp;demonstrate&amp;nbsp;the&amp;nbsp;Integrate&amp;nbsp;the charts in reports.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;I have Student Bean contain name, roll No, image and List of Semester paper beans. In&amp;nbsp;Semester paper bean contain name of the paper and mark(score).&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Student.java&lt;/b&gt;&lt;/u&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ import java.util.List;  /**  *  * @author ramki  */ public class Student {     private String name;     private String rollNo;     private String imagePath;     private List&lt;semesterpaper&gt; listOfSemesterPaper;      // getters and setters } &lt;/semesterpaper&gt;]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;SemesterPaper.java&lt;/b&gt;&lt;/u&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ public class SemesterPaper {          private String name;     private double mark;          public SemesterPaper(String name, double mark) {         this.name = name;         this.mark = mark;     }      // getters and setters      } ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;Create the Report&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; we can use either iReport Standalone version or Jasper report&amp;nbsp;Net-beans&amp;nbsp;plugins to create the jasper Reports. &lt;br /&gt;&lt;br /&gt;Create empty reports and create the&amp;nbsp;fields&amp;nbsp;and these fields are match with &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: purple;&quot;&gt;Student&lt;/span&gt;&lt;/b&gt;&lt;/span&gt; bean property&amp;nbsp;variables. here &lt;span style=&quot;color: magenta;&quot;&gt;name&lt;/span&gt;,&lt;span style=&quot;color: magenta;&quot;&gt;rollNo&lt;/span&gt; and &lt;span style=&quot;color: magenta;&quot;&gt;imagePath&lt;/span&gt; are String. so no need to change the data type of field. but &lt;span style=&quot;color: magenta;&quot;&gt;listOfSemesterPaper&lt;/span&gt; is List. so change the data type of the field to List.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-ThOSYtC6bfs/UEccX6dJchI/AAAAAAAACkQ/tdCyZKcPERI/s1600/fields_report.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-ThOSYtC6bfs/UEccX6dJchI/AAAAAAAACkQ/tdCyZKcPERI/s1600/fields_report.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;then drag Image component and static text&amp;nbsp;component&amp;nbsp;for making general&amp;nbsp;report&amp;nbsp;like this&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-VIiovgM-LuI/UEcdBbPf3qI/AAAAAAAACkY/5NA0QaojzBc/s1600/report_canvas.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;295&quot; src=&quot;http://2.bp.blogspot.com/-VIiovgM-LuI/UEcdBbPf3qI/AAAAAAAACkY/5NA0QaojzBc/s400/report_canvas.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;here &lt;span style=&quot;color: magenta;&quot;&gt;name&lt;/span&gt; and &lt;span style=&quot;color: magenta;&quot;&gt;rollNo&lt;/span&gt; fields are dragged into report canvas, then drag the Image component and change the expression of Image component to &lt;span style=&quot;color: magenta;&quot;&gt;imagePath&lt;/span&gt; field. Now we ready for bring the Chart component. But chart data are&amp;nbsp;stored&amp;nbsp;in &lt;span style=&quot;color: magenta;&quot;&gt;listOfSemesterPaper&lt;/span&gt; field. Its List. So we can&#39;t use directly. so we going to create sub data set from main data set. so create sub dataset named &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&quot;ChartDataset&quot;&lt;/b&gt;. and In sub data set create another 2 fields match with &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;&lt;b&gt;SemesterPaper&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; bean. here &lt;span style=&quot;color: magenta;&quot;&gt;name&lt;/span&gt; is String and &lt;span style=&quot;color: magenta;&quot;&gt;mark&lt;/span&gt; is double.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-LD9bsjpqkog/UEceO-N_T7I/AAAAAAAACkg/x53ZN6rdw9o/s1600/sub_dataset.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;170&quot; src=&quot;http://4.bp.blogspot.com/-LD9bsjpqkog/UEceO-N_T7I/AAAAAAAACkg/x53ZN6rdw9o/s200/sub_dataset.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Now drag the chart and choose the chart type. here i chosen Bar chart. its poped up the wizard. &amp;nbsp;we need to choose Data set. here we need to choose &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&quot;ChartDataset&quot;&lt;/b&gt;&amp;nbsp;sub data set, which one we created. then select the&amp;nbsp;Category&amp;nbsp;and Value&amp;nbsp;property&amp;nbsp;of Charts. here &lt;span style=&quot;color: magenta;&quot;&gt;name&lt;/span&gt; is category and &lt;span style=&quot;color: magenta;&quot;&gt;mark&lt;/span&gt; is value.&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; (see the screenshot)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-xvYpfBoyREk/UEcfgV_78BI/AAAAAAAACko/0xO_mg8_jhg/s1600/chart_wizard.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;321&quot; src=&quot;http://3.bp.blogspot.com/-xvYpfBoyREk/UEcfgV_78BI/AAAAAAAACko/0xO_mg8_jhg/s400/chart_wizard.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;and final step is we need to explicitly mention how main data set is divied into sub data set. In sub data set &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&quot;ChartDataset&quot;&lt;/b&gt; is take value of &lt;span style=&quot;color: magenta;&quot;&gt;listOfSemesterPaper&lt;/span&gt; field. this fields is List. so we need to wrap into &lt;b&gt;JRBeanCollectionDataSource&lt;/b&gt;.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-5qvdsVuf6Tw/UEcgfzaYi2I/AAAAAAAACkw/am_brwicp9k/s1600/subdataset.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;206&quot; src=&quot;http://1.bp.blogspot.com/-5qvdsVuf6Tw/UEcgfzaYi2I/AAAAAAAACkw/am_brwicp9k/s400/subdataset.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;that&#39;s&amp;nbsp;it. now compile the report and generate the .jasper format. then integrate into Netbeans project.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;DemoBean.java &lt;/u&gt;&lt;/b&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ @ManagedBean @SessionScoped public class DemoBean {      private List&lt;student&gt; listOfStudent;      public DemoBean() {         listOfStudent = new ArrayList&lt;student&gt;();          Student student = new Student();         student.setName(&quot;Ramki&quot;);         student.setRollNo(&quot;02CS24&quot;);         student.setImagePath(&quot;C:\\Users\\ramki\\Downloads\\ramki.jpg&quot;);          List&lt;semesterpaper&gt; listOfSemsterPaper = new ArrayList&lt;semesterpaper&gt;();         listOfSemsterPaper.add(new SemesterPaper(&quot;S/W Engg&quot;, 50.6));         listOfSemsterPaper.add(new SemesterPaper(&quot;Java&quot;, 88.6));         listOfSemsterPaper.add(new SemesterPaper(&quot;Data Struct&quot;, 66.6));         listOfSemsterPaper.add(new SemesterPaper(&quot;Algorithm&quot;, 77.6));         listOfSemsterPaper.add(new SemesterPaper(&quot;Lab 1&quot;, 90.6));         listOfSemsterPaper.add(new SemesterPaper(&quot;Lab 2&quot;, 99.6));          student.setListOfSemsterPaper(listOfSemsterPaper);          listOfStudent.add(student);       }      public String pdf() throws JRException, IOException {         JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listOfStudent);         String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath(&quot;/reports/chartReports.jasper&quot;);         JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap(), beanCollectionDataSource);         HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();         httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.pdf&quot;);         ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();         JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);         FacesContext.getCurrentInstance().responseComplete();         return null;     } }  &lt;/semesterpaper&gt;&lt;/semesterpaper&gt;&lt;/student&gt;&lt;/student&gt;]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;index.xhtml &lt;/u&gt;&lt;/b&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xhtml&quot;&gt;&lt;![CDATA[ &lt;h:head&gt;        &lt;title&gt;Facelet Title&lt;/title&gt;    &lt;/h:head&gt;    &lt;h:body&gt;        &lt;h:form&gt;            Generating Report : &lt;h:commandbutton action=&quot;#{demoBean.pdf()}&quot; value=&quot;Generate&quot;&gt;        &lt;/h:commandbutton&gt;&lt;/h:form&gt;    &lt;/h:body&gt; ]]&gt;&lt;/script&gt;&lt;b&gt;&lt;span style=&quot;background-color: #fff2cc; font-size: large;&quot;&gt;Download the Sample Project from my &amp;nbsp;&lt;a href=&quot;https://github.com/ramkicse/ChartJasperReport&quot; target=&quot;_blank&quot;&gt;GitHub&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Watch in HD&lt;br /&gt;&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/D2IsIzcuyBo&quot; width=&quot;700&quot;&gt;&lt;/iframe&gt; &lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Comments are Welcomed  &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-ThOSYtC6bfs/UEccX6dJchI/AAAAAAAACkQ/tdCyZKcPERI/s72-c/fields_report.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-89294498660745824</guid><pubDate>Fri, 22 Jun 2012 06:28:00 +0000</pubDate><atom:updated>2012-07-12T18:27:01.013+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><category domain="http://www.blogger.com/atom/ns#">javaEE</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><title>Deploy the Java Web Application to Jelastic Paas Cloud</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;a href=&quot;http://jelastic.com/&quot; target=&quot;_blank&quot;&gt;Jelastic&lt;/a&gt; is Java Paas (Platform as a Service) cloud for Java Server hosting. we can easily create the server&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;instances&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;(Tomcat, Glassfish ) and SQL Instances (MySQL, PostgreSQL) &amp;nbsp;and deploy the Java Web applications.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://jelastic.com/&quot; target=&quot;_blank&quot;&gt;Jelastic&lt;/a&gt;&amp;nbsp;website make its easy to use. when we logged in &amp;nbsp;one of the server then one window popped up, to create the environment&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-Q4HiwxKoQHA/T-QJ92YZo-I/AAAAAAAACU4/iEaFI1qz_DE/s1600/environment.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;328&quot; src=&quot;http://2.bp.blogspot.com/-Q4HiwxKoQHA/T-QJ92YZo-I/AAAAAAAACU4/iEaFI1qz_DE/s640/environment.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;here we select servers (Tomcat, GlassFish), Database Servers (MySQL,PostgreSQL) and give the unique name of ur environment. then&amp;nbsp;click&amp;nbsp;create button. Jelastic create the tomcat and&amp;nbsp;MySQL&amp;nbsp;instances. these&amp;nbsp;instance&amp;nbsp;are not shared to others. so we can start/stop these instance at any time. we can change the config files like Tomcat (server.xml, catalina.properties), MySQL(mysql.ini) files.&lt;br /&gt;&lt;br /&gt;When we create the instances they send mail contain the user name and password for accessing the Database server.&lt;br /&gt;&lt;br /&gt;In this&amp;nbsp;screen-cast&amp;nbsp;(below) i deploy the &amp;nbsp;previous post&lt;a href=&quot;http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html&quot; target=&quot;_blank&quot;&gt; Jasper Report +JSF+JPA &lt;/a&gt;Web Application into&amp;nbsp;Jelastic&amp;nbsp;paas cloud.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Screen Cast&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/P7PxUygPlyA&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/06/deploy-java-web-application-to-jelastic.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-Q4HiwxKoQHA/T-QJ92YZo-I/AAAAAAAACU4/iEaFI1qz_DE/s72-c/environment.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-938483298119133822</guid><pubDate>Thu, 21 Jun 2012 10:12:00 +0000</pubDate><atom:updated>2016-05-03T10:43:45.364+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><category domain="http://www.blogger.com/atom/ns#">Java SE</category><category domain="http://www.blogger.com/atom/ns#">javaEE</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>JSF + JPA + JasperReports (iReport) Part 2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In this post &amp;nbsp;is &amp;nbsp;a&amp;nbsp;continuation&amp;nbsp;of &lt;a href=&quot;http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html&quot; target=&quot;_blank&quot;&gt;Jasper Report Part 1&lt;/a&gt;. here we will discuss about some advanced jasper report concepts like passing complex object like List, Date object and how to create and use local variable in jasper report, Add the&amp;nbsp;sub-report&amp;nbsp;and background image to report.&amp;nbsp;Check my latest post about&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html&quot; target=&quot;_blank&quot;&gt;Integrate Charts into Jasper Reports&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;here i am using JPA (Java Persistence API) for accessing the Database. so i create the two entity ShoppingCart and Item. here ShoppingCart entity contain list of Item entities. then i am going to pass these objects to Jasper Report. &lt;span style=&quot;color: blue;&quot;&gt;(Check the video in below)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;ShoppingCart.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;     &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ @Entity public class ShoppingCart {     @Id     @GeneratedValue(strategy= GenerationType.AUTO)     private long id;     private String firstName;     private String lastName;     @Temporal(TemporalType.DATE)     private Date dop;     @OneToMany(cascade= CascadeType.ALL)     private List&lt;item&gt; listOfItems;      // getters and setters } &lt;/item&gt;]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Item.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;     &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ @Entity public class Item {     @Id     @GeneratedValue(strategy= GenerationType.AUTO)     private long id;     private String itemName;     private float price;     private int noOfUnits;      //getters and setters  } ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Create Report&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; now i am going create report. we can use iReport standalone or iReport Netbeans Plugin to create the report. first we need to create some fields in report. these&amp;nbsp;fields&amp;nbsp;are matched with ShoppingCart Bean property names and Data types also.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-EGefpjYQBUo/T-LnUWUKB8I/AAAAAAAACT4/hlQ2Dl1b7oA/s1600/fields.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-EGefpjYQBUo/T-LnUWUKB8I/AAAAAAAACT4/hlQ2Dl1b7oA/s1600/fields.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;and set the data types of these fields correctly.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;firstName &amp;nbsp;==&amp;gt; java.lang.String&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;lastName &amp;nbsp;==&amp;gt; java.lang.String&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;dop &amp;nbsp;==&amp;gt; java.util.Date&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;listOfItems ==&amp;gt; java.util.List&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;then drag these fields to detail pane of the report as per needs. then right click the Report and compile the report&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-8VtsYuGAz4c/T-Lo1tPqVKI/AAAAAAAACUM/avfXVqU4Zv8/s1600/compile.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;260&quot; src=&quot;http://4.bp.blogspot.com/-8VtsYuGAz4c/T-Lo1tPqVKI/AAAAAAAACUM/avfXVqU4Zv8/s320/compile.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;then its creates the jasper file. and its compiled format of jasper report. check&lt;a href=&quot;http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html&quot; target=&quot;_blank&quot;&gt; part 1&lt;/a&gt; for more details of overview of jasper report.&lt;br /&gt;&lt;br /&gt;now create one JSF page with single Command Button (Submit Button&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xhtml&quot;&gt;&lt;![CDATA[    &lt;h:head&gt;        &lt;title&gt;Facelet Title&lt;/title&gt;    &lt;/h:head&gt;    &lt;h:body&gt;        &lt;h:form&gt;            &lt;h:commandbutton action=&quot;#{demoBean.pdf()}&quot; value=&quot;Generate Jasper Report&quot;&gt;        &lt;/h:commandbutton&gt;&lt;/h:form&gt;    &lt;/h:body&gt;]]&gt;&lt;/script&gt;&lt;span style=&quot;background-color: white;&quot;&gt;and we create one managed bean for above JSF page&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;DemoBean.java&lt;/span&gt;&lt;br /&gt;     &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ @ManagedBean @SessionScoped  public class DemoBean {           public void pdf() throws JRException, IOException {                EntityManager em=PerisitenceManager.getEntityManager();         Query query= em.createQuery(&quot;select s from ShoppingCart s&quot;);          List&lt;shoppingcart&gt; listOfShoppingCart=(List&lt;shoppingcart&gt;)query.getResultList();         JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listOfShoppingCart);         String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath(&quot;/reports/report.jasper&quot;);         JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap(), beanCollectionDataSource);         HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();         httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.pdf&quot;);         ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();         JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);         FacesContext.getCurrentInstance().responseComplete();     } } &lt;/shoppingcart&gt;&lt;/shoppingcart&gt;]]&gt;&lt;/script&gt;&lt;br /&gt;Now when u run the project its generate the report in PDF file format.&lt;br /&gt;&lt;br /&gt;now we integrate the sub report. so drag the&amp;nbsp;sub-report&amp;nbsp;component from&amp;nbsp;palettes. then add the Item beans property as a fields names and correct data types.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-A8AepawzTdI/T-LwUB8FoFI/AAAAAAAACUY/amkJW4FSFls/s1600/sub.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-A8AepawzTdI/T-LwUB8FoFI/AAAAAAAACUY/amkJW4FSFls/s1600/sub.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;and data types&lt;br /&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;itemName ==&amp;gt; java.lang.String&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;price ==&amp;gt; java.lang.Float&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;noOfUnits ==&amp;gt; &amp;nbsp;java.lang.Integer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;once sub report is ready then compile the subreports.&lt;br /&gt;&lt;br /&gt;while create the subreport we passed the Empty Data Source. so now we need to change to listOfItems as a data source, we can&#39;t pass directly because its not accept List. so we need to wrap into the JRBeanCollectionDataSource Object.&lt;br /&gt;&lt;br /&gt;so in main report select the sub report and change the properties&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;Connection Type ==&amp;gt; Use a datasource Expression&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;DataSource Expression ==&amp;gt; new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listOfItems})&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-56uGSalJpNg/T-LxyDj5QDI/AAAAAAAACUg/B4AWQnVcoXA/s1600/datasource.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;268&quot; src=&quot;http://1.bp.blogspot.com/-56uGSalJpNg/T-LxyDj5QDI/AAAAAAAACUg/B4AWQnVcoXA/s320/datasource.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;You Can Download this complete example from &lt;a href=&quot;https://github.com/ramkicse/JasperReports-2.git&quot; target=&quot;_blank&quot;&gt;GitHub&lt;/a&gt; (or) &lt;a href=&quot;http://ramki-projects.googlecode.com/files/JasperDemo.zip&quot; target=&quot;_blank&quot;&gt;google code&lt;/a&gt; .&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 25px;&quot;&gt;&lt;u&gt;&lt;b&gt;How to use&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 25px;&quot;&gt;Change the properties in &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;persistence.xml&lt;/span&gt; file, like db name, db hostname ,username and password.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 25px;&quot;&gt;Add necessary lib to&amp;nbsp;class path&amp;nbsp;like Hibernate libs, MySQL lib, Jasper Report lib. for simplicity in this zip&amp;nbsp;contain&amp;nbsp;war file under dist/ folder. so just extract &amp;nbsp; and see all lib are located in &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;WEB-INF/lib&lt;/span&gt; section. copy all files and add to to ur&amp;nbsp;class path&amp;nbsp;(Libraries&amp;nbsp;)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 25px;&quot;&gt;Create the &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;jasperdb&lt;/b&gt; database in ur mysql server&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 25px;&quot;&gt;First run the &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;NewServlet&lt;/b&gt;&lt;/span&gt; , this servlet create necessary tables in ur database. and insert some sample rows to the table.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style=&quot;font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif;&quot;&gt;&lt;span style=&quot;line-height: 25px;&quot;&gt;Finally run the&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt; index.xhtml&lt;/b&gt;&lt;/span&gt; file and generate the report.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;strike&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;I deployed same example in &lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Jelastic Paas cloud,&amp;nbsp;&lt;/span&gt;&lt;/b&gt;you can access through&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;a href=&quot;http://ramkicse.jelastic.servint.net/jasper/&quot; style=&quot;background-color: #fce5cd;&quot;&gt;http://ramkicse.jelastic.servint.net/jasper/&lt;/a&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;URL&lt;/span&gt;&lt;/strike&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;strike&gt;click the button to generate the report.&amp;nbsp;&lt;/strike&gt;(Its expired)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;check &lt;a href=&quot;http://www.ramkitech.com/2012/06/deploy-java-web-application-to-jelastic.html&quot; target=&quot;_blank&quot;&gt;How to deploy the Web application to Jelastic cloud&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Check my latest post about &lt;a href=&quot;http://www.ramkitech.com/2012/09/integrate-charts-in-jasper-reports-jsf.html&quot; target=&quot;_blank&quot;&gt;Integrate Charts into Jasper Reports&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id=&quot;video&quot; style=&quot;font-size: large;&quot;&gt;&lt;b style=&quot;color: #990000;&quot;&gt;Screen Cast &lt;/b&gt;&lt;span style=&quot;background-color: #fff2cc; color: #990000;&quot;&gt;(Watch the video in HD)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/dgLjnnnvDmk&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt; &lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Comments are Welcomed  &lt;/b&gt;&lt;/span&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-EGefpjYQBUo/T-LnUWUKB8I/AAAAAAAACT4/hlQ2Dl1b7oA/s72-c/fields.png" height="72" width="72"/><georss:featurename>National Highway 4, Kasba Peth, Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-6996415716517830633</guid><pubDate>Sat, 28 Apr 2012 10:43:00 +0000</pubDate><atom:updated>2012-07-01T11:49:34.063+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">SSH</category><category domain="http://www.blogger.com/atom/ns#">SSH Tunneling</category><title>How to do SSH Tunneling (Port Forwarding) - Screen-cast</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In this post we will see how ssh works?,&amp;nbsp;what is SSH tunneling? what is important of ssh tunnels and how to setup the ssh tunnel.&lt;br /&gt;When SSH server is installed in machine then by default its allowed ssh tunneling.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;SSH Tunneling (Port Forwarding)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;Tunneling&amp;nbsp;is the concept to encapsulate the network protocol to another protocol. here we put into SSH. so all network communication are encrypted. It also called Port&amp;nbsp;Forwarding. because in ssh tunneling we are&amp;nbsp;going&amp;nbsp;to bind one local port. so what are the packet we are going to send that particular port, all&amp;nbsp;packets&amp;nbsp;are transparently encrypt and delivered to remote system.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;What is the need for SSH Tunneling?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;SSH is enough to administrate the remote system. its not enough to access the all services which are&amp;nbsp;available&amp;nbsp;in remote system.&lt;/div&gt;&lt;div&gt;let i describe in the following scenario,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-UwBBYy88FXM/T5ZGv9ack5I/AAAAAAAACMc/kjEY-69KYY8/s1600/scenario.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;312&quot; src=&quot;http://2.bp.blogspot.com/-UwBBYy88FXM/T5ZGv9ack5I/AAAAAAAACMc/kjEY-69KYY8/s640/scenario.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;now lets consider the scenario, System (192.168.56.101) is my system its connected to internet and server its called PrivateServer (192.168.56.102) &amp;nbsp;machine have two&amp;nbsp;Ethernet&amp;nbsp;interfaces. one is connected to Internet. and another is connected to 10.10.1.0/24 local network. Intranet (10.10.1.11) machine is part of&amp;nbsp;10.10.1.0/24&amp;nbsp; sub network.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note : here i mentioned local system(192.168.56.101) and remote system(192.168.56.102) are looking like local&amp;nbsp;sub-net&amp;nbsp;IP address. For VM&amp;nbsp;purpose&amp;nbsp;i used these IP address. But reality is it&amp;nbsp;should&amp;nbsp;be any public IP address.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Important Note : SSH Server&amp;nbsp;daemon&amp;nbsp;service is running in port 22 in all these three system and firewall is allowed to connect these system using SSH client.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;now&amp;nbsp;System (192.168.56.101) can&amp;nbsp;communicate&amp;nbsp;to&amp;nbsp;PrivateServer (192.168.56.102), because both system are connected to internet directly. But&amp;nbsp;System (192.168.56.101) can&#39;t communicate to Intranet (10.10.1.11) machine, because from&amp;nbsp;System (192.168.56.101) perspective 10.10.1.11 is non&amp;nbsp;route able&amp;nbsp;IP address. 10.10.1.11 is not public IP address, its local IP address. so we can&#39;t route the packets directly.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now the situation like that from System(192.168.56.101)&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; i want to access the Intranet (10.10.1.11) machine. &lt;b&gt;without&amp;nbsp;modifying&amp;nbsp;IP tables, redirect, like tools/services in intermediate (or) target machine. Because i m not sys-admin, so i&amp;nbsp;don&#39;t&amp;nbsp;have root&amp;nbsp;privilege.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;One of the possible&amp;nbsp;solution is first use ssh to&amp;nbsp;log in&amp;nbsp;into PrivateServer(192.168.56.102) and then again&amp;nbsp;(nested)&amp;nbsp;log in&amp;nbsp;&amp;nbsp;to Intranet(10.10.1.11). Yes its good idea, its works, now i can remotely&amp;nbsp;administrate&amp;nbsp;the Intranet(10.10.1.11). but if Intranet(10.10.1.11) offer some services like VNC, Apache httpd, smtp, pop3, squid proxy then&lt;b&gt; how we can access these services from System(192.168.56.101)?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here its not strictly Intranet(10.10.1.11) offer these service, it may be 10.10.1.0/24 sub net any one of the machine can offer these services. Even in 10.10.1.0/24&amp;nbsp;sub-net&amp;nbsp;have one intranet-website. how we can access&amp;nbsp;these&amp;nbsp;site from System(192.168.56.101) machine&amp;nbsp;Firefox?&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;The&amp;nbsp;solution&amp;nbsp;is SSH Tunneling or SSH Port Forwarding&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;How SSH Works&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt; &amp;nbsp; &amp;nbsp; In terminal when we type &lt;b style=&quot;background-color: #d9ead3;&quot;&gt;ssh ramki@Private-Server.org&lt;/b&gt;&amp;nbsp; then terminal application invoke the ssh client, ssh client connect to&amp;nbsp;Private-Server.org&#39;s&amp;nbsp;SSH server in port 22. then both client and server exchange the&amp;nbsp;identity,&amp;nbsp;&amp;nbsp;public keys, cipher suite&amp;nbsp;information and create one shell process in server side. then secure channel is established between client and server. then future all commands from 192.168.101 are go through this secure channel to server (192.168.56.102) and execute the command&amp;nbsp;and the response are come back in same secure channel.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For example after establish ssh, i will issue the ls command. the ls command goes to SSH client then that command encapsulate and&amp;nbsp;encrypted&amp;nbsp;then send to server. Server decrypt and extract the command and&amp;nbsp;execute&amp;nbsp;the command in shell (which is created when ssh is established), the&amp;nbsp;output&amp;nbsp;of ls command is not printed in shell. Its redirect the output to SSH client in same secure channel and follow the same procedure (encapsulate and&amp;nbsp;encrypt) . and finally Terminal application shows the&amp;nbsp;output&amp;nbsp;of ls command.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I think here all command is encoded to Base64 encoding before send to server and before encrypt.&lt;b&gt; &lt;span style=&quot;background-color: #fce5cd;&quot;&gt;(But i am not sure)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here very important note that SSH is not&amp;nbsp;disturb&amp;nbsp; the port&amp;nbsp;other than&amp;nbsp;22 (or which port ssh server is running).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-oIq-qgce-q8/T5ZGxFEmHiI/AAAAAAAACMg/8l8pL_wCIh4/s1600/ssh_works.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;419&quot; src=&quot;http://3.bp.blogspot.com/-oIq-qgce-q8/T5ZGxFEmHiI/AAAAAAAACMg/8l8pL_wCIh4/s640/ssh_works.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;SSH Tunneling&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;SSH can work many channel&#39;s simultaneously. In normal case we use shell channel. But now we are going to use data channel. so base concept is, in 192.168.56.101 machine ssh client bind one port and establish secure connection with server (192.168.56.102). and create one data&amp;nbsp;channel&amp;nbsp;and shell channel. (we can&amp;nbsp;omit&amp;nbsp;shell channel&amp;nbsp;using&amp;nbsp;-N option in ssh command).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now In system machine (&amp;nbsp;192.168.56.101) any application send data to that port (which one ssh client is bind), then ssh client transparently receive the data and encrypt and sent to server machine. In server&amp;nbsp;&amp;nbsp;(&amp;nbsp;192.168.56.102)&amp;nbsp;receive&amp;nbsp;and decrypt it and make the local call. (we discuss later)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;SSH Tunneling types&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;SSH offers three types of tunneling&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Dynamic Tunneling (SOCKS Proxy)&lt;/li&gt;&lt;li&gt;Local Port Forwarding&lt;/li&gt;&lt;li&gt;Remote Port Forwarding&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-family: Verdana, sans-serif;&quot;&gt;&lt;u&gt;Dynamic Tunneling&amp;nbsp;&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;Command : &lt;/b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; &lt;b&gt;&lt;span style=&quot;color: purple;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #20124d;&quot;&gt;ssh &amp;nbsp; &amp;nbsp; -D 8080 &amp;nbsp; &amp;nbsp; ramki@192.168.56.102&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;here -D 8080 is mention SOCKS v5 Proxy bind 8080 port in client side&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Now ssh client in 192.168.56.101 machine create one SOCKS proxy server in client side&amp;nbsp;and bind one local port.then connect to 192.168.56.102 remote machine and establish secure channel.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&amp;nbsp;Now all client application like Firefox, chrome,... need to configure the proxy setting &amp;nbsp;to SOCKS proxy server localhost and port number. (check video for reference below the post)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note : consider server (192.168.56.102) and Intranet (10.10.1.11) both machines run&amp;nbsp;Apache&amp;nbsp;httpd server and bind port 80&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;After configuration is&amp;nbsp;completes,&lt;br /&gt;in Firefox now type http://localhost/ , we know that in client machine (192.168.56.101) there is no service is running in port 80. but when we hit enter in browser, we can see the website of server machine (192.168.56.102).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;How we can access server website using http://localhost/ in client machine?&lt;/b&gt;&lt;br /&gt;we configure the proxy in browser. so browser send all HTTP request (even localhost anf 127.0.0.1) to port 8080, here SOCKS proxy is running in that port. Then socks proxy server packs our HTTP request to ssh client and encrypt and send to server. Server decrypt and&amp;nbsp;extract&amp;nbsp;the HTTP Request. Now in server side the HTTP request&lt;b&gt; http://localhost/&lt;/b&gt; is point to server machine itself. so server invoke the request. If any service is running in port 80, is called and response is send back to client using same secure channel. so browser shows server webpage in client side.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-uYmBjinJPTI/T5ZGqS3XB0I/AAAAAAAACL0/kEvBBWdw3Wc/s1600/dynamic.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;http://3.bp.blogspot.com/-uYmBjinJPTI/T5ZGqS3XB0I/AAAAAAAACL0/kEvBBWdw3Wc/s640/dynamic.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;We know that from client machine (192.168.56.101) , the IP address 10.10.1.11 is non routable. but now if we issue&lt;b&gt;&amp;nbsp;http://10.10.1.11/&lt;/b&gt;&amp;nbsp;in&amp;nbsp;Firefox&amp;nbsp;browser, its shows the 10.10.1.11&amp;nbsp;Apache&amp;nbsp;server webpage.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Advantage :&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;One proxy server is enough to access the all services of remote machine and its sub-net services&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Disadvantage:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;We need to configure the Proxy settings in client application, If&amp;nbsp;application&amp;nbsp;doesn&#39;t support the proxy then we can&#39;t access the service.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-family: Verdana, sans-serif;&quot;&gt;&lt;u&gt;Local Port Forwarding&lt;/u&gt;&lt;/span&gt;&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Command : &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; &amp;nbsp;ssh &amp;nbsp; &amp;nbsp; &amp;nbsp; -L &amp;nbsp;8000:localhost:80 &amp;nbsp; &amp;nbsp; ramki@192.168.56.102&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;here syntax is &amp;nbsp; -L &amp;nbsp; &amp;lt;local port&amp;gt; : &amp;lt;remote hostname&amp;gt; : &amp;lt;remote service port&amp;gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;so when we&amp;nbsp;execute&amp;nbsp;the command, its bind port 8000 in client side. now what are request send to port 6000 its redirect to ssh client, then encrypt and send to server machine. now server directly delivered the data to port 80.&lt;br /&gt;&lt;br /&gt;In dynamic tunnel, server checks the packet and decide where we need to send the packet, for example http://localhost/ then its send to 80, smtp then send to 25. But in local port it always send to single port which one we mention during setup the local port forwarding&amp;nbsp;&lt;b&gt;&amp;lt;remote hostname&amp;gt; : &amp;lt;remote service port&amp;gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;this time in Firefox no need to configure the proxy,&amp;nbsp;clear&amp;nbsp;the proxy(if its present)&lt;br /&gt;and type in address bar &lt;b&gt;&amp;nbsp;http://localhost:8000/&lt;/b&gt;&lt;br /&gt;then HTTP request is going to local port 8000, then its redirect and send to server. server directly send to port 80. (Its based on&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;remote hostname&amp;gt; : &amp;lt;remote service port&amp;gt;&lt;/span&gt;, here now &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;localhost:80&lt;/span&gt;&lt;/b&gt;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-nmmsmmfAetA/T5ZGrYJDRZI/AAAAAAAACL4/skeG6CJMhmg/s1600/local1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;436&quot; src=&quot;http://2.bp.blogspot.com/-nmmsmmfAetA/T5ZGrYJDRZI/AAAAAAAACL4/skeG6CJMhmg/s640/local1.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;If u want to access the 10.10.1.11 machine http service then we need to setup new local port forwarding.&lt;/div&gt;&lt;div&gt;we can&#39;t use prior port forwarding. because old one always pointing to localhost:80.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Command : &amp;nbsp; &amp;nbsp;&lt;/b&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt; ssh &amp;nbsp; -L &amp;nbsp;8000:10.10.1.11:80 &amp;nbsp; ramki@192.168.56.102&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;now client side local port 8000 is redirected to 10.10.1.11:80 machine via 192.168.56.102.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In&amp;nbsp;Firefox&amp;nbsp;using http://localhost:8080/ we can access the 10.10.1.11 machine http service.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(For further reference check the video below. in video i show the how to access remote desktop using VNC)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-qStTZlKH6Ig/T5ZGsQgDHUI/AAAAAAAACME/mtBGx0eghEk/s1600/local2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;372&quot; src=&quot;http://1.bp.blogspot.com/-qStTZlKH6Ig/T5ZGsQgDHUI/AAAAAAAACME/mtBGx0eghEk/s640/local2.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Advantage:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;no need to configure the proxy setting&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;Disadvantage:&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Each service we need to setup different local port forwarding, (i.e for example, 2 port forwarding is needed to get 192.168.56.102 and 10.10.1.11 http services)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-family: Verdana, sans-serif;&quot;&gt;&lt;u&gt;Remote Port&amp;nbsp;Forwarding&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Remote port forwarding is same like local port&amp;nbsp;forwarding. but this time we need to set the port forwarding in server side(192.168.56.102), not client side&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Command : &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;ssh &amp;nbsp; &amp;nbsp;-R 8000:localhost:80 &amp;nbsp; &amp;nbsp; &amp;nbsp; ramki@192.168.56.101&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;here very important changes is from server we going to connect client, so&amp;nbsp;&lt;span style=&quot;background-color: #fff2cc; font-weight: bold;&quot;&gt;&amp;nbsp;ramki@192.168.56.101&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;here its 192.168.56.101 not 102.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;when we&amp;nbsp;execute&amp;nbsp;this command its connect to client and create 8000 port in &lt;b&gt;client side(not server side)&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;as usual client use its local port 8000 to connect server. like local port forwarding.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Why Remote Port Forwarding is Important?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; Its&amp;nbsp;rarely&amp;nbsp;used, when we worked the machine. that machine is inside the NAT. so from outside no one can access it. that kind of situation&amp;nbsp;physically&amp;nbsp;access the machine and connect back to our client system (192.168.56.101) using remote port forward. then from client machine we can access the services.(Its seems to be little bit confusing, but its simple)&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;In Windows Machine&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;In windows machine if want to run ssh server then there is lots of ssh servers are&amp;nbsp;available&amp;nbsp;&lt;a href=&quot;http://www.bitvise.com/winsshd&quot; target=&quot;_blank&quot;&gt;WinSSHD&amp;nbsp;&lt;/a&gt;&lt;a href=&quot;http://www.freesshd.com/&quot; target=&quot;_blank&quot;&gt;freeSSHd&lt;/a&gt;, &lt;a href=&quot;http://sshwindows.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;openssh&lt;/a&gt;. If we want only ssh client then we can use &lt;a href=&quot;http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html&quot; target=&quot;_blank&quot;&gt;Putty&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;suppose in System(192.168.56.101) i am using Windows then how we access the ssh tunneling.&lt;br /&gt;&lt;br /&gt;open the putty and type the host ramki@192.168.56.102 and select Connection-&amp;gt;SSH-&amp;gt;Tunnels (see the image), then type &lt;b&gt;8080&lt;/b&gt; in source port and select &lt;b&gt;Dynamic&lt;/b&gt;, if u want dynamic tunnel (Its equal to -D 8080 in command option)&lt;br /&gt;&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-tue6bke7NeY/T5ZGt-pppfI/AAAAAAAACMM/JKaniuviBzM/s1600/putty.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;387&quot; src=&quot;http://1.bp.blogspot.com/-tue6bke7NeY/T5ZGt-pppfI/AAAAAAAACMM/JKaniuviBzM/s400/putty.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;If we want local port forwarding then put any unused port &lt;b&gt;6000&lt;/b&gt; in source port and destination is &lt;b&gt;localhost:80 &lt;/b&gt;and select &lt;b&gt;Local. &lt;/b&gt;(Its equal to -L 6000:localhost:80)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-cGNjRr5-5Ug/T5ZGu7mr3wI/AAAAAAAACMQ/YSP7jVJz_n8/s1600/putty1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;388&quot; src=&quot;http://4.bp.blogspot.com/-cGNjRr5-5Ug/T5ZGu7mr3wI/AAAAAAAACMQ/YSP7jVJz_n8/s400/putty1.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If u want to access 10.10.1.11 machine &amp;nbsp;the remote desktop then make local port&amp;nbsp;forward&amp;nbsp;(check above image) and&amp;nbsp;Destination&amp;nbsp;is &lt;b&gt;10.10.1.11:5900 &lt;/b&gt;here 5900 is the port used by vnc server. then using any vnc client (here i used tightvnc client) to connect ur local port 6000&lt;/div&gt;&lt;div&gt;so mention&lt;b&gt; localhost::6000, &amp;nbsp;&lt;/b&gt;&amp;nbsp;here we need to mention double colon &lt;b&gt;::&lt;/b&gt;, because in vnc client port no is specified in this manner. (Check the video )&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-sfLCbg2FbwA/T5ZGyO0vq5I/AAAAAAAACMo/NU4WolfupQU/s1600/vnc.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;168&quot; src=&quot;http://4.bp.blogspot.com/-sfLCbg2FbwA/T5ZGyO0vq5I/AAAAAAAACMo/NU4WolfupQU/s400/vnc.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;background-color: white; color: #660000; font-size: large;&quot;&gt;Bypass Firewall&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This SSH Tunnel&amp;nbsp;concept&amp;nbsp;can be use to bypass firewall. lets&amp;nbsp;consider&amp;nbsp;the scenario. In server side its enable firewall and some service are running and these services are can access through localhost or same machine. but u can&#39;t access through remote&amp;nbsp;machine. because firewall block the all the port except ssh port (22).&lt;br /&gt;&lt;br /&gt;this kind of situation we use tunnel and almost all services can be accessed from outside. because firewall is rule based. In firewall perspective all traffic is goes through port 22. so its allowed. but internally we made tunnel and access all services.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;How to prevent SSH Tunnel&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Open the ssh server config file&lt;b&gt; /etc/ssh/sshd_config &lt;/b&gt;&amp;nbsp;then set the parameter&lt;br /&gt;&lt;b style=&quot;background-color: #fce5cd;&quot;&gt;AllowTcpForwarding no&lt;/b&gt;&lt;br /&gt;then restart ssh service. then they not allow the ssh tunnel service, but still we can access ssh shell service.&lt;br /&gt;&lt;br /&gt;But in ssh man page they&amp;nbsp;clearly&amp;nbsp;mentioned&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&quot; Note that disabling TCP forwarding does not improve security unless&amp;nbsp;users are also denied shell access, as they can always install their own forwarders. &quot;&lt;/b&gt;&lt;br /&gt;&lt;div&gt;so still we can use use ssh tunnel even though &amp;nbsp;we set&amp;nbsp;&lt;b&gt;AllowTcpForwarding no.&lt;/b&gt; (I will show in my next post)&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;I hope everything is clear. If any&amp;nbsp;misunderstanding&amp;nbsp;please&amp;nbsp;let me know.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;Screen cast (Watch in HD)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/VdkLejEN3So?rel=0&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Resources:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a class=&quot;l&quot; href=&quot;http://www.snailbook.com/&quot; style=&quot;background-color: white; color: #1122cc; cursor: pointer; font-family: arial, sans-serif; text-align: -webkit-auto; white-space: nowrap;&quot;&gt;&lt;em style=&quot;font-style: normal; font-weight: bold;&quot;&gt;SSH&lt;/em&gt;, The Secure Shell: The Definitive Guide&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Comments Welcomed&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/04/how-to-do-ssh-tunneling-port-forwarding.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-UwBBYy88FXM/T5ZGv9ack5I/AAAAAAAACMc/kjEY-69KYY8/s72-c/scenario.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5380334423162876171</guid><pubDate>Tue, 24 Apr 2012 05:49:00 +0000</pubDate><atom:updated>2013-11-18T14:16:12.676+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Kernel</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><title>How to compile kernel step by step</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Recently I compiled the latest kernel by&amp;nbsp;manually for just fun. so i&amp;nbsp;logged&amp;nbsp;my experience here. I show the step by step to the compilation process. I&amp;nbsp;followed&amp;nbsp;the &lt;a href=&quot;http://www.howtoforge.com/kernel_compilation_ubuntu&quot; target=&quot;_blank&quot;&gt;this reference&lt;/a&gt; for compile the kernel.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Why Need to compile the Kernel?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Some time some software or modules expected that some&amp;nbsp;kernel&amp;nbsp;flags needed to set while compile (build) the kernel. This kind of scenario we need to rebuild the kernel with specified configuration flags are set.&lt;/li&gt;&lt;li&gt;When new kernel is&amp;nbsp;released, &amp;nbsp;compile the new kernel and install in our system. But this is not&amp;nbsp;recommend&amp;nbsp;way to install the system. so use our distribution(Ubuntu,&amp;nbsp;red-hat&amp;nbsp;release ) &amp;nbsp;kernel update.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;Check your&amp;nbsp;Linux&amp;nbsp;kernel version&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In Linux&amp;nbsp;system use &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;uname -r&lt;/b&gt;&lt;/span&gt; or &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;cat /proc/version&lt;/b&gt;&lt;/span&gt; to find the current kernel version&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-VwizV9ywLPA/T5FL5ibXkmI/AAAAAAAACK0/JJtMFWHudUg/s1600/uname.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;102&quot; src=&quot;http://4.bp.blogspot.com/-VwizV9ywLPA/T5FL5ibXkmI/AAAAAAAACK0/JJtMFWHudUg/s400/uname.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Linux Kernel Version&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;here &lt;b&gt;2.6.35.22&amp;nbsp;&lt;/b&gt;is current system kernel version&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;Step 1 : Download the latest kernel&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;Goto&amp;nbsp;&lt;a href=&quot;http://kernel.org/&quot;&gt;http://kernel.org/&lt;/a&gt;&amp;nbsp;website and get the latest version of the kernel source. i will get &lt;b&gt;3.3.3&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.3.3.tar.bz2&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;and extract&amp;nbsp;the source code.&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;tar xf linux-3.3.3.tar.bz2&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;cd linux-3.3.3&lt;/b&gt;&lt;br /&gt;in linux-3.3.3 folder&amp;nbsp;contain&amp;nbsp;lots of files and folders. some folders are use following purpose&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;arch&lt;/span&gt;&lt;/b&gt; - this folder shows the what are the&amp;nbsp;architecture&amp;nbsp;port the&amp;nbsp;Linux&lt;br /&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;crypto&lt;/b&gt;&lt;/span&gt;- contain&amp;nbsp;cryptography implementations like AES, DES&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;drivers&lt;/span&gt;&lt;/b&gt;- &amp;nbsp;all device drivers modules (IDE, SCSI, Ethernet device, Wireless)&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;fs&lt;/span&gt;&lt;/b&gt;- all&amp;nbsp;file-system&amp;nbsp;implementation code (ext4, FAT, NTFS)&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;net&lt;/span&gt;&lt;/b&gt; - all network protocol implementations (IPv4, IPv6, tcp, 802.11)&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;b style=&quot;color: #990000;&quot;&gt;Step 2 : make the configuration file&lt;/b&gt;&lt;br /&gt;&amp;nbsp; While compile the kernel source code, we need configuration file. that configuration file contain lots of variable to help to understand&amp;nbsp;what&amp;nbsp;are the modules we need to compile.&lt;br /&gt;&lt;br /&gt;For x86 specific&amp;nbsp;kernel&amp;nbsp;variable check &lt;a href=&quot;http://kernel.org/doc/menuconfig/x86.html&quot; target=&quot;_blank&quot;&gt;this reference&amp;nbsp;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;using make command we can build the configuration, but this command is interactive, its ask more than 1000 question about&amp;nbsp;enable&amp;nbsp;or disable the particular module, like which&amp;nbsp;file-system&amp;nbsp;r u want and IP-Tables related&amp;nbsp;modules&amp;nbsp;like SIP components (state-full&amp;nbsp;inspection firewall).&lt;br /&gt;&lt;br /&gt;so the best way is copy the current Linux config file. its stored in /boot/config-&amp;lt;version&amp;gt;.&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;cp /boot/config-&lt;/b&gt;&lt;b&gt;2.6.35.22-generic &amp;nbsp; &amp;nbsp; &amp;nbsp;.config&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;now we got old configuration. now we change/add new configuration settings.&lt;br /&gt;for this purpose therse is lots of options are avialable&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make help&lt;/b&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;&amp;nbsp; &amp;nbsp; ==&amp;gt;Provides the help&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;There is GUI&amp;nbsp;option&amp;nbsp;is also&amp;nbsp;available&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make &amp;nbsp; menuconfig &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ==&amp;gt; this provides Text based GUI&amp;nbsp;&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;Configuration&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-YrXAfpUms4g/T5FL4LnKeRI/AAAAAAAACKw/5sUvVfHIJkc/s1600/snapshot1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;286&quot; src=&quot;http://4.bp.blogspot.com/-YrXAfpUms4g/T5FL4LnKeRI/AAAAAAAACKw/5sUvVfHIJkc/s400/snapshot1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;here load the old config file and add/change the settings then save the config file.&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make &amp;nbsp; gconfig&amp;nbsp;&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;==&amp;gt; this provides GTK 2 based GUI Configuration for GNOME&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-6e-hTFPXIhM/T5FL2I-da1I/AAAAAAAACKg/QVBD97NEPfU/s1600/gconfig.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;267&quot; src=&quot;http://2.bp.blogspot.com/-6e-hTFPXIhM/T5FL2I-da1I/AAAAAAAACKg/QVBD97NEPfU/s400/gconfig.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;f&lt;/b&gt;or this we need to install&lt;b&gt; libgtk2.0-dev, libglad2-dev &lt;/b&gt;through apt-get install&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make &amp;nbsp; xconfig&amp;nbsp;&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;==&amp;gt; this provides QT based GUI Configuration for KDE&lt;/b&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-m6Onxy4ErJU/T5FL6pgEXFI/AAAAAAAACLA/sASX8eU-qFk/s1600/xconfig.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;http://3.bp.blogspot.com/-m6Onxy4ErJU/T5FL6pgEXFI/AAAAAAAACLA/sASX8eU-qFk/s400/xconfig.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;for this we need qt-dev tools&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Using any one of the above method modify the&amp;nbsp;configuration.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Step 3 : Compile the Kernel&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; There are two ways to compile the kernel&lt;br /&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Generic way (lots of steps)&lt;/li&gt;&lt;li&gt;Debian&amp;nbsp;specific way (simple, Use make-kpkg tool)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;u&gt;Step 3.1 : Generic Way&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&amp;nbsp;&lt;span style=&quot;color: magenta;&quot;&gt; Step 3.1.1 Compile the&amp;nbsp;Kernel&amp;nbsp;and its modules&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make &amp;nbsp;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;above code is take 1 to 2 hours depending on system performance. In this step it compile the kernel and store the&amp;nbsp;kernel&amp;nbsp;in binary form to &lt;b&gt;arch/x86/boot/&lt;/b&gt;&lt;b&gt;bzImage&amp;nbsp;&lt;/b&gt;file&lt;br /&gt;then based on&amp;nbsp;kernel headers&amp;nbsp;it will compile the&amp;nbsp;kernel&amp;nbsp; modules (device driver, file-system, network,...)&lt;br /&gt;and generate .ko files. ko means kernel object. These modules also called Loadable Kernel Modules (LKM).&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&amp;nbsp;Step 3.1.2 Install Kernel modules&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make &amp;nbsp;modules_install&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;This step copy the all kernel&amp;nbsp;modules (*.ko)&amp;nbsp;to&amp;nbsp;&lt;b style=&quot;background-color: #f4cccc;&quot;&gt;/lib/modules/&amp;lt;version&amp;gt;/kernel/&lt;/b&gt;&amp;nbsp; &amp;nbsp;folder.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&amp;nbsp;Step 3.1.3 Install Kernel&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make &amp;nbsp;install&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;This step copy the the kenel from&amp;nbsp;&lt;b&gt;arch/x86/boot/bzImage&amp;nbsp;&lt;/b&gt;to&lt;b&gt; /boot &lt;/b&gt;folder and copy the&lt;b&gt; .config&lt;/b&gt; file to &lt;b&gt;/boot/config-&amp;lt;latest-version&amp;gt;&lt;/b&gt; and generate the&amp;nbsp;&lt;b&gt;System.map &lt;/b&gt;file.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&amp;nbsp;Step 3.1.4 Create Initramfs file&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta; font-weight: bold;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;up to&amp;nbsp;now kernel and its modules are compiled and installed. when next boot up time we need to choose latest kernel. so we need to prepare the boot-loader and its support files. When system turns on, after bios and boot loader load the kernel to main memory and mount initial dummy&amp;nbsp;file system&amp;nbsp;as a root file system of system. this initial file system have necessary drivers for disk hardware (SCSI or IDE) and mount the correct file system as a root file system.&lt;br /&gt;&lt;br /&gt;so we need to create initramfs file using update-initramfs or mkinitfs tool&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;update-initramfs&amp;nbsp;-c -k 3.3.3&lt;/b&gt;&lt;br /&gt;here 3.3.3 is new kernel version.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: magenta;&quot;&gt;Step 3.1.5 &amp;nbsp;Update GRUB bootloader&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; the last step is update the boot loader here i m using GRUB boot-loader.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;update-grub&amp;nbsp;&lt;/b&gt;&lt;br /&gt;this command automatically probe the kernels in &lt;b&gt;/boot&lt;/b&gt; folder and add the entries in its configuration file, &lt;b&gt;grub.cfg&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;now restart the system , we will see the new kernel is added in boot loader entries. then choose new kernel in boot loader.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-RPM3M0gpFeM/T5FL3JLNOCI/AAAAAAAACKk/PnhMQMfWdxk/s1600/grub.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;295&quot; src=&quot;http://2.bp.blogspot.com/-RPM3M0gpFeM/T5FL3JLNOCI/AAAAAAAACKk/PnhMQMfWdxk/s400/grub.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;now open the terminal and issue&lt;b style=&quot;background-color: #fff2cc;&quot;&gt; uname -r&lt;/b&gt; command, its shows the &amp;nbsp;current kernel version.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-cujdCiZE3no/T5FL05Oe0yI/AAAAAAAACKY/vUGLB2ACtAo/s1600/after.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;96&quot; src=&quot;http://3.bp.blogspot.com/-cujdCiZE3no/T5FL05Oe0yI/AAAAAAAACKY/vUGLB2ACtAo/s400/after.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;u&gt;Step 3.2 :&amp;nbsp;Debian&amp;nbsp;specific way&amp;nbsp;Way&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In Debian system&#39;s (Ubuntu, Linux Mint,..) there is one&amp;nbsp;tool &quot;&lt;b&gt;make-kpkg&lt;/b&gt;&quot;&amp;nbsp;is&amp;nbsp;available&amp;nbsp;to automate the kernel compilation process.&lt;br /&gt;&lt;br /&gt;to install the make-kpkg, use apt-get&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;sudo apt-get install &amp;nbsp; &amp;nbsp;kernel-package &amp;nbsp; &amp;nbsp;libncurses5-dev&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;this one line command is compile the kernel and its modules and make the binary form in deb file.&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make-kpkg --initrd --append-to-version=-ramki &amp;nbsp; &amp;nbsp;kernel_image &amp;nbsp; &amp;nbsp; kernel_headers&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;this one line make the kernel and its headers with custom suffix &lt;b&gt;-ramki&lt;/b&gt;&lt;br /&gt;&lt;span style=&quot;color: purple;&quot;&gt;&lt;b&gt;--initrd &lt;/b&gt;&lt;/span&gt;specify that make initramfs disk file&lt;br /&gt;&lt;span style=&quot;color: purple;&quot;&gt;&lt;b&gt;kernel_image&lt;/b&gt;&lt;/span&gt; option to make the kernel and its modules&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: purple;&quot;&gt;kernel_headers&lt;/span&gt;&lt;/b&gt; option to make all header files of the kernel. &lt;b&gt;(optional)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;the final output is its create 2 DEB files.&lt;br /&gt;&lt;br /&gt;Install the Deb files&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Install the deb file is simple. use dpkg tool like normal installation in&amp;nbsp;Debian&amp;nbsp;system&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;dpkg -i kernel_image-ramki-i386.deb&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;while executing this line install the kernel to &lt;b&gt;/boot&lt;/b&gt; folder. install the modules in &lt;b&gt;/lib/modules&lt;/b&gt; folder and create the &lt;b&gt;initramfs&lt;/b&gt; file and update the grub like generic way. all the above operation is happen automatically.&lt;br /&gt;&lt;br /&gt;then in optional case we can install the kernel_headers-ramki-i386.deb file.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;why need the kernel headers are important?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;kernel_image is enough to run the system. but when we need to install drivers, for example we need to install the new driver in&amp;nbsp;Linux&amp;nbsp; that time while compile the driver, that time need the&amp;nbsp;kernel&amp;nbsp;headers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In my system its works fine. i tested in VM also.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Reference:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;a href=&quot;http://www.howtoforge.com/kernel_compilation_ubuntu&quot; target=&quot;_blank&quot;&gt;How To Compile A Kernel - The Ubuntu Way&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html&quot; target=&quot;_blank&quot;&gt;How to: Compile Linux kernel 2.6&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Comments Welcomed&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;style&gt;.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);} &lt;/style&gt;&lt;/div&gt;&lt;div&gt;&lt;style&gt;.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);} &lt;/style&gt;&lt;/div&gt;&lt;div&gt;&lt;style&gt;.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);} &lt;/style&gt;&lt;/div&gt;&lt;div&gt;&lt;style&gt;.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);} &lt;/style&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/04/how-to-compile-kernel-step-by-step.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-VwizV9ywLPA/T5FL5ibXkmI/AAAAAAAACK0/JJtMFWHudUg/s72-c/uname.png" height="72" width="72"/><georss:featurename>Unknown location.</georss:featurename><georss:point>33.431441335575293 -67.5</georss:point></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-5609480529308880140</guid><pubDate>Tue, 20 Mar 2012 07:45:00 +0000</pubDate><atom:updated>2013-06-04T18:55:20.396+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">apache</category><category domain="http://www.blogger.com/atom/ns#">mod_jk</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><category domain="http://www.blogger.com/atom/ns#">virtual hosting</category><title>Virtual Host + Apache httpd server + Tomcat + mod_jk connector</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In my last post (&lt;a href=&quot;http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html&quot; target=&quot;_blank&quot;&gt;Virtual Host in Tomcat&lt;/a&gt;) we discussed about how setup the&amp;nbsp;virtual&amp;nbsp;host in Tomcat. Its cost effective&amp;nbsp;technique&amp;nbsp;because only one public IP is&amp;nbsp;enough&amp;nbsp;to host multiple domain. If we have big organization and each department want to host their website in locally in different machine. then how to&amp;nbsp;achieve&amp;nbsp;the virtual host concept?. In this post we will see the how we do this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Update : &amp;nbsp;&lt;/span&gt;&lt;/b&gt;I posted&amp;nbsp;&lt;a href=&quot;http://www.ramkitech.com/2013/02/virtual-host-nginx-tomcat.html&quot; target=&quot;_blank&quot;&gt;Virtual Host&amp;nbsp;+ Nginx&amp;nbsp;+ Tomcat&lt;/a&gt;&amp;nbsp;Its easy to configure, compare to Apache httpd server&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: purple; font-size: large;&quot;&gt;&lt;b&gt;Problem Scenario:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In big organization they have multiple department, each department want to host their website in different machine. so these websites are accessed locally with different local IP address.&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-TLyyrW-Wk6Y/T2gOrugVt0I/AAAAAAAAB_k/7kyCrNCHl3s/s1600/outline_structure.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;427&quot; src=&quot;http://1.bp.blogspot.com/-TLyyrW-Wk6Y/T2gOrugVt0I/AAAAAAAAB_k/7kyCrNCHl3s/s640/outline_structure.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;When we mapping to public address then we face the problem. We have two choice either purchase as many public&amp;nbsp;address&amp;nbsp;or Put one server front &amp;nbsp;and delegate these request.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;We going to use 2nd option. we put&amp;nbsp;Apache&amp;nbsp;httpd web server in front of all department servers. so only one public IP is enough. All domain DNS&amp;nbsp;entries&amp;nbsp;are pointed to Apache httpd server. Then Apache server delegates these request to corresponding tomcat server. This process is completely transparent from users(browser) perspective.&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-wWtKl_9eNvA/T2gOtW0LCVI/AAAAAAAAB_0/weXELW0y8ag/s1600/virtual_host_apache_and_tomcat_outline.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;414&quot; src=&quot;http://4.bp.blogspot.com/-wWtKl_9eNvA/T2gOtW0LCVI/AAAAAAAAB_0/weXELW0y8ag/s640/virtual_host_apache_and_tomcat_outline.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Outline Structure of Virtual Host Implementation&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;b&gt;&lt;span style=&quot;color: purple; font-size: large;&quot;&gt;How Apache httpd web server communicate to Tomcat server&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Before we going to detail about how communication happen between httpd server and tomcat&lt;br /&gt;&lt;br /&gt;How many ports are bind when we start single tomcat?&lt;br /&gt;&lt;ul&gt;&lt;li&gt;shutdown port&lt;/li&gt;&lt;li&gt;http connector port&lt;/li&gt;&lt;li&gt;https connector port (optional)&lt;/li&gt;&lt;li&gt;ajp port&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;The port configuration are stored in $CATALINA_HOME/conf/server.xml file. we can change the ports when its&amp;nbsp;necessary.&lt;br /&gt;&lt;br /&gt;here AJP&lt;b&gt;(&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;Apache JServ Protocol)&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&amp;nbsp;is a binary protocol that can proxy inbound requests from a web server through to an application server that sits behind the web server.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;Apache httpd webserver&amp;nbsp;communicate&amp;nbsp;to Tomcat sever through &lt;b&gt;AJP&lt;/b&gt; protocol&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;When we install&amp;nbsp;Apache&amp;nbsp;httpd server, It&amp;nbsp;don&#39;t&amp;nbsp;have&amp;nbsp;inbuilt&amp;nbsp;capability to support ajp protocol. so we need &lt;b&gt;mod_jk&lt;/b&gt; module. Its add the ajp support to&amp;nbsp;Apache&amp;nbsp;httpd server.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: purple; font-size: large;&quot;&gt;Steps to Implement Virtual Host Concept in this Scenario:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Install Apache httpd Web Server&lt;/li&gt;&lt;li&gt;Install mod_jk connector&lt;/li&gt;&lt;li&gt;Configure JK Connector&lt;/li&gt;&lt;li&gt;Configure Apache httpd server apply virtual host concepts&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;b&gt;Prerequisite&lt;/b&gt; : We already installed Tomcat in different departments and&amp;nbsp;deployed&amp;nbsp;the application and works fine.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Install Apache httpd web&amp;nbsp;server&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: xx-small;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;We can install&amp;nbsp;Apache&amp;nbsp;web server in two ways.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- Binary module&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;- From Source&lt;br /&gt;&lt;br /&gt;We can install Apache httpd server from distribution&amp;nbsp;package&amp;nbsp;manager (either apt-get or yum). Or we can download the source code and then compile and install.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note : -&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;we need to install apr, apr-util and pcre libraries because Apache httpd server&amp;nbsp;depends&amp;nbsp;on these libs.&lt;br /&gt;But these libraries are no need to install from source. because we not going to do any customization.&lt;br /&gt;so install these lib as binary using apt-get (debian/ubuntu) or yum command (redhat/fedora).&lt;br /&gt;&lt;br /&gt;in ubuntu u can search through&lt;br /&gt;&lt;br /&gt;sudo apt-cache search apr&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;we use second option. First download the httpd server source code from &lt;a href=&quot;http://httpd.apache.org/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&amp;nbsp;. then extract it and install&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;./configure --prefix=/usr/local/apache&lt;/b&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; --enable-rewrite=shared&amp;nbsp;&lt;/b&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;--enable-proxy=shared&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;sudo make install&lt;/b&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;here&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;--prefix&lt;/b&gt;&amp;nbsp;option to mention where the location we going to install&amp;nbsp;Apache&amp;nbsp;httpd server.&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;--enable-rewrite&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;--enable-proxy &lt;/b&gt;options to enable these module in shared mode. These modules&amp;nbsp;are&amp;nbsp;not needed now. but we used in future for rewrite the&amp;nbsp;URL&amp;nbsp;before handover to next chain of servers and load-balancing support.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;color: #990000; font-size: x-large;&quot;&gt;Install mod_jk connector&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;Now&amp;nbsp;Apache&amp;nbsp;httpd server is ready. we&amp;nbsp;need&amp;nbsp;to add ajp support to server.&lt;b style=&quot;color: #990000; font-size: x-large;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;download the mod_jk connector module from &lt;a href=&quot;http://tomcat.apache.org/download-connectors.cgi&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. extract it and install it&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;cd native&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;./configure &amp;nbsp; &amp;nbsp;-&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;-with-apxs=/usr/local/apache/bin/apxs&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;make&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;sudo make install&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here&amp;nbsp;&lt;b&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;-&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;-with-apxs&lt;/span&gt;&lt;/b&gt;&amp;nbsp;option to specify where apxs module is located. so we&amp;nbsp;need&amp;nbsp;to give&amp;nbsp;Apache&amp;nbsp;httpd server location.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;now&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;&amp;nbsp;mod_jk.so&lt;/span&gt; files is created on modules directory in apache installed location (/usr/local/apache/modules)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;!-- adsense --&gt;&lt;br /&gt;&lt;div&gt;&lt;b style=&quot;color: #990000; font-size: x-large;&quot;&gt;Configure mod_jk connector&lt;/b&gt;&lt;/div&gt;&lt;div&gt;This step have 2 sub step&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;&amp;nbsp; Create workers.properties file&lt;/li&gt;&lt;li&gt;&amp;nbsp; &amp;nbsp;Load and configure the JK connector module in apache httpd.conf file&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;Create workers.properties file&lt;/span&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;mod_jk connector is ready. but this connector is works based on configuration file. so we need to create configuration file called&lt;b style=&quot;background-color: #fff2cc;&quot;&gt; workers.properties&lt;/b&gt; file&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;this file syntax is&lt;span style=&quot;background-color: #fce5cd;&quot;&gt; key=value&lt;/span&gt;&amp;nbsp;pair,&lt;/div&gt;&lt;div&gt;here we define the workers. i.e all department tomcat hosts IP address and ajp port for corressponding tomcat.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here entry format is look like&lt;/div&gt;&lt;div&gt;&lt;b&gt;worker&lt;span style=&quot;color: #20124d;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;lt;name&amp;gt;&lt;/span&gt;.property=&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;lt;value&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;for example&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;div&gt;worker.&amp;lt;name&amp;gt;.type=ajp13&lt;/div&gt;&lt;div&gt;worker.&amp;lt;name&amp;gt;.port=&amp;lt;ajp port&amp;gt;&lt;/div&gt;&lt;div&gt;worker.&amp;lt;name&amp;gt;.host=&amp;lt;tomcat ip addr&amp;gt;&lt;/div&gt;&lt;div&gt;worker.list=&amp;lt;name&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here&amp;nbsp;&lt;/div&gt;&lt;div&gt;worker.list key have all workers name&amp;nbsp;separated&amp;nbsp;by comma.&lt;/div&gt;&lt;div&gt;type = here type of the worker. we use ajp13 version&amp;nbsp;&lt;/div&gt;&lt;div&gt;port= we specify the ajp port &lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;(not http port )&lt;/span&gt;&lt;/b&gt; of that server&lt;/div&gt;&lt;div&gt;host= IP address or host name of tomcat server&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;u&gt;workers.properties&lt;/u&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.list=department1,department2,department3&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department1.type=ajp13&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department1.port=5000&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department1.host=192.168.5.10&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department2.type=ajp13&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department2.port=5000&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department2.host=192.168.6.10&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department3.type=ajp13&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department3.port=5000&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;worker.department3.host=192.168.7.10&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;Add Entry in httpd.conf&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Apache httpd server is installed. mod_jk module is installed and&amp;nbsp;workers.properties file is created. but these 3 are isolated. we put together,&lt;br /&gt;we need to configure the httpd server.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;find the&lt;b&gt;&lt;span style=&quot;color: #fff2cc;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;conf/httpd.conf&lt;/span&gt;&lt;/b&gt; file in&amp;nbsp;Apache&amp;nbsp;installed location and add these following entries to it&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;LoadModule &amp;nbsp; &amp;nbsp;jk_module &amp;nbsp;modules/mod_jk.so&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkWorkersFile conf/workers.properties&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkLogFile &amp;nbsp; &amp;nbsp; logs/mod_jk.log&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkLogLevel &amp;nbsp; &amp;nbsp;emerg&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkLogStampFormat &quot;[%a %b %d %H:%M:%S %Y] &quot;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkOptions &amp;nbsp; &amp;nbsp; +ForwardKeySize +ForwardURICompat -ForwardDirectories&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;JkRequestLogFormat &amp;nbsp; &amp;nbsp; &quot;%w %V %T&quot;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here&lt;/div&gt;&lt;div&gt;LoadModule &amp;nbsp; &amp;nbsp;- Load mod_jk shared module to Apache httpd server (enable the mod_jk module)&lt;/div&gt;JkWorkersFile -&amp;nbsp;Specify&amp;nbsp;the workers.properties file location&lt;/div&gt;&lt;div&gt;all others are logging system of mod_jk. Its&amp;nbsp;boilerplate&amp;nbsp;code just copy and paste.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Delegate httpd to Tomcat&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;now we inform to Apache httpd server how delegate the request to corresponding server.&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;JkMount &amp;nbsp;/department1*&amp;nbsp;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;department1&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;JkMount &amp;nbsp;/department2* &lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;department2&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;JkMount &amp;nbsp;/department3*&amp;nbsp;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;department3&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here&lt;/div&gt;&lt;div&gt;JkMount -&amp;nbsp;specify&amp;nbsp;the if URL have /department1* pattern then that request delegate to department1 worker. that worker IP address and port is&amp;nbsp;specified&amp;nbsp;in workers.properties file.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Iwe changed /etc/hosts file like &lt;a href=&quot;http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html&quot; style=&quot;font-weight: bold;&quot; target=&quot;_blank&quot;&gt;last post&amp;nbsp;&lt;/a&gt;&amp;nbsp;all web site domain pointed to apache httpd web server.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if we access &lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;http://www.ramki.com/department1/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;how Apache httpd server process the request&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-Mjl4sHW_eks/T2gOurUxLbI/AAAAAAAAB_8/hhAqLLS9P3o/s1600/virtual_host_apache_and_tomcat_processing.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;457&quot; src=&quot;http://1.bp.blogspot.com/-Mjl4sHW_eks/T2gOurUxLbI/AAAAAAAAB_8/hhAqLLS9P3o/s640/virtual_host_apache_and_tomcat_processing.jpg&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Its perfectly called correct tomcat server and we got right response.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;but we have 2 problem&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;1.&lt;/b&gt; i don&#39;t want the my URL like this&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;http://www.ramki.com/department1/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; i want the my URL like this&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;http://www.ramki.com/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;remove the department1 from my URL. but&amp;nbsp;department1&amp;nbsp;string is very important in URL because JkMount is works based on this matching string only.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2.&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;http://www.ramki.com/department1/index.html&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&amp;nbsp; is for first tomcat and second department have domain &amp;nbsp; http://www.krishnan.com then&amp;nbsp;&lt;/div&gt;&lt;div&gt;access second tomcat we use URL :&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;http://www.krishnan.com/department2/index.html&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;but same time when we use&amp;nbsp;URL&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: #cc0000; font-weight: bold;&quot;&gt;http://www.krishnan.com/department1/index.html &lt;/span&gt;then we access first tomcat data&lt;/div&gt;&lt;div&gt;(i.e&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;)&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;http://www.ramki.com/department1/index.html &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #fce5cd;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;background-color: #fff2cc; color: #cc0000; font-weight: bold;&quot;&gt;http://www.krishnan.com/department1/index.html&lt;/span&gt;&lt;/div&gt;&lt;div&gt;because both these URL have department1 key word.. so JkMount is works based on these keyword. As the Result wrong interpretation. How to solve this Issue?.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;Virtual Host in Apache httpd Server&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;we need add conditional JkMount. for example ramki.com domain asks the whereare paths like&amp;nbsp;department1,department2 we need to search in that tomcat only. not other place. to add this&amp;nbsp;conditioned&amp;nbsp;we add virtual host entries.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Add virtual host entry in &lt;span style=&quot;background-color: #fce5cd;&quot;&gt;httpd.conf&lt;/span&gt; file&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;Listen 80&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;NameVirtualHost *:80&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; ServerName www.ramki.com&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; JkMount &amp;nbsp;/department1*&amp;nbsp;department1&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; ServerName www.krishnan.com&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; JkMount &amp;nbsp;/department2*&amp;nbsp;department1&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;here&lt;/div&gt;&lt;div&gt;ServerName - domain name of the server&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #cc0000; font-weight: bold;&quot;&gt;http://www.krishnan.com/department1/index.html &lt;/span&gt;URL is like this now. server matches the&amp;nbsp;Server Name. here its matches 2nd virtual host entry. There are single JkMount entry is there in 2nd&amp;nbsp;Virtual-Host. and there&amp;nbsp;no matching&amp;nbsp;department1 string.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;JkMount &amp;nbsp;/department2*&amp;nbsp;department1&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;as the result 404 error page is responded. Its works good.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Now everythig works fine.&amp;nbsp;&lt;/div&gt;&lt;div&gt;now my URL is&amp;nbsp;&amp;nbsp;&lt;b style=&quot;color: #cc0000;&quot;&gt;http://www.ramki.com/department1/index.html &lt;/b&gt;here i don&#39;t want department1 path in my URL.&lt;/div&gt;&lt;div&gt;i want simply &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #cc0000; font-weight: bold;&quot;&gt;http://www.ramki.com/index.html &lt;/span&gt;then we use &lt;span style=&quot;background-color: #fce5cd;&quot;&gt;&lt;b&gt;mod_rewrite &lt;/b&gt;&lt;/span&gt;engine&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;Listen 80&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;NameVirtualHost *:80&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ServerName www.ramki.com&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;RewriteEngine on&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;RewriteLog logs/apache-mod_rewrite&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;RewriteRule ^/(.*)$ /department1/$1 [L,PT]&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;JkMount &amp;nbsp;/* &amp;lt;dept_name&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white;&quot;&gt;here&lt;/div&gt;&lt;div style=&quot;background-color: white;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;RewriteEngine on&lt;/b&gt;&amp;nbsp;- Turn on the Rewrite module&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;RewriteRule ^/(.*)$ /department1/$1 [L,PT]&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; - here&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;^/(.*)$ &lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;its matches any string it capture the value to $1 and change the URL to /department1/$1&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;i.e&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #cc0000; font-weight: bold;&quot;&gt;http://www.ramki.com/index.html&lt;/span&gt;&amp;nbsp;here&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;^/(.*)$&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: white;&quot;&gt;its&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;matches&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp; index.html it capture to $1 and&amp;nbsp;replaced&amp;nbsp;to&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;/department1/$1 ==&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;/department1/index.html&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-NPbEsb2bFpQ/T2gOsqGcbMI/AAAAAAAAB_o/H-Dq1pQHrQs/s1600/virtual_host_apache_and_tomcat_final_processing.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;416&quot; src=&quot;http://1.bp.blogspot.com/-NPbEsb2bFpQ/T2gOsqGcbMI/AAAAAAAAB_o/H-Dq1pQHrQs/s640/virtual_host_apache_and_tomcat_final_processing.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Rewrite is happen before delegate the request to Tomcat. so we change the URL transparently to browser.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;now client (browser) just send http://www.ramki.com is enough to access the Department 1 Tomcat.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Update : &amp;nbsp;&lt;/span&gt;&lt;/b&gt;I posted &lt;a href=&quot;http://www.ramkitech.com/2013/02/virtual-host-nginx-tomcat.html&quot; target=&quot;_blank&quot;&gt;Virtual Host&amp;nbsp;+ Nginx&amp;nbsp;+ Tomcat&lt;/a&gt; Its easy to configure, compare to Apache httpd server&lt;/span&gt;&lt;/h3&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;I hope everything is clear. If any&amp;nbsp;misunderstanding&amp;nbsp;please&amp;nbsp;let me know.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;Screen Cast :&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/Njx1V4ZW_g0&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Comments Welcomed&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-TLyyrW-Wk6Y/T2gOrugVt0I/AAAAAAAAB_k/7kyCrNCHl3s/s72-c/outline_structure.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4180145408253964903</guid><pubDate>Fri, 24 Feb 2012 08:35:00 +0000</pubDate><atom:updated>2016-05-03T10:44:58.648+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><category domain="http://www.blogger.com/atom/ns#">virtual hosting</category><title>Understanding Virtual Host Concept in Tomcat</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Hi in this post we will see how to setup virtual host in Apache Tomcat server. Virtual Host is in-built feature that allows to deploy multiple website(domains) in single instance of tomcat server.&amp;nbsp;The main benefit in this way is its cost effective.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Scenario:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am going to deploy 3 website with following domain names in single tomcat&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;http://www.ramki.com&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;http://www.krishnan.com&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;http://www.blog.ramki.com&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The following diagram is my outline.&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-50MAYcJxTgU/T0cX8gVvjFI/AAAAAAAAB80/EQgsZq9FtmM/s1600/virtual_host_tomcat_outline.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;440&quot; src=&quot;http://3.bp.blogspot.com/-50MAYcJxTgU/T0cX8gVvjFI/AAAAAAAAB80/EQgsZq9FtmM/s640/virtual_host_tomcat_outline.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Outline structure of Virtual Host Concept in Tomcat&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Here my tomcat IP address 192.168.1.15. or any IP address allocated my ISP. but it should be public IP address.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;How all domain names are&amp;nbsp;pointing&amp;nbsp;to my Tomcat?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; When we purchase the domain name we need to update the our tomcat IP address to it.&amp;nbsp;like&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-95QlCfqRnZk/T0cgiGyyn4I/AAAAAAAAB9M/17OIGdre3WM/s1600/virtual_host_tomcat_dns_entries.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;152&quot; src=&quot;http://4.bp.blogspot.com/-95QlCfqRnZk/T0cgiGyyn4I/AAAAAAAAB9M/17OIGdre3WM/s400/virtual_host_tomcat_dns_entries.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;or we can simulate same DNS Setup through hosts file in both Linux and Windows.&amp;nbsp;In Linux tha file is located at&lt;b style=&quot;background-color: #fff2cc;&quot;&gt; /etc/hosts&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Now How Setup&amp;nbsp;Virtual Host Concept?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Before going to setup the virtual host. first take look at the&lt;b&gt; server.xml &lt;/b&gt;file in &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;conf &lt;/span&gt;folder in tomcat directory.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;server.xml&lt;/b&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xml&quot;&gt;&lt;![CDATA[ &lt;server port=&quot;8005&quot; shutdown=&quot;SHUTDOWN&quot;&gt;     &lt;service name=&quot;Catalina&quot;&gt;               &lt;engine defaulthost=&quot;localhost&quot; name=&quot;Catalina&quot;&gt;             &lt;host appBase=&quot;webapps&quot; autodeploy=&quot;true&quot; name=&quot;localhost&quot; unpackwars=&quot;true&quot;&gt;            &lt;/host&gt;        &lt;/engine&gt;   &lt;/service&gt;&lt;/server&gt; ]]&gt;&lt;/script&gt;&lt;br /&gt;here &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;Engine&amp;gt;&lt;/span&gt; tag specified which engine is responsible for executing servlet. Here &lt;span style=&quot;background-color: #d9ead3;&quot;&gt;&lt;b&gt;Catalina &lt;/b&gt;&lt;/span&gt;is the Engine.&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;lt;Host&amp;gt;&lt;/span&gt; tag &amp;nbsp;specify&amp;nbsp;the domain name and web apps base&amp;nbsp;location. here default domain name is localhost and web apps base&amp;nbsp;location&amp;nbsp;is webapps folder in tomcat directory.&amp;nbsp;here&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;name&amp;nbsp;&lt;/span&gt;&lt;/b&gt;attribute to specify the domain name and&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;appbase&amp;nbsp;&lt;/span&gt;&lt;/b&gt;attribute to specify the location of domain&amp;nbsp;specific&amp;nbsp;web apps folder path.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;Now we need to add more &amp;lt;Host&amp;gt; tags to represent to our domains&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;lt;Host&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt; name=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&quot;www.ramki.com&quot;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;&amp;nbsp;appbase=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&quot;ramki_webapps&quot;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;lt;Host&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt; name=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&quot;www.krishnan.com&quot;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;&amp;nbsp;appbase=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&quot;krishnan_webapps&quot;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt; /&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&amp;lt;Host&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt; name=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&quot;www.blog.ramki.com&quot;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;appbase=&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&quot;blog_webapps&quot;&lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt; /&amp;gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Then we need to copy the webapps folder in tomcat and paste it anywhere and rename it to &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;ramki_webapps, krishnan_webapps, blog_webapps&lt;/span&gt; and update the path in &amp;lt;Host&amp;gt; tag&lt;br /&gt;&lt;br /&gt;&lt;!-- adsense --&gt;&lt;br /&gt;&lt;br /&gt;Modifies &lt;b&gt;server.xml&lt;/b&gt; file&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xml&quot;&gt;&lt;![CDATA[ &lt;server port=&quot;8005&quot; shutdown=&quot;SHUTDOWN&quot;&gt;  &lt;service name=&quot;Catalina&quot;&gt;         &lt;engine defaulthost=&quot;localhost&quot; name=&quot;Catalina&quot;&gt;           &lt;host appbase=&quot;webapps&quot; autodeploy=&quot;true&quot; name=&quot;localhost&quot; unpackwars=&quot;true&quot;&gt;&lt;/host&gt;         &lt;host appbase=&quot;ramki_webapps&quot; autodeploy=&quot;true&quot; name=&quot;www.ramki.com&quot; unpackwars=&quot;true&quot;&gt;&lt;/host&gt;         &lt;host appbase=&quot;krishnan_webapps&quot; autodeploy=&quot;true&quot; name=&quot;www.krishnan.com&quot; unpackwars=&quot;true&quot;&gt;&lt;/host&gt;         &lt;host appbase=&quot;blog_webapps&quot; autodeploy=&quot;true&quot; name=&quot;www.blog.ramki.com&quot; unpackwars=&quot;true&quot;&gt;&lt;/host&gt;         &lt;/engine&gt;  &lt;/service&gt;&lt;/server&gt; ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Simulate the DNS&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;Open the&lt;b style=&quot;background-color: #fff2cc;&quot;&gt; /etc/hosts&lt;/b&gt; file through root&amp;nbsp;privilege and add following entry&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;192.168.1.15 &amp;nbsp; &amp;nbsp; &amp;nbsp; www.ramki.com&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;192.168.1.15 &amp;nbsp; &amp;nbsp; &amp;nbsp; www.krishnan.com&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;192.168.1.15 &amp;nbsp; &amp;nbsp; &amp;nbsp; www.blog.ramki.com&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;deploy the websites to&amp;nbsp;respective&amp;nbsp;web apps folder and start the tomcat.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;Test:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;now open the browser and type&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; http://www.ramki.com &lt;/span&gt;then its shows the ramk website content. Other two sites&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; www.krishnan.com&lt;/span&gt; and &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;www.blog.ramki.com &lt;/span&gt;works respective webapps.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-V1tHM3N6s0o/T0cX-iGgqjI/AAAAAAAAB9A/h_q4r5vzulQ/s1600/virtual_host_tomcat_request_processing.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;360&quot; src=&quot;http://2.bp.blogspot.com/-V1tHM3N6s0o/T0cX-iGgqjI/AAAAAAAAB9A/h_q4r5vzulQ/s640/virtual_host_tomcat_request_processing.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;In above diagram represent when we access&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; www.ramki.com&lt;/span&gt; the tomcat server consult with&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt; server.xml&lt;/b&gt;&lt;/span&gt; file and serves the files from&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; ramki_webapps&lt;/span&gt; directory.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;How is Virtual Host Works&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Here big question all websites are pointed to same tomcat. How tomcat can&amp;nbsp;distinguished&amp;nbsp;the request. (i.e) how tomcat knows browser requested ramki.com or www.krishnan.com&lt;br /&gt;&lt;br /&gt;The answer is based &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;Host &lt;/b&gt;&lt;/span&gt;header field in HTTP request.&lt;br /&gt;when we accssed www.ramki.com then browser make HTTP request. and the request look like this&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;GET / HTTP/1.1&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Host: www.ramki.com&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Proxy-Connection: keep-alive&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Accept-Encoding: gzip,deflate,sdch&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Accept-Language: en-US,en;q=0.8&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: white; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; white-space: pre-wrap;&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; white-space: pre-wrap;&quot;&gt;ere Host Field contain domain name&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;b style=&quot;-webkit-text-size-adjust: none; background-color: #fff2cc; font-family: Consolas, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap;&quot;&gt;Host: www.ramki.com&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;when tomcat receive the request from any browser, it read the Host field and understand which domain we requested, then consult the server.xml file and delegate to appropriate Host process thread&lt;br /&gt;&lt;br /&gt;check my&amp;nbsp;screen&amp;nbsp;cast for setup&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue; text-align: center;&quot;&gt;Comments are welcomed&lt;/span&gt; &lt;br /&gt;&lt;span style=&quot;color: blue; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;screen-cast:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Consolas, &#39;Lucida Console&#39;, monospace;&quot;&gt;&lt;span style=&quot;-webkit-text-size-adjust: none; font-size: 12px; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/V598VXQzTog?rel=0&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;div&gt;&lt;style&gt;.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);} &lt;/style&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-50MAYcJxTgU/T0cX8gVvjFI/AAAAAAAAB80/EQgsZq9FtmM/s72-c/virtual_host_tomcat_outline.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-2138008618074123921</guid><pubDate>Mon, 02 Jan 2012 10:27:00 +0000</pubDate><atom:updated>2017-03-23T17:55:19.369+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">bootloader</category><category domain="http://www.blogger.com/atom/ns#">grub</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">themes</category><title>Understanding the GRUB boot loader and Customize the themes</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In this post we will discuss the&lt;span style=&quot;color: #cc0000;&quot;&gt; GRUB2 (GRand Unified&amp;nbsp;Boot-loader)&lt;/span&gt; in&amp;nbsp;Linux. recently i surfing the&amp;nbsp;Linux&amp;nbsp;base concepts then i came to know about grub2. here i ll share what is&amp;nbsp;boot loader?, how grub2 boot loader is works? and how we can&amp;nbsp;customize? and how we apply the themes?&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;What is the&amp;nbsp;Boot Loader&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Boot loader is small code reside in &lt;a href=&quot;http://en.wikipedia.org/wiki/Master_boot_record&quot; target=&quot;_blank&quot;&gt;MBR &lt;/a&gt;to load the&amp;nbsp;kernel(core) of the operating system and give the control to OS. When PC is switched on the system controls goes to BIOS. Bios initialize the&amp;nbsp;peripherals&amp;nbsp;and check the booting order of the device then select the highest priority of the device execute the code stored in MBR of that device. Each&amp;nbsp;Operating&amp;nbsp;System shipped with&amp;nbsp;boot loader&lt;br /&gt;&lt;br /&gt;For Example :-&lt;br /&gt;Microsoft&amp;nbsp;Windows&amp;nbsp;up to&amp;nbsp;Windows XP comes with &amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/NTLDR&quot; target=&quot;_blank&quot;&gt;NTLDR &lt;/a&gt;boot loader&lt;br /&gt;From Windows Vista&amp;nbsp;onward&amp;nbsp;they use &lt;a href=&quot;http://en.wikipedia.org/wiki/Windows_Vista_startup_process&quot; target=&quot;_blank&quot;&gt;BOOTMGR &lt;/a&gt;as a&amp;nbsp;boot loader.&lt;br /&gt;These&amp;nbsp;boot loaders&amp;nbsp;are&amp;nbsp;specifically&amp;nbsp;designed to load Windows OS. If want use these&amp;nbsp;boot loader&amp;nbsp;to boot other OS (Linux, Mac OS X) then we need to tweak using 3rd party tools like &lt;a href=&quot;http://neosmart.net/EasyBCD/&quot; target=&quot;_blank&quot;&gt;easyBCD&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For Linux Operating System uses many&amp;nbsp;different&amp;nbsp;boot loaders as distro choice like &lt;a href=&quot;http://en.wikipedia.org/wiki/SYSLINUX&quot; target=&quot;_blank&quot;&gt;ISOLINUX&lt;/a&gt;, &lt;a href=&quot;http://en.wikipedia.org/wiki/LILO_(boot_loader)&quot; target=&quot;_blank&quot;&gt;LILO&lt;/a&gt;, &lt;a href=&quot;http://en.wikipedia.org/wiki/GNU_GRUB&quot; target=&quot;_blank&quot;&gt;GRUB&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here we talk about GRUB2 boot loader.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;What is Master Boot Record (MBR)?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Master Boot Record (MBR) is one block with 512 bytes. Its located in first sector of HDD, CD, other device. Its holds the partition entries and boot code.&lt;br /&gt;Following MBR block, the actual partition are begin.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-NwYoKEwN4Hc/TwFo6L8SYZI/AAAAAAAAB6c/iOBGeBxnYsk/s1600/MBR.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;122&quot; src=&quot;https://1.bp.blogspot.com/-NwYoKEwN4Hc/TwFo6L8SYZI/AAAAAAAAB6c/iOBGeBxnYsk/s400/MBR.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;This is helps if disconnect the HDD and connected to other machine, that machine understands ur partitions and file systems.&lt;br /&gt;&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-VmKj_LMvAHo/TwFo7JyI9YI/AAAAAAAAB6o/Yuc0GkIgecE/s1600/mbr-detail.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;497&quot; src=&quot;https://2.bp.blogspot.com/-VmKj_LMvAHo/TwFo7JyI9YI/AAAAAAAAB6o/Yuc0GkIgecE/s640/mbr-detail.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;HDD Layout and MBR&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;We know Total size of MBR is 512 bytes. In this &lt;span style=&quot;background-color: #fff2cc; color: purple;&quot;&gt;446 bytes for Boot code&lt;/span&gt; (Boot loader code) and &lt;span style=&quot;color: purple;&quot;&gt;4 Partition entry, each 16 bytes long&lt;/span&gt; (64 bytes) and 2 bytes MBR signature.&lt;br /&gt;&lt;br /&gt;Here this is&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp;limitation&amp;nbsp;that one hdd is maximum 4 primary partition or 3 primary&amp;nbsp;partition&amp;nbsp;and 1 logical&amp;nbsp;partition&lt;/span&gt;. The reason is MBR can store maximum 4 entry in partition table.&lt;br /&gt;&lt;br /&gt;If we use logical partition, its not actually&amp;nbsp; partition&amp;nbsp;&amp;nbsp;its another partition entry tables. its called &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;extended partition table&lt;/span&gt;, it&amp;nbsp;contain&amp;nbsp;many entries to logical volumes. (see the above diagram)&lt;br /&gt;&lt;br /&gt;Here each volume (or) partition has&amp;nbsp;separate&amp;nbsp;boot sector its called &lt;a href=&quot;http://en.wikipedia.org/wiki/Volume_boot_record&quot; target=&quot;_blank&quot;&gt;volume boot record&lt;/a&gt; apart from MBR. its used for&amp;nbsp;chain-loader of boot loader. The reason is grub boot loader can boot all&amp;nbsp;Linux&amp;nbsp;and some&amp;nbsp;Unix&amp;nbsp;also (freeBSD, netBSD, openBSD).&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #ffe599; color: #990000;&quot;&gt; &amp;nbsp; &amp;nbsp; GRUB Boot loader --&amp;gt; Load Linux Kernel&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: #ffe599; color: #990000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;But it can&#39;t load the windows OS because GRUB don&#39;t know about Windows&amp;nbsp;start-up&amp;nbsp;process. Only Windows&amp;nbsp;Boot-loader&amp;nbsp;know about this. Windows Boot-loader stored in volume boot sector. First Grub is loaded and show the menu. Is user select the windows then GRUB load the volume boot sector code and give the control.&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;color: #990000;&quot;&gt;GRUB Boot loader --&amp;gt; Windows Boot loader --&amp;gt; Load Windows Kernel&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Here one limitation for some boot loaders&amp;nbsp;&amp;nbsp;like Windows boot-loader. They can&#39;t boot the OS, if OS is installed in logical partition.&amp;nbsp;that&#39;s&amp;nbsp;why windows OS we must install in primary partition. because that boot code can&#39;t capable to access the logical volume.&lt;br /&gt;&lt;br /&gt;The reason is if OS is installed primary partition then boot loaders easily can find the partition, because MBR contain primary partition entry.&lt;br /&gt;&lt;br /&gt;But when u installed in logical partition then that partition entry is residing&amp;nbsp;extended&amp;nbsp;partition table. Boot loader get overhead to&amp;nbsp;interpret&amp;nbsp;the&amp;nbsp;extended&amp;nbsp;&amp;nbsp; partition&amp;nbsp;table and get the entry then load the OS.&lt;br /&gt;&lt;br /&gt;&lt;!-- adsense --&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;Why GRUB2?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;we already seen for&amp;nbsp;Linux&amp;nbsp;there are many boot loader.&amp;nbsp;now&amp;nbsp;let see why GRUB2 is more powerful than others.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;GRUB2 is completely rewritten from original GRUB&lt;/li&gt;&lt;li&gt;Its modular based, so we can load any module when its needed&lt;/li&gt;&lt;li&gt;Its supports menu and themes&lt;/li&gt;&lt;li&gt;GRUB2 acts as a mini OS, we can mount many&amp;nbsp;file-system&lt;/li&gt;&lt;li&gt;Its capable to boot ISO&amp;nbsp;Linux&amp;nbsp;directly. &lt;a href=&quot;http://michael-prokop.at/blog/2009/05/25/boot-an-iso-via-grub2/&quot; target=&quot;_blank&quot;&gt;check here&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Its capable to load the OS&amp;nbsp;even though&amp;nbsp;its installed logical volume.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;GRUB2 comes as a default boot loader in many&amp;nbsp;Linux&amp;nbsp;like Ubuntu 9&amp;nbsp;onward&#39;s.&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-i1sg-KVkx7A/TwFo3ImXF6I/AAAAAAAAB6I/KIsdWESzj9U/s1600/grub.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;302&quot; src=&quot;https://3.bp.blogspot.com/-i1sg-KVkx7A/TwFo3ImXF6I/AAAAAAAAB6I/KIsdWESzj9U/s400/grub.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Normal GRUB Menu&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;How GRUB2 Works?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; In 446 bytes in MBR is &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;not enough&lt;/span&gt; to put entire grub code. so MBR contain small code called&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;boot.img&lt;/span&gt; &lt;/b&gt;and its capable to read first block of &lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;core.img&lt;/b&gt;&lt;/span&gt; file from any partition (logical volume too) before partition is mounted. Because that time they cant understand the file system. so they read directly one sector (block) where core.img file is located.&lt;br /&gt;&lt;br /&gt;The first block of core.img is called &lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;diskboot.img&lt;/span&gt;&lt;/b&gt; for HDD&amp;nbsp;or &lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;b&gt;cdboot.img&lt;/b&gt;&lt;/span&gt; for cd-rom or &lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;pxeboot.img&lt;/span&gt;&lt;/b&gt; for network boot. This block contain many address of blocks , to iterate these address and load blocks then the complete&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt; core.img &lt;/span&gt;&lt;/b&gt;(around 32 KB) comes into memory. This is job for boot code in GRUB.&lt;br /&gt;&lt;br /&gt;Actually &lt;b style=&quot;color: #cc0000;&quot;&gt;core.img&lt;/b&gt; file is generated when GRUB is installed . This file contain one or more necessary module to mount the File system, where GRUB is installed. So&amp;nbsp;&lt;b style=&quot;color: #cc0000;&quot;&gt;core.img&lt;/b&gt;&amp;nbsp;file is responsible for mount the File system and access the GRUB configuration file.&amp;nbsp;Once file system is mounted then we can&amp;nbsp;access&amp;nbsp;the files&amp;nbsp;normal&amp;nbsp;like&amp;nbsp;Linux. All other modules are located /boot/grub. Its loaded when its needed.&lt;br /&gt;&lt;br /&gt;All grub related configuration (menu entries, graphics resolution, timeout, etc...) are stored &lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;grub.cfg&lt;/span&gt;&lt;/b&gt; file in &lt;span style=&quot;color: #cc0000;&quot;&gt;/boot/grub/&lt;/span&gt; location. No need to put this line in MBR. because once File system is mounted then we can access through path &lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;/boot/grub/grub.cfg&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;now we see 2&amp;nbsp;important&amp;nbsp;command for GRUB&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;sudo update-grub &amp;nbsp; &amp;nbsp;&lt;/span&gt;(or) &lt;span style=&quot;color: #cc0000;&quot;&gt;sudo mk-config&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;this command generate the grub.cfg file dynamically. &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;Its &lt;b&gt;not update&lt;/b&gt;&lt;/span&gt; into MBR or volume boot record. Its just generate configuration file.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;sudo grup-install /dev/sda&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;this command &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;update the GRUB code in MBR&lt;/span&gt;. Its overwrite other boot loader code. (here sda is our HDD and dont mention any partition number)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;sudo grup-install /dev/sda5&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;this command update the GRUB code in Volume boot record. (here sda is our HDD and 5 is 5th partition)&lt;br /&gt;&lt;br /&gt;If u want to install GRUB in pendrive&lt;br /&gt;first mount the pendrive and use grup-install command with --root-directory option&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;sudo grup-install --root-directory=/media/pendrive /dev/sdb&lt;/span&gt;&lt;/b&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp;here /media/pendrive is mount point of pendrive and /dev/sdb is device file for pen drive , when want to know the device file run &lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;sudo fdisk -l&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;How grub.cfg file is generated?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; when i run the &lt;span style=&quot;color: #990000;&quot;&gt;update-grub&lt;/span&gt; command then its generate the&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt; grub.cfg&lt;/span&gt;&lt;/b&gt; file. But how?&lt;br /&gt;&lt;br /&gt;When install grub on our machine (its time of OS installation) they created some&amp;nbsp;supporting&amp;nbsp;files. they located in &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;/etc/default/grub &lt;/span&gt;&lt;/b&gt;file and&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt; /etc/grub.d/ &lt;/span&gt;&lt;/b&gt;folder.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;/etc/default/grub &lt;/span&gt;- contain environment variables of GRUB&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;/etc/grub.d/&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;- contain some helper scripts files like theme,OS probe,custom scripts file&lt;br /&gt;&lt;br /&gt;When we run update-grub command then its called scripts files sequentially&amp;nbsp;accenting&amp;nbsp;number order. These scripts files read environment variables from&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;/etc/default/grub&amp;nbsp;&lt;/span&gt;&lt;/b&gt;file and generate the&amp;nbsp;&amp;nbsp;grub.cfg file&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;grub.cfg&lt;/span&gt;&lt;/b&gt;&amp;nbsp;file is read only. so don&#39;t modify directly&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;Customize&amp;nbsp;the GRUB menu&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;grub.cfg&lt;/span&gt;&lt;/b&gt;&amp;nbsp;file is read only. so we need to modify the environment file or script file for customization.&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;Very important Note :&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&amp;nbsp; &amp;nbsp; If u modify the&amp;nbsp;&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;/etc/default/grub file &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;or&lt;/span&gt;&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;/etc/grub.d/ &lt;/span&gt;scripts &amp;nbsp;then its not reflected in &lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;grub.cfg file.&lt;/span&gt;&amp;nbsp;So we must call the &lt;b&gt;update-grub&lt;/b&gt; command to reflect these changes into &lt;b&gt;grub.cfg.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;1) Grub Time-Out&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;When we start the system, grub menu&amp;nbsp;appears&amp;nbsp;and wait for some time, is u not select the menu they load the default menu.&lt;br /&gt;if u want to modify&amp;nbsp;the&amp;nbsp;time out&amp;nbsp;option&amp;nbsp;then change &lt;span style=&quot;color: blue;&quot;&gt;GRUB_TIMEOUT=30&lt;/span&gt; in&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;/etc/default/grub&amp;nbsp;&lt;/span&gt;&lt;/b&gt;file&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;2) Change Graphics Resolution&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;Usually&amp;nbsp;graphics&amp;nbsp;menu appears in low graphics resolution like 640x480. If u know the resolution then change &lt;span style=&quot;color: blue;&quot;&gt;GRUB_GFXMODE&lt;/span&gt; environment&amp;nbsp;variable&lt;br /&gt;for ex: &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;GRUB_GFXMODE&amp;nbsp;= 1024x768x32,640x480 &lt;/span&gt;here &lt;span style=&quot;color: blue;&quot;&gt;width&amp;nbsp;&lt;/span&gt;x&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;height &lt;/span&gt;x&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;bit-depth&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;2) Change GRUB Background&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Grub menu appears in normal black background. If u want to change the image of the background then create &lt;span style=&quot;color: blue;&quot;&gt;GRUB_BACKGROUND&lt;/span&gt; variable.&lt;br /&gt;ex:&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;GRUB_BACKGROUND=/home/ramki/Desktop/ram.jpg&lt;/span&gt;&lt;br /&gt;Its accepts jpg,png,ttf format images&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-JRW86pi2hC8/TwFo4as703I/AAAAAAAAB6Q/DSB60d6Jhao/s1600/grub-background.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;476&quot; src=&quot;https://3.bp.blogspot.com/-JRW86pi2hC8/TwFo4as703I/AAAAAAAAB6Q/DSB60d6Jhao/s640/grub-background.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;GRUB with background&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;If u want change the font colors and highlighting color.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;Apply the Theme (see the video)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;b style=&quot;color: #990000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;&amp;nbsp; Above&amp;nbsp;customization are just change the color and background. They not change the menu&amp;nbsp;position&amp;nbsp;and we can&#39;t add new&amp;nbsp;labels&amp;nbsp;and&amp;nbsp;progress&amp;nbsp;bar.&lt;br /&gt;&lt;br /&gt;We can build the theme with some components (boot_menu, progress_bar, image, vbox, hbox) arranged our own way position and size in theme definition file.&lt;br /&gt;&lt;br /&gt;each component have left,top,width,height properties. we can&amp;nbsp;mention&amp;nbsp;in pixel value or in percentage vale. Percentage is&amp;nbsp;recommended.&lt;br /&gt;after theme is created then we need to specify in GRUB_THEME variable in /etc/default/grub file&lt;br /&gt;&lt;br /&gt;ex:&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;GRUB_THEME = /boot/grub/theme/theme.txt&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;This is screenshot of simple theme i used&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-JG4fHZFNFAU/TwFo5ZH6K2I/AAAAAAAAB6Y/pvICR_4erA0/s1600/grub-themes.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;478&quot; src=&quot;https://2.bp.blogspot.com/-JG4fHZFNFAU/TwFo5ZH6K2I/AAAAAAAAB6Y/pvICR_4erA0/s640/grub-themes.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;After&amp;nbsp;Applying&amp;nbsp;Theme&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&amp;nbsp;Here we can use custom fonts also. but our fonts are not directly supported. we need to convert into pf2 format&amp;nbsp;then&amp;nbsp;we can use it.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;b&gt;sudo grup-mkfont --size=14 --range=0x0-0x7F --output=aerial.pf2 aerial.ttf&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;above line convert the aerial.ttf font to pf2 format with size is 14 and cover all character range.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;If u want the above theme, u can get it &lt;a href=&quot;https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/ramki-projects/theme.zip&quot; target=&quot;_blank&quot;&gt;from here &amp;nbsp;&lt;/a&gt;&amp;nbsp;&lt;/b&gt;then u modify the background image and other details&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;&lt;b&gt;Update 1 :&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #cc0000; font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;b&gt;Why we need to install bootloader in Volume Boot Record (VBR)?&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; The reason is if MBR bootloader is not capable to boot Particular OS then that boot loader do the chain loading to load VBR boot loader and gives the control.&lt;br /&gt;&lt;br /&gt;for example there are 5 OS is there, but only one OS boot loader can sit in MBR. If that MBR bootloader is not capable to load other OS then how to load other OS. the answer is chain loading.&lt;br /&gt;&lt;br /&gt;so all 5 os install in different partition then bootloader is installed in VBR and MBR. but MBR is overrides based on which on recently installed. but VBR have one more copy of that OS specific boot loader. If MBR boot loader is capable to boot&amp;nbsp;another&amp;nbsp;OS then no need VBR boot loader. But If MBR&amp;nbsp;bootloader&amp;nbsp;is not capable to boot particular OS then MBR boot loader load the particular OS partition VBR and gives the control. now VBR boot loader can boot that OS.&lt;br /&gt;&lt;br /&gt;simple, 2 OS is there windows in sda2 partition and Linux in sda3 partition. and each partition contain their respective boot loader code in VBR. &amp;nbsp;so sda2 VBR contain windows boot loader.&lt;br /&gt;&lt;br /&gt;If GRUB bootloader is in MBR section, then it can load all Unix/Linux OS,but its can&#39;t load Windows OS. But windows boot loader is in sda2 VBR. so GRUB is load sda2 VBR to memory and gives control to it. Now Windows boot loader execute and load the Windows kernel.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Screen cast (Watch in HD)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/lCbQwrAQi8E&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;comments are welcomed&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;This entire post is based on my understanding of GRUB. If anything wrong or i misunderstood please let me know.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Resources:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/GNU_GRUB&quot;&gt;http://en.wikipedia.org/wiki/GNU_GRUB&lt;/a&gt; &lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://help.ubuntu.com/community/Grub2&quot;&gt;https://help.ubuntu.com/community/Grub2&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://grub.gibibit.com/&quot;&gt;http://grub.gibibit.com/&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://www.dedoimedo.com/computers/grub-2.html&quot;&gt;http://www.dedoimedo.com/computers/grub-2.html&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;http://www.4shared.com/file/lFCl6wxL/grub_guidetar.html&quot; target=&quot;_blank&quot;&gt;The ThemingDefinitive Guide to &amp;nbsp;GRUB2&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2012/01/grub2-and-themes-customization.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://1.bp.blogspot.com/-NwYoKEwN4Hc/TwFo6L8SYZI/AAAAAAAAB6c/iOBGeBxnYsk/s72-c/MBR.jpg" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-4178792325497526356</guid><pubDate>Wed, 07 Dec 2011 09:22:00 +0000</pubDate><atom:updated>2016-05-03T10:47:03.606+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">attack</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">javaEE</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">security</category><category domain="http://www.blogger.com/atom/ns#">sqlinjection</category><category domain="http://www.blogger.com/atom/ns#">vulnerability</category><title>Beware of SQLInjection in Java Application</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;Hi In this post we will discuss what is &lt;a href=&quot;http://en.wikipedia.org/wiki/SQL_injection&quot; target=&quot;_blank&quot;&gt;SQL Injection&lt;/a&gt; attack. and how its may affect ur any &amp;nbsp;web application its use the backend database. Here i concentrate on java web application. &lt;a href=&quot;http://www.applicure.com/blog/owasp-top-10-2010&quot; target=&quot;_blank&quot;&gt;Open Web Application Security Project(OWAP)&lt;/a&gt; listed that SQL Injection is the top vulnerability attack for web application. Hacker&#39;s they Inject the SQL code in web request to the web application and take the control of backend database, even that backend database is not directly connected to internet. And we will see how to solve and prevent the SQL Injection in java Web Application.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;For this purpose we need 1 tools. these tool are completely open source.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;SQL Map - SqlMap is an open source penetration testing tool that automates the process of detecting and exploiting SQL Injection. we can get it from &lt;a href=&quot;http://sqlmap.sourceforge.net/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-family: arial, helvetica, sans-serif; font-size: large;&quot;&gt;&lt;u&gt;SQLInjection&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SQL injection is the technique to extract the database information through web application.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red; font-family: arial, helvetica, sans-serif;&quot;&gt;Scenario:&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;we have one database server [MySQL] and web application server [Tomcat]. consider that database server is not connected to internet. but its connected with application server. Now we will see using web application how to extract the information using sql-injection method.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;Before see the&amp;nbsp;sql-injection,&amp;nbsp;we create small web application. It contain single jsp page like this&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #ffd966; color: red;&quot;&gt;&amp;nbsp;&amp;lt;form action=&quot;userCheck&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #ffd966; color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;input type=&quot;text&quot; name=&quot;user&quot; value=&quot;&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #ffd966; color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;input type=&quot;submit&quot; value=&quot;Submit&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #ffd966; color: red;&quot;&gt;&amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&amp;nbsp;In userCheck Servlet receives the user input field and connect to databse server and fire the sql query based on user input and receive the ResultSet and iterate it print into the web page.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, helvetica, sans-serif;&quot;&gt;&lt;u&gt;userCheck servlet&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ protected void processRequest(HttpServletRequest request, HttpServletResponse response)             throws ServletException, IOException {         response.setContentType(&quot;text/html;charset=UTF-8&quot;);         PrintWriter out = response.getWriter();         try {              String user = request.getParameter(&quot;user&quot;);             Connection conn = null;             String url = &quot;jdbc:mysql://192.168.2.128:3306/&quot;;             String dbName = &quot;anvayaV2&quot;;             String driver = &quot;com.mysql.jdbc.Driver&quot;;             String userName = &quot;root&quot;;             String password = &quot;&quot;;             try {                 Class.forName(driver).newInstance();                 conn = DriverManager.getConnection(url + dbName, userName, password);                  Statement st = conn.createStatement();                 String query = &quot;SELECT * FROM  User where userId=&#39;&quot; + user + &quot;&#39;&quot;;                 out.println(&quot;Query : &quot; + query);                 System.out.printf(query);                 ResultSet res = st.executeQuery(query);                  out.println(&quot;  Results&quot;);                 while (res.next()) {                     String s = res.getString(&quot;username&quot;);                     out.println(&quot;  \t\t&quot; + s);                 }                 conn.close();              } catch (Exception e) {                 e.printStackTrace();             }         } finally {             out.close();         }  ]]&gt;&lt;/script&gt;When we execute the above code. In normal input execution look like follows&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-3aQo3YIE_Z0/Tt8e-A5v28I/AAAAAAAAB5Y/eH4GdqkSfZY/s1600/sample_application.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-3aQo3YIE_Z0/Tt8e-A5v28I/AAAAAAAAB5Y/eH4GdqkSfZY/s1600/sample_application.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;When we give the normal value like &quot;ramki&quot; then click the submit button then output like this&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-QxN3tQW-jHs/Tt8e_1h5-FI/AAAAAAAAB5o/Cn7BvX2GpjM/s1600/sample_application_output.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-QxN3tQW-jHs/Tt8e_1h5-FI/AAAAAAAAB5o/Cn7BvX2GpjM/s1600/sample_application_output.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Its perfectly correct in normal behaviour. what happen when i put some special character or some sql statement in input box like this&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-UsUhr_FiXmA/Tt8fAwtT12I/AAAAAAAAB5w/FdDFzRYGHaU/s1600/sql_injection.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-UsUhr_FiXmA/Tt8fAwtT12I/AAAAAAAAB5w/FdDFzRYGHaU/s1600/sql_injection.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;when we click the submit button then it show all rows in my table like this&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-xf2dqqqqfZg/Tt8fBtSq1eI/AAAAAAAAB50/aB-YuDStquA/s1600/sql_injection_output.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-xf2dqqqqfZg/Tt8fBtSq1eI/AAAAAAAAB50/aB-YuDStquA/s1600/sql_injection_output.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Its big security breach in my application. what happen... Its one kind of sql injection&lt;br /&gt;&lt;br /&gt;lets see what happen&lt;br /&gt;when i enter normal value in input box my servlet receives and substitute in the sql query and&amp;nbsp;execute&amp;nbsp;it.&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;SELECT * FROM &amp;nbsp;User where userId=&#39;&lt;/span&gt; &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;ramki&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&#39;&lt;/span&gt;&lt;/div&gt;its correct and we got correct output.&lt;br /&gt;&lt;br /&gt;what happen when i put &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;sdfssd&#39; or &#39;1&#39;=&#39;1&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;userId&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;=&#39;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;sdfssd&#39; or &#39;1&#39;=&#39;1&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&#39;&lt;/span&gt;&lt;/div&gt;its means&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;userId&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;=&#39;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;sdfssd&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&#39; or &#39;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&#39;=&#39;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&#39;&lt;/span&gt;&lt;/div&gt;like this. so our query is altered. now new query have 2 condition. 2nd&amp;nbsp;condition&amp;nbsp;always true. 1st&amp;nbsp;condition&amp;nbsp;may be or may not be true. but these 2&amp;nbsp;condition&amp;nbsp;are connected with or logic. so where clause always true for all rows. the result is they bring all rows from our tables.&lt;br /&gt;&lt;br /&gt;This is called blind sql injection. If u want more details of sql injection the check here&lt;br /&gt;&lt;a href=&quot;http://www.unixwiz.net/techtips/sql-injection.html&quot;&gt;http://www.unixwiz.net/techtips/sql-injection.html&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://www.imperva.com/resources/glossary/sql_injection.html&quot;&gt;http://www.imperva.com/resources/glossary/sql_injection.html&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://www.applicure.com/blog/owasp-top-10-2010&quot;&gt;http://www.applicure.com/blog/owasp-top-10-2010&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now we can enter the sql statement directly in input box&lt;br /&gt;like&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt; ramki&#39;&amp;nbsp;UNION SELECT * FROM mysql.`user` u --&lt;/span&gt;&lt;br /&gt;then&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;userId&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;=&#39;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;ramki&#39;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;UNI&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;ON SELECT * FROM mysql.`user` u --&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;&#39;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;then its&amp;nbsp;&lt;/span&gt;means&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;SELECT * FROM &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;User&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;where&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;userId&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;=&#39;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;ramki&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;UNION SELECT * FROM mysql.`user` u --&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: magenta; text-align: center;&quot;&gt;&#39;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;here they wont use * because its not&amp;nbsp;matched&amp;nbsp;with first table. so they find how many columns then use Union with second table.the user&amp;nbsp;particular&amp;nbsp;column they want . as result the get mysql database user information its exposed through our web application.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;sqlmap&lt;br /&gt;It comes with a powerful detection engine, many niche features for the ultimate penetration tester and a broad range of switches lasting from database fingerprinting, over data fetching from the database&lt;br /&gt;&lt;br /&gt;Install the sqlmap in ur system or use &lt;a href=&quot;http://www.backtrack-linux.org/&quot; target=&quot;_blank&quot;&gt;BackTrack Linux&lt;/a&gt;&lt;br /&gt;Here I used backtrack linux. because its already pre installed lots of applications like sqlmap.&lt;br /&gt;In backtrack, sqlmap is located in /pentest/web/scanner/sqlmap&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;sqlmap commands&lt;/span&gt;&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;retrieve&amp;nbsp;all databases&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki&amp;nbsp; --dbs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;retrieve&amp;nbsp;all tables&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test --tables&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;retrieve&amp;nbsp;all columns from particular table&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test -T User --columns&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;Dump all column valued &amp;nbsp;from particular table&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test -T User --dump&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;Dump some column valued &amp;nbsp;from particular table&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;./sqlmap.py -u&amp;nbsp;http://localhost:8080/SQLInject/userCheck?user=ramki &amp;nbsp;-D test -T User -C userId,password --dump&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See the video for full demo (watch in HD)&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/C5PQ86nWMkM&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #990000; font-size: large;&quot;&gt;How To Prevent SQL Injection&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&amp;nbsp;Before&amp;nbsp;substitute&amp;nbsp;into query, we need to do the validation. for remove ir escaped the&amp;nbsp;special&amp;nbsp;character like single quote, key words like select, Union...&lt;/li&gt;&lt;li&gt;Use Prepared&amp;nbsp;Statement&amp;nbsp;with placeholder&lt;/li&gt;&lt;/ul&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ PreparedStatement  preparedStatement=conn.prepareStatement(&quot;SELECT * FROM  usercheck where username=?&quot;) ; preparedStatement.setString(1, user); ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;that setXXX() method do all the validation and escaping the special charcter&lt;br /&gt;Now if use same blind sql injection like&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;sdfssd&#39; or &#39;1&#39;=&#39;1&lt;/span&gt; then&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;SELECT * FROM &amp;nbsp;User where userId=&#39;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;sdfssd\&#39; or \&#39;1\&#39;=\&#39;1&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;&#39;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;here all special&amp;nbsp;character&amp;nbsp;are escaped&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;When we use JPA kind of ORM tools like Hibernate, EclipseLink, TopLink that time also may be sqlinjection is possible.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;Preventing the SQL injection we need to use NamedQuery instead of normal Query. Because NamedQuery internally used PreparedStement but normal query used norma Stement in java.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;Normal Query in JPA&lt;/span&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ String q=&quot;SELECT r FROM  User r where r.userId=&#39;&quot;+user+&quot;&#39;&quot;;  Query query=em.createQuery(q);  List users=query.getResultList(); ]]&gt;&lt;/script&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;text-align: center;&quot;&gt;so dont use normal query, use Named query like this &lt;/span&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ Query query=em.createNamedQuery(&quot;User.findByUserId&quot;);  query.setParameter(&quot;userId&quot;, user);  List users=query.getResultList(); ]]&gt;&lt;/script&gt; &lt;div style=&quot;text-align: center;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large; text-align: center;&quot;&gt;&lt;b&gt;U can download the demo code from&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&lt;a href=&quot;https://github.com/ramkicse/Sql-Injection-in-Java.git&quot; target=&quot;_blank&quot;&gt;GitHub&lt;/a&gt; &lt;/span&gt;(or)&lt;span style=&quot;color: blue;&quot;&gt; &lt;a href=&quot;http://ramki-projects.googlecode.com/files/Sqlinjection.zip&quot; target=&quot;_blank&quot;&gt;Google code&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; text-align: center;&quot;&gt;Comments are welcomed&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2011/12/beware-of-sqlinjection-in-java.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-3aQo3YIE_Z0/Tt8e-A5v28I/AAAAAAAAB5Y/eH4GdqkSfZY/s72-c/sample_application.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-3989018206833348694</guid><pubDate>Thu, 10 Nov 2011 04:11:00 +0000</pubDate><atom:updated>2016-05-03T10:51:09.370+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">iReport</category><category domain="http://www.blogger.com/atom/ns#">JasperReports</category><category domain="http://www.blogger.com/atom/ns#">Java EE 6</category><category domain="http://www.blogger.com/atom/ns#">JSF 2.0</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><title>JSF + JPA + JasperReports (iReport) Part 1</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Hi in this post we will see the overview of&amp;nbsp;&lt;a href=&quot;http://jasperforge.org/projects/jasperreports&quot; target=&quot;_blank&quot;&gt;JasperReports&amp;nbsp;&lt;/a&gt;and how to integrate into JSF application.&amp;nbsp;JasperReports is the world&#39;s most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Excel, OpenOffice and Word.&lt;/div&gt;&lt;br /&gt;&amp;nbsp;In &lt;a href=&quot;http://www.primefaces.org/&quot; target=&quot;_blank&quot;&gt;Primeface&amp;nbsp;&lt;/a&gt;library&amp;nbsp;also use this&amp;nbsp;JasperReports&amp;nbsp;to generate the PDF, CSV and DOC formats with single line of code. &lt;a href=&quot;http://www.primefaces.org/showcase-labs/ui/exporter.jsf&quot; target=&quot;_blank&quot;&gt;see here&lt;/a&gt;. but its not flexible and we cant change template. so here we see the how to use&amp;nbsp;JasperReports&amp;nbsp;for create the template and&amp;nbsp;integrate &amp;nbsp;JSF 2.0.&lt;br /&gt;&lt;br /&gt;We are using &lt;a href=&quot;http://jasperforge.org/projects/ireport&quot; target=&quot;_blank&quot;&gt;iReport &lt;/a&gt;tool for crating template.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Download JasperReports and iReport&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Jasper Reports download from &lt;a href=&quot;http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%204.1.3/jasperreports-4.1.3-project.zip/download&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. This zip contain jasper&amp;nbsp;library&amp;nbsp;and its dependencies and lots sample codes.&lt;/li&gt;&lt;li&gt;iReport&amp;nbsp;download&amp;nbsp;&amp;nbsp;from &lt;a href=&quot;http://jasperforge.org/website/ireportwebsite/IR%20Website/ir_download.html?header=project&amp;amp;target=ireport&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Now create the simple JSF Application to&amp;nbsp;retrieve&amp;nbsp;the data from database using JPA, then create the template using iReport and then integrate into&amp;nbsp;JSF application.&lt;/div&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;JSF+JPA&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; Java Persistence API is standard way to access the all ORM (Object Relational&amp;nbsp;Mapping) tools like Hibernate, EclipseLink, TopLink,.. . These tools are&amp;nbsp;internally&amp;nbsp;use JDBC to access the database.&lt;br /&gt;&lt;br /&gt;the Heart of JPA is&amp;nbsp;&lt;u&gt;consist&amp;nbsp;of two parts&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;&lt;b&gt;persistence.xml&lt;/b&gt;&lt;/span&gt; - Its xml file describe the persistence provider (ORM&amp;nbsp;provider) and&amp;nbsp;connection&amp;nbsp;information like database URL, username and password. or&amp;nbsp;data source.&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple;&quot;&gt;&lt;b&gt;Entity Classes&lt;/b&gt;&lt;/span&gt; - Its normal POJO class for each table in&amp;nbsp;underlying&amp;nbsp;table. This class is annotated with @Entity and some&amp;nbsp;annotation provided by JPA. Its way to express and map the property in the class into table in the DB.&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;These entity class are &amp;nbsp;manually&amp;nbsp;we can create or using IDE tools like&amp;nbsp;Net beans&amp;nbsp;IDE provide &quot;&lt;b&gt;Entity Classes From Database&lt;/b&gt;&quot; option to auto generate the Entity&amp;nbsp;Classes.&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt; (See &lt;a href=&quot;http://www.youtube.com/watch?v=8JUiW10eqK0&quot; target=&quot;_blank&quot;&gt;video &lt;/a&gt;in below)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Once these entity&amp;nbsp;classes&amp;nbsp;are created then we need to create CRUD methods to wrapping these entities for ease of use. These kind of classes also auto generate from &quot;&lt;b&gt;Session Beans from Entity Classes&lt;/b&gt;&quot; option.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;Here we using &lt;b&gt;GlassFish Server 3&lt;/b&gt;. Its supports EJB 3.1.&amp;nbsp;&lt;/div&gt;&lt;div&gt;Now we create the JSF page to display the entity&amp;nbsp;classes&amp;nbsp;in table structure and provide buttons for export into variety of formats.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;u&gt;&lt;b&gt;&lt;i&gt;index.xhtml &lt;/i&gt;&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xhtml&quot;&gt;&lt;![CDATA[ &lt;h:head&gt;        &lt;title&gt;Facelet Title&lt;/title&gt;    &lt;/h:head&gt;    &lt;h:body&gt;                 &lt;h:form&gt;            &lt;h:commandbutton actionlistener=&quot;#{demoBean.PDF}&quot; value=&quot;PDF&quot;&gt;             &lt;h:commandbutton actionlistener=&quot;#{demoBean.DOCX}&quot; value=&quot;Docx&quot;&gt;              &lt;h:commandbutton actionlistener=&quot;#{demoBean.XLSX}&quot; value=&quot;Xlsx&quot;&gt;               &lt;h:commandbutton actionlistener=&quot;#{demoBean.ODT}&quot; value=&quot;Odt&quot;&gt;               &lt;h:commandbutton actionlistener=&quot;#{demoBean.PPT}&quot; value=&quot;Ppt&quot;&gt;        &lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:commandbutton&gt;&lt;/h:form&gt;        &lt;h:datatable border=&quot;1&quot; value=&quot;#{demoBean.listOfUser}&quot; var=&quot;user&quot;&gt;            &lt;h:column&gt;                &lt;f:facet name=&quot;header&quot;&gt;                    User Name                 &lt;/f:facet&gt;                #{user.userId}             &lt;/h:column&gt;                         &lt;h:column&gt;                &lt;f:facet name=&quot;header&quot;&gt;                    Password                 &lt;/f:facet&gt;                #{user.password}             &lt;/h:column&gt;        &lt;/h:datatable&gt;    &lt;/h:body&gt; ]]&gt;&lt;/script&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;u&gt;Jasper Reports&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Once sample JSF application is completed then we going to integrate Jasper Reports.&amp;nbsp;&lt;/div&gt;&lt;div&gt;First, include all&amp;nbsp;necessary&amp;nbsp;lib into our application. We already download the jasper&amp;nbsp;library&amp;nbsp;zip file. Extract this file they have lots of folder. one for &lt;b&gt;dist &lt;/b&gt;folder contain main&lt;b&gt; jasperreports-4.1.3.jar&lt;/b&gt; file and &lt;b&gt;lib &lt;/b&gt;folder&amp;nbsp;contain&amp;nbsp;all&amp;nbsp;necessary&amp;nbsp;dependencies. see the&amp;nbsp;requirements&amp;nbsp;of jasper reports from &lt;a href=&quot;http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/requirements.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;This is flow diagram of JasperReports.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-koz7AoOMRPQ/TsDnA35Qu6I/AAAAAAAAB5A/MezzxcoVxM4/s1600/jasperreport_overview.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;539&quot; src=&quot;http://1.bp.blogspot.com/-koz7AoOMRPQ/TsDnA35Qu6I/AAAAAAAAB5A/MezzxcoVxM4/s640/jasperreport_overview.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Jasper Report Flow&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Here we use iReport tool to generate the JRXML template. this file is pure xml file to describe the layout and&amp;nbsp;place-holders. then we need to compile into jasper file. its binary format. this compilation process we can do in 2 ways.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt;&lt;ol&gt;&lt;li&gt;Using iReport to compile the jrxml file into jasper&lt;/li&gt;&lt;li&gt;Using JasperReport API we can do through programme.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;This is the code&amp;nbsp;snippet compile the jrxml file into jasper file&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ JasperCompileManager.compileReportToFile(&quot;report.jrxml&quot;, &quot;report.jasper&quot;); ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;or we can use iReport to compile&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-T4Vd3ApqbcE/TsI13WT9W6I/AAAAAAAAB5I/uvmi_41x-L8/s1600/jasper.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;512&quot; src=&quot;http://3.bp.blogspot.com/-T4Vd3ApqbcE/TsI13WT9W6I/AAAAAAAAB5I/uvmi_41x-L8/s640/jasper.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;now compilation is finished. data is also ready. here data is java beans (entity beans) . This entity beans can&#39;t use directly. we wrap into one more class&amp;nbsp;&lt;b&gt;JRBeanCollectionDataSource &lt;/b&gt;then using &lt;b&gt;JasperFillManager &lt;/b&gt;we generate JRPRINT object.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;code:&lt;/u&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ JRBeanCollectionDataSource beanCollectionDataSource=new JRBeanCollectionDataSource(listOfUser); JasperPrint jasperPrint=JasperFillManager.fillReport(&quot;report.jasper&quot;, new HashMap(),beanCollectionDataSource); ]]&gt;&lt;/script&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;once JasperPrint is ready then we export using &lt;b&gt;JasperExportManager&lt;/b&gt;&lt;/div&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ JasperExportManager.exportReportToPdfFile(jasperPrint, &quot;report.pdf&quot;); ]]&gt;&lt;/script&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;For exporting into &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;&lt;b&gt;docx, xlsx, odt, ods, pptx&lt;/b&gt;&lt;/i&gt;&lt;/span&gt; formats we should use &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;&lt;i&gt;&lt;b&gt;JRDocxExporter,&amp;nbsp;JRXlsxExporter,&amp;nbsp;JROdtExporter,&amp;nbsp;JROdsExporter,&amp;nbsp;JRPptxExporter&amp;nbsp;&lt;/b&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;and one more thing we don&#39;t want to store the exported format into file system. we need to send these formats to client via stream.&lt;/div&gt;&lt;u&gt;Code:&lt;/u&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse(); httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.docx&quot;); ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream(); JRDocxExporter docxExporter=new JRDocxExporter(); docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream); docxExporter.exportReport(); FacesContext.getCurrentInstance().responseComplete();  ]]&gt;&lt;/script&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;here we get the OutputStream via FacesContext.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;You can download this&amp;nbsp;complete&amp;nbsp;example from &lt;a href=&quot;https://github.com/ramkicse/JasperReports-1.git&quot; target=&quot;_blank&quot;&gt;GitHub&lt;/a&gt; (or)&lt;/span&gt;&amp;nbsp;&lt;a href=&quot;http://ramki-projects.googlecode.com/files/JasperReports.zip&quot; target=&quot;_blank&quot;&gt;Google Code&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;&lt;u&gt;DemoBean.xml &lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ /*  * To change this template, choose Tools | Templates  * and open the template in the editor.  */ package org.ramki.jsf;  import java.io.IOException; import java.util.HashMap; import java.util.List; import javax.ejb.EJB; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import net.sf.jasperreports.engine.export.oasis.JROdtExporter; import net.sf.jasperreports.engine.export.ooxml.JRDocxExporter; import net.sf.jasperreports.engine.export.ooxml.JRDocxExporterParameter; import net.sf.jasperreports.engine.export.ooxml.JRPptxExporter; import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter; import org.ramki.entity.User; import org.ramki.session.UserFacade;  /**  *  * @author ramki  */ @ManagedBean @SessionScoped public class DemoBean {     private List&lt;user&gt; listOfUser;      @EJB UserFacade userFacade;          public List&lt;user&gt; getListOfUser() {         listOfUser=userFacade.findAll();         return listOfUser;     }      public void setListOfUser(List&lt;user&gt; listOfUser) {         this.listOfUser = listOfUser;     }     JasperPrint jasperPrint;     public void init() throws JRException{         JRBeanCollectionDataSource beanCollectionDataSource=new JRBeanCollectionDataSource(listOfUser); String  reportPath=  FacesContext.getCurrentInstance().getExternalContext().getRealPath(&quot;/reports/report.jasper&quot;);        jasperPrint=JasperFillManager.fillReport(reportPath, new HashMap(),beanCollectionDataSource);     }         public void PDF(ActionEvent actionEvent) throws JRException, IOException{        init();        HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();       httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.pdf&quot;);        ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();        JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);        FacesContext.getCurrentInstance().responseComplete();                    }     public void DOCX(ActionEvent actionEvent) throws JRException, IOException{         init();        HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();        httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.docx&quot;);        ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();        JRDocxExporter docxExporter=new JRDocxExporter();        docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);        docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);        docxExporter.exportReport();        FacesContext.getCurrentInstance().responseComplete();    }      public void XLSX(ActionEvent actionEvent) throws JRException, IOException{         init();        HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();       httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.xlsx&quot;);        ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();        JRXlsxExporter docxExporter=new JRXlsxExporter();        docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);        docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);        docxExporter.exportReport();        FacesContext.getCurrentInstance().responseComplete();    }       public void ODT(ActionEvent actionEvent) throws JRException, IOException{        init();        HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();       httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.odt&quot;);        ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();        JROdtExporter docxExporter=new JROdtExporter();        docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);        docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);        docxExporter.exportReport();        FacesContext.getCurrentInstance().responseComplete();    }        public void PPT(ActionEvent actionEvent) throws JRException, IOException{        init();        HttpServletResponse httpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();       httpServletResponse.addHeader(&quot;Content-disposition&quot;, &quot;attachment; filename=report.pptx&quot;);        ServletOutputStream servletOutputStream=httpServletResponse.getOutputStream();        JRPptxExporter docxExporter=new JRPptxExporter();        docxExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);        docxExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, servletOutputStream);        docxExporter.exportReport();        FacesContext.getCurrentInstance().responseComplete();    }      }  ]]&gt;&lt;/script&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style=&quot;color: #990000; font-size: large;&quot;&gt;Update (02/01/2012):&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;table cellpadding=&quot;0&quot; class=&quot;cf gJ&quot; style=&quot;border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;&quot;&gt;&lt;/table&gt;&lt;span style=&quot;color: #990000;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;i&gt;&lt;b&gt;mourad mourad&lt;/b&gt;&lt;/i&gt; mentioned that &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;report’s absolute path is hardcoded like C:\\UsersramkiDesktopreport.jasper&quot;. This&amp;nbsp;doesn&#39;t&amp;nbsp;work once you deploy your application in another application server.&lt;/span&gt;&lt;br /&gt;&lt;table cellpadding=&quot;0&quot; class=&quot;cf gJ&quot; style=&quot;border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;&quot;&gt;&lt;/table&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Yes&amp;nbsp;that&#39;s&amp;nbsp;correct. now i fix it.. i used for simplicity purpose.&lt;/span&gt;&lt;br /&gt;&lt;table cellpadding=&quot;0&quot; class=&quot;cf gJ&quot; style=&quot;border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;&quot;&gt;&lt;/table&gt;&lt;span style=&quot;color: #990000;&quot;&gt;I try to used getResourceAsStream() method. But it wont work. the reason is our report needs some supporting files like images. If ur report contain no image then u can use getResourceAsStream() method.&lt;/span&gt;&lt;br /&gt;&lt;table cellpadding=&quot;0&quot; class=&quot;cf gJ&quot; style=&quot;border-collapse: collapse; margin-top: 0px; text-align: left; width: auto;&quot;&gt;&lt;/table&gt;&lt;span style=&quot;color: #990000;&quot;&gt;So here i want the path of the report jasper file. Then this report engine get the images from that path.&lt;/span&gt;&lt;br /&gt;&lt;table cellpadding=&quot;0&quot; class=&quot;cf gJ&quot; style=&quot;border-collapse: collapse; font-family: arial, sans-serif; margin-top: 0px; text-align: left; width: auto;&quot;&gt;&lt;tbody&gt;&lt;tr class=&quot;acZ&quot; style=&quot;height: 16px;&quot;&gt;&lt;td class=&quot;gF gK&quot; style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-right: 8px; padding-top: 0px; text-align: left; vertical-align: top; white-space: nowrap; width: 478px;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ String  reportPath=  FacesContext.getCurrentInstance().getExternalContext().getRealPath(&quot;/reports/report.jasper&quot;); jasperPrint=JasperFillManager.fillReport(reportPath, new HashMap(),beanCollectionDataSource);   ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Times New Roman&#39;; font-size: large; white-space: normal;&quot;&gt;&lt;b&gt;Update (22/02/2012):&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: rgba(255, 255, 255, 0.917969);&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue; font-family: arial, sans-serif;&quot;&gt;&lt;b&gt;DrAhmedJava&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: rgba(255, 255, 255, 0.917969); color: #222222; font-family: arial, sans-serif;&quot;&gt;commented&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: rgba(255, 255, 255, 0.917969);&quot;&gt;that &lt;/span&gt;&lt;span style=&quot;background-color: rgba(255, 255, 255, 0.917969); font-family: arial, sans-serif;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;i noticed that you have an exception - getOutputStream() has already been called for this response- in your output, and it also happened to me. and i want to share the solution:&lt;/span&gt;&lt;span style=&quot;color: #990000;&quot;&gt; &lt;b&gt;(Thanks for sharing solution, i updated the code)&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: rgba(255, 255, 255, 0.917969); font-family: arial, sans-serif; white-space: normal;&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #4c1130;&quot;&gt;&lt;b&gt;The idea is that after the pdf() method writes the pdf to http response, the jsf servlet itself tries to reopen the response to write the html rendered from rendering stage of the life cycle, so the solution is to tell the jsf servlet that the response is complete and to skip the rest of life cycle&lt;span style=&quot;font-size: x-small;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);  FacesContext.getCurrentInstance().responseComplete();  ]]&gt;&lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;Update : &lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;b&gt;For sub reports and Date Objects check&lt;a href=&quot;http://www.ramkitech.com/2012/06/jsf-jpa-jasperreports-ireport-part-2.html&quot; target=&quot;_blank&quot;&gt; Part 2 of this&amp;nbsp;Series&amp;nbsp;&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: magenta; font-size: large;&quot;&gt;&lt;b&gt;&lt;i&gt;Watch the video in HD&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;480&quot; src=&quot;http://www.youtube.com/embed/8JUiW10eqK0?rel=0&amp;amp;hd=1&quot; width=&quot;853&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red; font-size: large;&quot;&gt;Comments are Welcomed&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://www.ramkitech.com/2011/11/jsf-jpa-jasperreports-ireport.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-koz7AoOMRPQ/TsDnA35Qu6I/AAAAAAAAB5A/MezzxcoVxM4/s72-c/jasperreport_overview.jpg" height="72" width="72"/><georss:featurename>Paud Rd, Kothrud, Pune, Maharashtra, India</georss:featurename><georss:point>18.479609055831968 73.740234375</georss:point><georss:box>10.730568055831968 63.632812375 26.22865005583197 83.847656375</georss:box></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-8840303299955143894</guid><pubDate>Mon, 18 Jul 2011 11:56:00 +0000</pubDate><atom:updated>2016-05-03T10:53:24.625+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">javaSE</category><category domain="http://www.blogger.com/atom/ns#">javaSE7</category><title>Learn Java 7</title><description>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; line-height: 19px;&quot;&gt;Java 7 &amp;nbsp;is an upcoming major update to Java, releasing on July 28, its upgrade/add many features.&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; line-height: 19px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: sans-serif; line-height: 19px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: magenta;&quot;&gt;Upgraded Features&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;- Java 7 &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;update the XML and&amp;nbsp;Web Service&amp;nbsp;stack &lt;/span&gt;to current stable build &lt;a href=&quot;http://jaxp.java.net/&quot;&gt;JAXP&lt;/a&gt; 1.4, &lt;a href=&quot;http://www.oracle.com/technetwork/articles/javase/index-140168.html&quot;&gt;JAXB&lt;/a&gt; 2.2 and &lt;a href=&quot;http://jax-ws.java.net/&quot;&gt;JAX-WS&lt;/a&gt; 2.2.&lt;br /&gt;- Update the &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;&lt;a href=&quot;http://download.oracle.com/javase/6/docs/technotes/guides/jweb/otherFeatures/nimbus_laf.html&quot;&gt;Nimbus&lt;/a&gt; Look and Feel&lt;/span&gt; (Next Cross Platform UI). Its already added Java 6 Update 10. check &lt;a href=&quot;http://download.oracle.com/javase/6/docs/technotes/guides/jweb/otherFeatures/nimbus_laf.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://java.sun.com/developer/technicalArticles/javase/java6u10/images/nimbus.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;195&quot; src=&quot;http://java.sun.com/developer/technicalArticles/javase/java6u10/images/nimbus.gif&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;- &lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: yellow;&quot;&gt;Translucent and shaped Windows&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This feature is also included in java 6 update 10. &amp;nbsp;this features provide to create transparent and any shape window in java. for more info &lt;a href=&quot;http://www.pushing-pixels.org/2008/03/18/more-tricks-with-translucent-swing-windows.html&quot;&gt;check this&lt;/a&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.pushing-pixels.org/wp-content/uploads/2008/03/window-soft-clipped-translucent.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://www.pushing-pixels.org/wp-content/uploads/2008/03/window-soft-clipped-translucent.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: magenta; font-size: large;&quot;&gt;New features in java 7&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-size: large;&quot;&gt;Small languages changes (Project Coin Part 1)&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://blogs.oracle.com/darcy/entry/project_coin_jsr_334_pr&quot;&gt;Project Coin&lt;/a&gt;&amp;nbsp;is one of the &amp;nbsp;project in java 7 for java language spec (JLS). Project Coin have 2 parts. the first part is add to java 7. and next part is comes with java 8 in next year (2012).&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&amp;nbsp;Binary literals and underscore in numeric literals&lt;/li&gt;&lt;/ul&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;now we can assign binary values directly.&lt;br /&gt;&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ int currency=19_00_000; int binary=0b100000;      System.out.println(binary); System.out.println(currency); ]]&gt;&lt;/script&gt;the output of above code snippets is 32 and 1900000&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Strings in switch statements&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;now we can use string literals in switch statements.&lt;br /&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: java&quot;&gt;&lt;![CDATA[ public static void main(String[] args) {        String data=&quot;java 7&quot;;                switch(data)        {            case &quot;java&quot;:            case &quot;JAVA&quot;:                System.out.println(&quot;Java&quot;);                break;            case &quot;java 7&quot;:            case &quot;JAVA 7&quot;:                System.out.println(&quot;Java 7&quot;);                 break;             default:                    System.out.println(&quot;Otherthan java&quot;);                       }          } ]]&gt;&lt;/script&gt;it prints &quot;Java 7&quot;.&lt;br /&gt;&lt;br /&gt;&lt;!-- adsense --&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&amp;nbsp;Multi-catch statements and good re throw. &lt;a href=&quot;http://www.baptiste-wicht.com/2010/05/better-exception-handling-in-java-7-multicatch-and-final-rethrow/&quot;&gt;Check Here&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&amp;nbsp;try with resource stements. check &lt;a href=&quot;http://java.dzone.com/articles/java-7-new-try-resources?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed:+javalobby/frontpage+(Javalobby+/+Java+Zone)&quot;&gt;here&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&amp;nbsp;new&amp;nbsp;diamond &amp;lt;&amp;gt;&amp;nbsp;operator. check &lt;a href=&quot;http://marxsoftware.blogspot.com/2011/03/jdk-7-diamond-operator.html&quot;&gt;here&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;some other features of project coin will come with Java 8 in next year.&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-size: large;&quot;&gt;NIO 2 (New I/O 2)&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; This one of the biggest update in java 7. It fill the gap between &amp;nbsp;underlaying OS and Java in terms of file manipulation. Oracle provide good tutorial about NIO 2 &lt;a href=&quot;http://download.oracle.com/javase/tutorial/essential/io/fileio.html&quot;&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-size: large;&quot;&gt;JLayer&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;code style=&quot;font-size: 1.2em;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/code&gt;&lt;code&gt;JLayer&lt;/code&gt;&amp;nbsp;is a universal decorator for Swing components which enables you to implement various advanced painting effects as well as receive notifications of all&amp;nbsp;&lt;code&gt;AWTEvent&lt;/code&gt;s generated within its borders.&amp;nbsp;&lt;/span&gt;check&lt;a href=&quot;http://download.oracle.com/javase/tutorial/uiswing/misc/jlayer.html&quot;&gt; this tutorial&lt;/a&gt;&amp;nbsp;about how to decorate JLayer in existing swing component.&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-size: large;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 21px;&quot;&gt;Support for dynamically-typed languages (&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-size: large;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 21px;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; cursor: auto; display: inline; font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; cursor: auto; display: inline; font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;InvokeDynamic&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; line-height: 21px;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This feature is not for normal developers. Its only for those are porting his language into JVM. Check &lt;a href=&quot;http://en.wikipedia.org/wiki/List_of_JVM_languages&quot;&gt;here&lt;/a&gt; for list of languages supported by JVM.&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-size: large;&quot;&gt;other features&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;Upgrade class-loader architecture&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;Support Uncode 6.0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;Elliptic-curve cryptography (ECC)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;JDBC 4.1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;border-collapse: separate;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span class=&quot; aptureTMMSelection&quot; style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;&lt;span style=&quot;background-color: transparent; background-image: none; border-bottom-width: 0px; border-collapse: collapse; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: none; color: inherit; cursor: auto; display: inline; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; letter-spacing: inherit; line-height: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: none; outline-width: initial; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; position: relative; text-decoration: inherit; text-indent: 0px; text-transform: inherit; vertical-align: baseline; white-space: inherit; word-spacing: inherit;&quot;&gt;XRender Pipeline for mordern GPU&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;The Next Java 8 will give support for Modular JVM and modular programming (Project Jigsaw), Project Coin part 2, Project Lamda, collection literals and very importantly oracle going to merge JRockit into Hotspot VM.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;comments are welcomed,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</description><link>http://www.ramkitech.com/2011/07/learn-java-7.html</link><author>noreply@blogger.com (Ramakrishnan)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5956132650471213105.post-663118231264977643</guid><pubDate>Mon, 11 Jul 2011 13:54:00 +0000</pubDate><atom:updated>2016-05-03T10:54:12.109+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">multiple_instances</category><category domain="http://www.blogger.com/atom/ns#">screencast</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><title>Running Multiple Tomcat Instances on Single Machine</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In this post we will see how to run&amp;nbsp;multiple&amp;nbsp;tomcat instances on single machine and under single user account.&lt;br /&gt;We first see the &amp;nbsp;tomcat directory structure. .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-vrVNkx2Hbsc/ThsBrNEDQWI/AAAAAAAAB1w/yAuv8T8DoDU/s1600/tomcat_structure.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-vrVNkx2Hbsc/ThsBrNEDQWI/AAAAAAAAB1w/yAuv8T8DoDU/s400/tomcat_structure.png&quot; height=&quot;125&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;here each folder uses&amp;nbsp;following&amp;nbsp;purpose.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;bin&lt;/b&gt; - &amp;nbsp;It contains all binary and script files for running tomcat.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;lib&lt;/b&gt; - contains all shared&amp;nbsp;libraries&amp;nbsp;used for tomcat&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;conf&lt;/b&gt; -&amp;nbsp;contains&amp;nbsp;configuration information like which port tomcat can bind , etc...&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;logs&lt;/b&gt; - it contain all logging details&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;temp&lt;/b&gt; - this folder tomcat used for&amp;nbsp;temporary&amp;nbsp;files purpose&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;webapps&lt;/b&gt; - this folder is very important. here we put all application war files.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;work&lt;/b&gt; - If application contain any jsp then jsp is translated and&amp;nbsp;converted&amp;nbsp;into servlet its stores here.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;In when run the tomcat its uses 5 environment variables. They are&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;CATALINA_HOME, CATALINA_BASE,&amp;nbsp;CATALINA_TMPDIR,&amp;nbsp;JRE_HOME/JAVA_HOME,&amp;nbsp;CLASSPATH&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;in above list&amp;nbsp;CATALINA_HOME and JAVA_HOME is mandatory environment variables. all others are optional and its can be calculated using&amp;nbsp;CATALINA_HOME.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;CATALINA_HOME&lt;/b&gt; - this environment variable should point to tomcat base folder, where tomcat binary are &amp;nbsp;installed/extracted. so based on CATALINA_HOME we can get &lt;b&gt;bin&lt;/b&gt; and &lt;b&gt;lib&lt;/b&gt; folder&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;CATALINA_BASE&lt;/b&gt; - If we not specified then&amp;nbsp;CATALINA_HOME value is set. This variable pointed to configuration and webapps folder. Based on this variable server uses &lt;b&gt;conf, logs, temp, webapps, work&lt;/b&gt; folders.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Usual ways to run the tomcat is only set CATALINA_HOME environment variable. and run the &lt;b&gt;startup.sh&lt;/b&gt; script file. this startup.sh file automatically calculate and&amp;nbsp;assign&amp;nbsp;the&amp;nbsp;values&amp;nbsp;of other variables what we are not set.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-zn1ijTFg4LI/Thwmpa5MxKI/AAAAAAAAB10/licoYKPUL_k/s1600/startup_tomcat.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-zn1ijTFg4LI/Thwmpa5MxKI/AAAAAAAAB10/licoYKPUL_k/s400/startup_tomcat.png&quot; height=&quot;85&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;startup.sh file set the environment variable and &amp;nbsp;then call catalina.sh file. this files is read CATALINA_BASE value and attach conf i.e $CATALINA_BASE/conf folder and get server.xml. this file is heart of tomcat. it contains all configuration information. like which tomcat uses as shoutdown port, connector post, host name, application folder ,.. for example usually tomcat uses 8080 is a connector port, so we can access http://localhost:8080/&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;if we set the $CATALINA_BASE explicitly then tomcat uses our variable to search and get the server.xml file from our target place, what we specified in&amp;nbsp;CATALINA_BASE.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;this is trick to run multiple tomcat in single machine. we don&#39;t change&amp;nbsp;CATALINA_HOME value. we need to change&amp;nbsp;CATALINA_BASE value before start/shutdown the tomcat.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;create one folder named &quot;&lt;b&gt;tomcat-instance1&lt;/b&gt;&quot; anywhere, and copy&lt;b&gt; conf, temp, webapps and logs&lt;/b&gt;&amp;nbsp; folder from&amp;nbsp;CATALINA_HOME folder and change conf/server.xml file in&amp;nbsp;&lt;b&gt;tomcat-instance1&lt;/b&gt;. we need to change 3 port shutdown port, connector port and ajp port.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;shutdown port&lt;/b&gt; - this port is used for shutdown the tomcat. when we call the shutdown.sh script they send&amp;nbsp;signal&amp;nbsp;to shutdown port. this port listen by tomcat java process. if&amp;nbsp;signal&amp;nbsp;is received the that process then its cleanup and exit by itself.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;connector Port &lt;/b&gt;-This port is actual port to expose the application to outside client.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;b&gt;ajp port&lt;/b&gt; - this port is used to apache httpd server &amp;nbsp;communicate to tomcat. this port used when we setup load balanced server.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;see the sample server.xml file&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;server port=&quot;8005&quot; shutdown=&quot;SHUTDOWN&quot;&gt;&lt;/server&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;.... ..&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xml&quot;&gt;&lt;![CDATA[ &lt;server port=&quot;8005&quot; shutdown=&quot;SHUTDOWN&quot;&gt;.....  &lt;connector connectiontimeout=&quot;20000&quot; port=&quot;8080&quot; protocol=&quot;org.apache.coyote.http11.Http11NioProtocol&quot; redirectport=&quot;8443&quot;&gt; &lt;connector port=&quot;8009&quot; protocol=&quot;AJP/1.3&quot; redirectport=&quot;8443&quot;&gt;&lt;/connector&gt;&lt;/connector&gt;&lt;/server&gt;]]&gt;&lt;/script&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;so we change these three port to different number, because once this port is binded &amp;nbsp;then other process can&#39;t bind it again. so wee bind different port. so tomcat-instance1/conf/server.xml file i configured server port =8105, connector port = 8181, ajp port = 8109.&lt;/div&gt; &lt;script type=&quot;syntaxhighlighter&quot; class=&quot;brush: xml&quot;&gt;&lt;![CDATA[&lt;server port=&quot;8105&quot; shutdown=&quot;SHUTDOWN&quot;&gt;.....  &lt;connector connectiontimeout=&quot;20000&quot; port=&quot;8181&quot; protocol=&quot;org.apache.coyote.http11.Http11NioProtocol&quot; redirectport=&quot;8443&quot;&gt;&lt;connector port=&quot;8109&quot; protocol=&quot;AJP/1.3&quot; redirectport=&quot;8443&quot;&gt;&lt;/connector&gt;&lt;/connector&gt;&lt;/server&gt;]]&gt;&lt;/script&gt;&lt;br /&gt;now we can create two script file for startup and shutdown the tomcat-instance1.&lt;br /&gt;&lt;u&gt;startup-instance1.sh&lt;/u&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;export CATALINA_BASE= /home/ramki/tomcat-instance1&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;cd $CATALINA_HOME/bin&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;./startup.sh&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style=&quot;color: black; font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;u&gt;shutdown-instance1.sh&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: black; font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;export CATALINA_BASE= /home/ramki/tomcat-instance1&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: black; font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;cd $CATALINA_HOME/bin&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: black; font-family: &#39;Times New Roman&#39;; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: purple; font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;./shutdown.sh&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;here we explicitly set the&amp;nbsp;&lt;/span&gt;CATALINA_BASE variable and point to new tomcat-instance1&lt;br /&gt;the we go to&amp;nbsp;CATALINA_HOME/bin folder because all binary for running tomcat is still present in&amp;nbsp;CATALINA_HOME folder then startup/shutdown the script.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-BSsNs8Ze5eI/Thw7w1m9DSI/AAAAAAAAB18/-bHb7I6TkQo/s1600/tomcat1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-BSsNs8Ze5eI/Thw7w1m9DSI/AAAAAAAAB18/-bHb7I6TkQo/s400/tomcat1.png&quot; height=&quot;72&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Based on above technique we can create many instance folder and change conf/server.xml file port values and run that instance with own newly created script files.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #660000; font-size: large;&quot;&gt;&lt;b&gt;Update 1:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Java Experience&amp;nbsp;created&amp;nbsp;a small&amp;nbsp;utility&amp;nbsp;for automatically generate the multiple tomcat instances in Windows/Linux Systems. &lt;a href=&quot;http://www.javaexperience.com/run-multiple-tomcat-instances/&quot; target=&quot;_blank&quot;&gt;Check Here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style=&quot;color: #990000;&quot;&gt;see the latest post&amp;nbsp;:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html&quot; target=&quot;_blank&quot;&gt;Understanding Virtual Host in Tomcat&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;see the screen cast for running mutiple instance of tomcat&lt;br /&gt;&lt;br /&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;349&quot; src=&quot;http://www.youtube.com/embed/n9l8WHHp_30?rel=0&amp;amp;hd=1&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;comments are welcomed&lt;/div&gt;</description><link>http://www.ramkitech.com/2011/07/running-multiple-tomcat-instances-on.html</link><author>noreply@blogger.com (Ramakrishnan)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-vrVNkx2Hbsc/ThsBrNEDQWI/AAAAAAAAB1w/yAuv8T8DoDU/s72-c/tomcat_structure.png" height="72" width="72"/><georss:featurename>Unknown location.</georss:featurename><georss:point>18.521283325496277 73.8720703125</georss:point><georss:box>14.640897325496278 68.818359312500007 22.401669325496279 78.925781312499993</georss:box></item></channel></rss>