You can lookup the runtime JMX which is the same for all application. No need to enter address, user or password.
1) Lookup the MBeanServer
InitialContext ctx = new InitialContext();
MBeanServer mBeanServer = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
2) Then you need to retrieve the name of the server running the application. Here there is two ways (maybe more).
The simplest
String serverName = System.getProperty("weblogic.Name");
But I don't know if it's a reliable way.
The other way to get the server name is to look for it in the runtime service attributes.
ObjectName serviceObjectName = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
String serverName = (String) mBeanServer.getAttribute(serviceObjectName, "ServerName");
3) Now we can create the runtime server ObjectName ...
ObjectName serverRuntime = new ObjectName("com.bea:Name="+serverName+",Type=ServerRuntime");
4) ... and get the attributes we need
String listenAddress = mBeanServer.getAttribute(serverRuntime, "ListenAddress");
Integer listenPort = mBeanServer.getAttribute(serverRuntime, "ListenPort");
rem: listenAddress is formatted as hostname
/IP
, you have to manipulate it to only get IP or host
From there you can access to a lot of information; like the address of the admin server that manage the runtime server, the runtime cluster, ... .
Here is a list I get from the WLST console (WL12.2.1), didn't test if we have access to all attributes/MBean's.
dr-- ApplicationRuntimes
dr-- AsyncReplicationRuntime
dr-- BatchJobRepositoryRuntime
dr-- ClassLoaderRuntime
dr-- ClusterRuntime
dr-- ConcurrentManagedObjectsRuntime
dr-- ConnectorServiceRuntime
dr-- DefaultExecuteQueueRuntime
dr-- EntityCacheCumulativeRuntime
dr-- EntityCacheCurrentStateRuntime
dr-- EntityCacheHistoricalRuntime
dr-- ExecuteQueueRuntimes
dr-- JDBCServiceRuntime
dr-- JMSRuntime
dr-- JTARuntime
dr-- JVMRuntime
dr-- JoltRuntime
dr-- LibraryRuntimes
dr-- LogBroadcasterRuntime
dr-- LogRuntime
dr-- MANAsyncReplicationRuntime
dr-- MANReplicationRuntime
dr-- MailSessionRuntimes
dr-- MaxThreadsConstraintRuntimes
dr-- MessagingBridgeRuntime
dr-- MessagingBridgeRuntimes
dr-- MinThreadsConstraintRuntimes
dr-- PartitionRuntimes
dr-- PathServiceRuntime
dr-- PathServiceRuntimes
dr-- PersistentStoreRuntimes
dr-- RequestClassRuntimes
dr-- SAFRuntime
dr-- SNMPAgentRuntime
dr-- ServerChannelRuntimes
dr-- ServerLogRuntime
dr-- ServerSecurityRuntime
dr-- ServerServices
dr-- SingleSignOnServicesRuntime
dr-- ThreadPoolRuntime
dr-- TimerRuntime
dr-- WANReplicationRuntime
dr-- WLDFRuntime
dr-- WTCRuntime
dr-- WebServerRuntimes
dr-- WorkManagerRuntimes
dr-- WseeClusterFrontEndRuntime
dr-- WseeWsrmRuntime
-r-- ActivationTime
-r-- AdminServer
-r-- AdminServerHost
-r-- AdminServerListenPort
-r-- AdminServerListenPortSecure
-r-- AdministrationPort
-r-- AdministrationPortEnabled
-r-- AdministrationURL
-r-- AsyncReplicationRuntime
-r-- ClusterRuntime
-r-- CurrentDirectory
-rw- CurrentMachine
-r-- DefaultExecuteQueueRuntime
-r-- DefaultURL
-r-- EntityCacheCumulativeRuntime
-r-- EntityCacheCurrentStateRuntime
-r-- EntityCacheHistoricalRuntime
-r-- HealthState
-r-- HealthStateJMX
-r-- JoltRuntime
-r-- ListenAddress
-r-- ListenPort
-r-- ListenPortEnabled
-r-- MANAsyncReplicationRuntime
-r-- MANReplicationRuntime
-r-- MessagingBridgeRuntime
-r-- MiddlewareHome
-r-- Name
-r-- OpenSocketsCurrentCount
-r-- OracleHome
-r-- OverallHealthState
-r-- OverallHealthStateJMX
-rw- Parent
-r-- PathServiceRuntime
-r-- RestartRequired
-r-- RestartsTotalCount
-r-- SSLListenAddress
-r-- SSLListenPort
-r-- SSLListenPortEnabled
-r-- ServerClasspath
-r-- SocketsOpenedTotalCount
-r-- State
-r-- StateVal
-r-- Type
-r-- WANReplicationRuntime
-r-- WeblogicHome
-r-- WeblogicVersion
-r-- WseeClusterFrontEndRuntime
InetAddress.getLocalHost().getHostName()
– PreviousDomainRuntimeServiceMBean
. All of the newer weblogic examples point to something like this: docs.oracle.com/cd/E23943_01/web.1111/e13728/… It should be portable as long as you reference environment variables, etc for the admin url – PreviousADMIN_URL
when your managed server is started via thestartManagedWebLogic
script. How are you supposed to run a server without knowing any of this information? – Previous