tomcat « Intelligrape Groovy & Grails Blogs

Posts Tagged ‘ tomcat ’

Sharing HTTP Session between subdomains

Posted by on March 21st, 2012

Recently, I had a usecase to share same http session between different subdomains. The idea was that if a user is logged in on “somedomain.com“, he need not to login again to go to subdomain.somedomain.com. The same http session should be usable. I started off on the wrong foot by looking into the SpringSecurity plugin, which I had been using. But, later on, I found that this is to be done by configuring the Tomcat. The solution is to configure tomcat to recongnize session cookies from the subdomains. So all it takes is to modify element tomcat/conf/Context.xml to:

 <Context sessionCookiePath="/" sessionCookieDomain=".yourdomain.com">

and you are good to go. The solution works for Tomcat version 6.0.27 and above.

Cheers,
Imran Mir
imran[at]intelligrape[dot]com

Posted in Grails, System

Increasing the connection timeout between browser and the tomcat server

Posted by on December 21st, 2011

Hi,

There is a case stuck recently in my project where i need to increase the connection timeout between browser and the server, because of the reason before the response get completed server leave the connection which result in no response. My colleague Himanshu told me to change the setting in server.xml, which help in my purpose.

To increase the connection timeout on tomcat server follow the following steps :

1. Open the file server.xml residing in tomcat6/conf/.
2. You just need to set variable connectionTimeout in it to Value in Milliseconds.(i.e 1000 milliseconds = 1 second)

For example :

File : server.xml

<Connector port="8080" protocol="HTTP/1.1"  connectionTimeout="20000" URIEncoding="UTF-8"            redirectPort="8443" />

I thought it will be useful to share, hope it helps.
 

Thanks,
Tarun Pareek
tarun@intelligrape.com
http://in.linkedin.com/in/tarunpareek

Posted in System

Tomcat 6 in-memory session replication

Posted by on July 22nd, 2010

Hi All,

Here are the few basic steps that you need to follow in order to achieve the in-memory session replication between two or more Tomcat 6 instances.

This blog refers the Apache Tomcat documentation as found here: http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html.
The Tomcat documentation provides more detailed explanation of the Clustering concepts as well as the definition of tags, attributes etc. used in server.xml file.

Step 1: Include the <distributable> tag in web.xml file i.e. you can simple write the following line in your deployment descriptor(i.e. web.xml):

 <distributable />

Please read the following link to know more about this tag: http://wiki.metawerx.net/wiki/Web.xml.Distributable

Step 2: Add the following lines of XML in the server.xml file inside the <Engine> element/tag:

<Engine name="Catalina" defaultHost="localhost">
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
            channelSendOptions="8">
                     <Manager className="org.apache.catalina.ha.session.DeltaManager"
                      expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
                     <Channel className="org.apache.catalina.tribes.group.GroupChannel"> 
                               <Membership className="org.apache.catalina.tribes.membership.McastService" 
                               address="228.0.0.4" port="45564" frequency="500" dropTime="3000"/> 
                              <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
                                 address="auto" port="4000" autoBind="100" selectorTimeout="5000" maxThreads="6"/>
                               <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> 
                                             <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> 
                                </Sender>
                      <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
                      <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
                  </Channel>
           <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/> 
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/> 
          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" 
                   tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/" watchDir="/tmp/war-listen/"
                   watchEnabled="false"/> 
                   <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
                  <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
     </Cluster>
 .
 .
 .
 .
 </Engine>

Please note that there might be some other elements such as <Host>, <Realm> etc. inside the <Engine> element. Also, for each tomcat instance the value defined for the ‘port’ attribute of the <Receiver> tag must be unique.

And, that’s all. You now have a basic session-replication in place. Your sessions are replicated amongst all the tomcat instances which are part of your cluster.

NOTE: Please make sure if you make any changes to the “context.xml” file, you have to delete the following xml file located in the <TOMCAT_HOME>/conf/Catalina/localhost/{yourAppName}.xml. If you don’t delete this file, then your changes will be ignored and the settings defined in this file will take effect.

Cheers!!!

Abhishek Tejpaul
abhishek@intelligrape.com
[Intelligrape Software Pvt. Ltd.]

Posted in System

Tomcat 6 Session Persistence through JDBCStore

Posted by on July 21st, 2010

In one of our recent projects, we needed to save the HTTP session in the database.
This blog refers the Apache documentation as found here: http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html

These are the following steps that need to be followed:

Step 1: Create a database named tomcat (as shown in our example in Step 3 below) or any other name as specified in the ‘connectionURL’ attribute of the <Store> element.

Step 2: Create the following table in the newly created database:

create table sessions (
session_id     varchar(100) not null primary key,
valid_session  char(1) not null,
max_inactive   int not null,
last_access    bigint not null,
app_name       varchar(255),
session_data   mediumblob,
KEY kapp_name(app_name)
);

Step 3: Copy the context.xml file available at the global level at this location: <TOMCAT_HOME>/conf to your application’s META-INF folder and replace the <Manager> element with the following:

<Manager className='org.apache.catalina.session.PersistentManager'
 saveOnRestart='false' minIdelSwap='0' maxIdleSwap='0'  maxIdleBackup='1'> 
<Store className="org.apache.catalina.session.JDBCStore" 
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost/tomcat?user=username&amp;password=password" 
sessionTable="sessions" 
sessionIdCol="session_id"
sessionDataCol="session_data"
sessionValidCol="valid_session" 
sessionMaxInactiveCol="max_inactive"
sessionLastAccessedCol="last_access"
sessionAppCol='app_name' />
 </Manager>

If these settings are placed in the ‘<TOMCAT_HOME>/conf/context.xml‘, it will have a global effect on all the applications running on the server. For an application specific setting, you can place a newly created “context.xml” file in the <APP_HOME>/META-INF sub-folder inside the webapps folder.
Please note that attributes used in the <Store> element make use of the table columns as created in the database in Step 2.

Step 4: Set the following system properties named – ‘org.apache.catalina.session.StandardSession.ACTIVITY_CHECK‘ to ‘true‘.
For further information on this, read the ‘Persistent Manager Implementation’ section at this link : http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html

Step 5: Make sure you have placed the MySql jar in the <TOMCAT_HOME>/lib folder.

Now you can try to hit the application’s URL and check the database table to see the newly persisted session. Please note that it takes around 60 seconds to see the stored session in the database so you might have to wait a bit. You can have multiple instances of tomcat running your application pointing to the same database and can share this persisted session in case any of the tomcat instance crashes.

Cheers!!!

Abhishek & Imran

abhishek@intelligrape.com | imran@intelligrape.com

[Intelligrape Software Pvt. Ltd.]

Posted in Database, System

Apache-Tomcat integration on Ubuntu server

Posted by on February 13th, 2008

Follow the steps mentioned below to integrate Apache with Tomcat on an Ubuntu system. The steps assume that Apache and Tomcat are already installed and working fine independently.

  • Install Apache module for tomcat

sudo apt-get install libapache2-mod-jk

  • Create a file by the name “worker.properties” in /etc/apache2 directory. Sample worker.properties file below

workers.tomcat_home=/opt/servers/tomcat5.5
workers.java_home=/opt/java/jdk1.5
ps=/
worker.list=worker1
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

  • Add the following line to your site configuration file (/etc/apache2/sites-available/dellServer)

jkMount /* worker1

  • Add the following lines to the end of your /etc/apache2/apache2.conf file

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk logs
JkLogFile /tmp/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

Tags: ,
Posted in Linux, System