Skip to content


June 29, 2010

Subdomain handling

If subdomain and you can try using urlrewrite using Tuckey OR mod_ajp/mod_proxy with tomcat.  or you can create two service/engine nodes each having connector bound to different IP address.
Environment tag  inside context used for property creation (name/value/type).

factoryName with Resource tag to state the encryption of password factory class name.
catalina.home and catalina.base env variables can be used.

Download vs open (Difference in content-disposition header value)

response.setContentType(“application/pdf”); response.setHeader(“Content-disposition”, “inline”);

For an attachment / download you will want to do:

response.setContentType(“application/pdf”); response.setHeader(“Content-disposition”,

To view the details of datasource connection in the container:

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

        Context ctx = new InitialContext();

        DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/mydb");

        if(null == ds)
                throw new NamingException("Cannot obtain DataSource");

        int maxActiveConnections = 0;
        int maxIdleConnections = 0;
        int minIdleConnections = 0;
        int activeConnections = 0;
        int idleConnections = 0;

        if(ds instanceof BasicDataSource)
            BasicDataSource bds = (BasicDataSource)ds;

            maxActiveConnections = bds.getMaxActive();
            maxIdleConnections = bds.getMaxIdle();
            minIdleConnections = bds.getMinIdle();
            activeConnections = bds.getNumActive();
            idleConnections = bds.getNumIdle();

PortMon for port monitoring on windows. When running Tomcat as windows service the _environment variable_ is NOT used when running Tomcat as a Windows service – the registry entry is. The environment variable does come into play when _installing_ the service.

netstat -ano
To see ports at which tomcat listening

To restart tomcat
Set CATALINA_PID to some file path.
The script will store the PID of the Tomcat process in that file.
Call “ stop 10 -force” which will wait up to 10 seconds for Tomcat to shutdown before it kills the Tomcat process.

Packet Sniffing:
Wirshark or tcpdump. Both use libpcap format for the raw packet capture. So you can e.g. sniff using the commandline tool tcpdump which will be simpler to use on the server, and then have a look at the data using wireshark. If you are familar with tcdump, you can do the analysis also using only tcpdump, if you need a GUI to suppot you in doing the analysis, wireshark is helpful.

Issue faced
packets were not coming rom the browser, but instead from some other network security device. The device decided the traffic was malicious and send a reset packet. The traffic was not going through the device, it simply sniffed the LAN traffic and inserted a reset packet when it thought it would help security …

Shutdown of process

kill -15 <pid> (or kill -TERM <pid>) can be catch by the signal handler. Programmer can write a signal handler to catch this signal.On the other hand kill -9 <pid> (or kill -KILL <pid>) can not be catch by the signal handler. This will send direct this command to operating system to kill the specified process. If shutdown port is removed then can use the signal 15 to close the process in a clean way. Use Ctrl-C or kill windows signal to the PID ID – if in windows.
Host and Alias
If you only have one <Host> element, aliases are unnecessary.  You only need <Alias> elements when :
  • multiple <Host>s are configured and
  • you want Tomcat to route more than one domain to them.

Another potential reason for using separate s is to (somewhat) guarantee availability of each of your webapps. If you have an with 100 threads available, a single webapp(‘s users) can consume all the threads and (temporarily) starve the other webapps. Also Alias can have IP address in it (other than hostname).

Utility : netstat or download a utility offered from microsoft called tcpview.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: