How to get weblogic managed server listen port in runtime?

crabhit picture crabhit · Mar 26, 2012 · Viewed 20.1k times · Source

I deployed two weblogic managed instance in one server. These two instance using different port number, let say 7001 and 7002. My question is how to get port number in runtime? For example, if in intance1, I want to get 7001, if in instance2, I want to get 7002.

Answer

sweetfa picture sweetfa · Mar 27, 2012

A simple solution is to use WLST. The script below will get the port numbers of all servers within your WebLogic server domain.

#!/usr/bin/python

connect('weblogic','password','t3://localhost:7001')
domainConfig()
servers = cmo.getServers()
print "Server\t\tPort\tSSL"
for server in servers:
        print server.name + "\t" + str(server.getListenPort()) + "\t" + str(server.getSSL().getListenPort())
disconnect()

NOTE: You will probably have to replace the spaces at the beginning of the second last line with a tab character.

This script will work equally on Unix or Windows environments.

From a command prompt wlst scriptName

The output of such a script resembles:

Server          Port    SSL
AdminServer     7001    7002
bam_server1     9001    9002
osb_server1     7003    7004
soa_server1     8001    8002