1 23 24 package com.sun.enterprise.admin.server.core.mbean.test; 25 26 import java.io.*; 28 import java.util.*; 29 30 import javax.management.*; 32 33 import com.sun.enterprise.admin.common.*; 35 import com.sun.enterprise.admin.common.constant.*; 36 import com.sun.enterprise.admin.util.*; 37 import com.sun.enterprise.admin.server.core.jmx.*; 38 import com.sun.enterprise.admin.server.core.mbean.config.*; 39 import com.sun.enterprise.admin.server.core.mbean.meta.*; 40 import com.sun.enterprise.admin.server.core.*; 41 public class ConfigBeansTest 42 { 43 44 45 48 49 public static void main(String args[]) 50 { 51 ConfigBeansTest testMain = new ConfigBeansTest(); 52 testMain.test(); 53 } 54 55 private void printLine(String str) 56 { 57 System.out.println(str); 58 } 59 60 private void printAttrList(AttributeList attrList, String title) 61 { 62 Iterator it = attrList.iterator(); 63 printLine("\n\n\n################## " + title +" ##################"); 64 AdminLocalStringsManager messages = AdminLocalStringsManager.createMessagesManager(this); 65 while (it.hasNext()) 66 { 67 Attribute attribute = (Attribute) it.next(); 68 String name = attribute.getName(); 69 Object value = attribute.getValue(); 70 printLine(messages.getString("mbeanstest.attrvalue", "======DO NOT KNOW=====", new Object []{name,value})); 71 printLine("Attribute name="+name+" value="+value); 72 } 73 } 74 75 private ObjectName getObjectName(String instance, String type, String name) throws Exception 76 { 77 String objname = "ias:" + 78 ObjectNames.kServerInstanceKeyName + "=" + instance + "," + 79 ObjectNames.kTypeKeyName + "=" + type; 80 if(name!=null) 81 { 82 objname += ("," + ObjectNames.kNameKeyName + "=" + name); 83 } 84 return new ObjectName(objname); 86 } 87 88 private String maskDots(String instance) 89 { 90 int idx = 0; 91 while((idx=instance.indexOf('.', idx))>=0) 92 { 93 instance = instance.substring(0,idx)+'\\'+instance.substring(idx); 94 idx += 2; 95 } 96 return instance; 97 } 98 99 private void test() 100 { 101 try 102 { 103 String instance = "ias1"; 104 String maskedInstance = maskDots(instance); 105 106 111 AdminServiceLifeCycle aslc = new AdminServiceLifeCycle(); 112 aslc.onInitialization(null); 113 MBeanServer mbs = SunoneInterceptor.getMBeanServerInstance(); 114 GenericConfigurator genConf = new GenericConfigurator(); 115 117 AttributeList attrList; 118 119 120 ManagedJ2EEEjbJarModule ejbmod = new ManagedJ2EEEjbJarModule(instance, "app", "helloworldEjb.jar"); 122 { 123 String [] arr = ejbmod.getEnterpriseBeans(); 124 for(int j=0; j<arr.length; j++) 125 printLine("&&&&&&&&&+++++> "+arr[j]); 126 } 127 128 ManagedJ2EEApplication app = new ManagedJ2EEApplication(instance, "app"); 130 { 131 String [] arr = app.getModules(); 132 for(int j=0; j<arr.length; j++) 133 printLine("*************+++++> "+arr[j]); 134 arr = app.getEjbModules(); 135 for(int j=0; j<arr.length; j++) 136 printLine("------> "+arr[j]); 137 arr = app.getModules(); 138 for(int j=0; j<arr.length; j++) 139 printLine("*************+++++> "+arr[j]); 140 } 141 if(genConf!=null) 142 return; 143 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".application.app.*"}); 144 printAttrList(attrList, "Standalone application TEST"); 145 if(genConf!=null) 146 return; 147 148 ManagedHTTPService httpService = new ManagedHTTPService(instance); 150 genConf.setGenericAttribute(maskedInstance + ".httpservice.bandwidthLimit", "TESTbandWidthLimit"); 151 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".httpservice.*"}); 152 printAttrList(attrList, "HTTPService TEST"); 153 157 if(genConf!=null) 158 return; 159 160 ManagedJDBCResource jdbc = new ManagedJDBCResource(instance,"name1"); 162 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".jdbc.name1.*"}); 165 printAttrList(attrList, "JDBC TEST"); 166 ManagedJDBCConnectionPool jdbcpool = new ManagedJDBCConnectionPool(instance,"pool1"); 168 genConf.setGenericAttribute(maskedInstance + ".jdbcpool.pool1.url", "TESTURL2"); 170 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".jdbcpool.pool1.*"}); 171 printAttrList(attrList, "JDBCConnectionPool TEST"); 172 173 174 177 ManagedORBComponent orb = new ManagedORBComponent(instance); 179 genConf.setGenericAttribute(maskedInstance + ".orb.max", new Integer (333)); 181 attrList = genConf.getGenericAttributes(new String [] 182 {maskedInstance + ".orb.max"}); 183 printAttrList(attrList, "ORB max TEST"); 184 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".orb.*"}); 185 printAttrList(attrList, "ORB TEST"); 186 187 ManagedORBListener orbListener = new ManagedORBListener(instance, "myTestId5"); 190 192 194 genConf.setGenericAttribute(maskedInstance + ".orblistener.myTestId5.address", "TESTADDRESS2"); 196 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".orblistener.myTestId5.*"}); 197 printAttrList(attrList, "ORBListener TEST"); 198 199 200 202 ManagedJNDIResource jndi = new ManagedJNDIResource(instance, "myjndi"); 203 genConf.setGenericAttribute(maskedInstance + ".jndi.myjndi.description", "my test description"); 205 attrList = genConf.getGenericAttributes(new String [] {maskedInstance + ".jndi.myjndi.*"}); 206 printAttrList(attrList, "JNDI Resource test"); 207 208 209 ManagedTransactionService transService = new ManagedTransactionService(instance); 211 genConf.setGenericAttribute(maskedInstance + ".transaction.transactionLogDir", "logDir"); 213 attrList = genConf.getGenericAttributes(new String [] {maskedInstance + ".transaction.*"}); 214 printAttrList(attrList, "Transaction TEST"); 215 216 ManagedMdbContainer MdbContainer = new ManagedMdbContainer(instance); 218 genConf.setGenericAttribute(maskedInstance + ".mdbcontainer.queueConnectionFactoryJndiName", "jndi1"); 220 attrList =genConf.getGenericAttributes(new String [] {maskedInstance + ".mdbcontainer.*"}); 221 printAttrList(attrList, "MDB Container test"); 222 223 225 ManagedEjbContainer EjbContainer = new ManagedEjbContainer(instance); 226 genConf.setGenericAttribute(maskedInstance + ".ejbcontainer.minBeansInPool", new Integer (20)); 228 attrList = genConf.getGenericAttributes(new String [] {maskedInstance + ".ejbcontainer.*"}); 229 printAttrList(attrList, "EJB Container test"); 230 231 233 ManagedWebContainer WebContainer = new ManagedWebContainer(instance); 234 genConf.setGenericAttribute(maskedInstance + ".ejbcontainer.minBeansInPool", new Integer (20)); 236 attrList = genConf.getGenericAttributes(new String [] {maskedInstance + ".webcontainer.*"}); 237 printAttrList(attrList, "WEB Container test"); 238 239 241 ManagedJVM Jvm = new ManagedJVM(instance); 242 attrList = genConf.getGenericAttributes(new String [] {maskedInstance + ".jvmconfig.*"}); 245 printAttrList(attrList, "JVM test"); 246 247 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".security.*"}); 251 printAttrList(attrList, "SecurityService TEST"); 252 253 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".application.app.*"}); 256 printAttrList(attrList, "Standalone application TEST"); 257 258 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".ejbmodule.ejb.*"}); 261 printAttrList(attrList, "Standalone EjbJar module TEST"); 262 263 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".webmodule.web.*"}); 266 printAttrList(attrList, "Standalone Web Module TEST"); 267 268 attrList = genConf.getGenericAttributes(new String []{maskedInstance + ".connectormodule.conn.*"}); 271 printAttrList(attrList, "Standalone Connector Module TEST"); 272 } 273 catch(MBeanException m) 274 { 275 printLine(m.getMessage()); 276 Exception t = m.getTargetException(); 277 while(t instanceof MBeanException) 278 { 279 t = ((MBeanException)t).getTargetException(); 280 } 281 printLine(t.getMessage()); 282 printLine(t.toString()); 283 m.printStackTrace(); 284 } 285 catch(Throwable e) 286 { 287 printLine(e.getMessage()); 288 printLine(e.toString()); 289 e.printStackTrace(); 290 } 291 } 292 293 294 } 295 | Popular Tags |