Skip to content

Commit 1affc8c

Browse files
committed
Fix the getServerMBean method
1 parent 2ee2ff4 commit 1affc8c

File tree

1 file changed

+25
-64
lines changed

1 file changed

+25
-64
lines changed

integration-tests/src/test/resources/sitconfig/java/SitConfigTests.java

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
public class SitConfigTests {
6565

6666
private MBeanServerConnection runtimeMbs;
67+
private MBeanServerConnection editMbs;
6768
private DomainMBean domainMBean = null;
69+
private EditServiceMBean editServiceMBean = null;
70+
private ConfigurationManagerMBean cfgMgr;
6871
private JMXConnector jmxConnector;
6972
private static ObjectName service;
7073
private RuntimeServiceMBean runtimeServiceMBean;
@@ -93,7 +96,7 @@ public static void main(String args[]) throws Exception {
9396
String adminHost = args[0];
9497
String adminPort = args[1];
9598
String adminUser = args[2];
96-
String adminPassword = args[3];
99+
String adminPassword = args[3];
97100
String serverName = args[4];
98101
String testName = args[5];
99102

@@ -109,7 +112,6 @@ public static void main(String args[]) throws Exception {
109112
test.verifyDebugFlagJMXCore(serverName, true);
110113
test.verifyDebugFlagServerLifeCycle(serverName, true);
111114
test.verifyMaxMessageSize(serverName, 78787878);
112-
test.verifyMaxMessageSize(serverName, 77777777);
113115
test.verifyConnectTimeout(serverName, 120);
114116
test.verifyRestartMax(serverName, 5);
115117
test.verifyT3ChannelPublicAddress(serverName, adminHost);
@@ -177,8 +179,17 @@ private void createConnections() throws Exception {
177179
runtimeServiceMBean =
178180
(RuntimeServiceMBean)
179181
MBeanServerInvocationHandler.newProxyInstance(runtimeMbs, runtimeserviceObjectName);
180-
181182
ObjectName domainServiceObjectName = new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME);
183+
editMbs =
184+
lookupMBeanServerConnection(
185+
adminHost, adminPort, adminUser, adminPassword, EditServiceMBean.MBEANSERVER_JNDI_NAME);
186+
ObjectName serviceObjectName = new ObjectName(EditServiceMBean.OBJECT_NAME);
187+
editServiceMBean =
188+
(EditServiceMBean)
189+
MBeanServerInvocationHandler.newProxyInstance(editMbs, serviceObjectName);
190+
cfgMgr = editServiceMBean.getConfigurationManager();
191+
192+
cfgMgr.startEdit(-1, -1);
182193
}
183194

184195
/**
@@ -254,11 +265,14 @@ protected void verifyDebugFlagJMXCore(String serverName, boolean expectedValue)
254265
* with the expected value, a boolean value set in the configuration override file config.xml.Uses
255266
* Java assertions to verify if both the values match.
256267
*
268+
* @param serverName name of the weblogic server instance for which the debug flag to be checked
269+
* as a String
257270
* @param expectedValue - boolean value to be checked in the debug-server-life-cycle attribute in
258271
* ServerMBean in ServerConfig MBean tree * @param serverName - name of the weblogic server
259272
* instance for which the debug flag to be checked as a String
260273
*/
261-
protected void verifyDebugFlagServerLifeCycle(String serverName, boolean expectedValue) {
274+
protected void verifyDebugFlagServerLifeCycle(String serverName, boolean expectedValue)
275+
{
262276
ServerMBean serverMBean = getServerMBean(serverName);
263277
ServerDebugMBean serverDebugMBean = serverMBean.getServerDebug();
264278
boolean debugFlag = serverDebugMBean.getDebugServerLifeCycle();
@@ -276,7 +290,7 @@ protected void verifyDebugFlagServerLifeCycle(String serverName, boolean expecte
276290
* @param serverName - name of the weblogic server instance for which the connect timeout to be
277291
* checked as a String
278292
*/
279-
protected void verifyConnectTimeout(String serverName, int expectedValue) {
293+
protected void verifyConnectTimeout(String serverName, int expectedValue) {
280294
ServerMBean serverMBean = getServerMBean(serverName);
281295
int got = serverMBean.getConnectTimeout();
282296
assert expectedValue == got
@@ -317,44 +331,18 @@ protected void verifyMaxMessageSize(String serverName, int expectedValue) {
317331
: "Didn't get the expected value " + expectedValue + " for MaxMessageSize";
318332
}
319333

320-
/**
321-
* A utility method to check if the max-message-size in the ServerConfig tree of a managed server
322-
* matches with the expected value, a integer value set in the configuration override file
323-
* config.xml. Uses Java assertions to verify if both the values match.
324-
*
325-
* @param expectedValue - integer value to be checked in the max-message-size attribute in
326-
* EditMBean in ServerConfig tree
327-
*/
328-
protected void verifyMsSeverMaxMessageSize(int expectedValue, String serverName) {
329-
330-
try {
331-
EditServiceMBean editSvc = getEditService();
332-
ConfigurationManagerMBean cfgMgr = editSvc.getConfigurationManager();
333-
cfgMgr.startEdit(-1, -1);
334-
DomainMBean editDomainMBean = editSvc.getDomainConfiguration();
335-
336-
ServerMBean serverMbean = editDomainMBean.lookupServer(serverName);
337-
int got = serverMbean.getMaxMessageSize();
338-
assert expectedValue == got
339-
: "Didn't get the expected value "
340-
+ expectedValue
341-
+ " for "
342-
+ serverName
343-
+ " MaxMessageSize";
344-
} catch (Exception e) {
345-
e.printStackTrace();
346-
}
347-
}
348-
349334
/**
350335
* A utility method to check if the Network Access Point public-address in the ServerConfig tree
351336
* matches with the expected value, a string value set in the configuration override file
352337
* config.xml. Uses Java assertions to verify if both the values match.
353338
*
339+
* @param serverName name of the weblogic server instance for which the t3 public address to be checked
340+
* as a String
354341
* @param expectedValue - string value to be checked in the public-address attribute in
355342
* ServerMBean in ServerConfig tree.
356343
*/
357-
protected void verifyT3ChannelPublicAddress(String serverName, String expectedValue) {
344+
protected void verifyT3ChannelPublicAddress(String serverName, String expectedValue)
345+
{
358346
boolean got = false;
359347
ServerMBean serverMBean = getServerMBean(serverName);
360348
NetworkAccessPointMBean[] networkAccessPoints = serverMBean.getNetworkAccessPoints();
@@ -396,35 +384,8 @@ protected void verifyT3ChannelPublicPort(String serverName, int expectedValue) {
396384
* @return the ServerMBean reference
397385
*/
398386
private ServerMBean getServerMBean(String serverName) {
399-
ServerMBean servermbean = null;
400-
ServerMBean[] servers = runtimeServiceMBean.getDomainConfiguration().getServers();
401-
for (ServerMBean server : servers) {
402-
if (server.getName().equals(serverName)) {
403-
servermbean = server;
404-
}
405-
}
406-
println("ServerMBean: " + servermbean);
407-
return servermbean;
408-
}
409-
410-
/**
411-
* Looks up the EditServiceMBean from MBeanServerConnection.
412-
*
413-
* @return the EditServiceMBean reference
414-
*/
415-
// Get edit Service
416-
private EditServiceMBean getEditService() throws Exception {
417-
MBeanServerConnection msc =
418-
lookupMBeanServerConnection(
419-
adminHost,
420-
adminPort,
421-
adminUser,
422-
adminPassword,
423-
"weblogic.management.mbeanservers.edit");
424-
ObjectName serviceObjectName = new ObjectName(EditServiceMBean.OBJECT_NAME);
425-
EditServiceMBean editSvc =
426-
(EditServiceMBean) MBeanServerInvocationHandler.newProxyInstance(msc, serviceObjectName);
427-
return editSvc;
387+
DomainMBean editDomainMBean = editServiceMBean.getDomainConfiguration();
388+
return editDomainMBean.lookupServer(serverName);
428389
}
429390

430391
/**

0 commit comments

Comments
 (0)