java 如何在运行时获取 weblogic 托管服务器监听端口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9869348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:42:45  来源:igfitidea点击:

How to get weblogic managed server listen port in runtime?

javaweblogicportlisten

提问by crabhit

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.

我在一台服务器上部署了两个 weblogic 托管实例。这两个实例使用不同的端口号,比如说 7001 和 7002。我的问题是如何在运行时获取端口号?例如,如果在intance1中,我想得到7001,如果在instance2中,我想得到7002。

回答by sweetfa

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

一个简单的解决方案是使用 WLST。下面的脚本将获取 WebLogic 服务器域中所有服务器的端口号。

#!/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.

该脚本在 Unix 或 Windows 环境中同样有效。

From a command prompt wlst scriptName

从命令提示符 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

回答by Marc

You can use a script like this

您可以使用这样的脚本

export IDM_WLS_DOMAIN=IDMDomain 
export IDM_DOMAIN_HOME="$FMW_HOME/user_projects/domains/$IDM_WLS_DOMAIN"
...
export IDM_WLS_ADMIN_PORT=`cat $IDM_DOMAIN_HOME/bin/startManagedWebLogic.sh | grep 'ADMIN_URL="http' | cut -d '"' -f2 | cut -d ':' -f3`

-> IDM_WLS_ADMIN_PORT will be equal to 7001 or 7002, ...

-> IDM_WLS_ADMIN_PORT 将等于 7001 或 7002,...

回答by JoseK

Use JMX.

使用 JMX。

you can write a java program which will look up the RuntimeService MBean

你可以编写一个java程序来查找RuntimeService MBean

"com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean"

“com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean”

and from this you can look up all the members of the cluster including the Admin.

从中您可以查找集群的所有成员,包括管理员。

and find their complete IP Address / DNS and port numbers

并找到他们完整的 IP 地址/DNS 和端口号

Here is a starter example

这是一个入门示例

http://middlewaremagic.com/weblogic/?p=210

http://middlewaremagic.com/weblogic/?p=210