GeeCON Prague 2014*
The moose likes Tomcat and the fly likes get port number in tomcat 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "get port number in tomcat 7" Watch "get port number in tomcat 7" New topic
Author

get port number in tomcat 7

Angei Angie
Greenhorn

Joined: Feb 05, 2013
Posts: 1
Hi

I have currently moved to tomcat 7 where i need to access the port .A sample code which wrks fine on tomcat 6
Server server = ServerFactory.getServer();
Service[] services = server.findServices();
for (Service service : services) {
for (Connector connector : service.findConnectors()) {
ProtocolHandler protocolHandler = connector.getProtocolHandler();
if (protocolHandler instanceof Http11Protocol
|| protocolHandler instanceof Http11AprProtocol
|| protocolHandler instanceof Http11NioProtocol) {
serverPort = connector.getPort();
System.out.println("HTTP Port: " + connector.getPort());
}
}


}


is there something similar in tomcat 7 ?
I tried this but this aint working either ..
import javax.management.*;
import org.apache.catalina.Server;

MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName name = new ObjectName("Catalina", "type", "Server");
Server server = (Server) mBeanServer.getAttribute(name, "managedResource");


Thanks in advance



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get port number in tomcat 7