1 23 24 28 29 package com.sun.enterprise.admin.mbeans; 30 31 import java.util.List ; 32 import java.util.Properties ; 33 import java.util.Set ; 34 import java.util.Enumeration ; 35 import java.util.Arrays ; 36 import java.util.ArrayList ; 37 import java.util.Vector ; 38 import java.util.logging.Level ; 39 import java.util.logging.Logger ; 40 import java.util.Iterator ; 41 import java.lang.reflect.InvocationTargetException ; 42 import java.util.StringTokenizer ; 43 import java.util.Map ; 44 import java.util.HashMap ; 45 46 import javax.management.Attribute ; 48 import javax.management.AttributeList ; 49 import javax.management.ObjectName ; 50 import javax.management.MBeanException ; 51 import javax.management.MalformedObjectNameException ; 52 import javax.management.RuntimeOperationsException ; 53 import javax.management.MBeanServerFactory ; 54 import javax.management.MBeanServer ; 55 import javax.management.modelmbean.ModelMBeanOperationInfo ; 56 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 57 import javax.management.MBeanInfo ; 58 import javax.management.AttributeNotFoundException ; 59 60 import com.sun.enterprise.jms.IASJmsUtil; 62 63 import com.sun.messaging.jmq.jmsspi.JMSAdmin; 65 import com.sun.messaging.jmq.jmsspi.JMSAdminFactory; 66 import com.sun.messaging.jmq.jmsspi.JMSConstants; 67 68 import com.sun.enterprise.config.ConfigContext; 70 import com.sun.enterprise.config.ConfigException; 71 72 import com.sun.enterprise.admin.MBeanHelper; 73 import com.sun.enterprise.admin.config.BaseConfigMBean; 74 import com.sun.enterprise.admin.config.ConfigMBeanHelper; 75 import com.sun.enterprise.admin.config.MBeanConfigException; 76 import com.sun.enterprise.admin.common.constant.AdminConstants; 77 import com.sun.enterprise.admin.common.exception.AFResourceException; 78 79 import com.sun.enterprise.admin.server.core.AdminService; 80 import com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor; 81 import com.sun.enterprise.util.i18n.StringManager; 82 83 import com.sun.enterprise.config.serverbeans.ServerTags; 84 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 85 import com.sun.enterprise.config.serverbeans.JmsService; 86 import com.sun.enterprise.config.serverbeans.JmsHost; 87 import com.sun.enterprise.config.serverbeans.ResourceRef; 88 import com.sun.enterprise.config.serverbeans.Resources; 89 import com.sun.enterprise.config.serverbeans.ResourceHelper; 90 import com.sun.enterprise.config.serverbeans.ServerHelper; 91 import com.sun.enterprise.config.serverbeans.ClusterHelper; 92 import com.sun.enterprise.config.ConfigBeansFactory; 93 import com.sun.enterprise.config.serverbeans.Config; 94 95 import com.sun.enterprise.admin.event.EventBuilder; 97 import com.sun.enterprise.admin.event.EventContext; 98 import com.sun.enterprise.admin.event.ConfigChangeEvent; 99 import com.sun.enterprise.admin.event.BaseDeployEvent; 100 101 import javax.resource.ResourceException ; 103 import javax.jms.JMSException ; 104 import com.sun.enterprise.connectors.ConnectorRuntime; 105 import com.sun.enterprise.connectors.ConnectorConstants; 106 import com.sun.enterprise.connectors.util.JmsRaMapping; 107 import com.sun.enterprise.connectors.util.ConnectionDefinitionUtils; 108 import com.sun.enterprise.resource.Resource; 109 import com.sun.enterprise.resource.ResourcesXMLParser; 110 import com.sun.enterprise.admin.common.exception.JMSAdminException; 111 import com.sun.enterprise.admin.common.constant.JMSAdminConstants; 112 import com.sun.enterprise.admin.common.JMSStatus; 113 import com.sun.enterprise.admin.common.JMSDestinationInfo; 114 115 import com.sun.enterprise.server.ApplicationServer; 116 117 import com.sun.enterprise.admin.mbeanapi.IResourcesMBean; 118 119 import com.sun.enterprise.admin.target.Target; 120 import com.sun.enterprise.admin.target.TargetType; 121 import com.sun.enterprise.admin.target.TargetBuilder; 122 123 import com.sun.enterprise.admin.configbeans.ResourceReferenceHelper; 124 125 public class ResourcesMBean extends BaseConfigMBean 126 implements IResourcesMBean 127 { 128 private static final String CUSTOM_RESOURCE = ServerTags.CUSTOM_RESOURCE; 129 private static final String JDBC_CONNECTION_POOL = ServerTags.JDBC_CONNECTION_POOL; 130 private static final String CONNECTOR_RESOURCE = ServerTags.CONNECTOR_RESOURCE; 131 private static final String ADMIN_OBJECT_RESOURCE = ServerTags.ADMIN_OBJECT_RESOURCE; 132 private static final String JDBC_RESOURCE = ServerTags.JDBC_RESOURCE; 133 private static final String RESOURCE_ADAPTER_CONFIG = ServerTags.RESOURCE_ADAPTER_CONFIG; 134 private static final String MAIL_RESOURCE = ServerTags.MAIL_RESOURCE; 135 private static final String EXTERNAL_JNDI_RESOURCE = ServerTags.EXTERNAL_JNDI_RESOURCE; 136 private static final String CONNECTOR_CONNECTION_POOL = ServerTags.CONNECTOR_CONNECTION_POOL; 137 private static final String PERSISTENCE_MANAGER_FACTORY_RESOURCE = ServerTags.PERSISTENCE_MANAGER_FACTORY_RESOURCE; 138 139 public static final Logger sLogger = Logger.getLogger(AdminConstants.kLoggerName); 140 private static final StringManager localStrings = StringManager.getManager( ResourcesMBean.class ); 141 142 private static final String GET = "get"; 143 private static final String BYNAME = "ByName"; 144 private static final String BYJNDINAME = "ByJndiName"; 145 private static final String PMF_SUFFIX = "PM"; 146 147 private static final String QUEUE = "javax.jms.Queue"; 149 private static final String TOPIC = "javax.jms.Topic"; 150 private static final String QUEUE_CF = "javax.jms.QueueConnectionFactory"; 151 private static final String TOPIC_CF = "javax.jms.TopicConnectionFactory"; 152 private static final String UNIFIED_CF = "javax.jms.ConnectionFactory"; 153 154 private static final String RESOURCES = "resources"; 155 private static final String POOL_NAME = "pool-name"; 156 private static final String POOL_TYPE = "connector-connection-pool"; 157 private static final String CONFIG = "config"; 158 159 private static final String CREATE_SECURITY_MAP = "createSecurityMap"; 161 162 private static final String DEST_NAME = "destName"; 164 private static final String DEST_TYPE = "destType"; 165 166 172 private static final TargetType[] VALID_CREATE_DELETE_TYPES = new TargetType[] { 173 TargetType.CONFIG, 174 TargetType.SERVER, 175 TargetType.DOMAIN, 176 TargetType.CLUSTER, 177 TargetType.STANDALONE_SERVER, 178 TargetType.UNCLUSTERED_SERVER, 179 TargetType.STANDALONE_CLUSTER, 180 TargetType.DAS}; 181 182 private static final TargetType[] VALID_LIST_TYPES = new TargetType[] { 183 TargetType.CONFIG, 184 TargetType.SERVER, 185 TargetType.DOMAIN, 186 TargetType.CLUSTER, 187 TargetType.STANDALONE_SERVER, 188 TargetType.UNCLUSTERED_SERVER, 189 TargetType.STANDALONE_CLUSTER, 190 TargetType.DAS}; 191 192 194 public ResourcesMBean() 195 { 196 super(); 197 } 198 199 private ResourceReferenceHelper getResourceReferenceHelper() 200 { 201 return new ResourceReferenceHelper(getConfigContext()); 202 } 203 204 212 public String [] getSystemConnectorsAllowingPoolCreation() { 213 return ConnectorRuntime.getRuntime().getSystemConnectorsAllowingPoolCreation(); 214 } 215 216 218 public ObjectName createCustomResource( AttributeList attrList, 219 Properties props, 220 String tgtName ) 221 throws Exception 222 { 223 return createResource( CUSTOM_RESOURCE, attrList, props, tgtName ); 224 } 225 226 public ObjectName createExternalJndiResource( AttributeList attrList, 227 Properties props, 228 String tgtName) 229 throws Exception 230 { 231 return createResource( EXTERNAL_JNDI_RESOURCE, attrList, props, tgtName ); 232 } 233 234 public ObjectName createPersistenceManagerFactoryResource( AttributeList attrList, 235 Properties props, 236 String tgtName) 237 throws Exception 238 { 239 return createResource( PERSISTENCE_MANAGER_FACTORY_RESOURCE, attrList, props, tgtName ); 240 } 241 242 public ObjectName createPMFResourceWithJDBCResource( AttributeList attrList, 243 Properties props, 244 String tgtName) 245 throws Exception 246 { 247 String poolName = null; 249 String jndiName = null; 250 int indx = 0; 251 252 for (int i=0; i<attrList.size(); i++) 253 { 254 Attribute attr = (Attribute )attrList.get(i); 255 if (isAttrNameMatch(attr, "pool-name")) { 256 poolName = (String )attr.getValue(); 257 indx = i; 258 } 259 if (isAttrNameMatch(attr, "jndi-name")) 260 jndiName = (String )attr.getValue(); 261 } 262 263 if (poolName != null && !(poolName.equals(""))) { 264 jndiName = jndiName + PMF_SUFFIX; AttributeList jdbcAttrList = new AttributeList (); 266 jdbcAttrList.add(new Attribute ("jndi_name", (Object )jndiName)); 267 jdbcAttrList.add(new Attribute ("pool_name", (Object )poolName)); 268 269 createResource( JDBC_RESOURCE, jdbcAttrList, null, tgtName ); 270 271 attrList.remove(indx); 273 attrList.add(new Attribute ("jdbc_resource_jndi_name", (Object )jndiName)); 275 } 276 277 return createResource( PERSISTENCE_MANAGER_FACTORY_RESOURCE, attrList, props, tgtName ); 278 } 279 280 public ObjectName createJmsConnectionFactory( AttributeList attrList, 281 Properties props, 282 String tgtName) 283 throws Exception 284 { 285 return createJmsResource(attrList, props, tgtName); 286 } 287 288 public ObjectName createJmsDestinationResource( AttributeList attrList, 289 Properties props, 290 String tgtName) 291 throws Exception 292 { 293 return createJmsResource(attrList, props, tgtName); 294 } 295 296 public String getJmsRaMappedName(String name) { 298 return ConnectorRuntime.getRuntime().getJmsRaMapping().getMappedName(name); 299 } 300 301 public ObjectName createJmsResource( AttributeList attrList, 302 Properties props, 303 String tgtName) 304 throws Exception 305 { 306 sLogger.info("createJmsResource -------------------" ); 307 ObjectName mbean = null; 308 Properties properties = null; 309 310 Target target = getResourceTarget(tgtName); 311 312 JmsRaMapping ramap = ConnectorRuntime.getRuntime().getJmsRaMapping(); 314 315 316 if (props != null) { 317 Enumeration en = props.keys(); 318 properties = new Properties (); 319 while (en.hasMoreElements()) { 320 String key = (String ) en.nextElement(); 321 String raKey = ramap.getMappedName(key); 322 if (raKey == null) raKey = key; 323 properties.put(raKey, (String ) props.get(key)); 324 } 325 } 326 327 String raName = ConnectorRuntime.DEFAULT_JMS_ADAPTER; 329 330 String resourceType = null; 332 String jndiName = null; 333 String description = null; 334 Object enabled = null; 335 String steadyPoolSize = null; 336 String maxPoolSize = null; 337 String poolResizeQuantity = null; 338 String idleTimeoutInSecs = null; 339 String maxWaitTimeInMillis = null; 340 String failAllConnections = null; 341 String transactionSupport = null; 342 343 for (int i=0; i<attrList.size(); i++) 344 { 345 Attribute attr = (Attribute )attrList.get(i); 346 if (isAttrNameMatch(attr, "res-type")) 347 resourceType = (String )attr.getValue(); 348 else if (isAttrNameMatch(attr, "jndi-name")) 349 jndiName = (String )attr.getValue(); 350 else if (isAttrNameMatch(attr, "enabled")) 351 enabled = attr.getValue(); 352 else if (isAttrNameMatch(attr, "description")) 353 description = (String )attr.getValue(); 354 else if (isAttrNameMatch(attr, "steady-pool-size")) 355 steadyPoolSize = (String ) attr.getValue(); 356 else if (isAttrNameMatch(attr, "max-pool-size")) 357 maxPoolSize = (String ) attr.getValue(); 358 else if (isAttrNameMatch(attr, "pool-resize-quantity")) 359 poolResizeQuantity = (String ) attr.getValue(); 360 else if (isAttrNameMatch(attr, "idle-timeout-in-seconds")) 361 idleTimeoutInSecs = (String ) attr.getValue(); 362 else if (isAttrNameMatch(attr, "max-wait-time-in-millis")) 363 maxWaitTimeInMillis = (String ) attr.getValue(); 364 else if (isAttrNameMatch(attr, "transaction-support")) 365 transactionSupport = (String ) attr.getValue(); 366 else if(isAttrNameMatch(attr, "fail-all-connections")) 367 failAllConnections = (String ) attr.getValue(); 368 369 370 } 371 372 if (resourceType == null) 373 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_res_type")); 374 375 ObjectName resObjName = m_registry.getMbeanObjectName(RESOURCES, new String []{getDomainName()}); 376 if (resourceType.equals(TOPIC_CF) || resourceType.equals(QUEUE_CF) || resourceType.equals(UNIFIED_CF)) 377 { 378 380 String defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName); 381 382 ObjectName connPool = null; 384 try { 385 connPool = (ObjectName )getMBeanServer().invoke(resObjName, "getConnectorConnectionPoolByName", 386 new Object [] {defPoolName, tgtName}, 387 new String [] {"java.lang.String", "java.lang.String"}); 388 } catch (Exception ee){} 389 390 if (connPool == null) { 392 AttributeList cpAttrList = new AttributeList (); 394 cpAttrList.add(new Attribute ("name", (Object )defPoolName)); 395 cpAttrList.add(new Attribute ("resource_adapter_name", (Object )raName)); 396 cpAttrList.add(new Attribute ("connection_definition_name", (Object )resourceType)); 397 cpAttrList.add(new Attribute ("max_pool_size", (maxPoolSize == null) ? (Object )"250" : (Object )maxPoolSize)); 398 cpAttrList.add(new Attribute ("steady_pool_size", (steadyPoolSize == null) ? (Object )"1" : (Object )steadyPoolSize)); 399 if (poolResizeQuantity != null) { 400 cpAttrList.add(new Attribute ("pool_resize_quantity", (Object )poolResizeQuantity)); 401 } 402 if (idleTimeoutInSecs != null) { 403 cpAttrList.add(new Attribute ("idle_timeout_in_seconds", (Object )idleTimeoutInSecs)); 404 } 405 if (maxWaitTimeInMillis != null) { 406 cpAttrList.add(new Attribute ("max_wait_time_in_millis", (Object )maxWaitTimeInMillis)); 407 } 408 if (failAllConnections != null) { 409 cpAttrList.add(new Attribute ("fail-all-connections",(Object )failAllConnections)); 410 } 411 if (transactionSupport != null) { 412 cpAttrList.add(new Attribute ("transaction-support", (Object )transactionSupport)); 413 } 414 415 416 getMBeanServer().invoke(resObjName, "createConnectorConnectionPool", 417 new Object [] {cpAttrList, properties, tgtName}, 418 new String [] {AttributeList .class.getName(), Properties .class.getName(), "java.lang.String"}); 419 } 420 421 AttributeList crAttrList = new AttributeList (); 423 crAttrList.add(new Attribute ("jndi_name", (Object )jndiName)); 424 crAttrList.add(new Attribute ("pool_name", (Object )defPoolName)); 425 if(enabled!=null) 426 crAttrList.add(new Attribute ("enabled", enabled)); 427 if(description!=null) 428 crAttrList.add(new Attribute ("description", description)); 429 try { 430 mbean = (ObjectName )getMBeanServer().invoke(resObjName, "createConnectorResource", 431 new Object [] {crAttrList, null, tgtName}, 432 new String [] {AttributeList .class.getName(), Properties .class.getName(), "java.lang.String"}); 433 } catch (MBeanException me) { 434 me.printStackTrace(); 435 if(connPool==null) 438 { 439 getMBeanServer().invoke(resObjName, "deleteConnectorConnectionPool", 440 new Object [] {defPoolName, tgtName}, 441 new String [] {"java.lang.String", "java.lang.String"}); 442 } 443 throw me; 444 } 445 } 446 else if (resourceType.equals("javax.jms.Topic") || 447 resourceType.equals("javax.jms.Queue")) 448 { 449 validateDestinationResource(properties, jndiName); 450 AttributeList aoAttrList = new AttributeList (); 452 aoAttrList.add(new Attribute ("jndi_name", (Object )jndiName)); 453 aoAttrList.add(new Attribute ("res_type", (Object )resourceType)); 454 aoAttrList.add(new Attribute ("res_adapter", (Object )raName)); 455 if(enabled!=null) 456 aoAttrList.add(new Attribute ("enabled", enabled)); 457 if(description!=null) 458 aoAttrList.add(new Attribute ("description", description)); 459 sLogger.info("props = " + properties); 460 461 mbean = (ObjectName )getMBeanServer().invoke(resObjName, "createAdminObjectResource", 462 new Object [] {aoAttrList, properties, tgtName}, 463 new String [] {AttributeList .class.getName(), Properties .class.getName(), "java.lang.String"}); 464 } else { 465 throw new Exception (localStrings.getString("admin.mbeans.rmb.invalid_res_type", resourceType)); 466 } 467 475 return mbean; 476 } 477 478 private void validateDestinationResource(Properties props, String jndiName) 479 throws Exception { 480 if (props == null) { 481 throw new Exception (localStrings.getString( 482 "admin.mbeans.rmb.destination_name_missing", jndiName)); 483 } 484 for (Enumeration e = props.keys() ; e.hasMoreElements() ;) { 485 String key = (String )e.nextElement(); 486 String value = (String )props.get(key); 487 if(key.equals("Name") || key.equals("imqDestinationName")){ 488 if (value != null && value.length() != 0) return; 489 } 490 } 491 throw new Exception (localStrings.getString( 492 "admin.mbeans.rmb.destination_name_missing", jndiName)); 493 494 } 495 496 public ObjectName createJdbcConnectionPool( AttributeList attrList, 497 Properties props, 498 String tgtName) 499 throws Exception 500 { 501 return createResource( JDBC_CONNECTION_POOL, attrList, props, tgtName ); 502 } 503 504 public ObjectName createConnectorConnectionPool( AttributeList attrList, 505 Properties props, 506 String tgtName) 507 throws Exception 508 { 509 return createResource( CONNECTOR_CONNECTION_POOL, attrList, props, tgtName ); 511 } 512 513 public ObjectName createConnectorResource( AttributeList attrList, 514 Properties props, 515 String tgtName) 516 throws Exception 517 { 518 return createResource( CONNECTOR_RESOURCE, attrList, props, tgtName ); 519 } 520 521 public ObjectName createAdminObjectResource( AttributeList attrList, 522 Properties props, 523 String tgtName) 524 throws Exception 525 { 526 String raName = null; 527 String resType = null; 528 boolean validResType = false; 529 530 for (int i=0; i<attrList.size(); i++) 532 { 533 Attribute attr = (Attribute )attrList.get(i); 534 535 if (isAttrNameMatch(attr, "res-adapter")) { 536 raName = (String )attr.getValue(); 537 } 538 if (isAttrNameMatch(attr, "res-type")) { 539 resType = (String )attr.getValue(); 540 } 541 } 542 543 if (isValidRAName(raName)) { 544 String [] resTypes = ConnectorRuntime.getRuntime().getAdminObjectInterfaceNames(raName); 548 if (resTypes == null || resTypes.length <= 0) 549 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_ao_intf", raName)); 550 551 for (int i=0; i<resTypes.length; i++) { 552 if (resTypes[i].equals(resType)) { 553 validResType = true; 554 break; 555 } 556 } 557 558 if (!validResType) { 559 throw new Exception (localStrings.getString("admin.mbeans.rmb.invalid_res_type", resType)); 560 } 561 562 return createResource( ADMIN_OBJECT_RESOURCE, attrList, props, tgtName ); 563 } 564 else return null; 565 } 566 567 public ObjectName createJdbcResource( AttributeList attrList, 568 Properties props, 569 String tgtName) 570 throws Exception 571 { 572 return createResource( JDBC_RESOURCE, attrList, props, tgtName ); 573 } 574 575 public ObjectName createMailResource( AttributeList attrList, 576 Properties props, 577 String tgtName) 578 throws Exception 579 { 580 return createResource( MAIL_RESOURCE, attrList, props, tgtName ); 581 } 582 583 public ObjectName createResourceAdapterConfig( AttributeList attrList, 584 Properties props, 585 String tgtName) 586 throws Exception 587 { 588 final ObjectName on = createResource( RESOURCE_ADAPTER_CONFIG, attrList, props, tgtName ); 589 590 return on; 591 } 592 593 private ObjectName createResource( String resourceType, 594 AttributeList attrList, 595 Properties props, 596 String tgtName ) throws Exception { 597 return createResource(resourceType, attrList, props, tgtName,true); 598 } 599 600 private ObjectName createResource( String resourceType, 601 AttributeList attrList, 602 Properties props, 603 String tgtName, 604 boolean createResourceRefs ) 605 throws Exception 606 { 607 if (resourceType.equals(CONNECTOR_CONNECTION_POOL)) 608 validateCnctorConnPoolAttrList(attrList); 609 610 611 ObjectName mbean = null; 612 613 final Target target = TargetBuilder.INSTANCE.createTarget( 614 VALID_CREATE_DELETE_TYPES, 615 tgtName, getConfigContext()); boolean hasReferences = isResourceReferenceValid(resourceType, target.getType()); 617 618 boolean enabled = true; 619 String resName = getResourceName(resourceType, attrList); 620 int idxEnabled = -1; 621 if (attrList != null) 622 { 623 for(int i=0; i<attrList.size(); i++) 624 { 625 Attribute attr = (Attribute )attrList.get(i); 626 if (attr.getName().equals("enabled")) 627 { 628 enabled = Boolean.valueOf(attr.getValue().toString()).booleanValue(); 629 idxEnabled = i; 630 } 631 } 632 } 633 634 635 Attribute saveEnabledAtttr = null; 636 if(!enabled && hasReferences) 637 { saveEnabledAtttr = (Attribute )attrList.get(idxEnabled); 639 attrList.set(idxEnabled, new Attribute ("enabled", "true")); 640 } 641 mbean = (ObjectName )super.invoke( "create" + ConfigMBeanHelper.convertTagName(resourceType), 642 new Object [] {attrList}, 643 new String [] {AttributeList .class.getName()}); 644 645 if(!enabled && hasReferences) 646 { attrList.set(idxEnabled, saveEnabledAtttr); 648 } 649 650 if (props != null) 652 { 653 setProperties(mbean, props); 654 } 655 656 662 if (!hasReferences) 663 { 664 return mbean; 665 } 666 667 if (target.getType() == TargetType.SERVER || 670 target.getType() == TargetType.CLUSTER || 671 target.getType() == TargetType.DAS) 672 { 673 if ( (resName != null) && !(resName.equals("")) && createResourceRefs ) 674 { 675 getResourceReferenceHelper().createResourceReference( 677 target.getName(), enabled, resName); 678 } 679 } 680 return mbean; 681 } 682 683 689 private boolean isResourceReferenceValid(String resourceType, TargetType targetType) { 690 boolean hasReferences = (!( resourceType.equals(CONNECTOR_CONNECTION_POOL) || 691 resourceType.equals(JDBC_CONNECTION_POOL) || 692 resourceType.equals(RESOURCE_ADAPTER_CONFIG) || 693 (targetType == TargetType.DOMAIN))); 694 return hasReferences; 695 } 696 697 701 private String getResourceName(String resourceType, AttributeList attrList) { 702 if (attrList != null) { 703 if (resourceType.equals(RESOURCE_ADAPTER_CONFIG)) { 704 for(int i=0; i<attrList.size(); i++) { 705 Attribute attr = (Attribute )attrList.get(i); 706 if ( attr.getName().equals("resource-adapter-name") ){ 707 return (String )attr.getValue(); 708 } 709 } 710 } else { 711 for(int i=0; i<attrList.size(); i++) { 712 Attribute attr = (Attribute )attrList.get(i); 713 if (attr.getName().equals("name") || attr.getName().equals("jndi_name") || 715 attr.getName().equals("jndi-name")) { 716 return (String )attr.getValue(); 717 } 718 } 719 } 720 } 721 return ""; 722 } 723 724 public void createResourceReference(String targetName, boolean enabled, 727 String referenceName) throws ConfigException 728 { 729 getResourceReferenceHelper().createResourceReference( 731 targetName, enabled, referenceName); 732 } 733 734 740 public void createResourceReference(String targetName, boolean enabled, 741 Resource resource) throws ConfigException { 742 this.createResourceReference(targetName, enabled, getResourceName(resource.getType(), resource.getAttributes())); 743 } 744 745 753 public void createResourceReference(List <Resource> res, List <String > tgtNames, 754 Boolean isEnabled) throws Exception { 755 Iterator <Resource> resources = res.iterator(); 756 while (resources.hasNext()) { 759 createAResourceReference(resources.next(), tgtNames, isEnabled); 760 } 761 } 762 763 private void createAResourceReference(Resource res, List <String > tgtNames, Boolean isEnabled) 764 throws Exception { 765 for (String target : tgtNames) { 766 createAResourceReference(res, target, isEnabled); 767 } 768 } 769 770 private void createAResourceReference(Resource res, String target, Boolean isEnabled) 771 throws Exception { 772 TargetType targetType = getResourceTarget(target).getType(); 773 String resourceType = res.getType(); 774 if (isResourceReferenceValid(resourceType,targetType)) { 775 createResourceReference(target, isEnabled.booleanValue(), getResourceName(res.getType(), res.getAttributes())); 776 } 777 } 778 779 786 public void deleteResourceReference(String targetName, Resource resource) throws Exception { 787 Target target = getResourceTarget(targetName); 788 this.deleteResourceRef(getResourceName(resource.getType(), resource.getAttributes()), target, targetName); 789 } 790 791 798 public void deleteResourceReference(List <Resource> res, List <String > targetNames) throws Exception { 799 int size = res.size(); 801 for (int i = (size -1); i >= 0 ; i--) { 803 Resource resource = res.get(i); 804 deleteAResourceRef(resource, targetNames); 805 } 806 } 807 808 809 private void deleteAResourceRef(Resource resource, List <String > targetNames) throws Exception { 810 for (String tgt : targetNames) { 812 Target target = getResourceTarget(tgt); 813 if (isResourceReferenceValid(resource.getType(),target.getType())) { 814 this.deleteResourceRef(getResourceName(resource.getType(), resource.getAttributes()), target, tgt); 815 } 816 } 817 } 818 819 820 private void setProperties(ObjectName objName, Properties props) 821 throws Exception 822 { 823 if ( props != null ) 824 { 825 Enumeration keys = props.keys(); 826 while (keys.hasMoreElements()) 827 { 828 final String key = (String )keys.nextElement(); 829 final Attribute property = new Attribute (key, props.get(key)); 830 getMBeanServer().invoke(objName, "setProperty", new Object []{property}, new String []{Attribute .class.getName()}); 831 } 832 } 833 } 834 835 private boolean isValidRAName(String raName) throws Exception 836 { 837 boolean retVal = false; 838 839 if ((raName == null) || (raName.equals(""))) 841 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_res_adapter")); 842 843 if (raName.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER) || raName.equals(ConnectorRuntime.JAXR_RA_NAME)) { 845 retVal = true; 847 } else { 848 853 ObjectName applnObjName = m_registry.getMbeanObjectName(ServerTags.APPLICATIONS, new String []{getDomainName()}); 854 int indx = raName.indexOf( 855 ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER); 856 if (indx != -1) { 857 String appName = raName.substring(0, indx); 858 ObjectName j2eeAppObjName = (ObjectName )getMBeanServer().invoke(applnObjName, "getJ2eeApplicationByName", new Object []{appName}, new String []{"java.lang.String"}); 859 860 if (j2eeAppObjName == null) 861 throw new Exception (localStrings.getString("admin.mbeans.rmb.invalid_ra_app_not_found", appName)); 862 else retVal = true; 863 } else { 864 ObjectName connectorModuleObjName = (ObjectName )getMBeanServer().invoke(applnObjName, "getConnectorModuleByName", new Object []{raName}, new String []{"java.lang.String"}); 865 866 if (connectorModuleObjName == null) 867 throw new Exception (localStrings.getString("admin.mbeans.rmb.invalid_ra_cm_not_found", raName)); 868 else retVal = true; 869 } 870 } 871 879 return retVal; 880 } 881 882 883 884 887 private void validateCnctorConnPoolAttrList(AttributeList list) throws Exception { 888 String raName = getAttributeValueFromList("resource_adapter_name",list); 889 String connDef = getAttributeValueFromList("connection_definition_name",list); 890 if(isValidRAName(raName)) { 891 if(!isValidConnectionDefinition(connDef,raName)) { 892 throw new Exception (localStrings.getString( 893 "admin.mbeans.rmb.invalid_ra_connectdef_not_found",connDef)); 894 } 895 } 896 } 897 898 901 private boolean isValidConnectionDefinition(String connectionDef,String raName) throws Exception { 902 String [] names = 903 ConnectorRuntime.getRuntime().getConnectionDefinitionNames(raName); 904 for(int i = 0; i < names.length; i++) { 905 if(names[i].equals(connectionDef)) { 906 return true; 907 } 908 } 909 return false; 910 } 911 912 913 916 private String getAttributeValueFromList(String name, AttributeList list) { 917 for (int i=0; i<list.size(); i++) { 918 Attribute attr = (Attribute )list.get(i); 919 if (isAttrNameMatch(attr, name)) { 920 return (String )attr.getValue(); 921 } 922 } 923 return ""; 924 } 925 926 927 930 public ObjectName getCustomResourceByJndiName( String key, String tgtName ) 931 throws Exception 932 { 933 return getResourceByName( CUSTOM_RESOURCE, key, tgtName ); 934 } 935 936 public ObjectName getJdbcResourceByJndiName( String key, String tgtName ) 937 throws Exception 938 { 939 return getResourceByName( JDBC_RESOURCE, key, tgtName ); 940 } 941 942 public ObjectName getJdbcConnectionPoolByName( String key, String tgtName ) 943 throws Exception 944 { 945 return getResourceByName( JDBC_CONNECTION_POOL, key, tgtName ); 946 } 947 948 public ObjectName getExternalJndiResourceByJndiName( String key, String tgtName ) 949 throws Exception 950 { 951 return getResourceByName( EXTERNAL_JNDI_RESOURCE, key, tgtName ); 952 } 953 954 public ObjectName getMailResourceByJndiName( String key, String tgtName ) 955 throws Exception 956 { 957 return getResourceByName( MAIL_RESOURCE, key, tgtName ); 958 } 959 960 public ObjectName getConnectorResourceByJndiName( String key, String tgtName ) 961 throws Exception 962 { 963 return getResourceByName( CONNECTOR_RESOURCE, key, tgtName ); 964 } 965 966 public ObjectName getResourceAdapterConfigByResourceAdapterName( String key, String tgtName ) 967 throws Exception 968 { 969 return getResourceByName( RESOURCE_ADAPTER_CONFIG, key, tgtName ); 970 } 971 972 public ObjectName getAdminObjectResourceByJndiName( String key, String tgtName ) 973 throws Exception 974 { 975 return getResourceByName( ADMIN_OBJECT_RESOURCE, key, tgtName ); 976 } 977 978 public ObjectName getPersistenceManagerFactoryResourceByJndiName( String key, String tgtName ) 979 throws Exception 980 { 981 return getResourceByName( PERSISTENCE_MANAGER_FACTORY_RESOURCE, key, tgtName ); 982 } 983 984 public ObjectName getConnectorConnectionPoolByName( String key, String tgtName ) 985 throws Exception 986 { 987 return getResourceByName( CONNECTOR_CONNECTION_POOL, key, tgtName ); 988 } 989 990 private ObjectName getResourceByName( String resType, String key, String tgtName ) 991 throws Exception 992 { 993 ObjectName mbean = null; 994 995 { 997 final Target target = TargetBuilder.INSTANCE.createTarget( 998 VALID_LIST_TYPES, tgtName, getConfigContext()); 999 String opName = ""; 1000 if (resType.equals(RESOURCE_ADAPTER_CONFIG)) { 1001 opName = GET + ConfigMBeanHelper.convertTagName(resType) + "By" + ConfigMBeanHelper.convertTagName(ServerTags.RESOURCE_ADAPTER_NAME); 1003 } else if (resType.equals(JDBC_CONNECTION_POOL) || resType.equals(CONNECTOR_CONNECTION_POOL)) { 1004 opName = GET + ConfigMBeanHelper.convertTagName(resType) + BYNAME; 1006 } else opName = GET + ConfigMBeanHelper.convertTagName(resType) + BYJNDINAME; 1007 1008 mbean = (ObjectName )super.invoke(opName, new Object [] {key}, 1009 new String [] {key.getClass().getName()}); 1010 } 1011 1021 return mbean; 1022 } 1023 1024 1027 public ObjectName [] getCustomResource( String tgtName ) 1028 throws Exception 1029 { 1030 return getResource( CUSTOM_RESOURCE, tgtName ); 1031 } 1032 1033 public ObjectName [] getPersistenceManagerFactoryResource( String tgtName ) 1034 throws Exception 1035 { 1036 return getResource( PERSISTENCE_MANAGER_FACTORY_RESOURCE, tgtName ); 1037 } 1038 1039 public ObjectName [] getJmsResource( String tgtName ) 1040 throws Exception 1041 { 1042 return getJmsResource( null, tgtName ); 1043 } 1044 1045 public ObjectName [] getJmsConnectionFactory( String tgtName ) 1046 throws Exception 1047 { 1048 ObjectName [] QRes = null; 1049 ObjectName [] TRes = null; 1050 ObjectName [] uRes = null; 1051 ObjectName [] retVal = null; 1052 1053 QRes = getJmsResource( QUEUE_CF, tgtName ); 1054 TRes = getJmsResource( TOPIC_CF, tgtName ); 1055 uRes = getJmsResource( UNIFIED_CF, tgtName ); 1056 1057 int i = 0; 1058 if (QRes != null) i = QRes.length; 1059 if (TRes != null) i = i + TRes.length; 1060 if (uRes != null) i = i + uRes.length; 1061 1062 if (i > 0) { 1063 ArrayList ret = new ArrayList (); 1064 if (QRes != null) ret.addAll(Arrays.asList(QRes)); 1065 if (TRes != null) ret.addAll(Arrays.asList(TRes)); 1066 if (uRes != null) ret.addAll(Arrays.asList(uRes)); 1067 1068 if (ret.size() > 0) { 1069 retVal = new ObjectName [ret.size()]; 1070 ret.toArray(retVal); 1071 } 1072 } 1073 1074 return retVal; 1075 } 1076 1077 public ObjectName [] getJmsDestinationResource( String tgtName ) 1078 throws Exception 1079 { 1080 ObjectName [] QRes = null; 1081 ObjectName [] TRes = null; 1082 ObjectName [] retVal = null; 1083 1084 QRes = getJmsResource( QUEUE, tgtName ); 1085 TRes = getJmsResource( TOPIC, tgtName ); 1086 1087 int i = 0; 1088 if (QRes != null) i = QRes.length; 1089 if (TRes != null) i = i + TRes.length; 1090 1091 if (i > 0) { 1092 ArrayList ret = new ArrayList (); 1093 if (QRes != null) ret.addAll(Arrays.asList(QRes)); 1094 if (TRes != null) ret.addAll(Arrays.asList(TRes)); 1095 1096 if (ret.size() > 0) { 1097 retVal = new ObjectName [ret.size()]; 1098 ret.toArray(retVal); 1099 } 1100 } 1101 1102 return retVal; 1103 } 1104 1105 public ObjectName [] getJmsResource( String resType, String tgtName ) 1106 throws Exception 1107 { 1108 Target target = getResourceTarget(tgtName); 1109 1110 ObjectName [] QRes = null; 1111 ObjectName [] TRes = null; 1112 ObjectName [] QCFRes = null; 1113 ObjectName [] TCFRes = null; 1114 ObjectName [] uCFRes = null; 1115 ObjectName [] retVal = null; 1116 1117 if (resType == null || resType.equals("null")) { 1119 QRes = getJmsResourceForResType(QUEUE); 1121 TRes = getJmsResourceForResType(TOPIC); 1122 QCFRes = getJmsResourceForResType(QUEUE_CF); 1123 TCFRes = getJmsResourceForResType(TOPIC_CF); 1124 uCFRes = getJmsResourceForResType(UNIFIED_CF); 1125 1126 int i = 0; 1127 if (QRes != null) i = QRes.length; 1128 if (TRes != null) i = i + TRes.length; 1129 if (QCFRes != null) i = i + QCFRes.length; 1130 if (TCFRes != null) i = i + TCFRes.length; 1131 if (uCFRes != null) i = i + uCFRes.length; 1132 if (i > 0) { 1133 ArrayList ret = new ArrayList (); 1134 if (QRes != null) ret.addAll(Arrays.asList(QRes)); 1135 if (TRes != null) ret.addAll(Arrays.asList(TRes)); 1136 if (QCFRes != null) ret.addAll(Arrays.asList(QCFRes)); 1137 if (TCFRes != null) ret.addAll(Arrays.asList(TCFRes)); 1138 if (uCFRes != null) ret.addAll(Arrays.asList(uCFRes)); 1139 1140 if (ret.size() > 0) { 1141 retVal = new ObjectName [ret.size()]; 1142 ret.toArray(retVal); 1143 } 1144 } 1145 } else { 1146 if (!(resType.equals(QUEUE) || resType.equals(TOPIC) 1147 || resType.equals(QUEUE_CF) || resType.equals(TOPIC_CF) || resType.equals(UNIFIED_CF))) { 1148 throw new Exception (localStrings.getString("admin.mbeans.rmb.invalid_res_type", resType)); 1149 } else { 1150 retVal = getJmsResourceForResType(resType); 1151 } 1152 } 1153 1163 return retVal; 1164 } 1165 1166 private ObjectName [] getJmsResourceForResType( String resType ) 1167 throws MBeanException 1168 { 1169 ObjectName [] retVal = null; 1170 ArrayList al = new ArrayList (); 1171 try { 1172 if (resType.equals(QUEUE) || resType.equals(TOPIC)) { 1173 ObjectName o = m_registry.getMbeanObjectName(RESOURCES, new String []{getDomainName()}); 1176 ObjectName [] adminObjNames = (ObjectName [])getMBeanServer().invoke(o, "getAdminObjectResource", null, null); 1177 if (adminObjNames != null) { 1178 for (int i=0; i<adminObjNames.length; i++) { 1179 String adminResType = (String )getMBeanServer().getAttribute(adminObjNames[i], "res_type"); 1180 if ((adminResType != null) && ((adminResType.equals(QUEUE) && resType.equals(QUEUE)) || (adminResType.equals(TOPIC) && resType.equals(TOPIC)))) { 1181 String adminResAdapter = (String )getMBeanServer().getAttribute(adminObjNames[i], "res_adapter"); 1183 if ((adminResAdapter != null) && (adminResAdapter.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER))) 1184 al.add(adminObjNames[i]); 1185 } 1186 } 1187 if (!al.isEmpty()) { 1188 retVal = new ObjectName [al.size()]; 1189 al.toArray(retVal); 1190 } 1191 } 1192 } else { 1193 ObjectName o = m_registry.getMbeanObjectName(RESOURCES, new String []{getDomainName()}); 1198 ObjectName [] CRObjNames = CRObjNames = (ObjectName [])getMBeanServer().invoke(o, "getConnectorResource", null, null); 1199 if (CRObjNames != null) { 1200 for (int i=0; i<CRObjNames.length; i++) { 1201 String poolName = (String )getMBeanServer().getAttribute(CRObjNames[i], "pool_name"); 1202 if (poolName != null) { 1203 ObjectName CCPObjName = null; 1204 try { 1205 CCPObjName = (ObjectName )getMBeanServer().invoke(o, "getConnectorConnectionPoolByName", new Object []{poolName}, new String []{"java.lang.String"}); 1206 } catch (Exception ee){}; 1207 if (CCPObjName != null) { 1208 String cdn = (String )getMBeanServer().getAttribute(CCPObjName, "connection_definition_name"); 1209 if ((cdn != null) && ((cdn.equals(resType)) || ((cdn.equals(resType))))) { 1210 String resAdapter = (String )getMBeanServer().getAttribute(CCPObjName, "resource_adapter_name"); 1212 if ((resAdapter != null) && (resAdapter.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER))) 1213 al.add(CRObjNames[i]); 1214 } 1215 } 1216 } 1217 } 1218 1219 if (!al.isEmpty()) { 1220 retVal = new ObjectName [al.size()]; 1221 al.toArray(retVal); 1222 } 1223 } 1224 } } catch (javax.management.InstanceNotFoundException infe) {} 1227 catch (javax.management.ReflectionException re) {} 1228 catch (javax.management.AttributeNotFoundException anf) {} 1229 1230 return retVal; 1231 } 1232 1233 public ObjectName [] getJdbcConnectionPool( String tgtName ) 1234 throws Exception 1235 { 1236 return getResource( JDBC_CONNECTION_POOL, tgtName ); 1237 } 1238 1239 public ObjectName [] getConnectorResource( String tgtName ) 1240 throws Exception 1241 { 1242 return getResource( CONNECTOR_RESOURCE, tgtName ); 1243 } 1244 1245 public ObjectName [] getAdminObjectResource( String tgtName ) 1246 throws Exception 1247 { 1248 return getResource( ADMIN_OBJECT_RESOURCE, tgtName ); 1249 } 1250 1251 public ObjectName [] getConnectorConnectionPool( String tgtName ) 1252 throws Exception 1253 { 1254 return getResource( CONNECTOR_CONNECTION_POOL, tgtName ); 1255 } 1256 1257 public ObjectName [] getJdbcResource( String tgtName ) 1258 throws Exception 1259 { 1260 return getResource( JDBC_RESOURCE, tgtName ); 1261 } 1262 1263 public ObjectName [] getResourceAdapterConfig( String tgtName ) 1264 throws Exception 1265 { 1266 return getResource( RESOURCE_ADAPTER_CONFIG, tgtName ); 1267 } 1268 1269 public String getResourceAdapterConfig( String resAdapterConfig, Boolean verbose, String tgtName ) 1270 throws Exception 1271 { 1272 String retVal = null; 1273 StringBuffer sb = new StringBuffer (); 1274 1275 if ((resAdapterConfig != null) && !(resAdapterConfig.equals("")) && !(resAdapterConfig.equals("null"))) { 1277 ObjectName rac = null; 1278 try { 1279 rac = (ObjectName ) super.invoke("getResourceAdapterConfigByResourceAdapterName", new Object []{resAdapterConfig}, new String []{"java.lang.String"}); 1280 } catch (Exception ee){}; 1281 if (rac == null) { 1282 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_rac")); 1283 } 1284 else { 1285 1289 retVal = verbose.booleanValue() ? 1290 getFormattedProperties(rac) : 1291 rac.getKeyProperty("resource-adapter-name"); 1292 } 1293 } 1294 else { 1295 ObjectName [] rac = getResource( RESOURCE_ADAPTER_CONFIG, tgtName ); 1296 1297 if (verbose.booleanValue() && rac != null && rac.length>0) { 1298 for (int i=0; i<rac.length; i++) { 1299 sb.append(getFormattedProperties(rac[i])); 1300 sb.append("\n"); 1301 } 1302 } else if(!verbose.booleanValue() && rac != null && rac.length>0) { 1303 for (int i=0; i<rac.length; i++) { 1304 sb.append(rac[i].getKeyProperty("resource-adapter-name")); 1305 sb.append("\n"); 1306 } 1307 } else sb.append("No resource-adapter-config found."); 1308 1309 retVal = sb.toString(); 1310 } 1311 1319 return retVal; 1320 } 1321 1322 private String getFormattedProperties(ObjectName objName) throws Exception 1323 { 1324 StringBuffer retVal = new StringBuffer (); 1325 1326 if (objName == null) 1328 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_rac")); 1329 1330 retVal.append(objName.getKeyProperty("resource-adapter-name")); 1331 1332 AttributeList props = (AttributeList ) getMBeanServer().invoke(objName, "getProperties", null, null); 1333 1334 if (!props.isEmpty()) { 1335 for (int i=0; i<props.size(); i++) { 1336 Attribute attrib = (Attribute )props.get(i); 1337 if (i==0) retVal.append("\n"); 1338 retVal.append("\t"); 1339 retVal.append(attrib.getName()); 1340 retVal.append("="); 1341 retVal.append(attrib.getValue()); 1342 retVal.append("\n"); 1343 } 1344 } 1345 1351 return retVal.toString(); 1352 } 1353 1354 public ObjectName [] getMailResource( String tgtName ) 1355 throws Exception 1356 { 1357 return getResource( MAIL_RESOURCE, tgtName ); 1358 } 1359 1360 public ObjectName [] getExternalJndiResource( String tgtName ) 1361 throws Exception 1362 { 1363 return getResource( EXTERNAL_JNDI_RESOURCE, tgtName ); 1364 } 1365 1366 private ObjectName [] getResource( String resType, String tgtName ) 1367 throws Exception 1368 { 1369 ArrayList result = new ArrayList (); 1370 1371 final Target target = TargetBuilder.INSTANCE.createTarget( 1372 VALID_LIST_TYPES, tgtName, getConfigContext()); 1373 ObjectName [] mbean = (ObjectName [])super.invoke( GET + ConfigMBeanHelper.convertTagName(resType), null, null); 1374 1375 1383 if (CONNECTOR_CONNECTION_POOL.equals(resType) || 1384 JDBC_CONNECTION_POOL.equals(resType) || 1385 RESOURCE_ADAPTER_CONFIG.equals(resType) || 1386 (target.getType() == TargetType.DOMAIN)) 1387 { 1388 return mbean; 1389 } 1390 1391 1392 if (target.getType() == TargetType.SERVER || 1393 target.getType() == TargetType.CLUSTER || 1394 target.getType() == TargetType.DAS) { 1395 ResourceRef[] refs = target.getResourceRefs(); 1397 String objectProps = null; 1398 for (int i = 0; i < mbean.length; i++) { 1399 for (int j = 0; j < refs.length; j++) { 1400 objectProps = mbean[i].getKeyPropertyListString(); 1401 if (objectProps.indexOf(refs[j].getRef()) > 0) { 1402 result.add(mbean[i]); 1403 break; 1404 } 1405 } 1406 } 1407 } 1408 1409 return (ObjectName [])result.toArray(new ObjectName [result.size()]); 1410 } 1411 1412 1415 public void deleteCustomResource( String name, String tgtName ) 1416 throws Exception 1417 { 1418 this.deleteResource(CUSTOM_RESOURCE, name, tgtName); 1419 } 1420 1421 public void deleteJdbcConnectionPool( String name, String tgtName ) 1422 throws Exception 1423 { 1424 this.deleteJdbcConnectionPool(name, new Boolean (false), tgtName); 1425 } 1426 1427 public void deleteJdbcConnectionPool( String name, Boolean cascade, String tgtName ) 1428 throws Exception 1429 { 1430 deleteConnectionPool(JDBC_RESOURCE, name, cascade, tgtName); 1433 } 1434 1435 void deleteResourceRefFromTargets(String ref) throws Exception 1436 { 1437 final ConfigContext ctx = getConfigContext(); 1439 final String targets = ResourceHelper.getResourceReferenceesAsString( 1440 ctx, ref); 1441 final StringTokenizer strTok = new StringTokenizer (targets, ","); 1442 while (strTok.hasMoreTokens()) 1443 { 1444 final String target = strTok.nextToken(); 1445 if (ServerHelper.isAServer(ctx, target) && 1446 ServerHelper.isServerClustered (ctx, target)) 1447 { 1448 continue; 1450 } 1451 getResourceReferenceHelper().deleteResourceReference( 1452 target, ref); 1453 } 1454 } 1455 1456 private void deleteConnectionPool( String resType, String name, Boolean cascade, String tgtName ) 1457 throws Exception 1458 { 1459 boolean crFound = false; 1463 boolean pmfFound = false; 1464 1465 Target target = getResourceTarget(tgtName); 1466 1467 String [] resArr = null; 1469 String [] pmfArr = null; 1470 1471 String opName = GET + ConfigMBeanHelper.convertTagName(resType); 1472 ObjectName [] resObjNames = (ObjectName [])super.invoke(opName, new Object []{tgtName}, new String []{"java.lang.String"}); 1473 1474 if (resObjNames != null && resObjNames.length > 0) 1475 { 1476 int k=0; 1477 resArr = new String [resObjNames.length]; 1478 for (int i=0; i<resObjNames.length; i++) 1479 { 1480 String poolName = (String )getMBeanServer().getAttribute(resObjNames[i], "pool_name"); 1481 if (poolName.equals(name)) { 1482 String jndiName = (String )getMBeanServer().getAttribute(resObjNames[i], "jndi_name"); 1483 resArr[k++] = jndiName; 1484 crFound = true; 1485 } 1486 } 1487 } 1488 1489 if (resType.equalsIgnoreCase(JDBC_RESOURCE) && crFound) 1490 { 1491 String pmfOp = GET + ConfigMBeanHelper.convertTagName(PERSISTENCE_MANAGER_FACTORY_RESOURCE); 1494 ObjectName [] pmfObjNames = (ObjectName [])super.invoke(pmfOp, new Object []{tgtName}, new String []{"java.lang.String"}); 1495 1496 if (pmfObjNames != null && pmfObjNames.length > 0) 1497 { 1498 int k=0; 1499 pmfArr = new String [pmfObjNames.length]; 1500 for (int i=0; i<pmfObjNames.length; i++) 1501 { 1502 String jrjnName = (String )getMBeanServer().getAttribute(pmfObjNames[i], "jdbc_resource_jndi_name"); 1503 for (int j=0; j<resArr.length && resArr[j] != null; j++) 1504 { 1505 if (jrjnName.equals(resArr[j])) { 1506 String pmfJndiName = (String )getMBeanServer().getAttribute(pmfObjNames[i], "jndi_name"); 1507 pmfArr[k++] = pmfJndiName; 1508 pmfFound = true; 1509 break; 1510 } 1511 } 1512 } 1513 } 1514 } 1515 1516 if (!cascade.booleanValue() && (crFound || pmfFound)) 1517 { 1518 if (resType.equalsIgnoreCase(JDBC_RESOURCE)) 1519 throw new Exception (localStrings.getString("admin.mbeans.rmb.jdbc_res_pmf_ref_exists")); 1520 else 1521 throw new Exception (localStrings.getString("admin.mbeans.rmb.conn_res_ref_exists")); 1522 } else if(cascade.booleanValue()) { 1523 if (pmfFound && (pmfArr!=null)) 1524 { 1525 for (int i=0; i<pmfArr.length && pmfArr[i] != null; i++) { 1527 deleteResourceRefFromTargets(pmfArr[i]); 1528 boolean isDeleted = destroyResource(PERSISTENCE_MANAGER_FACTORY_RESOURCE, pmfArr[i]); 1529 if (!isDeleted) { 1530 throw new Exception (localStrings.getString("admin.mbeans.rmb.pmf_not_deleted", pmfArr[i])); 1531 } 1532 } 1533 } 1534 1535 if (resArr != null) { 1536 for (int i=0; i<resArr.length && resArr[i] != null; i++) { 1538 deleteResourceRefFromTargets(resArr[i]); 1539 boolean isDeleted = destroyResource(resType, resArr[i]); 1540 if (!isDeleted) { 1541 if (resType.equalsIgnoreCase(JDBC_RESOURCE)) 1542 throw new Exception (localStrings.getString("admin.mbeans.rmb.jdbc_res_not_deleted", resArr[i])); 1543 else 1544 throw new Exception (localStrings.getString("admin.mbeans.rmb.conn_res_not_deleted", resArr[i])); 1545 } 1546 } 1547 } 1548 } 1549 1550 1556 if (resType.equalsIgnoreCase(JDBC_RESOURCE)) 1557 destroyResource(JDBC_CONNECTION_POOL,name); 1558 else 1559 destroyResource(CONNECTOR_CONNECTION_POOL,name); 1560 1561 1569 } 1570 1571 public void deletePersistenceManagerFactoryResource( String name, String tgtName ) 1572 throws Exception 1573 { 1574 this.deleteResource(PERSISTENCE_MANAGER_FACTORY_RESOURCE, name, tgtName); 1578 1579 1580 Resources resources = (Resources)this.getBaseConfigBean(); 1583 if (resources.getJdbcResourceByJndiName(name + PMF_SUFFIX)!=null) 1584 { 1585 this.deleteResource(JDBC_RESOURCE, name + PMF_SUFFIX, tgtName); 1586 } 1587 1588 } 1589 1590 1593 public void deleteJmsConenctionFactory( String name, String tgtName ) 1594 throws Exception 1595 { 1596 deleteJmsResource(name, tgtName); 1597 } 1598 1599 1602 public void deleteJmsDestinationResource( String name, String tgtName ) 1603 throws Exception 1604 { 1605 deleteJmsResource(name, tgtName); 1606 } 1607 1608 public void deleteJmsResource( String name, String tgtName ) 1609 throws Exception 1610 { 1611 Target target = getResourceTarget(tgtName); 1613 ObjectName connResource = null; 1614 try { 1615 connResource = (ObjectName )super.invoke("getConnectorResourceByJndiName", new Object []{name}, new String []{"java.lang.String"}); 1616 } catch (Exception ee){}; 1617 1618 if (connResource == null) 1619 { 1620 super.invoke("deleteAdminObjectResource", new Object []{name, tgtName}, new String []{"java.lang.String", "java.lang.String"}); 1622 } else { 1623 String defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(name); 1625 String poolName = (String ) getMBeanServer().getAttribute(connResource, "pool_name"); 1626 if (poolName != null && poolName.equals(defPoolName)) 1627 { 1628 deleteResourceRef(name, target, tgtName); 1629 destroyResource(CONNECTOR_RESOURCE, name); 1631 1632 ObjectName connPool = getObjectNameForResType(CONNECTOR_CONNECTION_POOL, poolName); 1633 if (connPool != null) { 1634 destroyResource(CONNECTOR_CONNECTION_POOL,poolName); 1635 } 1636 } 1637 else 1638 { 1639 ObjectName connResMBean = getObjectNameForResType(CONNECTOR_RESOURCE, name); 1646 super.invoke("removeConnectorResourceByJndiName",new Object []{name},new String [] {"java.lang.String"}); 1647 } 1648 } 1649 1657 } 1658 1659 public void deleteConnectorResource( String name, String tgtName ) 1660 throws Exception 1661 { 1662 this.deleteResource(CONNECTOR_RESOURCE, name, tgtName); 1663 } 1664 1665 public void deleteAdminObjectResource( String name, String tgtName ) 1666 throws Exception 1667 { 1668 this.deleteResource(ADMIN_OBJECT_RESOURCE, name, tgtName); 1669 } 1670 1671 public void deleteConnectorConnectionPool( String name, String tgtName ) 1672 throws Exception 1673 { 1674 this.deleteConnectorConnectionPool( name, new Boolean (false), tgtName); 1675 } 1676 1677 public void deleteConnectorConnectionPool( String name, Boolean cascade, String tgtName ) 1678 throws Exception 1679 { 1680 deleteConnectionPool( CONNECTOR_RESOURCE, name, cascade, tgtName); 1683 } 1684 1685 public void deleteJdbcResource( String name, String tgtName ) 1686 throws Exception 1687 { 1688 this.deleteResource(JDBC_RESOURCE, name, tgtName); 1689 } 1690 1691 public void deleteResourceAdapterConfig( String name, String tgtName ) 1692 throws Exception 1693 { 1694 this.deleteResource(RESOURCE_ADAPTER_CONFIG, name, tgtName); 1695 } 1696 1697 public void deleteMailResource( String name, String tgtName ) 1698 throws Exception 1699 { 1700 this.deleteResource(MAIL_RESOURCE, name, tgtName); 1701 } 1702 1703 public void deleteExternalJndiResource( String name, String tgtName ) 1704 throws Exception 1705 { 1706 this.deleteResource(EXTERNAL_JNDI_RESOURCE, name, tgtName); 1707 } 1708 1709 private Target getResourceTarget( String tgtName ) 1710 throws Exception 1711 { 1712 return TargetBuilder.INSTANCE.createTarget(VALID_CREATE_DELETE_TYPES, 1715 tgtName, getConfigContext()); 1716 1723 } 1724 1725 private void deleteResource( String resType, String name, String tgtName ) 1726 throws Exception 1727 { 1728 String operation = null; 1729 String suffix = null; 1730 1731 if (resType.equals(RESOURCE_ADAPTER_CONFIG)) 1732 suffix = "ByResourceAdapterName"; 1733 else if (resType.equals(JDBC_CONNECTION_POOL) || resType.equals(CONNECTOR_CONNECTION_POOL)) 1734 suffix = "ByName"; 1735 else suffix = "ByJndiName"; 1736 1737 operation = "remove" + ConfigMBeanHelper.convertTagName(resType) + suffix; 1738 1739 if (!(RESOURCE_ADAPTER_CONFIG.equals(resType) || 1740 JDBC_CONNECTION_POOL.equals(resType) || 1741 CONNECTOR_CONNECTION_POOL.equals(resType))) { 1742 1746 Target target = getResourceTarget(tgtName); 1747 deleteResourceRef(name, target, tgtName); 1748 } 1749 1750 super.invoke(operation,new Object []{name},new String [] {"java.lang.String"}); 1752 } 1753 1754 1760 public void deleteResource(List <Resource> res) throws Exception { 1761 int size = res.size(); 1763 for (int i = (size -1); i >= 0 ; i--) { 1764 Resource resource = res.get(i); 1765 deleteAResource(resource); 1766 } 1767 } 1768 1769 private void deleteAResource(Resource resource) throws Exception { 1770 this.destroyResource(resource.getType(), 1772 getResourceName(resource.getType(), resource.getAttributes())); 1773 } 1774 1775 1776 private boolean destroyResource(String resType, String name) 1777 throws Exception 1778 { 1779 String operation = null; 1780 String suffix = null; 1781 boolean isDeleted = false; 1782 1783 if (resType.equals(RESOURCE_ADAPTER_CONFIG)){ 1784 suffix = "ByResourceAdapterName"; 1785 }else if (resType.equals(JDBC_CONNECTION_POOL) || resType.equals(CONNECTOR_CONNECTION_POOL)){ 1786 suffix = "ByName"; 1787 }else{ 1788 suffix = "ByJndiName"; 1789 } 1790 1791 operation = "remove" + ConfigMBeanHelper.convertTagName(resType) + suffix; 1792 try { 1793 super.invoke(operation, new Object []{name}, new String [] {"java.lang.String"}); 1794 isDeleted = true; 1795 } 1796 catch (javax.management.ReflectionException re) {} 1797 1798 return isDeleted; 1799 } 1800 1801 1802 private ObjectName getObjectNameForResType(String resType, String name) 1803 throws Exception 1804 { 1805 return m_registry.getMbeanObjectName(resType, new String []{getDomainName(), name}); 1806 } 1807 1808 private void deleteResourceRef(String resRef, Target target, String tgtName) 1809 throws Exception 1810 { 1811 1814 final String resType = getResourceReferenceHelper().getResourceType(resRef); 1816 1817 if (target.getType() == TargetType.SERVER || 1820 target.getType() == TargetType.DAS) { 1821 1822 if (!ServerHelper.serverReferencesResource(getConfigContext(), 1825 tgtName, resRef)) { 1826 throw new ConfigException(localStrings.getString("serverResourceRefDoesNotExist", 1827 tgtName, resRef)); 1828 } else if (ResourceHelper.isResourceReferencedByServerOnly(getConfigContext(), 1829 resRef, tgtName)) { 1830 getResourceReferenceHelper().deleteResourceReference(tgtName, resRef); 1831 } else { 1832 throw new ConfigException(localStrings.getString("resourceHasMultipleRefs", 1833 tgtName, resRef, ResourceHelper.getResourceReferenceesAsString( 1834 getConfigContext(), resRef))); 1835 } 1836 } else if (target.getType() == TargetType.CLUSTER) { 1837 if (!ClusterHelper.clusterReferencesResource(getConfigContext(), 1840 tgtName, resRef)) { 1841 throw new ConfigException(localStrings.getString("clusterResourceRefDoesNotExist", 1842 tgtName, resRef)); 1843 } else if (ResourceHelper.isResourceReferencedByClusterOnly(getConfigContext(), 1844 resRef, tgtName)) { 1845 getResourceReferenceHelper().deleteResourceReference(tgtName, resRef); 1846 } else { 1847 throw new ConfigException(localStrings.getString("resourceHasMultipleRefs", 1848 tgtName, resRef, ResourceHelper.getResourceReferenceesAsString( 1849 getConfigContext(), resRef))); 1850 } 1851 } 1852 if (ResourceHelper.isResourceReferenced(getConfigContext(), resRef)) { 1855 throw new ConfigException(localStrings.getString("resourceIsReferenced", 1856 resRef, ResourceHelper.getResourceReferenceesAsString( 1857 getConfigContext(), resRef))); 1858 } 1859 1864 } 1865 1866 1871 public ArrayList createResource(String resourceXMLFile, String tgtName) 1872 throws Exception { 1873 boolean retVal = false; 1875 ArrayList results = new ArrayList (); 1876 com.sun.enterprise.resource.ResourcesXMLParser resourcesParser = 1877 new com.sun.enterprise.resource.ResourcesXMLParser(resourceXMLFile); 1878 List <Resource> resources = resourcesParser.getResourcesList(); 1879 ; 1881 Iterator <Resource> nonConnectorResources = ResourcesXMLParser.getNonConnectorResourcesList(resources,false).iterator(); 1882 while (nonConnectorResources.hasNext()) { 1883 Resource resource = (Resource) nonConnectorResources.next(); 1884 String s = ""; 1885 try { 1886 s = createAResource(resource, tgtName, true); 1887 } catch (Exception e) { 1888 s = e.getMessage(); 1889 } 1890 results.add(s); 1891 } 1892 1893 Iterator connectorResources = ResourcesXMLParser.getConnectorResourcesList(resources, false).iterator(); 1895 while (connectorResources.hasNext()) { 1896 Resource resource = (Resource) connectorResources.next(); 1897 String s = ""; 1898 try { 1899 s = createAResource(resource, tgtName, true); 1900 } catch (Exception e) { 1901 s = e.getMessage(); 1902 } 1903 results.add(s); 1904 } 1905 1906 return results; 1907 } 1908 1909 1910 1915 public void createResource(List <Resource> res, 1916 Boolean isEnabled) throws Exception { 1917 Iterator <Resource> resources = res.iterator(); 1920 while (resources.hasNext()) { 1921 Resource resource = (Resource) resources.next(); 1922 createAResource(resource, null, false); 1923 } 1924 } 1925 1926 public void createResourceAndResourceReference( 1927 List <Resource> resources, List <String > targetNameList, 1928 Boolean enabled) throws Exception { 1929 Iterator <Resource> resourceList = resources.iterator(); 1930 while (resourceList.hasNext()) { 1931 Resource resource = (Resource) resourceList.next(); 1932 for (String target : targetNameList) { 1933 createAResource(resource, target, false); 1934 createAResourceReference(resource, target, enabled); 1935 } 1936 1937 } 1938 } 1939 1940 public void deleteResourceAndResourceReference ( 1941 List <Resource> resources, 1942 List <String > targetNameList) throws Exception { 1943 int size = resources.size(); 1945 for (int i = (size -1); i >= 0 ; i--) { 1946 Resource resource = (Resource)resources.get(i); 1947 deleteAResourceRef(resource, targetNameList); 1949 deleteAResource(resource); 1950 } 1951 } 1952 1953 1959 private String createAResource(Resource resource, String tgtName, boolean createResourceRefs ) throws Exception { 1960 String resourceType = resource.getType(); 1962 1968 if(resourceType.equals(ServerTags.SECURITY_MAP)){ 1969 AttributeList mapAttributes = resource.getAttributes(); 1970 String poolName = null; 1972 String username = null ; 1973 String password = null; 1974 if(mapAttributes != null){ 1975 int s = mapAttributes.size(); 1976 for(int i=0;i<s;i++){ 1977 Attribute attribute =(Attribute )mapAttributes.get(i); 1978 String n= attribute.getName(); 1979 if((attribute.getName()).equalsIgnoreCase("pool-name")) 1980 poolName = (String )attribute.getValue(); 1981 if((attribute.getName()).equalsIgnoreCase("user-name")) 1982 username = (String )attribute.getValue(); 1983 if((attribute.getName()).equalsIgnoreCase("password")) 1984 password = (String )attribute.getValue(); 1985 1986 } 1987 } 1988 mapAttributes.add(new Attribute (POOL_NAME,poolName)); 1989 ObjectName poolObj = m_registry.getMbeanObjectName(POOL_TYPE, 1990 new String []{getDomainName(),poolName,CONFIG}); 1991 1992 try{ 1993 ObjectName map =(ObjectName )getMBeanServer().invoke(poolObj, 1994 CREATE_SECURITY_MAP, new Object [] {mapAttributes,username, 1995 password, tgtName}, 1996 new String [] {AttributeList .class.getName(),"java.lang.String", 1997 "java.lang.String","java.lang.String"}); 1998 String s = localStrings.getString("admin.mbeans.rmb.res_type_added", resourceType); 1999 sLogger.log(Level.INFO, s); 2000 return s; 2001 }catch(Exception e){ 2002 e.printStackTrace(); 2003 String s = localStrings.getString("admin.mbeans.rmb.res_type_not_added", resourceType, e.getMessage()); 2004 sLogger.log(Level.INFO, s); 2005 throw new Exception (s, e); 2006 } 2007 } 2008 else{ 2009 AttributeList attr = resource.getAttributes(); 2010 String desc = resource.getDescription(); 2011 if (desc != null) 2012 attr.add(new Attribute ("description", desc)); 2013 2014 Properties props = resource.getProperties(); 2015 try{ 2016 ObjectName objName = createResource(resource.getType(), 2017 attr, props, tgtName, createResourceRefs); 2018 String s = localStrings.getString("admin.mbeans.rmb.res_type_added", resourceType); 2020 sLogger.log(Level.INFO, s); 2021 return s; 2022 }catch(Exception e){ 2023 e.printStackTrace(); 2024 String s = localStrings.getString("admin.mbeans.rmb.res_type_not_added", resourceType, e.getMessage()); 2027 sLogger.log(Level.INFO, s); 2028 throw new Exception (s, e); 2029 } 2030 } 2031 2032 } 2033 2034 2040 public Map getConnectionDefinitionPropertiesAndDefaults(String dataSource) 2041 { 2042 try { 2043 return new HashMap ( ConnectionDefinitionUtils. 2044 getConnectionDefinitionPropertiesAndDefaults(dataSource.trim())); 2045 } catch(Throwable t) { 2046 return null; 2047 } 2048 } 2049 2050 2055 public Map getResourceAdapterBeanProperties(String location) 2056 { 2057 try { 2058 return new HashMap (ConnectorRuntime.getRuntime(). 2059 getResourceAdapterBeanProperties(location)); 2060 } catch(Throwable t) { 2061 return null; 2062 } 2063 } 2064 2065 2069 public String [] getConnectionDefinitionNames(String rarName) 2070 throws Exception 2071 { 2072 return ConnectorRuntime.getRuntime(). 2074 getConnectionDefinitionNames(rarName); 2075 2079 } 2080 2081 2085 public Properties getResourceAdapterConfigProps(AttributeList attrList) 2086 throws Exception 2087 { 2088 String rarName = null; 2089 2090 if (attrList != null) 2092 { 2093 int s = attrList.size(); 2094 for(int i=0; i<s; i++) 2095 { 2096 Attribute attribute =(Attribute )attrList.get(i); 2097 String n= attribute.getName(); 2098 2099 if(isAttrNameMatch(attribute, "resource-adapter-name")) 2100 rarName = (String )attribute.getValue(); 2101 } 2102 } else 2103 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_attrib_list")); 2104 2105 return ConnectorRuntime.getRuntime(). 2106 getResourceAdapterConfigProps(rarName); 2107 2111 } 2112 2113 2118 public Properties getMCFConfigProps(AttributeList attrList) 2119 throws Exception 2120 { 2121 String rarName = null; 2122 String connDefName = null; 2123 2124 if (attrList != null) 2126 { 2127 int s = attrList.size(); 2128 for(int i=0; i<s; i++){ 2129 Attribute attribute =(Attribute )attrList.get(i); 2130 String n= attribute.getName(); 2131 2132 if(isAttrNameMatch(attribute, "resource-adapter-name")) 2133 rarName = (String )attribute.getValue(); 2134 2135 if(isAttrNameMatch(attribute, "connection-definition-name")) 2136 connDefName = (String )attribute.getValue(); 2137 } 2138 } else 2139 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_attrib_list_mcf")); 2140 2141 return ConnectorRuntime.getRuntime(). 2142 getMCFConfigProps(rarName, connDefName); 2143 2147 } 2148 2149 2154 public Properties getAdminObjectConfigProps(AttributeList attrList) 2155 throws Exception 2156 { 2157 String rarName = null; 2158 String adminObjIntf = null; 2159 2160 if (attrList != null) 2162 { 2163 int s = attrList.size(); 2164 for(int i=0; i<s; i++){ 2165 Attribute attribute =(Attribute )attrList.get(i); 2166 String n= attribute.getName(); 2167 2168 if(isAttrNameMatch(attribute, "resource-adapter-name")) 2169 rarName = (String )attribute.getValue(); 2170 2171 if(isAttrNameMatch(attribute, "admin-object-interface")) 2172 adminObjIntf = (String )attribute.getValue(); 2173 } 2174 } else 2175 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_attrib_list_ao")); 2176 2177 return ConnectorRuntime.getRuntime(). 2178 getAdminObjectConfigProps(rarName, adminObjIntf); 2179 2183 } 2184 2185 2189 public String [] getAdminObjectInterfaceNames(String rarName) 2190 throws Exception 2191 { 2192 if (rarName == null) 2193 throw new Exception (localStrings.getString("admin.mbeans.rmb.null_raname_ao")); 2195 2196 return ConnectorRuntime.getRuntime().getAdminObjectInterfaceNames(rarName); 2197 } 2198 2199 2202 public Boolean pingConnectionPool(String poolName, String tgtName) throws Exception 2203 { 2204 boolean retVal = false; 2205 final Target target; 2206 2207 { 2209 final TargetType[] validTargets = new TargetType[] 2213 {TargetType.CLUSTER, TargetType.DOMAIN, 2214 TargetType.SERVER, TargetType.DAS}; 2215 2216 target = TargetBuilder.INSTANCE.createTarget(validTargets, 2217 tgtName, getConfigContext()); 2218 retVal = ConnectorRuntime.getRuntime().testConnectionPool(poolName); 2219 } 2220 2228 return new Boolean (retVal); 2229 } 2230 2231 protected MBeanServer getMBeanServer() 2232 { 2233 return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer(); 2234 } 2235 2236 2242 public JMSStatus JMSPing() throws JMSAdminException 2243 { 2244 try { 2245 JMSAdmin jmsAdmin = getJMSAdmin(); 2246 jmsAdmin.pingProvider(); 2247 } catch (Exception e) { 2248 sLogger.throwing(getClass().getName(), "JMSPing", e); 2249 handleException(e); 2250 } 2251 2252 JMSStatus js = new JMSStatus(); 2253 return (js); 2254 2255 } 2256 2257 2262 public JMSStatus JMSPing(String username, String password, int port) 2263 throws JMSAdminException 2264 { 2265 try { 2266 JMSAdmin jmsAdmin = getJMSAdmin(); 2267 jmsAdmin.pingProvider(username, password, port); 2268 } catch (Exception e) { 2269 sLogger.throwing(getClass().getName(), "JMSPing", e); 2270 handleException(e); 2271 } 2272 2273 JMSStatus js = new JMSStatus(); 2274 return (js); 2275 } 2276 2277 2284 public String JMSPing(String targetName) 2285 throws JMSAdminException 2286 { 2287 try { 2288 Target target = getResourceTarget(targetName); 2289 if (JMSDestination.useJMX(target)) { 2291 JMSDestination jmsd = new JMSDestination(); 2292 return(jmsd.JMSPing(target.getName())); 2293 } else { 2294 JMSAdmin jmsAdmin = getJMSAdmin(targetName); 2295 jmsAdmin.pingProvider(); 2296 } 2297 } catch (Exception e) { 2298 sLogger.throwing(getClass().getName(), "JMSPing", e); 2299 handleException(e); 2300 } 2301 2302 return JMSAdminConstants.JMS_HOST_RUNNING; 2303 } 2304 2305 2306 2314 public void createJMSDestination(String destName, 2315 String destType, 2316 Properties destProps, 2317 String tgtName) 2318 throws JMSAdminException 2319 { 2320 sLogger.entering(getClass().getName(), "createJMSDestination", 2321 new Object [] {destName, destType, destProps, tgtName}); 2322 2323 validateJMSDestName(destName); 2324 validateJMSDestType(destType); 2325 2326 int newDestType = JMSConstants.QUEUE; 2327 JMSAdmin jmsAdmin = null; 2328 boolean connected = false; 2329 2330 2331 try { 2332 if (isClustered(tgtName) 2333 && destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) { 2334 if (destProps == null) { 2335 destProps = new Properties (); 2336 } 2337 String maxConsumersProperty = IASJmsUtil.getMaxActiveConsumersProperty(); 2338 String maxConsumersAttribute = IASJmsUtil.getMaxActiveConsumersAttribute(); 2339 String maxConsumersValue = IASJmsUtil.getDefaultMaxActiveConsumers(); 2340 if (!destProps.containsKey(maxConsumersProperty) && 2341 !destProps.containsKey(maxConsumersAttribute) ) { 2342 destProps.put(maxConsumersAttribute, maxConsumersValue); 2343 } 2344 } 2345 2346 Target target = getResourceTarget(tgtName); 2348 if (JMSDestination.useJMX(target)) { 2349 JMSDestination jmsd = new JMSDestination(); 2350 jmsd.createJMSDestination(destName, destType, destProps, tgtName); 2351 return; 2352 } else { 2353 jmsAdmin = getJMSAdmin(tgtName); 2354 jmsAdmin.connectToProvider(); 2355 connected = true; 2356 2357 if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC)) { 2358 newDestType = JMSConstants.TOPIC; 2359 } else if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) { 2360 newDestType = JMSConstants.QUEUE; 2361 } 2362 2363 jmsAdmin.createProviderDestination(destName, newDestType, destProps); 2364 } 2365 } catch (Exception e) { 2366 handleException(e); 2367 } finally { 2368 if (connected) { 2369 try { 2370 jmsAdmin.disconnectFromProvider(); 2371 } catch (Exception ex) { 2372 handleException(ex); 2373 } 2374 } 2375 } 2376 } 2377 2378 2385 public void deleteJMSDestination(String destName, String destType, String tgtName) 2386 throws JMSAdminException 2387 { 2388 sLogger.entering(getClass().getName(), "deleteJMSDestination", 2389 new Object [] {destName, destType}); 2390 2391 validateJMSDestName(destName); 2392 validateJMSDestType(destType); 2393 2394 int newDestType = JMSConstants.QUEUE; 2395 JMSAdmin jmsAdmin = null; 2396 boolean connected = false; 2397 2398 try { 2399 Target target = getResourceTarget(tgtName); 2401 if (JMSDestination.useJMX(target)) { 2402 JMSDestination jmsd = new JMSDestination(); 2403 jmsd.deleteJMSDestination(destName, destType, tgtName); 2404 return; 2405 } else { 2406 jmsAdmin = getJMSAdmin(tgtName); 2407 jmsAdmin.connectToProvider(); 2408 connected = true; 2409 2410 if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC)) { 2411 newDestType = JMSConstants.TOPIC; 2412 } else if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) { 2413 newDestType = JMSConstants.QUEUE; 2414 } 2415 2416 jmsAdmin.deleteProviderDestination(destName, newDestType); 2417 } 2418 } catch (Exception e) { 2419 sLogger.throwing(getClass().getName(), "deleteJMSDestination", e); 2420 handleException(e); 2421 } finally { 2422 if (connected) { 2423 try { 2424 jmsAdmin.disconnectFromProvider(); 2425 } catch (Exception ex) { 2426 handleException(ex); 2427 } 2428 } 2429 } 2430 } 2431 2432 2433 2438 public void flushJMSDestination(String destName, String destType, String tgtName) 2439 throws JMSAdminException { 2440 try { 2442 Target target = getResourceTarget(tgtName); 2443 if (JMSDestination.useJMX(target)) { 2444 JMSDestination jmsd = new JMSDestination(); 2445 jmsd.purgeJMSDestination(destName, destType, tgtName); 2446 } else { 2447 sLogger.log(Level.WARNING, "Flush JMS destination not supported in the JMS SPI"); 2448 } 2449 } catch (Exception e) { 2450 sLogger.throwing(getClass().getName(), "flushJMSDestination", e); 2451 handleException(e); 2452 } 2453 } 2454 2455 2465 public JMSDestinationInfo[] listJMSDestinations(String destType, String tgtName) 2466 throws JMSAdminException 2467 { 2468 JMSDestinationInfo destInfoArray[] = null; 2469 JMSAdmin jmsAdmin = null; 2470 boolean connected = false; 2471 2472 sLogger.entering(getClass().getName(), "listJMSDestinations", destType); 2473 2474 try { 2475 Target target = getResourceTarget(tgtName); 2477 if (JMSDestination.useJMX(target)) { 2478 JMSDestination jmsd = new JMSDestination(); 2479 return (jmsd.listJMSDestinations(tgtName, destType)); 2480 } else { 2481 String s[][] = {null, null}; 2482 jmsAdmin = getJMSAdmin(tgtName); 2483 jmsAdmin.connectToProvider(); 2484 connected = true; 2485 2486 s = jmsAdmin.getProviderDestinations(); 2487 2488 if (destType == null) { 2489 destInfoArray = listAllDestinations(s); 2490 } else if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC) || 2491 destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) { 2492 destInfoArray = listDestinationsByType(destType, s); 2493 } else { 2494 destInfoArray = listAllDestinations(s); 2495 } 2496 return (destInfoArray); 2497 } 2498 } catch (Exception e) { 2499 sLogger.throwing(getClass().getName(), "listJMSDestinations", e); 2500 handleException(e); 2501 } finally { 2502 if (connected) { 2503 try { 2504 jmsAdmin.disconnectFromProvider(); 2505 } catch (Exception ex) { 2506 handleException(ex); 2507 } 2508 } 2509 } 2510 return null; 2511 } 2512 2513 2514 private void validateJMSDestName(String destName) { 2515 if(destName==null || destName.length() <= 0) 2516 throw new IllegalArgumentException (localStrings.getString("admin.mbeans.rmb.invalid_jms_destname",destName)); 2517 } 2518 2519 private void validateJMSDestType(String destType) { 2520 if(destType==null || destType.length() <= 0) 2521 throw new IllegalArgumentException (localStrings.getString("admin.mbeans.rmb.invalid_jms_desttype",destType)); 2522 if(!destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE) && 2523 !destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC)) 2524 throw new IllegalArgumentException (localStrings.getString("admin.mbeans.rmb.invalid_jms_desttype",destType)); 2525 } 2526 2527 2535 public void createPhysicalDestination(AttributeList attrList ,Properties props, 2536 String target)throws JMSAdminException,MBeanException 2537 { 2538 String destType = null; 2539 String destName = null; 2540 if(attrList == null) 2541 throw new IllegalArgumentException (); 2542 2543 int size = attrList.size(); 2544 for(int i=0;i<size;i++){ 2545 Attribute attribute =(Attribute )attrList.get(i); 2546 if((attribute.getName().equalsIgnoreCase(DEST_TYPE))) 2547 destType = (String )attribute.getValue(); 2548 if((attribute.getName().equalsIgnoreCase(DEST_NAME))) 2549 destName = (String )attribute.getValue(); 2550 } 2551 createJMSDestination(destName,destType,props, target); 2553 } 2554 2555 2563 public void deletePhysicalDestination(String destName, String destType, 2564 String target)throws JMSAdminException,MBeanException 2565 { 2566 deleteJMSDestination(destName,destType, target); 2567 } 2568 2569 2570 2576 public ObjectName [] listPhysicalDestinations(String target) 2577 throws JMSAdminException,MBeanException 2578 { 2579 ObjectName [] objectNames = null; 2580 2581 JMSDestinationInfo[] destInfos = listJMSDestinations(null, target); 2582 int infoLength=0; 2583 if (destInfos != null && destInfos.length >0 ) 2584 infoLength = destInfos.length; 2585 2586 if (infoLength ==0 ) 2588 return null; 2589 2590 objectNames = new ObjectName [infoLength]; 2591 for(int i=0;i<infoLength;i++) { 2592 String destName = destInfos[i].getDestinationName(); 2593 String destType = destInfos[i].getDestinationType(); 2594 try { 2595 ObjectName objectName = 2596 new ObjectName (getDomainName()+":"+DEST_NAME+"="+destName+","+DEST_TYPE+"="+destType); 2597 objectNames[i]=objectName; 2598 }catch(javax.management.MalformedObjectNameException e){ 2599 sLogger.warning(e.toString()); 2600 } 2601 } 2602 2603 return objectNames; 2604 } 2605 2606 2608 2612 public String [] getMessageListenerTypes(String raName) 2613 throws Exception { 2614 return ConnectorRuntime.getRuntime(). 2616 getMessageListenerTypes(raName); 2617 2621 } 2622 2623 2628 public Properties getActivationConfProps(String raName, 2629 String msgLsnrType) 2630 throws Exception { 2631 return ConnectorRuntime.getRuntime(). 2633 getMessageListenerConfigProps(raName, msgLsnrType); 2634 2638 } 2639 2640 2648 public Properties getActivationConfPropTypes(String raName, 2649 String msgLsnrType) 2650 throws Exception { 2651 return ConnectorRuntime.getRuntime(). 2653 getMessageListenerConfigPropTypes(raName, msgLsnrType); 2654 2658 } 2659 2660 2665 2678 2679 2681 2686 private synchronized JMSAdmin getJMSAdmin() throws Exception 2687 { 2688 ConfigContext serverContext; 2689 JmsService jmsService; 2690 JMSAdminFactory jmsaf; 2691 JMSAdmin _jmsAdmin = null; 2692 String instanceName, portStr, username, password, localhost, jmsAdminURL; 2693 2694 serverContext = getConfigContext(); 2695 2696 jmsaf = IASJmsUtil.getJMSAdminFactory(); 2697 2698 jmsService = (JmsService)ConfigBeansFactory.getConfigBeanByXPath( 2699 serverContext, ServerXPathHelper.XPATH_JMS_SERVICE); 2700 2701 localhost = java.net.InetAddress.getLocalHost().getHostName(); 2702 JmsHost hostElement = jmsService.getJmsHost(0); portStr = hostElement.getPort(); 2704 username = hostElement.getAdminUserName(); 2705 password = hostElement.getAdminPassword(); 2706 jmsAdminURL = localhost + ((portStr == null) ? 2707 "" : ":" + portStr); 2708 2709 _jmsAdmin = jmsaf.getJMSAdmin(jmsAdminURL, username, password); 2710 2711 return _jmsAdmin; 2712 } 2713 2714 private JMSAdmin getJMSAdmin(String targetName) throws Exception 2715 { 2716 final TargetType[] vaildTargetTypes = new TargetType[] { 2717 TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS, TargetType.CONFIG}; 2718 final Target target = TargetBuilder.INSTANCE.createTarget( 2719 vaildTargetTypes, targetName, getConfigContext()); 2720 assert target != null; 2721 2722 final Config config = target.getConfigs()[0]; 2723 final JmsService jmsService = config.getJmsService(); 2724 JmsHost host = jmsService.getJmsHostByName(jmsService.getDefaultJmsHost()); 2725 if (host == null) 2726 { 2727 host = jmsService.getJmsHost(0); 2728 } 2729 2730 final String hostName = host.getHost(); 2731 final String port = host.getPort(); 2732 final String adminUser = host.getAdminUserName(); 2733 final String adminPassword = host.getAdminPassword(); 2734 String url = hostName + (port == null ? "" : ":" + port); 2735 if (adminUser == null) 2736 { 2737 return IASJmsUtil.getJMSAdminFactory().getJMSAdmin(url); 2738 } 2739 else 2740 { 2741 return IASJmsUtil.getJMSAdminFactory().getJMSAdmin( 2742 url, adminUser, adminPassword); 2743 } 2744 } 2745 2746 private JMSDestinationInfo[] listAllDestinations(String [][] s) 2747 { 2748 JMSDestinationInfo destInfo; 2749 Vector dests = new Vector (); 2750 String destName, destType; 2751 2752 for (int i = 0; i < s[1].length; i++) { 2755 destName = s[0][i]; 2756 2757 if (s[1][i].equals(new Integer (JMSConstants.QUEUE).toString())) { 2758 destType = JMSAdminConstants.JMS_DEST_TYPE_QUEUE; 2759 } else if (s[1][i].equals(new Integer (JMSConstants.TOPIC).toString())) { 2760 destType = JMSAdminConstants.JMS_DEST_TYPE_TOPIC; 2761 } else { 2762 destType = ""; 2763 } 2764 2765 destInfo = new JMSDestinationInfo(destName, destType); 2766 dests.addElement(destInfo); 2767 } 2768 2769 if (dests.size() > 0) { 2770 Object objArray[] = dests.toArray(); 2771 JMSDestinationInfo jmsDestArray[]; 2772 int size = dests.size(); 2773 2774 jmsDestArray = new JMSDestinationInfo [size]; 2775 2776 for (int i = 0; i < size; ++i) { 2777 jmsDestArray[i] = (JMSDestinationInfo)objArray[i]; 2778 } 2779 2780 return (jmsDestArray); 2781 } 2782 2783 return (null); 2784 } 2785 2786 private JMSDestinationInfo[] listDestinationsByType(String destType, String [][] s) 2787 { 2788 JMSDestinationInfo destInfo; 2789 Vector dests = new Vector (); 2790 String destName, type; 2791 String lookFor = null; 2792 2793 if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC)) 2794 lookFor = new Integer (JMSConstants.TOPIC).toString(); 2795 else 2796 lookFor = new Integer (JMSConstants.QUEUE).toString(); 2797 2798 int j = 0; 2801 for (int i = 0; i < s[1].length; i++) { 2802 if (s[1][i].equals(lookFor)) { 2803 destName = s[0][i]; 2804 2805 if (s[1][i].equals(new Integer (JMSConstants.QUEUE).toString())) { 2806 type = JMSAdminConstants.JMS_DEST_TYPE_QUEUE; 2807 } else if (s[1][i].equals(new Integer (JMSConstants.TOPIC).toString())) { 2808 type = JMSAdminConstants.JMS_DEST_TYPE_TOPIC; 2809 } else { 2810 type = ""; 2811 } 2812 2813 destInfo = new JMSDestinationInfo(destName, type); 2814 dests.addElement(destInfo); 2815 } 2816 } 2817 2818 if (dests.size() > 0) { 2819 Object objArray[] = dests.toArray(); 2820 JMSDestinationInfo jmsDestArray[]; 2821 int size = dests.size(); 2822 2823 jmsDestArray = new JMSDestinationInfo [size]; 2824 2825 for (int i = 0; i < size; ++i) { 2826 jmsDestArray[i] = (JMSDestinationInfo)objArray[i]; 2827 } 2828 2829 return (jmsDestArray); 2830 } 2831 2832 return (null); 2833 } 2834 2835 2836 private void handleException(Exception e) throws JMSAdminException 2837 { 2838 if (e instanceof JMSAdminException) { 2839 throw ((JMSAdminException)e); 2840 } 2841 2842 String msg = e.getMessage(); 2843 2844 JMSAdminException jae; 2845 2846 if (msg == null) { 2847 jae = new JMSAdminException(); 2848 } else { 2849 jae = new JMSAdminException(msg); 2850 } 2851 2852 2858 2859 throw jae; 2860 } 2861 2862 private static boolean isAttrNameMatch(Attribute attr, String name) 2863 { 2864 return attr.getName().replace('_','-').equals(name.replace('_','-')); 2867 } 2868 2869 private boolean isClustered(String tgt) throws ConfigException{ 2871 final TargetType[] vaildTargetTypes = new TargetType[] { 2872 TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS, TargetType.CONFIG}; 2873 final Target target = TargetBuilder.INSTANCE.createTarget( 2874 vaildTargetTypes, tgt, getConfigContext()); 2875 assert target != null; 2876 return target.getType() == TargetType.CLUSTER; 2877 } 2878 2879} 2880 2881 | Popular Tags |