1 23 24 package com.sun.enterprise.connectors.system; 25 26 import com.sun.enterprise.deployment.ConnectorDescriptor; 27 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor; 28 import com.sun.enterprise.deployment.runtime.BeanPoolDescriptor; 29 import com.sun.enterprise.deployment.EnvironmentProperty; 30 31 import com.sun.enterprise.connectors.*; 32 import com.sun.enterprise.connectors.inflow.*; 33 import com.sun.enterprise.connectors.util.JmsRaUtil; 34 import com.sun.logging.LogDomains; 35 import com.sun.enterprise.config.ConfigBean; 36 import com.sun.enterprise.config.ConfigContext; 37 import com.sun.enterprise.config.ConfigException; 38 import com.sun.enterprise.server.ApplicationServer; 39 import com.sun.enterprise.server.ResourcesUtil; 40 41 import com.sun.enterprise.server.ServerContext; 42 import com.sun.enterprise.config.serverbeans.ClusterHelper; 43 import com.sun.enterprise.config.serverbeans.JavaConfig; 44 import com.sun.enterprise.config.serverbeans.JdbcConnectionPool; 45 import com.sun.enterprise.config.serverbeans.JmsAvailability; 46 import com.sun.enterprise.config.serverbeans.Resources; 47 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 48 import com.sun.enterprise.config.serverbeans.ConnectorResource; 49 import com.sun.enterprise.config.serverbeans.AdminObjectResource; 50 import com.sun.enterprise.config.serverbeans.ConnectorConnectionPool; 51 import com.sun.enterprise.config.serverbeans.ElementProperty; 52 import com.sun.enterprise.config.serverbeans.AvailabilityService; 53 import com.sun.enterprise.config.serverbeans.JmsService; 54 import com.sun.enterprise.config.serverbeans.JmsHost; 55 import com.sun.enterprise.config.serverbeans.AdminService; 56 import com.sun.enterprise.config.serverbeans.JmxConnector; 57 import com.sun.enterprise.config.serverbeans.ServerHelper; 58 import com.sun.enterprise.instance.ServerManager; 59 import com.sun.enterprise.jms.IASJmsUtil; 60 import com.sun.enterprise.jms.JmsProviderLifecycle; 61 import com.sun.enterprise.util.SystemPropertyConstants; 62 import com.sun.enterprise.util.i18n.StringManager; 63 64 import java.rmi.Naming ; 65 import java.util.ArrayList ; 66 import java.util.HashSet ; 67 import java.util.List ; 68 import java.util.Properties ; 69 import java.util.Set ; 70 import java.util.Iterator ; 71 import java.util.StringTokenizer ; 72 import java.io.BufferedWriter ; 73 import java.io.File ; 74 import java.io.FileWriter ; 75 import java.io.IOException ; 76 import java.lang.reflect.Method ; 77 import java.util.logging.Level ; 78 import java.util.logging.Logger ; 79 import javax.resource.spi.ManagedConnectionFactory ; 80 import javax.resource.spi.ResourceAdapter ; 81 82 92 public class ActiveJmsResourceAdapter extends ActiveInboundResourceAdapter { 93 94 static Logger logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 95 96 private final String SETTER = "setProperty"; 97 private static final String SEPARATOR = "#"; 98 private static final String MQ_PASS_FILE_PREFIX = "asmq"; 99 private static final String MQ_PASS_FILE_KEY = "imq.imqcmd.password="; 100 101 public static final String CONNECTION_URL = "ConnectionURL"; 103 private final String RECONNECTENABLED = "ReconnectEnabled"; 104 private final String RECONNECTINTERVAL = "ReconnectInterval"; 105 private final String RECONNECTATTEMPTS = "ReconnectAttempts"; 106 private static final String GROUPNAME = "GroupName"; 107 private static final String CLUSTERCONTAINER = "InClusteredContainer"; 108 109 public static final String BROKERTYPE="BrokerType"; 111 private static final String BROKERINSTANCENAME="BrokerInstanceName"; 112 private static final String BROKERBINDADDRESS="BrokerBindAddress"; 113 private static final String BROKERPORT="BrokerPort"; 114 private static final String BROKERARGS="BrokerArgs"; 115 private static final String BROKERHOMEDIR="BrokerHomeDir"; 116 private static final String BROKERVARDIR="BrokerVarDir"; 117 private static final String BROKERJAVADIR="BrokerJavaDir"; 118 private static final String BROKERSTARTTIMEOUT="BrokerStartTimeOut"; 119 private static final String ADMINUSERNAME="AdminUserName"; 120 private static final String ADMINPASSWORD="AdminPassword"; 121 private static final String ADMINPASSFILE="AdminPassFile"; 122 123 private static final String MASTERBROKER="MasterBroker"; 124 125 private static final String JMXSERVICEURL="JMXServiceURL"; 127 private static final String JMXSERVICEURLLIST="JMXServiceURLList"; 128 private static final String JMXCONNECTORENV="JMXConnectorEnv"; 129 private static final String USEJNDIRMISERVICEURL="useJNDIRMIServiceURL"; 130 private static final String RMIREGISTRYPORT="RmiRegistryPort"; 131 private static final String USEEXTERNALRMIREGISTRY="startRMIRegistry"; 132 private static final String SSLJMXCONNECTOR="SslJMXConnector"; 133 134 private static final String HAREQUIRED = "HARequired"; 136 private static final String CLUSTERID = "ClusterId"; 137 private static final String BROKERID = "BrokerId"; 138 private static final String PINGINTERVAL = "PingInterval"; 139 private static final String DBTYPE = "DBType"; 140 private static final String DBTYPE_HADB="hadb"; 141 private static final String BROKERENABLEHA = "BrokerEnableHA"; 142 143 private static final String DB_HADB_PROPS = "DBProps"; 144 private static final String DB_HADB_USER = "hadb.user"; 146 private static final String DB_HADB_PASSWORD = "hadb.password"; 147 private static final String DB_HADB_DRIVERCLASS = "hadb.driverClass"; 148 private static final String DS_HADB_PROPS = "DSProps"; 149 private static final String DS_HADB_SERVERLIST = "hadb.serverList"; 151 152 private final String CONTAINER = "InAppClientContainer"; 154 155 public static String DESTINATION = "Destination"; 157 public static String DESTINATION_TYPE = "DestinationType"; 158 private static String SUBSCRIPTION_NAME = "SubscriptionName"; 159 private static String CLIENT_ID = "ClientID"; 160 public static String PHYSICAL_DESTINATION = "Name"; 161 private static String MAXPOOLSIZE = "EndpointPoolMaxSize"; 162 private static String MINPOOLSIZE = "EndpointPoolSteadySize"; 163 private static String RESIZECOUNT = "EndpointPoolResizeCount"; 164 private static String RESIZETIMEOUT = "EndpointPoolResizeTimeout"; 165 private static String REDELIVERYCOUNT = "EndpointExceptionRedeliveryAttempts"; 166 public static String ADDRESSLIST = "AddressList"; 167 private static String ADRLIST_BEHAVIOUR = "AddressListBehavior"; 168 private static String ADRLIST_ITERATIONS = "AddressListIterations"; 169 private static final String MDBIDENTIFIER = "MdbName"; 170 171 private static final String MCFADDRESSLIST = "MessageServiceAddressList"; 173 174 private StringManager sm = 175 StringManager.getManager(ActiveJmsResourceAdapter.class); 176 177 MQAddressList urlList = null; 178 179 private static final String DUSERNAME = "User"; 181 private static final String DPASSWORD = "Password"; 182 private static final String DSERVERLIST = "ServerList"; 183 private static final String HADB_CONNECTION_URL_PREFIX = "jdbc:sun:hadb:"; 184 185 public static final String EMBEDDED="EMBEDDED"; 187 public static final String LOCAL="LOCAL"; 188 public static final String REMOTE="REMOTE"; 189 190 private final String DEFAULT_STORE_POOL_JNDI_NAME = "jdbc/hastore"; 191 192 private static String MQRmiPort = 194 System.getProperty("com.sun.enterprise.connectors.system.MQRmiPort"); 195 private static final String DASRMIPORT = "31099"; 196 197 private Properties dbProps = null; 198 private Properties dsProps = null; 199 private String brokerInstanceName = null; 200 201 private File mqPassFile = null; 202 203 212 public ActiveJmsResourceAdapter( 213 ResourceAdapter ra, ConnectorDescriptor desc, String moduleName, 214 ClassLoader jcl) throws ConnectorRuntimeException { 215 super(ra,desc,moduleName,jcl); 216 217 if (mqPassFile != null) { 219 mqPassFile.delete(); 220 } 221 } 222 223 228 protected void loadRAConfiguration() throws ConnectorRuntimeException{ 229 if (ConnectorRuntime.getRuntime().getEnviron() 230 == ConnectorRuntime.SERVER) { 231 try { 233 if (!JmsProviderLifecycle.shouldUseMQRAForLifecycleControl()) { 234 JmsProviderLifecycle.checkProviderStartup(); 235 } else { 236 setLifecycleProperties(); 237 } 238 } catch (Exception e) { 239 ConnectorRuntimeException cre = new ConnectorRuntimeException 240 (e.getMessage()); 241 throw (ConnectorRuntimeException) cre.initCause(e); 242 } 243 244 setMdbContainerProperties(); 245 setJmsServiceProperties(null); 246 setClusterRABeanProperties(); 247 setAvailabilityProperties(); 248 } else { 249 setAppClientRABeanProperties(); 250 } 251 super.loadRAConfiguration(); 252 postRAConfiguration(); 253 } 254 255 261 private void setAvailabilityProperties() throws ConnectorRuntimeException { 262 try { 263 ConfigContext ctx = ApplicationServer.getServerContext().getConfigContext(); 264 AvailabilityService as = ServerBeansFactory.getConfigBean(ctx).getAvailabilityService(); 265 if (as == null) { 266 logFine("Availability Service is null. Not setting HA attributes"); 267 return; 268 } 269 270 if (isJMSAvailabilityOn(as)) { 272 ConnectorDescriptor cd = getDescriptor(); 273 EnvironmentProperty envProp1 = new EnvironmentProperty ( 276 HAREQUIRED , "true","HA Required", 277 "java.lang.String"); 278 setProperty(cd, envProp1); 279 280 JmsService jmsService = ServerBeansFactory.getConfigBean(ctx). 281 getJmsService(); 282 if (isClustered()) { 283 if (jmsService.getType().equals(REMOTE)) { 284 return; 287 } else { 288 String clusterName = getMQClusterName(); 290 EnvironmentProperty envProp2 = new EnvironmentProperty ( 291 CLUSTERID , clusterName,"Cluster Id", 292 "java.lang.String"); 293 setProperty(cd, envProp2); 294 295 if(brokerInstanceName == null) { 296 brokerInstanceName = getBrokerInstanceName(jmsService); 297 } 298 EnvironmentProperty envProp3 = new EnvironmentProperty ( 299 BROKERID , brokerInstanceName,"Broker Id", 300 "java.lang.String"); 301 setProperty(cd, envProp3); 302 303 304 EnvironmentProperty envProp4 = new EnvironmentProperty ( 305 DBTYPE , DBTYPE_HADB,"DBType", 306 "java.lang.String"); 307 setProperty(cd, envProp4); 308 309 320 EnvironmentProperty envProp5 = new EnvironmentProperty ( 321 BROKERENABLEHA , "true", 322 "BrokerEnableHA flag","java.lang.Boolean"); 323 setProperty(cd, envProp5); 324 325 String poolJNDIName = as.getJmsAvailability().getMqStorePoolName(); 327 if (poolJNDIName == null || poolJNDIName =="" ) { 332 poolJNDIName = as.getWebContainerAvailability(). 334 getHttpSessionStorePoolName(); 335 logFine("HTTP Session store pool jndi name " + 336 "is " + poolJNDIName); 337 } 338 341 JdbcConnectionPool jdbcConPool = getJDBCConnectionPoolInfo( 342 poolJNDIName); 343 String userName = getPropertyFromPool(jdbcConPool, DUSERNAME); 345 logFine("HA username is " + userName); 346 347 String password = getPropertyFromPool(jdbcConPool, DPASSWORD); 348 logFine("HA Password is " + password); 349 350 String driverClass = jdbcConPool.getDatasourceClassname(); 351 logFine("HA driverclass" + driverClass); 352 353 dbProps = new Properties (); 354 dbProps.setProperty(DB_HADB_USER, userName); 355 dbProps.setProperty(DB_HADB_PASSWORD, password); 356 dbProps.setProperty(DB_HADB_DRIVERCLASS, driverClass); 357 358 String serverList = getPropertyFromPool(jdbcConPool, DSERVERLIST); 360 logFine("HADB server list is " + serverList); 361 dsProps = new Properties (); 362 363 if (serverList != null) { 364 dsProps.setProperty(DS_HADB_SERVERLIST, serverList); 365 } else { 366 logger.warning("ajra.incorrect_hadb_server_list"); 367 } 368 369 Properties p = getDSPropertiesFromThePool(jdbcConPool); 371 Iterator iterator = p.keySet().iterator(); 372 while (iterator.hasNext()) { 373 String key = (String ) iterator.next(); 374 String val = (String )p.get(key); 375 dsProps.setProperty(key, val); 376 } 377 } 378 } else { 379 logFine("Instance not clustered. Not setting HA " + 381 "attributes"); 382 } 383 } 384 } catch (ConfigException e) { 385 ConnectorRuntimeException crex = new ConnectorRuntimeException( 386 e.getMessage()); 387 throw (ConnectorRuntimeException)crex.initCause(e); 388 } 389 } 390 391 395 private Properties getDSPropertiesFromThePool(JdbcConnectionPool jdbcConPool) { 396 Properties p = new Properties (); 397 ElementProperty[] elemProp = jdbcConPool.getElementProperty(); 398 Set <String > excludeList = new HashSet <String >(); 399 excludeList.add(DUSERNAME); 400 excludeList.add(DPASSWORD); 401 excludeList.add(DSERVERLIST); 402 403 for(ElementProperty e: elemProp) { 404 String propName = e.getAttributeValue("name"); 405 if (!excludeList.contains(propName)) { 406 p.setProperty(propName, e.getAttributeValue("value")); 407 } 408 } 409 logFine("Additional DataSource properties from pool " 410 + jdbcConPool.getName() + " are " + p); 411 return p; 412 } 413 414 421 protected void postRAConfiguration() throws ConnectorRuntimeException { 422 try { 424 if (dbProps != null) { 425 Method [] mthds = this.resourceadapter_.getClass().getMethods(); 426 for (int i = 0; i < mthds.length; i++) { 427 if(mthds[i].getName().equalsIgnoreCase("set" + DB_HADB_PROPS)) { 428 logFine("Setting property:" + DB_HADB_PROPS 429 + "=" + dbProps.toString()); 430 mthds[i].invoke(this.resourceadapter_, 431 new Object []{dbProps}); 432 } else if(mthds[i].getName().equalsIgnoreCase("set" + DS_HADB_PROPS)) { 433 logFine("Setting property:" + DS_HADB_PROPS 434 + "=" + dsProps.toString()); 435 mthds[i].invoke(this.resourceadapter_, new Object []{dsProps}); 436 } 437 } 438 } 439 } catch (Exception e) { 440 ConnectorRuntimeException crex = new ConnectorRuntimeException( 441 e.getMessage()); 442 throw (ConnectorRuntimeException)crex.initCause(e); 443 } 444 } 445 446 private String getPropertyFromPool(JdbcConnectionPool jdbcConPool, 447 String poolPropertyName) { 448 String poolPropertyValue = null; 449 if(jdbcConPool == null) { 450 return null; 451 } 452 ElementProperty[] props = jdbcConPool.getElementProperty(); 453 for (int i = 0; i < props.length; i++) { 454 String name = props[i].getAttributeValue("name"); 455 String value = props[i].getAttributeValue("value"); 456 if (name.equalsIgnoreCase(poolPropertyName)) { 457 poolPropertyValue = value; 459 } 460 } 461 logFine("ActiveJMSResourceAdapter :: got property " + poolPropertyName 462 + "="+ poolPropertyValue); 463 return poolPropertyValue; 464 } 465 466 private JdbcConnectionPool getJDBCConnectionPoolInfo(String poolJndiName) 467 throws ConfigException { 468 return ResourcesUtil.getInstance().getJDBCPoolForResource(poolJndiName); 469 } 470 471 private boolean isJMSAvailabilityOn(AvailabilityService as) { 472 JmsAvailability ja = as.getJmsAvailability(); 474 boolean jmsAvailability = ja.isAvailabilityEnabled(); 475 logFine("JMS availability :: " + jmsAvailability); 476 return jmsAvailability; 477 } 478 479 482 private void setLifecycleProperties() throws 483 ConfigException, ConnectorRuntimeException { 484 ConfigContext ctx = ApplicationServer.getServerContext().getConfigContext(); 485 486 487 JmsService jmsService = ServerBeansFactory.getJmsServiceBean(ctx); 498 String defaultJmsHost = jmsService.getDefaultJmsHost(); 499 logFine("Default JMS Host :: " + defaultJmsHost); 500 501 JmsHost jmsHost = null; 502 if (defaultJmsHost == null || defaultJmsHost.equals("")) { 503 jmsHost = ServerBeansFactory.getJmsHostBean(ctx); 504 } else { 505 jmsHost = jmsService.getJmsHostByName(defaultJmsHost); 506 } 507 508 if (jmsHost != null && jmsHost.isEnabled()) { 509 JavaConfig javaConfig = ServerBeansFactory.getJavaConfigBean(ctx); 510 String java_home = javaConfig.getJavaHome(); 511 512 String brokerType = jmsService.getType(); 514 String brokerPort = jmsHost.getPort(); 515 String adminUserName = jmsHost.getAdminUserName(); 516 String adminPassword = jmsHost.getAdminPassword(); 517 518 createMQVarDirectoryIfNecessary(); 519 String brokerVarDir = getMQVarDir(); 520 521 String tmpString = jmsService.getStartArgs(); 522 if (tmpString == null) { 523 tmpString = ""; 524 } 525 526 String brokerArgs = tmpString; 527 528 529 ElementProperty[] jmsProperties = 531 jmsService.getElementProperty(); 532 533 String brokerHomeDir = getBrokerHomeDir(); 534 if (brokerInstanceName == null) { 535 brokerInstanceName = getBrokerInstanceName(jmsService); 536 } 537 538 long brokerTimeOut = getBrokerTimeOut(jmsService); 539 540 ConnectorDescriptor cd = getDescriptor(); 545 EnvironmentProperty envProp1 = new EnvironmentProperty ( 546 BROKERTYPE, brokerType, "Broker Type", "java.lang.String"); 547 setProperty(cd, envProp1); 548 EnvironmentProperty envProp2 = new EnvironmentProperty ( 549 BROKERINSTANCENAME, brokerInstanceName , 550 "Broker Instance Name", "java.lang.String"); 551 setProperty(cd, envProp2); 552 EnvironmentProperty envProp3 = new EnvironmentProperty ( 553 BROKERPORT , brokerPort , 554 "Broker Port", "java.lang.String"); 555 setProperty(cd, envProp3); 556 EnvironmentProperty envProp4 = new EnvironmentProperty ( 557 BROKERARGS , brokerArgs , 558 "Broker Args", "java.lang.String"); 559 setProperty(cd, envProp4); 560 EnvironmentProperty envProp5 = new EnvironmentProperty ( 561 BROKERHOMEDIR , brokerHomeDir , 562 "Broker Home Dir", "java.lang.String"); 563 setProperty(cd, envProp5); 564 EnvironmentProperty envProp6 = new EnvironmentProperty ( 565 BROKERJAVADIR , java_home , 566 "Broker Java Dir", "java.lang.String"); 567 setProperty(cd, envProp6); 568 EnvironmentProperty envProp7 = new EnvironmentProperty ( 569 BROKERVARDIR , brokerVarDir , 570 "Broker Var Dir", "java.lang.String"); 571 setProperty(cd, envProp7); 572 EnvironmentProperty envProp8 = new EnvironmentProperty ( 573 BROKERSTARTTIMEOUT , "" + brokerTimeOut , 574 "Broker Start Timeout", "java.lang.String"); 575 setProperty(cd, envProp8); 576 EnvironmentProperty envProp9 = new EnvironmentProperty ( 577 ADMINUSERNAME , adminUserName, 578 "Broker admin username", "java.lang.String"); 579 setProperty(cd, envProp9); 580 EnvironmentProperty envProp10 = new EnvironmentProperty ( 581 ADMINPASSWORD , adminPassword , 582 "Broker admin password", "java.lang.String"); 583 setProperty(cd, envProp10); 584 585 if (!jmsService.getType().equals(REMOTE)) { 587 String adminPassFilePath = getAdminPassFilePath(adminPassword); 591 if (adminPassFilePath != null) { 592 EnvironmentProperty envProp11 = new EnvironmentProperty ( 593 ADMINPASSFILE , adminPassFilePath , 594 "Broker admin password", "java.lang.String"); 595 setProperty(cd, envProp11); 596 } 597 } 598 } 599 } 602 603 private String getAdminPassFilePath(String adminPassword) { 604 try { 605 mqPassFile = File.createTempFile(MQ_PASS_FILE_PREFIX,null); 606 BufferedWriter out = new BufferedWriter (new FileWriter (mqPassFile)); 607 out.write(MQ_PASS_FILE_KEY + adminPassword); 608 out.newLine(); 609 out.flush(); 610 out.close(); 611 return mqPassFile.getCanonicalPath(); 612 } catch (IOException e) { 613 logger.log(Level.WARNING, "IOException while creating MQ admin pass file" + e.getMessage()); 614 } 615 return null; 616 } 617 618 private long getBrokerTimeOut(JmsService jmsService) { 619 long defaultTimeout = 30 * 1000; long timeout = defaultTimeout; 622 623 String specifiedTimeOut = jmsService.getInitTimeoutInSeconds(); 624 if (specifiedTimeOut != null) 625 timeout = Integer.parseInt(specifiedTimeOut) * 1000; 626 return timeout; 627 } 628 629 public static String getBrokerInstanceName(JmsService js) 630 throws ConfigException, ConnectorRuntimeException { 631 String asInstance = ApplicationServer.getServerContext().getInstanceName(); 632 String domainName = null; 633 if (isClustered()) { 634 domainName = ClusterHelper.getClusterForInstance( 635 ApplicationServer.getServerContext().getConfigContext(), 636 asInstance).getName(); 637 } else { 638 domainName = ServerManager.instance().getDomainName(); 639 } 640 String s = IASJmsUtil.getBrokerInstanceName(domainName, asInstance, js); 641 logFine("IASJMSUtil gave broker Instancename as " + s); 642 String converted = convertStringToValidMQIdentifier(s); 643 logFine("converted instance name " + converted); 644 return converted; 645 } 646 647 private void createMQVarDirectoryIfNecessary(){ 648 String asInstanceRoot = ApplicationServer.getServerContext(). 649 getInstanceEnvironment().getInstancesRoot(); 650 String mqInstanceDir = asInstanceRoot + java.io.File.separator 651 + IASJmsUtil.MQ_DIR_NAME; 652 java.io.File instanceDir = new java.io.File (mqInstanceDir); 655 if (!(instanceDir.exists() && instanceDir.isDirectory())) { 656 instanceDir.mkdirs(); 657 } 658 } 659 660 private String getMQVarDir(){ 661 String asInstanceRoot = ApplicationServer.getServerContext(). 662 getInstanceEnvironment().getInstancesRoot(); 663 String mqInstanceDir = asInstanceRoot + java.io.File.separator 664 + IASJmsUtil.MQ_DIR_NAME; 665 return mqInstanceDir; 666 } 667 668 private String getBrokerHomeDir() { 669 String brokerHomeDir = java.lang.System.getProperty(SystemPropertyConstants.IMQ_BIN_PROPERTY); 672 logFine("broker home dir from system property " + brokerHomeDir); 673 674 if (brokerHomeDir == null) { 678 String IMQ_INSTALL_SUBDIR = java.io.File.separator + 679 ".." + java.io.File.separator + ".." + 680 java.io.File.separator + "imq" ; 681 brokerHomeDir = ApplicationServer.getServerContext().getInstallRoot() 684 + IMQ_INSTALL_SUBDIR; 685 } else { 686 brokerHomeDir = brokerHomeDir + java.io.File.separator + ".." ; 688 } 689 690 logFine("Broker Home Directory :: " + brokerHomeDir); 691 logFine("broker home dir finally" + brokerHomeDir); 692 return brokerHomeDir; 693 694 } 695 696 699 700 701 705 private void setClusterRABeanProperties() throws ConnectorRuntimeException { 706 ConnectorDescriptor cd = super.getDescriptor(); 707 try { 708 if (isClustered()) { 709 String val = getGroupName(); 710 EnvironmentProperty envProp = new EnvironmentProperty ( 711 GROUPNAME, val, "Group Name", "java.lang.String"); 712 setProperty(cd, envProp); 713 EnvironmentProperty envProp1 = new EnvironmentProperty ( 714 CLUSTERCONTAINER, "true", "Cluster container flag", 715 "java.lang.Boolean"); 716 setProperty(cd, envProp1); 717 logFine("CLUSTERED instance - setting groupname as" + val); 718 } else { 719 logFine("Instance not Clustered and hence not setting " + 720 "groupname"); 721 } 722 } catch (ConfigException e) { 723 ConnectorRuntimeException crex = new ConnectorRuntimeException(e.getMessage()); 724 throw (ConnectorRuntimeException)crex.initCause(e); 725 } 726 } 727 728 729 733 private void setAppClientRABeanProperties() throws ConnectorRuntimeException { 734 logFine("In Appclient container!!!"); 735 ConnectorDescriptor cd = super.getDescriptor(); 736 EnvironmentProperty envProp1 = new EnvironmentProperty ( 737 BROKERTYPE, REMOTE, "Broker Type", "java.lang.String"); 738 setProperty(cd, envProp1); 739 740 EnvironmentProperty envProp2 = new EnvironmentProperty ( 741 GROUPNAME, "", "Group Name", "java.lang.String"); 742 cd.removeConfigProperty(envProp2); 743 EnvironmentProperty envProp3 = new EnvironmentProperty ( 744 CLUSTERCONTAINER, "false", "Cluster flag", "java.lang.Boolean"); 745 setProperty(cd, envProp3); 746 } 747 748 749 private static boolean isClustered() throws ConnectorRuntimeException { 750 return JmsRaUtil.isClustered(); 751 } 752 753 private String getGroupName() throws ConfigException{ 754 return getDomainName() + SEPARATOR + getClusterName(); 755 } 756 757 private String getClusterName() throws ConfigException { 758 return ClusterHelper.getClusterForInstance( 759 ApplicationServer.getServerContext().getConfigContext(), 760 ApplicationServer.getServerContext().getInstanceName()).getName(); 761 } 762 763 767 private String getMQClusterName() throws ConfigException { 768 return convertStringToValidMQIdentifier(getClusterName()) + "_MQCluster"; 769 } 770 771 private static String convertStringToValidMQIdentifier(String s) { 775 if (s == null) return ""; 776 777 StringBuffer buf = new StringBuffer (); 778 for(int i = 0; i < s.length(); i++) { 779 if(Character.isLetterOrDigit(s.charAt(i))){ 780 buf.append(s.charAt(i)); 782 } 783 } 784 return buf.toString(); 785 } 786 787 private String getDomainName() throws ConfigException { 788 ConfigContext ctxt = ApplicationServer.getServerContext().getConfigContext(); 789 796 return ""; 798 } 799 800 806 public void reloadRA(JmsService js) throws ConnectorRuntimeException { 807 setMdbContainerProperties(); 808 setJmsServiceProperties(js); 809 810 super.loadRAConfiguration(); 811 rebindDescriptor(); 812 } 813 814 820 public void addJmsHost(JmsHost host) throws ConnectorRuntimeException { 821 urlList.addMQUrl(host); 822 setAddressList(); 823 } 824 825 831 public void deleteJmsHost(JmsHost host) throws ConnectorRuntimeException { 832 urlList.removeMQUrl(host); 833 setAddressList(); 834 } 835 836 842 public void updateJmsHost(JmsHost host) throws ConnectorRuntimeException { 843 urlList.updateMQUrl(host); 844 setAddressList(); 845 } 846 847 private void setMdbContainerProperties() throws ConnectorRuntimeException { 848 JmsRaUtil raUtil = new JmsRaUtil(null); 849 850 ConnectorDescriptor cd = super.getDescriptor(); 851 raUtil.setMdbContainerProperties(); 852 853 String val = ""+MdbContainerProps.getReconnectEnabled(); 854 EnvironmentProperty envProp2 = new EnvironmentProperty ( 855 RECONNECTENABLED, val, val, "java.lang.Boolean"); 856 setProperty(cd, envProp2); 857 858 val = ""+MdbContainerProps.getReconnectDelay(); 859 EnvironmentProperty envProp3 = new EnvironmentProperty ( 860 RECONNECTINTERVAL, val, val, "java.lang.Integer"); 861 setProperty(cd, envProp3); 862 863 val = ""+MdbContainerProps.getReconnectMaxRetries(); 864 EnvironmentProperty envProp4 = new EnvironmentProperty ( 865 RECONNECTATTEMPTS, val, val, "java.lang.Integer"); 866 setProperty(cd, envProp4); 867 868 } 872 873 private void setAddressList() throws ConnectorRuntimeException { 874 try { 877 ConfigContext ctx = ApplicationServer.getServerContext().getConfigContext(); 878 JmsService jmsService = ServerBeansFactory.getJmsServiceBean(ctx); 879 setConnectionURL(jmsService, urlList); 880 } catch (ConfigException e) { 881 e.printStackTrace(); 882 } 883 super.loadRAConfiguration(); 884 } 885 886 private void setConnectionURL(JmsService jmsService, MQAddressList urlList) { 890 ConnectorDescriptor cd = super.getDescriptor(); 891 String val = urlList.toString(); 892 if (val != null) { 893 logger.info("JMS Service Connection URL is :" + val); 894 EnvironmentProperty envProp1 = new EnvironmentProperty ( 895 CONNECTION_URL, val, val, "java.lang.String"); 896 setProperty(cd, envProp1); 897 } 898 } 899 900 private void setJmsServiceProperties(JmsService service) throws 901 ConnectorRuntimeException { 902 JmsRaUtil jmsraUtil = new JmsRaUtil(service); 903 904 urlList = jmsraUtil.getUrlList(); 905 906 ConnectorDescriptor cd = super.getDescriptor(); 907 setConnectionURL(service, urlList); 908 909 String val = ""+jmsraUtil.getReconnectEnabled(); 910 EnvironmentProperty envProp2 = new EnvironmentProperty ( 911 RECONNECTENABLED, val, val, "java.lang.Boolean"); 912 setProperty(cd, envProp2); 913 914 int newval = (new Integer (jmsraUtil.getReconnectInterval())).intValue() * 1000; 916 val = "" + newval; 917 EnvironmentProperty envProp3 = new EnvironmentProperty ( 918 RECONNECTINTERVAL, val, val, "java.lang.Integer"); 919 setProperty(cd, envProp3); 920 921 val = ""+jmsraUtil.getReconnectAttempts(); 922 EnvironmentProperty envProp4 = new EnvironmentProperty ( 923 RECONNECTATTEMPTS, val, val, "java.lang.Integer"); 924 setProperty(cd, envProp4); 925 926 val = ""+jmsraUtil.getAddressListBehaviour(); 927 EnvironmentProperty envProp5 = new EnvironmentProperty ( 928 ADRLIST_BEHAVIOUR, val, val, "java.lang.String"); 929 setProperty(cd, envProp5); 930 931 val = ""+jmsraUtil.getAddressListIterations(); 932 EnvironmentProperty envProp6 = new EnvironmentProperty ( 933 ADRLIST_ITERATIONS, val, val, "java.lang.Integer"); 934 setProperty(cd, envProp6); 935 936 boolean useExternal = shouldUseExternalRmiRegistry(jmsraUtil); 937 val = (new Boolean (useExternal)).toString(); 938 EnvironmentProperty envProp7 = new EnvironmentProperty ( 939 USEEXTERNALRMIREGISTRY, val, val, "java.lang.Boolean"); 940 setProperty(cd, envProp7); 941 942 if (!useExternal) { 946 String configuredRmiRegistryPort = getRmiRegistryPort(); 947 val = configuredRmiRegistryPort; 948 if (val != null) { 949 EnvironmentProperty envProp8 = new EnvironmentProperty ( 950 RMIREGISTRYPORT, val, val, "java.lang.Integer"); 951 setProperty(cd, envProp8); 952 } else { 953 logger.log(Level.WARNING, "Invalid RMI registry port"); 954 } 955 } 956 } 957 958 961 private boolean shouldUseExternalRmiRegistry (JmsRaUtil jmsraUtil) { 962 boolean useExternalRmiRegistry = ( !isASRmiRegistryPortAvailable(jmsraUtil) ); 963 return useExternalRmiRegistry; 965 } 966 967 970 private String getRmiRegistryPort() { 971 String val = null; 972 if (MQRmiPort != null && !MQRmiPort.trim().equals("")){ 973 return MQRmiPort; 974 } else { 975 String configuredPort = null; 976 try { 977 configuredPort = getConfiguredRmiRegistryPort(); 978 } catch (ConfigException ex) { 979 logger.log(Level.WARNING, ex.getMessage()); 980 logger.log(Level.FINE, "Exception while getting configured rmi " + 981 "registry port", ex); 982 } 983 if (configuredPort != null) { 984 return configuredPort; 985 } 986 987 if (ResourcesUtil.isDAS()) { 990 return DASRMIPORT; 991 } 992 } 993 return val; 994 } 995 996 private String getConfiguredRmiRegistryHost() throws ConfigException { 997 return getJmxConnector().getAddress(); 998 } 999 1000 private String getConfiguredRmiRegistryPort() throws ConfigException { 1001 return getJmxConnector().getPort(); 1002 } 1003 1004 private JmxConnector getJmxConnector() throws ConfigException{ 1005 AdminService as = ServerBeansFactory.getConfigBean( 1006 ApplicationServer.getServerContext().getConfigContext()).getAdminService(); 1007 return as.getJmxConnectorByName(as.getSystemJmxConnectorName()); 1008 } 1009 1010 private boolean isASRmiRegistryPortAvailable(JmsRaUtil jmsraUtil) { 1011 logFine("isASRmiRegistryPortAvailable - JMSService Type:" + jmsraUtil.getJMSServiceType()); 1012 1013 if (jmsraUtil.getJMSServiceType().equals(REMOTE)) { 1016 return false; 1017 } 1018 1019 String name = null; 1020 try { 1021 name = "rmi://"+getConfiguredRmiRegistryHost() + ":" + getConfiguredRmiRegistryPort(); 1023 if (logger.isLoggable(Level.FINE)) { 1024 logger.fine("Attempting to list " + name); 1025 } 1026 String [] ss = Naming.list(name); 1027 if (logger.isLoggable(Level.FINE)) { 1028 logger.fine("List on " + name + " succeeded"); 1029 } 1030 return true; 1032 } catch (Exception e) { 1033 logger.fine(e.getMessage() + " " + name); 1034 return false; 1035 } 1036 } 1037 1038 private void setProperty(ConnectorDescriptor cd, EnvironmentProperty envProp){ 1039 cd.removeConfigProperty(envProp); 1040 cd.addConfigProperty(envProp); 1041 } 1042 1043 1044 private void rebindDescriptor() throws ConnectorRuntimeException { 1045 try { 1046 String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(super.getModuleName()); 1047 com.sun.enterprise.Switch.getSwitch().getNamingManager(). 1048 publishObject( descriptorJNDIName, super.getDescriptor(), true); 1049 } catch (javax.naming.NamingException ne) { 1050 ConnectorRuntimeException cre = new ConnectorRuntimeException (ne.getMessage()); 1051 throw (ConnectorRuntimeException) cre.initCause(ne); 1052 } 1053 } 1054 1055 1056 1066 public ManagedConnectionFactory createManagedConnectionFactory 1067 (com.sun.enterprise.connectors.ConnectorConnectionPool cpr, 1068 ClassLoader loader) { 1069 ManagedConnectionFactory mcf = 1070 super.createManagedConnectionFactory(cpr, loader); 1071 if ( mcf != null ) { 1072 Set s = cpr.getConnectorDescriptorInfo().getMCFConfigProperties(); 1073 Iterator it = s.iterator(); 1074 while (it.hasNext()) { 1075 EnvironmentProperty prop = (EnvironmentProperty) it.next(); 1076 String propName = prop.getName(); 1077 1078 propName.substring(1); 1079 if (propName.startsWith("imq") && prop.getValue() != "") { 1082 try { 1083 Method meth = mcf.getClass().getMethod 1084 (SETTER, new Class [] {java.lang.String .class, 1085 java.lang.String .class}); 1086 meth.invoke(mcf, new Object [] {prop.getName(), 1087 prop.getValueObject()}); 1088 } catch (NoSuchMethodException ex) { 1089 logger.log(Level.WARNING, "no.such.method", 1090 new Object [] {SETTER, mcf.getClass().getName()}); 1091 } catch (Exception ex) { 1092 logger.log(Level.SEVERE, "error.execute.method", 1093 new Object [] {SETTER, mcf.getClass().getName()}); 1094 } 1095 } 1096 } 1097 1098 } 1099 return mcf; 1100 } 1101 1102 1118 public void updateMDBRuntimeInfo(EjbMessageBeanDescriptor descriptor_, 1119 BeanPoolDescriptor poolDescriptor) throws ConnectorRuntimeException{ 1120 1121 String jndiName = descriptor_.getJndiName(); 1122 1123 if (jndiName == null) { logger.log (Level.SEVERE, "Missing Destination JNDI Name"); 1127 String msg = sm.getString("ajra.error_in_dd"); 1128 throw new RuntimeException (msg); 1129 } 1130 1131 String resourceAdapterMid = ConnectorRuntime.DEFAULT_JMS_ADAPTER; 1132 1133 descriptor_.setResourceAdapterMid(resourceAdapterMid); 1134 1135 1136 String destName = getPhysicalDestinationFromConfiguration(jndiName); 1137 1138 descriptor_.putRuntimeActivationConfigProperty( 1140 new EnvironmentProperty(DESTINATION, 1141 destName, null)); 1142 1143 1144 if (descriptor_.getDestinationType() != null && 1147 !"".equals(descriptor_.getDestinationType())) { 1148 descriptor_.putRuntimeActivationConfigProperty( 1149 new EnvironmentProperty(DESTINATION_TYPE, 1150 descriptor_.getDestinationType(), null)); 1151 } else { 1152 1162 ConfigBean[] cb; 1163 try { 1164 cb = ResourcesUtil.getInstance().getEnabledAdminObjectResources( 1165 ConnectorConstants.DEFAULT_JMS_ADAPTER); 1166 for (int i = 0; i < cb.length; i++) { 1167 AdminObjectResource aor = (AdminObjectResource) cb[i]; 1168 if (aor.getJndiName().equals(jndiName)) { 1169 descriptor_.putRuntimeActivationConfigProperty( 1170 new EnvironmentProperty(DESTINATION_TYPE, 1171 aor.getResType(), null)); 1172 logger.log(Level.INFO, "endpoint.determine.destinationtype", new 1173 Object []{aor.getResType() , aor.getJndiName() , descriptor_.getName()}); 1174 } 1175 } 1176 } catch (ConfigException e) { 1177 1178 } 1179 } 1180 1181 1182 descriptor_.putRuntimeActivationConfigProperty( 1184 new EnvironmentProperty(SUBSCRIPTION_NAME, 1185 descriptor_.getDurableSubscriptionName(), null)); 1186 1187 String mdbCF = null; 1188 try { 1189 mdbCF = descriptor_.getIASEjbExtraDescriptors(). 1190 getMdbConnectionFactory().getJndiName(); 1191 } catch(NullPointerException ne ) { 1192 } 1194 1195 if (mdbCF != null && mdbCF != "") { 1196 setValuesFromConfiguration(mdbCF, descriptor_); 1197 } 1198 1199 1202 if (poolDescriptor != null) { 1203 descriptor_.putRuntimeActivationConfigProperty 1204 (new EnvironmentProperty (MAXPOOLSIZE, ""+ 1205 poolDescriptor.getMaxPoolSize(),"", "java.lang.Integer" )); 1206 descriptor_.putRuntimeActivationConfigProperty 1207 (new EnvironmentProperty (MINPOOLSIZE,""+ 1208 poolDescriptor.getSteadyPoolSize(),"", "java.lang.Integer")); 1209 descriptor_.putRuntimeActivationConfigProperty 1210 (new EnvironmentProperty (RESIZECOUNT,""+ 1211 poolDescriptor.getPoolResizeQuantity(),"", "java.lang.Integer")); 1212 descriptor_.putRuntimeActivationConfigProperty 1213 (new EnvironmentProperty (RESIZETIMEOUT,""+ 1214 poolDescriptor.getPoolIdleTimeoutInSeconds(),"", "java.lang.Integer")); 1215 descriptor_.putRuntimeActivationConfigProperty 1216 (new EnvironmentProperty (REDELIVERYCOUNT,""+ 1217 MdbContainerProps.getMaxRuntimeExceptions(),"", "java.lang.Integer")); 1218 } 1219 1220 try { 1222 boolean clustered = isClustered(); 1223 logFine("Are we in a Clustered contained ? " + clustered); 1224 if (clustered) { 1225 setClusterActivationSpecProperties(descriptor_); 1226 logFine("Creating physical destination " + destName); 1227 logFine("Destination is Queue? " + descriptor_.hasQueueDest()); 1228 if (descriptor_.hasQueueDest()) { 1229 autoCreatePhysicalDest(destName, true); 1230 } else { 1231 autoCreatePhysicalDest(destName, false); 1232 } 1233 } 1234 } catch (ConfigException e) { 1235 ConnectorRuntimeException crex = new ConnectorRuntimeException(e.getMessage()); 1236 throw (ConnectorRuntimeException)crex.initCause(e); 1237 } 1238 } 1239 1240 void autoCreatePhysicalDest(String destName, boolean isQueue) 1241 throws ConnectorRuntimeException{ 1242 MQAdministrator mqAdmin = new MQAdministrator(); 1243 mqAdmin.createPhysicalDestination(destName, isQueue); 1244 } 1245 1246 1251 private void setClusterActivationSpecProperties(EjbMessageBeanDescriptor 1252 descriptor_) throws ConfigException { 1253 descriptor_.putRuntimeActivationConfigProperty(new 1255 EnvironmentProperty(MDBIDENTIFIER,""+ 1256 getMDBIdentifier(descriptor_),"MDB Identifier", 1257 "java.lang.String")); 1258 logFine("CLUSTERED instance - setting MDB identifier as" + 1259 getMDBIdentifier(descriptor_)); 1260 1261 } 1262 1263 1269 private String getMDBIdentifier(EjbMessageBeanDescriptor descriptor_) throws ConfigException { 1270 return getDomainName() + SEPARATOR + getClusterName() + SEPARATOR + descriptor_.getUniqueId() ; 1271 } 1272 1273 private String getPhysicalDestinationFromConfiguration(String logicalDest) 1274 throws ConnectorRuntimeException{ 1275 ElementProperty ep = null; 1276 try { 1277 ServerContext sc = ApplicationServer.getServerContext(); 1278 ConfigContext ctx = sc.getConfigContext(); 1279 Resources rbeans = 1280 ServerBeansFactory.getDomainBean(ctx).getResources(); 1281 AdminObjectResource res = (AdminObjectResource) 1282 rbeans.getAdminObjectResourceByJndiName(logicalDest); 1283 if (res == null) { 1284 String msg = sm.getString("ajra.err_getting_dest", logicalDest ); 1285 throw new ConnectorRuntimeException(msg); 1286 } 1287 1288 ep = res.getElementPropertyByName(PHYSICAL_DESTINATION); 1289 } catch(ConfigException ce) { 1290 String msg = sm.getString("ajra.err_getting_dest", logicalDest); 1291 ConnectorRuntimeException cre = new ConnectorRuntimeException( msg ); 1292 cre.initCause( ce ); 1293 throw cre; 1294 } 1295 1296 if (ep == null) { 1297 String msg = sm.getString("ajra.cannot_find_phy_dest", ep); 1298 throw new ConnectorRuntimeException(msg); 1299 } 1300 1301 return ep.getValue(); 1302 } 1303 1304 1305 private void setValuesFromConfiguration(String cfName, EjbMessageBeanDescriptor 1306 descriptor_) throws ConnectorRuntimeException{ 1307 ElementProperty[] ep = null; 1308 try { 1309 ServerContext sc = ApplicationServer.getServerContext(); 1310 ConfigContext ctx = sc.getConfigContext(); 1311 Resources rbeans = ServerBeansFactory.getDomainBean(ctx).getResources(); 1312 ConnectorResource res = (ConnectorResource) 1313 rbeans.getConnectorResourceByJndiName(cfName); 1314 if (res == null) { 1315 String msg = sm.getString("ajra.mdb_cf_not_created", cfName); 1316 throw new ConnectorRuntimeException(msg); 1317 } 1318 1319 ConnectorConnectionPool ccp = (ConnectorConnectionPool) 1320 rbeans.getConnectorConnectionPoolByName(res.getPoolName()); 1321 1322 ep = ccp.getElementProperty(); 1323 } catch(ConfigException ce) { 1324 String msg = sm.getString("ajra.mdb_cf_not_created", cfName); 1325 ConnectorRuntimeException cre = new ConnectorRuntimeException( msg ); 1326 ce.initCause( ce ); 1327 throw cre; 1328 } 1329 1330 if (ep == null) { 1331 String msg = sm.getString("ajra.cannot_find_phy_dest"); 1332 throw new ConnectorRuntimeException( msg ); 1333 } 1334 1335 for (int i=0; i < ep.length; i++) { 1336 ElementProperty prop = ep[i]; 1337 String name = prop.getName(); 1338 if (name.equals(MCFADDRESSLIST)) { 1339 name = ADDRESSLIST; 1340 } 1341 String val = prop.getValue(); 1342 if (val == null || val.equals("")) { 1343 continue; 1344 } 1345 descriptor_.putRuntimeActivationConfigProperty( 1346 new EnvironmentProperty(name, val, null)); 1347 } 1348 1349 } 1350 1351 private static void logFine(String s) { 1352 if (logger.isLoggable(Level.FINE)){ 1353 logger.fine(s); 1354 } 1355 } 1356} 1357 | Popular Tags |