Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in

...

Yet another way is to use authbind (part of Debian- and CentOS based distributions) which allows a program that would normally require superuser privileges to access privileged network services to run as a non-privileged user. The article at http://java-notes.com/index.php/installing-tomcat-with-http-port-80-on-linux discusses how to install and configure the authbind package with Tomcat 6.0 on Linux.

Configuration

How do I set up multiple sites sharing the same war application/war file?

...

  1. Start your Tomcat and check that you have access to http://localhost:8080/manager/jmxproxy/. It means that JMX is enabled on your Tomcat configuration (if not, check if the following line is in your /conf/server.xml file : <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />. Otherwise, check the Tomcat documentation to activate it). Let this page opened to check further if your custom Mbean is detected by Tomcat.


2. Build your custom MBean by following the Christopher Blunck's example :
ServerMBean.java :

No Format
  package org.wxnet.mbeans;

  public interface ServerMBean {
    public void setLoggingLevel(int level);
    public long getUptime();
  }

...

No Format
package org.wxnet.mbeans;

  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.ObjectName;

  import java.util.ArrayList;

  public class Server implements ServerMBean {
    private int _logLevel = 1;
    private long _startTime = 0L;

    public Server() {
      MBeanServer server = getServer();

      ObjectName name = null;
      try {
        name = new ObjectName("Application:Name=Server,Type=Server");
        server.registerMBean(this, name);
      } catch (Exception e) {
        e.printStackTrace();
      }

      _startTime = System.currentTimeMillis();
    }


    private MBeanServer getServer() {
      MBeanServer mbserver = null;

      ArrayList mbservers = MBeanServerFactory.findMBeanServer(null);

      if (mbservers.size() > 0) {
        mbserver = (MBeanServer) mbservers.get(0);
      }

      if (mbserver != null) {
        System.out.println("Found our MBean server");
      } else {
        mbserver = MBeanServerFactory.createMBeanServer();
      } 

      return mbserver;
    }


    // interface method implementations
    public void setLoggingLevel(int level) { _logLevel = level; }
    public long getUptime() { return System.currentTimeMills() - _startTime; }
  }

In this implementation, firstly notice the ObjectName representing the MBean (in the constructor) : name = new ObjectName("Application:Name=Server,Type=Server"); Do not hesitate to change the domain name (the first parameter) by your own to easily find your MBean reference in the http://localhost:8080/manager/jmxproxy page.
Secondly, take a look at your MBean constructor :

...

A good question right now could be : what happens if I decide to create my own MBeanServer? The answer is very simple : nothing.
After many research in the (empty) Tomcat's documentation and on the internet, after many tests, I conclued that you can't create your custom MBean server. More precisely, you can create it but Tomcat won't keep any reference to it.
You can replace the previous getServer() method by this one to test:

No Format
private MBeanServer getServer() {
        MBeanServer mbserver = null;

        MBeanServer myMBServer = MBeanServerFactory.createMBeanServer("myMBServer");
        
        ArrayList<MBeanServer> mbservers = MBeanServerFactory.findMBeanServer(null);
        System.out.println("****** TOMCAT'S LIST OF REGISTERED MBEANSERVERS ********** ");
        System.out.println(mbservers.toString());
        
        System.out.println("****** TRYING TO RETRIEVE MY OWN MBEANSERVER FROM ITS AgentId ********** ");
        ArrayList<MBeanServer> mbservers_2 = MBeanServerFactory.findMBeanServer("myMBServer");
        System.out.println(mbservers_2.toString());
        
        
        if (mbservers.size() > 0) {
            mbserver = (MBeanServer) mbservers.get(0);
        }

        if (mbserver != null) {
            System.out.println("MBeanServer has been found!");
        } else {
            mbserver = MBeanServerFactory.createMBeanServer();
        }

        return mbserver;
    }

Here is a capture of the println() : Tomcat's javadoc] https://picasaweb.google.com/lh/photo/jzVX9-NBGwF57A0m8qqv2Q?feat=directlink. Tomcat seems to register 2 Mbean server but when I try to fetch mine from its AgentId (here "myMBServer"), nothing is found. In my opinion, Tomcat might re-implement the MBeanServerFactory java class to control the server creation. Then, it doesn't keep a reference to the newly created MBean server. Moreover, if Tomcat re-implement the MBeanFactory class, there is no method to directly add MBean (see the [ http://tomcat.apache.org/tomcat-6.0-doc/api/index.html).

...

No Format
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
//call operations with invoke(...) and attributes with getAttributes(...)

...