1 25 26 27 package org.objectweb.jonas.resource; 28 29 import java.io.File ; 30 import java.net.URL ; 31 import java.util.Enumeration ; 32 import java.util.Hashtable ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 import java.util.Properties ; 36 import java.util.Vector ; 37 import java.util.jar.JarEntry ; 38 39 import javax.management.InstanceNotFoundException ; 40 import javax.management.MBeanRegistrationException ; 41 import javax.management.MBeanServer ; 42 import javax.management.MalformedObjectNameException ; 43 import javax.management.ObjectName ; 44 import javax.management.modelmbean.ModelMBean ; 45 import javax.naming.Context ; 46 import javax.naming.InitialContext ; 47 import javax.naming.NamingException ; 48 import javax.resource.Referenceable ; 49 import javax.resource.spi.ActivationSpec ; 50 import javax.resource.spi.ConnectionManager ; 51 import javax.resource.spi.ManagedConnectionFactory ; 52 import javax.resource.spi.ResourceAdapter ; 53 import javax.resource.spi.ResourceAdapterAssociation ; 54 import javax.resource.spi.ResourceAllocationException ; 55 import javax.resource.spi.work.WorkManager ; 56 57 import org.apache.commons.modeler.ManagedBean; 58 import org.apache.commons.modeler.Registry; 59 60 import org.objectweb.transaction.jta.TransactionManager; 61 62 import org.objectweb.jonas_ejb.deployment.api.ActivationConfigPropertyDesc; 63 64 import org.objectweb.jonas_rar.deployment.api.AdminobjectDesc; 65 import org.objectweb.jonas_rar.deployment.api.AuthenticationMechanismDesc; 66 import org.objectweb.jonas_rar.deployment.api.ConfigPropertyDesc; 67 import org.objectweb.jonas_rar.deployment.api.ConnectionDefinitionDesc; 68 import org.objectweb.jonas_rar.deployment.api.ConnectorDesc; 69 import org.objectweb.jonas_rar.deployment.api.InboundResourceadapterDesc; 70 import org.objectweb.jonas_rar.deployment.api.JonasActivationspecDesc; 71 import org.objectweb.jonas_rar.deployment.api.JonasAdminobjectDesc; 72 import org.objectweb.jonas_rar.deployment.api.JonasConnectionDefinitionDesc; 73 import org.objectweb.jonas_rar.deployment.api.JonasConnectorDesc; 74 import org.objectweb.jonas_rar.deployment.api.MessageadapterDesc; 75 import org.objectweb.jonas_rar.deployment.api.MessagelistenerDesc; 76 import org.objectweb.jonas_rar.deployment.api.OutboundResourceadapterDesc; 77 import org.objectweb.jonas_rar.deployment.api.RarDeploymentDesc; 78 import org.objectweb.jonas_rar.deployment.api.RequiredConfigPropertyDesc; 79 import org.objectweb.jonas_rar.deployment.api.ResourceadapterDesc; 80 import org.objectweb.jonas_rar.deployment.api.TmConfigPropertyDesc; 81 import org.objectweb.jonas_rar.deployment.lib.wrapper.RarManagerWrapper; 82 83 import org.objectweb.jonas.common.JJarFile; 84 import org.objectweb.jonas.common.Log; 85 import org.objectweb.jonas.ear.EarServiceImpl; 86 import org.objectweb.jonas.jmx.J2eeObjectName; 87 import org.objectweb.jonas.jmx.JmxService; 88 import org.objectweb.jonas.jmx.JonasObjectName; 89 import org.objectweb.jonas.jtm.TransactionService; 90 import org.objectweb.jonas.management.JonasMBeanTools; 91 import org.objectweb.jonas.service.ServiceException; 92 import org.objectweb.jonas.service.ServiceManager; 93 94 import org.objectweb.util.monolog.api.BasicLevel; 95 import org.objectweb.util.monolog.api.Logger; 96 97 101 102 public class Rar { 103 104 107 private static Logger logger = null; 108 111 private static Logger poolLogger = null; 112 115 private static Logger setterLogger = null; 116 119 private static Logger manageLogger = null; 120 121 String rarFileName = null; 122 ClassLoader curLoader = null; 123 boolean isInEar; 124 URL earUrl = null; 125 Context rCtx = null; 126 String jDomain = null; 127 String jServer = null; 128 Vector jndinames = new Vector (); 129 130 String lnkJndiName = ""; 131 String lnkRarFilename = ""; 132 133 JCAResource jcaResourceMBean = null; 134 String JCAResourceName = null; 135 Registry oRegistry = null; 136 137 private WorkManager workMgr = null; 139 private ResourceBootstrapContext bootCtx = null; 140 141 143 public static final String CLASS = "jonas.service.resource.class"; 145 public static final String JNDI_NAME = "jndiname"; 146 public static final String RAR_FILENAME = "rarfilename"; 147 public static final String LNK_JNDI_NAME = "lnkjndiname"; 148 public static final String LNK_RAR_FILENAME = "lnkrarfilename"; 149 public static final String OBJ_TYPE = "objtype"; 150 public static final String RESOURCE_LIST = "jonas.service.resource.resources"; 151 152 public static final int DEF_WRK_THREADS = 5; 153 public static final int DEF_EXEC_TIME = 0; 154 155 public static final String JCD = "JCD"; 156 public static final String JAS = "JAS"; 157 public static final String JAO = "JAO"; 158 159 public String objectName = null; 160 public String pathName = null; 161 public ResourceAdapter resAdp = null; 162 public ConnectorDesc raConn = null; 163 public JonasConnectorDesc lnkJonasConn = null; 164 public JonasConnectorDesc jonasConn = null; 165 166 public String xmlContent = null; 167 public String jonasXmlContent = null; 168 169 170 private class ConfigObj { 171 public String type; 172 public int offset; 173 public String jndiName; 174 public String rarFilename; 175 public String lnkJndiName; 176 public String lnkRarFilename; 177 public String interfaceStr; 178 public String classStr; 179 public Object factory; 180 public ConnectionManager cm; 181 public boolean basicPass; 182 public boolean defaultAS; 183 public List reqConfigProps; 184 public ConfigObj(String fType, int off, String jndi, String fName, 185 String intStr, String clsStr, Object fact) { 186 type = fType; 187 offset = off; 188 jndiName = jndi; 189 rarFilename = fName; 190 interfaceStr = intStr; 191 classStr = clsStr; 192 factory = fact; 193 cm = null; 194 reqConfigProps = null; 195 lnkJndiName = ""; 196 lnkRarFilename = ""; 197 defaultAS = false; 198 } 199 } 200 201 204 private static Vector defaultAS = new Vector (); 205 206 209 public static Hashtable fileName2RA = new Hashtable (); 210 213 public static Hashtable jndiName2RA = new Hashtable (); 214 215 private Hashtable cfgObjs = new Hashtable (); 216 219 private static Hashtable jndiName2Factory = new Hashtable (); 220 221 224 private TransactionManager tm = null; 225 226 229 private MBeanServer mbeanServer = null; 230 231 234 private String jcaResourceObjectName = null; 235 236 241 private ConnectionManagerImpl cm = null; 242 243 246 private Context ictx = null; 247 248 251 ResourceUtility ru = null; 252 253 261 public Rar() { 262 if (logger == null) { 263 logger = Log.getLogger(Log.JONAS_JCA_PREFIX+".process"); 264 } 265 if (poolLogger == null) { 266 poolLogger = Log.getLogger(Log.JONAS_JCA_PREFIX+".pool"); 267 } 268 if (setterLogger == null) { 269 setterLogger = Log.getLogger(Log.JONAS_JCA_PREFIX+".setters"); 270 } 271 if (manageLogger == null) { 272 manageLogger = Log.getLogger(Log.JONAS_JCA_PREFIX+".management"); 273 } 274 275 curLoader = Thread.currentThread().getContextClassLoader(); 276 277 ru = new ResourceUtility(null, null, logger, setterLogger, manageLogger); 278 } 279 280 288 public Rar(Context ctx, String jDom, String jServ, 289 WorkManager wrkMgr, ResourceBootstrapContext btCtx) { 290 if (logger == null) { 291 logger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".process"); 292 } 293 if (poolLogger == null) { 294 poolLogger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".pool"); 295 } 296 if (setterLogger == null) { 297 setterLogger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".setters"); 298 } 299 if (manageLogger == null) { 300 manageLogger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".management"); 301 } 302 303 try { 304 rarFileName = (String ) ctx.lookup("rarFileName"); 305 isInEar = ((Boolean ) ctx.lookup("isInEar")).booleanValue(); 306 if (isInEar) { 307 earUrl = (URL ) ctx.lookup("earUrl"); 308 } 309 curLoader = (ClassLoader ) ctx.lookup("classloader"); 310 } catch (NamingException e) { 311 String err = "Error while getting parameter from context param."; 312 logger.log(BasicLevel.ERROR, err + e.getMessage()); 313 throw new ResourceServiceException(err, e); 314 } catch (Exception ex) { 315 String err = "Error while getting parameter from context param."; 316 logger.log(BasicLevel.ERROR, err + ex.getMessage()); 317 throw new ResourceServiceException(err, ex); 318 } 319 320 workMgr = wrkMgr; 321 bootCtx = btCtx; 322 rCtx = ctx; 323 jDomain = jDom; 324 jServer = jServ; 325 326 try { 328 ictx = new InitialContext (); 329 } catch (NamingException e) { 330 logger.log(BasicLevel.ERROR, "Cannot create initial context when Resource service initializing"); 331 throw new ServiceException("Cannot create initial context when Resource service initializing", e); 332 } 333 334 try { 336 ServiceManager sm = ServiceManager.getInstance(); 337 TransactionService ts = (TransactionService) sm.getTransactionService(); 338 tm = ts.getTransactionManager(); 339 } catch (Exception e) { 340 logger.log(BasicLevel.ERROR, "Cannot get the Transaction service: " + e); 341 throw new ServiceException("Cannot get the Transaction service: ", e); 342 } 343 344 try { 346 mbeanServer = 347 ((JmxService) ServiceManager.getInstance().getJmxService()).getJmxServer(); 348 } catch (Exception e) { 349 mbeanServer = null; 351 } 352 353 oRegistry = JonasMBeanTools.getRegistry(); 355 356 ru = new ResourceUtility(mbeanServer, oRegistry, logger, setterLogger, manageLogger); 357 } 358 359 363 public Context processRar() throws Exception { 364 365 String onRar = null; 366 RarDeploymentDesc radesc = null; 368 ConnectorDesc conn = null; 369 JonasConnectorDesc jConn = null; 370 xmlContent = null; 371 jonasXmlContent = null; 372 ConnectionManager cm = null; 373 ManagedConnectionFactory mcf = null; 374 375 radesc = RarManagerWrapper.getInstance(rCtx); 376 conn = radesc.getConnectorDesc(); 377 jConn = radesc.getJonasConnectorDesc(); 378 xmlContent = radesc.getXmlContent(); 379 jonasXmlContent = radesc.getJOnASXmlContent(); 380 381 if(conn == null && jConn == null) { 382 logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName 383 + ") must be a valid RAR file."); 384 throw new Exception ("resource input file incorrect"); 385 } 386 387 String rarVal = null; 392 if (jConn != null) { 393 rarVal = (jConn.getRarlink() == null 394 ? null 395 : jConn.getRarlink()); 396 if (rarVal != null && rarVal.length() > 0) { 397 lnkJndiName = rarVal; 398 conn = getConnectorDesc(rarVal); 399 if (conn == null) { 400 return rCtx; 401 } 402 ConfigObj co = (ConfigObj) getConfigObject(rarVal); 403 lnkRarFilename = co.rarFilename; 404 xmlContent = getXmlContent(rarVal); 405 lnkJonasConn = getJonasConnectorDesc(rarVal); 407 } else if (conn == null) { 408 logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName 409 + ") is not valid."); 410 throw new Exception ("resource input file incorrect: no ra.xml file"); 411 } 412 bldSecurityTable(lnkJonasConn, jConn); 413 raConn = conn; 414 jonasConn = jConn; 415 } else { 416 logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName 417 + ") must be a valid RAR file, there must be jonas-ra.xml file."); 418 throw new Exception ("resource input file incorrect: no jonas-ra.xml file"); 419 } 420 421 ConnectionManagerPoolParams pParams = 423 ru.configurePoolParams(jConn.getPoolParamsDesc(), 424 jConn.getJdbcConnParamsDesc(), 425 null); 426 427 430 extractJars(rarFileName, jConn); 431 432 ResourceadapterDesc ra = conn.getResourceadapterDesc(); 434 435 boolean basicPass = true; 438 List authList = ra.getAuthenticationMechanismList(); 439 if (authList != null && authList.size() > 0) { 440 basicPass = false; 441 for (Iterator i = authList.iterator(); i.hasNext();) { 442 AuthenticationMechanismDesc am = (AuthenticationMechanismDesc) i.next(); 443 if (am.getAuthenticationMechanismType().equalsIgnoreCase("BasicPassword")) { 444 basicPass = true; 445 break; 446 } 447 } 448 if (!basicPass) { 449 logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName + ") doesn't contain an AuthenticationMechanismType that is supported by JOnAS(BasicPassword)."); 450 throw new Exception ("No AuthenticationMechanismType that is supported by JOnAS(BasicPassword)."); 451 } 452 } 453 454 ConfigPropertyDesc [] cfgRaJonas = null; 455 456 String logEnabled = null; 457 if (jConn.getLogEnabled() != null) { 458 logEnabled = jConn.getLogEnabled().trim(); 459 } 460 String logTopic = null; 461 if (jConn.getLogTopic() != null) { 462 logTopic = jConn.getLogTopic().trim(); 463 } 464 465 Referenceable cf = null; 466 String jndiName = null; 467 String mcfc = null; 468 ConfigObj cObj = null; 469 470 if (lnkJonasConn != null) { 471 cfgRaJonas = ru.buildConfigProperty(ra.getConfigPropertyList(), 472 jConn.getJonasConfigPropertyList(), 473 lnkJonasConn.getJonasConfigPropertyList()); 474 } else { 475 cfgRaJonas = ru.buildConfigProperty(ra.getConfigPropertyList(), 476 jConn.getJonasConfigPropertyList(), 477 null); 478 } 479 480 Properties tmProp = new Properties (); 481 if (jConn.getTmParamsDesc() != null) { 482 List tmParams = jConn.getTmParamsDesc().getTmConfigPropertyList(); 483 if (tmParams != null) { 484 for (Iterator i = tmParams.iterator(); i.hasNext();) { 485 TmConfigPropertyDesc tpd = (TmConfigPropertyDesc) i.next(); 486 String tpdVal = tpd.getTmConfigPropertyValue(); 487 if (tpdVal == null) { 488 tpdVal = ""; 489 } 490 tmProp.setProperty(tpd.getTmConfigPropertyName(), tpdVal); 491 } 492 if (logger.isLoggable(BasicLevel.DEBUG)) { 493 logger.log(BasicLevel.DEBUG, "TM Properties: " + tmProp); 494 } 495 } 496 } 497 498 String specVersion = conn.getSpecVersion(); 499 if (specVersion.equals("1.0")) { 500 jndiName = jConn.getJndiName().trim(); 501 ConnectionManagerPoolParams cmpp = ru.configurePoolParams(jConn.getPoolParamsDesc(), 502 jConn.getJdbcConnParamsDesc(), null); 503 onRar = registerRarMBean(cfgRaJonas, specVersion, jndiName); 504 cm = ru.createConnectionManager(ra.getTransactionSupport(), tm, 505 logger, poolLogger); 506 mcfc = ra.getManagedconnectionfactoryClass(); 508 mcf = (ManagedConnectionFactory ) ru.processMCF(conn, jConn, cm, curLoader, rarFileName, 509 mcfc, 510 jndiName, logEnabled, logTopic, 511 cfgRaJonas, resAdp, 0); 512 ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, cmpp); 513 514 cf = (Referenceable ) mcf.createConnectionFactory(cm); 515 516 cObj = new ConfigObj(JCD, 0, jndiName, rarFileName, null, mcfc, cf); 518 cObj.cm = cm; 519 cObj.basicPass = basicPass; 520 521 cfgObjs.put(jndiName, cObj); 522 523 jndinames.add(jndiName); 524 525 ru.registerMBean(cf, jndiName, onRar, conn, jonasConn, JCD, 0, 526 jcaResourceMBean, JCAResourceName, jDomain, jServer, ictx, 527 buildProp(cfgRaJonas), "", (ConnectionManagerImpl)cm); 528 ((ConnectionManagerImpl) cm).setXAName(ru.getJcaMcfName(jndiName)); 529 ((ConnectionManagerImpl) cm).registerXAResource(tmProp); 530 531 } else if (conn.getSpecVersion().equals("1.5")) { 532 String raStr = conn.getResourceadapterDesc().getResourceadapterClass().trim(); 533 boolean isResAdapt = false; 534 logger.log(BasicLevel.INFO, "Starting deployment of " + rarFileName); 535 if (raStr != null && raStr.length() > 0) { 536 isResAdapt = true; 537 538 Class raClass = curLoader.loadClass(raStr); 540 resAdp = (ResourceAdapter) raClass.newInstance(); 541 542 ru.processSetters(raClass, resAdp, rarFileName, cfgRaJonas); 543 544 try { 546 resAdp.start(bootCtx); 547 } catch (Exception ex) { 548 logger.log(BasicLevel.ERROR, "Rar: Error from resource (" 549 + rarFileName + ") start method."); 550 throw new Exception ("Error from start method. " + ex); 551 } catch (Throwable th) { 552 logger.log(BasicLevel.ERROR, "Rar: Error from resource (" 553 + rarFileName + ") start method."); 554 throw new Exception ("Error from start method. ", th); 555 } 556 } 557 558 onRar = registerRarMBean(cfgRaJonas, specVersion, null); 559 560 OutboundResourceadapterDesc outRa = ra.getOutboundResourceadapterDesc(); 562 List cdList = null; 563 if (outRa != null) { 564 cdList = outRa.getConnectionDefinitionList(); 565 } 566 ConnectionDefinitionDesc conDef = null; 567 JonasConnectionDefinitionDesc jConDef = null; 568 String id = null; 569 int idOffset = -1; 570 if (cdList != null) { 571 for (int cd = 0; cd < cdList.size(); cd++) { 572 conDef = (ConnectionDefinitionDesc) cdList.get(cd); 573 id = conDef.getId(); 574 idOffset++; 575 jConDef = (JonasConnectionDefinitionDesc) 576 ru.getJonasXML(jConn, id, idOffset, JCD); 577 578 579 if (jConDef.getLogEnabled() != null) { 580 logEnabled = jConDef.getLogEnabled().trim(); 581 } 582 if (jConDef.getLogTopic() != null) { 583 logTopic = jConDef.getLogTopic().trim(); 584 } 585 ConfigPropertyDesc [] cfgCdDesc = 586 ru.buildConfigProperty(conDef.getConfigPropertyList(), 587 jConDef.getJonasConfigPropertyList(), 588 null); 589 ConnectionManagerPoolParams pool = 590 ru.configurePoolParams(jConDef.getPoolParamsDesc(), 591 jConDef.getJdbcConnParamsDesc(), 592 pParams); 593 cm = ru.createConnectionManager(outRa.getTransactionSupport(), tm, 594 logger, poolLogger); 595 596 jndiName = jConDef.getJndiName().trim(); 597 mcfc = conDef.getManagedconnectionfactoryClass(); 598 mcf = (ManagedConnectionFactory ) 599 ru.processMCF(conn, jConn, cm, curLoader, rarFileName, 600 mcfc, jndiName, logEnabled, logTopic, 601 cfgCdDesc, resAdp, idOffset); 602 ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, pool); 603 604 cf = (Referenceable ) mcf.createConnectionFactory(cm); 605 606 cObj = new ConfigObj(JCD, idOffset, jndiName, rarFileName, null, mcfc, cf); 608 cObj.cm = cm; 609 cObj.basicPass = basicPass; 610 611 cfgObjs.put(jndiName, cObj); 612 613 jndinames.add(jndiName); 614 615 String desc = ""; 616 List descList = jConDef.getDescriptionList(); 617 if (descList != null) { 618 for (int i = 0; i < descList.size(); i++) { 619 String tmp = (String ) descList.get(i); 620 desc = desc + tmp; 621 } 622 } 623 ru.registerMBean(cf, jndiName, onRar, conn, jonasConn, JCD, idOffset, 624 jcaResourceMBean, JCAResourceName, jDomain, jServer, ictx, 625 buildProp(cfgCdDesc), desc, (ConnectionManagerImpl)cm); 626 627 ((ConnectionManagerImpl) cm).setXAName(ru.getJcaMcfName(jndiName)); 628 ((ConnectionManagerImpl) cm).registerXAResource(tmProp); 629 } 630 } 631 632 if (isResAdapt) { 635 InboundResourceadapterDesc inAdapt = ra.getInboundResourceadapterDesc(); 637 MessageadapterDesc msgAdapt = null; 638 List mlList = null; 639 if (inAdapt != null) { 640 msgAdapt = inAdapt.getMessageadapterDesc(); 641 mlList = null; 642 if (msgAdapt != null) { 643 mlList = msgAdapt.getMessagelistenerList(); 644 } 645 } 646 MessagelistenerDesc msgList = null; 647 JonasActivationspecDesc jAct = null; 648 id = null; 649 idOffset = -1; 650 if (mlList != null) { 651 for (int ml = 0; ml < mlList.size(); ml++) { 652 msgList = (MessagelistenerDesc) mlList.get(ml); 653 id = msgList.getId(); 654 idOffset++; 655 jAct = (JonasActivationspecDesc) 656 ru.getJonasXML(jConn, id, idOffset, JAS); 657 658 processJAS(rarFileName, msgList, jAct, idOffset); 659 } 660 } 661 662 List aoList = ra.getAdminobjectList(); 664 AdminobjectDesc admObj = null; 665 JonasAdminobjectDesc jAObj = null; 666 id = null; 667 idOffset = -1; 668 if (aoList != null) { 669 for (int ao = 0; ao < aoList.size(); ao++) { 670 admObj = (AdminobjectDesc) aoList.get(ao); 671 id = admObj.getId(); 672 idOffset++; 673 jAObj = (JonasAdminobjectDesc) 674 ru.getJonasXML(jConn, id, idOffset, JAO); 675 676 ConfigPropertyDesc [] cfgCdDesc = 677 ru.buildConfigProperty(admObj.getConfigPropertyList(), 678 jAObj.getJonasConfigPropertyList(), 679 null); 680 681 processJAO(rarFileName, admObj, jAObj, cfgCdDesc, idOffset); 682 } 683 } 684 } 685 } else { 686 logger.log(BasicLevel.ERROR, "ResourceService.createRA: Resource (" 687 + rarFileName 688 + ") must be specify a valid specification of 1.0 or 1.5."); 689 throw new Exception ("resource input file incorrect: invalid specification support(only 1.0 & 1.5 are valid)"); 690 } 691 692 logger.log(BasicLevel.INFO, rarFileName + " available"); 693 try { 694 rCtx.rebind("onRar", onRar); 695 rCtx.rebind("deployed", new Boolean (true)); 696 } catch (Exception ex) { 697 String err = "Error while getting parameter from context param."; 698 logger.log(BasicLevel.ERROR, err + ex.getMessage()); 699 throw new ResourceServiceException(err, ex); 700 } 701 return rCtx; 702 } 703 704 705 706 714 private String registerRarMBean(ConfigPropertyDesc [] cfgRaJonas, String specVersion, String jndiName) throws Exception { 715 716 if (mbeanServer != null) { 720 721 String raName = null; Properties p = buildProp(cfgRaJonas); 726 727 String jmxRaName = (new File (rarFileName)).toURL().getFile().replace(':', '|'); 729 mbeanServer.registerMBean(new JmxResourceAdapter(p, jndiName, rarFileName, isInEar, earUrl), 730 JonasObjectName.resourceAdapter(jmxRaName)); 731 732 String appName = null; 735 if (isInEar) { 736 appName = EarServiceImpl.buildJ2eeApplicationName(earUrl); 737 } 738 739 String resourceAdapaterModuleName = buildModuleName(jmxRaName, appName); 741 742 ObjectName onResourceAdapterModule = 743 J2eeObjectName.getResourceAdapterModule(jDomain, 744 jServer, 745 appName, 746 resourceAdapaterModuleName); 747 748 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 749 manageLogger.log(BasicLevel.DEBUG, "ObjectName created for ResourceAdapterModule: " + onResourceAdapterModule.toString()); 750 } 751 752 ResourceAdapterModule raModuleMBean = new ResourceAdapterModule(onResourceAdapterModule.toString(), 753 isInEar, earUrl); 754 raModuleMBean.setFileName(jmxRaName); 755 raModuleMBean.setDeploymentDescriptor(xmlContent); 756 raModuleMBean.setJonasDeploymentDescriptor(jonasXmlContent); 757 ManagedBean oManaged = oRegistry.findManagedBean("ResourceAdapterModule"); 758 759 ModelMBean oMBean = oManaged.createMBean(raModuleMBean); 760 761 mbeanServer.registerMBean(oMBean, onResourceAdapterModule); 762 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 763 manageLogger.log(BasicLevel.DEBUG, "ResourceAdapterModule MBean created"); 764 } 765 766 raName = resourceAdapaterModuleName; 769 ObjectName onResourceAdapter = J2eeObjectName.getResourceAdapter(jDomain, 770 resourceAdapaterModuleName, 771 appName, 772 jServer, 773 raName); 774 org.objectweb.jonas.resource.ResourceAdapter raMBean = 775 new org.objectweb.jonas.resource.ResourceAdapter(onResourceAdapter.toString(), 776 p, 777 jndiName, 778 jmxRaName, 779 isInEar, 780 earUrl, 781 specVersion); 782 oManaged = oRegistry.findManagedBean("ResourceAdapter"); 783 oMBean = oManaged.createMBean(raMBean); 784 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 785 manageLogger.log(BasicLevel.DEBUG, "ResourceAdapter ManagedBean created"); 786 } 787 mbeanServer.registerMBean(oMBean, onResourceAdapter); 788 789 raModuleMBean.setResourceAdapter(onResourceAdapter.toString()); 791 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 792 manageLogger.log(BasicLevel.DEBUG, "ResourceAdapterModule ManagedBean updated"); 793 } 794 795 JCAResourceName = raName; ObjectName onJCAResource = 799 J2eeObjectName.getJCAResource(jDomain, 800 jServer, 801 raName, 802 JCAResourceName); 803 jcaResourceMBean = new JCAResource(onJCAResource.toString()); 804 oManaged = oRegistry.findManagedBean("JCAResource"); 805 oMBean = oManaged.createMBean(jcaResourceMBean); 806 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 807 manageLogger.log(BasicLevel.DEBUG, "JCAResource J2EEResource created"); 808 } 809 mbeanServer.registerMBean(oMBean, onJCAResource); 810 811 raMBean.setJcaResource(onJCAResource.toString()); 813 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 814 manageLogger.log(BasicLevel.DEBUG, "JCAResource J2EEResource updated"); 815 } 816 817 return onResourceAdapterModule.toString(); 818 } else { 819 String jmxRaName = (new File (rarFileName)).toURL().getFile().replace(':', '|'); 820 return jmxRaName; 821 } 822 } 823 824 825 830 public void unRegister() throws Exception { 831 832 for (int i = 0; i < jndinames.size(); i++) { 833 String jName = (String ) jndinames.get(i); 834 ConfigObj co = (ConfigObj) cfgObjs.get(jName); 835 try { 836 ictx.unbind(jName); 838 } catch (NamingException ex) { 839 if (logger.isLoggable(BasicLevel.DEBUG)) { 840 logger.log(BasicLevel.DEBUG, "ResourceService: cannot unbind jndiname of " 841 + jName + " for ResourceAdapter " 842 + rarFileName, ex); 843 } 844 throw new ServiceException("Cannot unregister", ex); 845 } 846 847 if (co.defaultAS) { 848 removeDefaultAS(jName); 849 } 850 if (co != null) { if (co.cm != null) { 852 ((ConnectionManagerImpl) co.cm).cleanResourceAdapter(); 854 } 855 } 856 857 } 858 cfgObjs.clear(); 859 860 if (mbeanServer != null) { 864 String jmxRaName = (new File (rarFileName)).toURL().getFile().replace(':', '|'); 866 mbeanServer.unregisterMBean(JonasObjectName.resourceAdapter(jmxRaName)); 867 868 String appName = null; 871 if (isInEar) { 872 appName = EarServiceImpl.buildJ2eeApplicationName(earUrl); 873 } 874 String resourceAdapaterModuleName = buildModuleName(jmxRaName, appName); 876 ObjectName onResourceAdapterModule = 877 J2eeObjectName.getResourceAdapterModule(jDomain, 878 jServer, 879 appName, 880 resourceAdapaterModuleName); 881 try { 882 String [] resourceAdapaterNames = (String []) mbeanServer.getAttribute(onResourceAdapterModule, "resourceAdapters"); 883 884 mbeanServer.unregisterMBean(onResourceAdapterModule); 886 887 for (int i = 0; i < resourceAdapaterNames.length; i++) { 889 String resourceAdapaterName = resourceAdapaterNames[i]; 890 ObjectName onResourceAdapater = new ObjectName (resourceAdapaterName); 891 String jcaResourceName = (String ) mbeanServer.getAttribute(onResourceAdapater, "jcaResource"); 893 mbeanServer.unregisterMBean(onResourceAdapater); 895 ObjectName onJCAResource = new ObjectName (jcaResourceName); 896 String [] connectionFactoriesNames = (String []) mbeanServer.getAttribute(onJCAResource, "connectionFactories"); 897 for (int j = 0; j < connectionFactoriesNames.length; j++) { 899 String connectionFactoryName = (String ) connectionFactoriesNames[j]; 900 ObjectName onJCAConnectionFactory = new ObjectName (connectionFactoryName); 901 String managedConnectionFactoryName = (String ) mbeanServer.getAttribute(onJCAConnectionFactory, "managedConnectionFactory"); 902 mbeanServer.unregisterMBean(onJCAConnectionFactory); 903 mbeanServer.unregisterMBean(new ObjectName (managedConnectionFactoryName)); 904 } 905 String [] adminObjectNames = (String []) mbeanServer.getAttribute(onJCAResource, "adminObjects"); 906 for (int j = 0; j < adminObjectNames.length; j++) { 908 String adminObjectName = (String ) adminObjectNames[j]; 909 ObjectName onJCAAdminObject = new ObjectName (adminObjectName); 910 mbeanServer.unregisterMBean(onJCAAdminObject); 911 } 912 String [] activationSpecNames = (String []) mbeanServer.getAttribute(onJCAResource, "activationSpecs"); 913 for (int j = 0; j < activationSpecNames.length; j++) { 915 String activationSpecName = (String ) activationSpecNames[j]; 916 ObjectName onJCAActivationSpec = new ObjectName (activationSpecName); 917 mbeanServer.unregisterMBean(onJCAActivationSpec); 918 } 919 mbeanServer.unregisterMBean(onJCAResource); 920 } 921 } catch (MalformedObjectNameException ma) { 922 logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: ", ma); 923 } catch (MBeanRegistrationException mr) { 924 logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: ", mr); 925 } catch (InstanceNotFoundException infe) { 926 logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: ", infe); 927 } catch (Exception e) { 928 logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: ", e); 929 } 930 } 931 932 if (resAdp != null) { 934 resAdp.stop(); 935 } 936 937 } 938 939 943 949 public Object getConfigObj(String jndiName) { 950 synchronized (cfgObjs) { 951 ConfigObj co = (ConfigObj) cfgObjs.get(jndiName); 952 return co; 953 } 954 } 955 956 961 public ConnectorDesc getConnectorDesc() { 962 return raConn; 963 } 964 965 970 public void setConnectorDesc(ConnectorDesc cd) { 971 raConn = cd; 972 } 973 974 979 public String getXmlContent() { 980 return xmlContent; 981 } 982 983 988 public JonasConnectorDesc getJonasConnectorDesc() { 989 return jonasConn; 990 } 991 992 997 public void setJonasConnectorDesc(JonasConnectorDesc jcd) { 998 jonasConn = jcd; 999 } 1000 1001 public Object getFactory(String jndiname) { 1002 ConfigObj co = (ConfigObj) cfgObjs.get(jndiname); 1003 return (co == null ? null : co.factory ); 1004 } 1005 1006 public String getInterface(String jndiname) { 1007 ConfigObj co = (ConfigObj) cfgObjs.get(jndiname); 1008 return (co == null ? null : co.interfaceStr ); 1009 } 1010 1011 public Vector getJndinames() { 1012 return jndinames; 1013 } 1014 1015 public ResourceAdapter getResourceAdapter() { 1016 return resAdp; 1017 } 1018 1019 public void configureAS(ActivationSpec as, List acp, List jacp, String jndiname, 1020 String ejbName) throws Exception { 1021 ConfigPropertyDesc [] asCp = ru.buildConfigProperty(null, acp, jacp); 1022 1023 if (((ResourceAdapterAssociation ) as).getResourceAdapter() == null) { 1025 ((ResourceAdapterAssociation ) as).setResourceAdapter(resAdp); 1026 } 1027 ru.processSetters(as.getClass(), as, ejbName, asCp); 1028 validateAS(as, jndiname, acp, jacp); 1029 } 1030 1031 1035 private void validateAS(ActivationSpec as, String jndiname, 1036 List acp, List jacp) throws Exception { 1037 boolean found = false; 1038 String reqName = null; 1039 RequiredConfigPropertyDesc rcProp = null; 1040 ActivationConfigPropertyDesc acProp = null; 1041 ConfigObj co = (ConfigObj) cfgObjs.get(jndiname); 1043 for (Iterator r = co.reqConfigProps.iterator(); r.hasNext();) { 1044 rcProp = (RequiredConfigPropertyDesc) r.next(); 1045 found = false; 1046 reqName = rcProp.getConfigPropertyName(); 1047 if (acp != null) { 1048 for (Iterator i = acp.iterator(); i.hasNext();) { 1049 acProp = (ActivationConfigPropertyDesc) i.next(); 1050 if (reqName.equals(acProp.getActivationConfigPropertyName())) { 1051 found = true; 1052 break; 1053 } 1054 } 1055 } 1056 if (!found && jacp != null) { 1057 for (Iterator i = jacp.iterator(); i.hasNext();) { 1058 acProp = (ActivationConfigPropertyDesc) i.next(); 1059 if (reqName.equals(acProp.getActivationConfigPropertyName())) { 1060 found = true; 1061 break; 1062 } 1063 } 1064 } 1065 if (!found) { 1066 logger.log(BasicLevel.ERROR, "Required property " + reqName + " not specified "); 1067 throw new ResourceAllocationException ("Required property " + reqName + " not specified "); 1068 } 1069 } 1070 1071 try { 1073 as.validate(); 1074 } catch (UnsupportedOperationException uoe) { 1075 } catch (Exception ex) { 1077 logger.log(BasicLevel.ERROR, "Error from ActivationSpec.validate(). " + ex); 1078 throw new ResourceAllocationException ("Error from ActivationSpec.validate(). ", ex); 1079 } 1080 1081 } 1082 1083 1084 1088 private void bldSecurityTable(JonasConnectorDesc lnkJCon, JonasConnectorDesc jCon) { 1089 } 1090 1091 1097 public static String buildModuleName(String rarFileName, String appName) { 1098 String sName = null; 1099 try { 1100 sName = new File (rarFileName).getName(); 1101 int iPos = sName.lastIndexOf('.'); 1102 if (iPos > -1) { 1103 sName = sName.substring(0, iPos); 1104 } 1105 } catch (NullPointerException e) { 1106 } 1108 if (appName != null) { 1109 StringBuffer sbName = new StringBuffer (appName); 1110 sbName.append("."); 1111 sbName.append(sName); 1112 sName = sbName.toString(); 1113 } 1114 1115 return sName; 1116 } 1117 1118 1121 1122 1134 public Object createFactory(String jndiName, String rarObjectName, int factoryOffset, 1135 String factoryType, ConnectorDesc conn, JonasConnectorDesc jConn) 1136 throws Exception { 1137 1138 ResourceUtility ru = new ResourceUtility(null, null, logger, setterLogger, manageLogger); 1139 Object factory = null; 1140 ManagedConnectionFactory mcf = null; 1141 ResourceadapterDesc ra = conn.getResourceadapterDesc(); 1142 1146 boolean basicPass = true; 1147 1150 ResourceAdapter resAdp = null; 1151 1152 String logEnabled = null; 1153 if (jConn.getLogEnabled() != null) { 1154 logEnabled = jConn.getLogEnabled().trim(); 1155 } 1156 String logTopic = null; 1157 if (jConn.getLogTopic() != null) { 1158 logTopic = jConn.getLogTopic().trim(); 1159 } 1160 String specVersion = conn.getSpecVersion(); 1161 1162 ConnectionManager cm = null; 1163 String jBase = null; 1164 try { 1165 jBase = System.getProperty("jonas.base"); 1166 if (jBase != null) { 1167 try { 1169 ServiceManager sm = ServiceManager.getInstance(); 1170 TransactionService ts = (TransactionService) sm.getTransactionService(); 1171 tm = ts.getTransactionManager(); 1172 } catch (Exception e) { 1173 logger.log(BasicLevel.ERROR, "Cannot get the Transaction service: " + e); 1174 throw new Exception ("Cannot get the Transaction service: ", e); 1175 } 1176 1177 cm = ru.createConnectionManager(ra.getTransactionSupport(), tm, 1178 logger, poolLogger); 1179 } 1180 } catch (Exception ex) { 1181 logger.log(BasicLevel.ERROR, "Use default ConnectionManager: " + rarObjectName); 1182 } 1183 1184 ConfigPropertyDesc [] cfgRaJonas = 1186 ru.buildConfigProperty(ra.getConfigPropertyList(), 1187 jConn.getJonasConfigPropertyList(), 1188 null); 1189 ConnectionManagerPoolParams cmpp = ru.configurePoolParams(jConn.getPoolParamsDesc(), 1190 jConn.getJdbcConnParamsDesc(), 1191 null); 1192 Properties tmProp = new Properties (); 1193 if (jConn.getTmParamsDesc() != null) { 1194 List tmParams = jConn.getTmParamsDesc().getTmConfigPropertyList(); 1195 if (tmParams != null) { 1196 for (Iterator i = tmParams.iterator(); i.hasNext();) { 1197 TmConfigPropertyDesc tpd = (TmConfigPropertyDesc) i.next(); 1198 String tpdVal = tpd.getTmConfigPropertyValue(); 1199 if (tpdVal == null) { 1200 tpdVal = ""; 1201 } 1202 tmProp.setProperty(tpd.getTmConfigPropertyName(), tpdVal); 1203 } 1204 if (logger.isLoggable(BasicLevel.DEBUG)) { 1205 logger.log(BasicLevel.DEBUG, "TM Properties: " + tmProp); 1206 } 1207 } 1208 } 1209 1210 if (specVersion.equals("1.0")) { 1211 mcf = (ManagedConnectionFactory ) ru.processMCF(conn, jConn, cm, curLoader, rarObjectName, 1213 ra.getManagedconnectionfactoryClass(), 1214 jndiName, logEnabled, logTopic, 1215 cfgRaJonas, resAdp, 0); 1216 if (cm != null) { 1217 ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, cmpp); 1218 factory = mcf.createConnectionFactory(cm); 1219 } else { 1220 factory = mcf.createConnectionFactory(); 1221 } 1222 1223 } else if (specVersion.equals("1.5")) { 1224 boolean callStart = false; 1226 1227 String raStr = conn.getResourceadapterDesc().getResourceadapterClass().trim(); 1228 if (raStr != null && raStr.length() > 0) { 1229 1230 Class raClass = curLoader.loadClass(raStr); 1232 resAdp = (ResourceAdapter) raClass.newInstance(); 1233 1234 ru.processSetters(raClass, resAdp, rarObjectName, cfgRaJonas); 1235 1236 try { 1238 if (callStart) { 1239 resAdp.start(bootCtx); 1240 } 1241 } catch (Exception ex) { 1242 logger.log(BasicLevel.ERROR, "Rar: Error from resource (" + rarObjectName 1243 + ") start method."); 1244 throw new Exception ("Error from start method. " + ex); 1245 } catch (Throwable th) { 1246 logger.log(BasicLevel.ERROR, "Rar: Error from resource (" + rarObjectName 1247 + ") start method."); 1248 throw new Exception ("Error from start method. ", th); 1249 } 1250 } 1251 1252 if (factoryType.equals(ru.JCD)) { 1254 OutboundResourceadapterDesc outRa = ra.getOutboundResourceadapterDesc(); 1255 List cdList = null; 1256 if (outRa != null) { 1257 cdList = outRa.getConnectionDefinitionList(); 1258 } 1259 ConnectionDefinitionDesc conDef = null; 1260 JonasConnectionDefinitionDesc jConDef = null; 1261 String id = null; 1262 if (cdList != null) { 1263 conDef = (ConnectionDefinitionDesc) cdList.get(factoryOffset); 1264 id = conDef.getId(); 1265 jConDef = (JonasConnectionDefinitionDesc) 1266 ru.getJonasXML(jConn, id, factoryOffset, ru.JCD); 1267 1268 if (jConDef.getLogEnabled() != null) { 1269 logEnabled = jConDef.getLogEnabled().trim(); 1270 } 1271 if (jConDef.getLogTopic() != null) { 1272 logTopic = jConDef.getLogTopic().trim(); 1273 } 1274 1275 ConfigPropertyDesc [] cfgCdDesc = 1277 ru.buildConfigProperty(conDef.getConfigPropertyList(), 1278 jConDef.getJonasConfigPropertyList(), 1279 null); 1280 1281 mcf = (ManagedConnectionFactory ) ru.processMCF(conn, jConn, cm, curLoader, rarObjectName, 1283 conDef.getManagedconnectionfactoryClass(), 1284 jndiName, logEnabled, logTopic, 1285 cfgCdDesc, resAdp, factoryOffset); 1286 if (cm != null) { 1287 ConnectionManagerPoolParams pool = 1288 ru.configurePoolParams(jConDef.getPoolParamsDesc(), 1289 jConDef.getJdbcConnParamsDesc(), 1290 cmpp); 1291 ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, pool); 1292 factory = mcf.createConnectionFactory(cm); 1293 } else { 1294 factory = mcf.createConnectionFactory(); 1295 } 1296 1297 } 1298 } else if (factoryType.equals(ru.JAO)) { 1299 if (logger.isLoggable(BasicLevel.DEBUG)) { 1300 logger.log(BasicLevel.DEBUG, "Cannot lookup remote admin object of " + jndiName); 1301 } 1302 return null; 1303 } else if (factoryType.equals(ru.JAS)) { 1304 if (logger.isLoggable(BasicLevel.DEBUG)) { 1305 logger.log(BasicLevel.DEBUG, "Cannot lookup remote activationspec of " + jndiName); 1306 } 1307 return null; 1308 } 1309 } 1310 1311 if (logger.isLoggable(BasicLevel.DEBUG)) { 1312 logger.log(BasicLevel.DEBUG, "cf = " + factory); 1313 } 1314 if (factoryType.equals(ru.JCD) && cm != null) { 1316 ((ConnectionManagerImpl) cm).setXAName(ru.getJcaMcfName(jndiName)); 1318 ((ConnectionManagerImpl) cm).registerXAResource(tmProp); 1319 } 1320 return factory; 1321 } 1322 1323 1328 public static void addDefaultAS(String jndiName) { 1329 defaultAS.add(jndiName); 1330 } 1331 1332 1336 public static String getDefaultAS() { 1337 String ret = null; 1338 try { 1339 ret = (String ) defaultAS.firstElement(); 1340 } catch (Exception ex) { 1341 if (logger.isLoggable(BasicLevel.DEBUG)) { 1342 logger.log(BasicLevel.DEBUG, "No default activationspec"); 1343 } 1344 } 1345 return ret; 1346 } 1347 1348 1352 public static void removeDefaultAS(String jndiName) { 1353 try { 1354 defaultAS.remove(jndiName); 1355 } catch (Exception ex) { 1356 if (logger.isLoggable(BasicLevel.DEBUG)) { 1357 logger.log(BasicLevel.DEBUG, "Unable to remove default activationspec"); 1358 } 1359 } 1360 } 1361 1362 1367 public static ConnectorDesc getConnectorDesc(String jndiName) { 1368 synchronized (jndiName2RA) { 1369 Rar rar = (Rar) jndiName2RA.get(jndiName); 1370 if (rar != null) { 1371 return (rar.getConnectorDesc()); 1372 } 1373 if (logger.isLoggable(BasicLevel.DEBUG)) { 1374 logger.log(BasicLevel.DEBUG, "Can't find " + jndiName + " in " + jndiName2RA); 1375 } 1376 return null; 1377 } 1378 } 1379 1380 1385 public static JonasConnectorDesc getJonasConnectorDesc(String jndiName) { 1386 synchronized (jndiName2RA) { 1387 Rar rar = (Rar) jndiName2RA.get(jndiName); 1388 if (rar != null) { 1389 return (rar.getJonasConnectorDesc()); 1390 } 1391 return null; 1392 } 1393 } 1394 1395 1401 public static Rar getRar(String jndiName) { 1402 synchronized (jndiName2RA) { 1403 Rar ra = (Rar) jndiName2RA.get(jndiName); 1404 return (ra); 1405 } 1406 } 1407 1408 1414 public static Object getResourceObject(String jndiName) { 1415 Rar ra = null; 1416 synchronized (jndiName2RA) { 1417 ra = (Rar) jndiName2RA.get(jndiName); 1418 } 1419 if (ra != null) { 1420 return (ra.getFactory(jndiName)); 1421 } 1422 Object fact = null; 1423 synchronized (jndiName2Factory) { 1424 fact = jndiName2Factory.get(jndiName); 1425 } 1426 return fact; 1427 } 1428 1429 1432 1433 1436 private Properties buildProp(ConfigPropertyDesc [] cfgRaJonas) { 1437 Properties ret = new Properties (); 1438 if (cfgRaJonas != null) { 1439 for (int i = 0; i < cfgRaJonas.length; i++) { 1440 String val = cfgRaJonas[i].getConfigPropertyValue() != null ? 1441 cfgRaJonas[i].getConfigPropertyValue() : ""; 1442 ret.setProperty(cfgRaJonas[i].getConfigPropertyName(), val); 1443 } 1444 } 1445 return ret; 1446 } 1447 1448 1456 private void extractJars(String resFileName, JonasConnectorDesc jonasConn) 1457 throws ResourceServiceException { 1458 1459 String jarPath = ResourceServiceImpl.WORK_RARS_DIR + File.separator + "jonas" + File.separator; 1460 String binPath = null; 1461 if (jonasConn.getNativeLib() != null && jonasConn.getNativeLib().trim().length() > 0) { 1462 binPath = jonasConn.getNativeLib().trim() + File.separator; 1463 if (binPath.startsWith("/") || binPath.startsWith("\\") 1464 || binPath.charAt(1) == ':') { 1465 ; 1466 } else { 1467 binPath = ResourceServiceImpl.JONAS_BASE + File.separator + binPath; 1468 } 1469 1470 } 1471 1472 String rarName = resFileName; 1474 if (rarName.endsWith(".rar")) { 1475 rarName = resFileName.substring(0, resFileName.lastIndexOf('.')); 1476 } 1477 1478 int off = rarName.lastIndexOf(File.separator); 1479 rarName = rarName.substring(++off); 1480 if (File.separatorChar == '\\') { 1481 off = rarName.lastIndexOf("/"); 1482 rarName = rarName.substring(++off); 1483 } 1484 1485 JJarFile jjar = null; 1486 1487 try { 1488 jjar = new JJarFile(resFileName); 1489 for (Enumeration ent = jjar.entries(); ent.hasMoreElements();) { 1490 JarEntry je = (JarEntry ) ent.nextElement(); 1491 if (!je.isDirectory() && je.getName().endsWith(".jar")) { 1492 File newd = new File (jarPath); 1493 if (!newd.exists()) { 1494 newd.mkdirs(); 1495 } 1496 1497 String fileName = jarPath + "_" + rarName + "_" + je.getName(); 1498 jjar.extract(je, fileName); 1499 ((org.objectweb.jonas.server.JClassLoader) curLoader).addURL((new File (fileName)).toURL()); 1500 } else if (!je.isDirectory() && !je.getName().startsWith("META-INF") 1501 && binPath != null) { 1502 File newf = new File (binPath); 1503 if (!newf.exists()) { 1504 newf.mkdirs(); 1505 } 1506 String fileName = binPath + je.getName(); 1507 jjar.extract(je, fileName); 1508 } 1509 } 1510 } catch (Exception ex) { 1511 String err = "Error while extracting the files from " + resFileName; 1512 logger.log(BasicLevel.ERROR, err + ex.getMessage()); 1513 throw new ResourceServiceException(err, ex); 1514 } 1515 1516 } 1517 1518 1524 private Object getConfigObject(String jndiName) { 1525 Rar ra = null; 1526 synchronized (jndiName2RA) { 1527 ra = (Rar) jndiName2RA.get(jndiName); 1528 } 1529 if (ra != null) { 1530 return (ra.getConfigObj(jndiName)); 1531 } 1532 return null; 1533 } 1534 1535 1541 private String getXmlContent(String jndiName) { 1542 synchronized (jndiName2RA) { 1543 Rar rar = (Rar) jndiName2RA.get(jndiName); 1544 if (rar != null) { 1545 return (rar.getXmlContent()); 1546 } 1547 return null; 1548 } 1549 } 1550 1551 private void processJAO(String rarFilename, AdminobjectDesc aObj, JonasAdminobjectDesc jao, 1552 ConfigPropertyDesc [] cfgRaJonas, int idOff) throws Exception { 1553 1554 ConfigObj cObj = null; 1555 String jndiName = jao.getJndiName(); 1556 String aoDesc = ""; 1557 for (Iterator r = jao.getDescriptionList().iterator(); r.hasNext();) { 1558 String desc = (String ) r.next(); 1559 aoDesc += desc + " "; 1560 } 1561 if (jndiName == null || jndiName.length() == 0) { 1562 logger.log(BasicLevel.ERROR, 1563 "Rar: jndi-name not set in jonas-ra.xml for Adminobject: " + idOff); 1564 throw new Exception ("configuration file incorrect"); 1565 } 1566 1567 String admObj = aObj.getAdminobjectClass(); 1569 Class aoClass = curLoader.loadClass(admObj); 1570 Object ao = aoClass.newInstance(); 1571 1572 ru.processSetters(aoClass, ao, rarFileName, cfgRaJonas); 1573 1574 jndinames.add(jndiName); 1575 if (logger.isLoggable(BasicLevel.DEBUG)) { 1576 logger.log(BasicLevel.DEBUG, "jndiName=" + jndiName); 1577 } 1578 1579 cObj = new ConfigObj(JAO, idOff, jndiName, rarFileName, aObj.getAdminobjectInterface(), admObj, ao); 1581 1582 cfgObjs.put(jndiName, cObj); 1583 try { 1586 ictx.rebind(jndiName, ao); 1587 1588 } catch (Exception e) { 1589 logger.log(BasicLevel.ERROR, "Rar: Cannot register ResourceAdapter with the name " 1590 + jndiName); 1591 logger.log(BasicLevel.ERROR, "Rar: Exception caught : " + e); 1592 throw new Exception ("Error binding jndiName: " + jndiName, e.getCause()); 1593 } 1594 1595 if (mbeanServer != null) { 1599 1600 String jcaAdminobjectName = jndiName; 1605 Properties p = buildProp(cfgRaJonas); 1606 ObjectName onJCAAdminobject = 1607 J2eeObjectName.getJCAAdminObject(jDomain, 1608 JCAResourceName, 1609 jServer, 1610 jcaAdminobjectName); 1611 JCAAdminObject jcaAdminobjectMBean = new JCAAdminObject(onJCAAdminobject.toString(), jndiName, aoDesc, p); 1612 ManagedBean oManaged = oRegistry.findManagedBean("JCAAdminObject"); 1613 ModelMBean oMBean = oManaged.createMBean(jcaAdminobjectMBean); 1614 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 1615 manageLogger.log(BasicLevel.DEBUG, "JCAAdminObject created"); 1616 } 1617 mbeanServer.registerMBean(oMBean, onJCAAdminobject); 1618 1619 jcaResourceMBean.setAdminObjects(onJCAAdminobject.toString()); 1622 1623 } 1625 } 1626 1627 private void processJAS(String rarFilename, MessagelistenerDesc mlst, JonasActivationspecDesc jas, 1628 int idOff) throws Exception { 1629 1630 ConfigObj cObj = null; 1631 String jndiName = jas.getJndiName(); 1632 String asDesc = ""; 1633 for (Iterator r = jas.getDescriptionList().iterator(); r.hasNext();) { 1634 String desc = (String ) r.next(); 1635 asDesc += desc + " "; 1636 } 1637 if (jndiName == null || jndiName.length() == 0) { 1638 logger.log(BasicLevel.ERROR, 1639 "Rar: jndi-name not set in jonas-ra.xml for Activationspec: " + idOff); 1640 throw new Exception ("configuration file incorrect"); 1641 } 1642 1643 String mlIntf = mlst.getMessagelistenerType(); 1645 String actSpec = mlst.getActivationspecDesc().getActivationspecClass(); 1646 Class asClass = curLoader.loadClass(actSpec); 1647 ActivationSpec as = 1648 (ActivationSpec ) asClass.newInstance(); 1649 1650 jndinames.add(jndiName); 1651 if (logger.isLoggable(BasicLevel.DEBUG)) { 1652 logger.log(BasicLevel.DEBUG, "jndiName=" + jndiName); 1653 } 1654 1655 cObj = new ConfigObj(JAS, idOff, jndiName, rarFilename, mlIntf, actSpec, as); 1657 cObj.reqConfigProps = mlst.getActivationspecDesc().getRequiredConfigPropertyList(); 1658 if (jas.getDefaultAS() != null && jas.getDefaultAS().equals("true")) { 1659 cObj.defaultAS = true; 1660 addDefaultAS(jndiName); 1661 } 1662 1663 cfgObjs.put(jndiName, cObj); 1664 try { 1667 ictx.rebind(jndiName, as); 1668 1669 } catch (Exception e) { 1670 logger.log(BasicLevel.ERROR, "Rar.processJAS: Cannot register ResourceAdapter with the name " + jndiName); 1671 logger.log(BasicLevel.ERROR, "Rar.processJAS: Exception caught : " + e); 1672 throw new Exception ("Error binding jndiName: " + jndiName, e.getCause()); 1673 } 1674 1675 if (mbeanServer != null) { 1679 1680 String jcaActivationSpecName = jndiName; 1685 ObjectName onJCAActivationSpec = 1686 J2eeObjectName.getJCAActivationSpec(jDomain, 1687 JCAResourceName, 1688 jServer, 1689 jcaActivationSpecName); 1690 JCAActivationSpec jcaActivationSpecMBean = new JCAActivationSpec(onJCAActivationSpec.toString(), jndiName, asDesc, cObj.reqConfigProps); 1691 ManagedBean oManaged = oRegistry.findManagedBean("JCAActivationSpec"); 1692 ModelMBean oMBean = oManaged.createMBean(jcaActivationSpecMBean); 1693 if (manageLogger.isLoggable(BasicLevel.DEBUG)) { 1694 manageLogger.log(BasicLevel.DEBUG, "JCAActivationSpec created"); 1695 } 1696 mbeanServer.registerMBean(oMBean, onJCAActivationSpec); 1697 1698 jcaResourceMBean.setActivationSpecs(onJCAActivationSpec.toString()); 1701 1702 } 1704 } 1705 1706} 1707 1708 1709 | Popular Tags |