1 25 26 package org.objectweb.jonas.container; 27 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.net.MalformedURLException ; 31 import java.net.URL ; 32 import java.net.URLClassLoader ; 33 import java.util.ArrayList ; 34 import java.util.Enumeration ; 35 import java.util.HashMap ; 36 import java.util.HashSet ; 37 import java.util.Iterator ; 38 import java.util.List ; 39 import java.util.Map ; 40 import java.util.Properties ; 41 import java.util.Set ; 42 import java.util.StringTokenizer ; 43 import java.util.Vector ; 44 import java.util.jar.Attributes ; 45 import java.util.jar.JarFile ; 46 import java.util.jar.Manifest ; 47 48 import javax.management.MBeanException ; 49 import javax.management.MBeanServer ; 50 import javax.management.ObjectName ; 51 import javax.management.OperationsException ; 52 import javax.management.modelmbean.ModelMBean ; 53 import javax.naming.Context ; 54 import javax.naming.InitialContext ; 55 import javax.naming.NamingException ; 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.carol.util.configuration.ConfigurationRepository; 63 import org.objectweb.carol.util.configuration.ProtocolConfiguration; 64 65 import org.objectweb.jonas_ejb.container.BeanFactory; 66 import org.objectweb.jonas_ejb.container.Container; 67 import org.objectweb.jonas_ejb.container.JContainer; 68 import org.objectweb.jonas_ejb.container.JEntityFactory; 69 import org.objectweb.jonas_ejb.container.JMdbEndpointFactory; 70 import org.objectweb.jonas_ejb.container.JMdbFactory; 71 import org.objectweb.jonas_ejb.container.JSessionFactory; 72 import org.objectweb.jonas_ejb.container.JStatelessFactory; 73 import org.objectweb.jonas_ejb.container.PermissionManager; 74 import org.objectweb.jonas_ejb.deployment.api.BeanDesc; 75 import org.objectweb.jonas_ejb.deployment.api.DeploymentDesc; 76 import org.objectweb.jonas_ejb.deployment.api.EntityBmpDesc; 77 import org.objectweb.jonas_ejb.deployment.api.EntityCmpDesc; 78 import org.objectweb.jonas_ejb.deployment.api.SessionStatefulDesc; 79 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc; 80 import org.objectweb.jonas_ejb.deployment.lib.wrapper.EjbManagerWrapper; 81 82 import org.objectweb.jonas_lib.JWorkManager; 83 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 84 import org.objectweb.jonas_lib.deployment.work.CleanerException; 85 import org.objectweb.jonas_lib.deployment.work.DeployerLog; 86 import org.objectweb.jonas_lib.deployment.work.DeployerLogException; 87 import org.objectweb.jonas_lib.deployment.work.FileManager; 88 import org.objectweb.jonas_lib.deployment.work.JarCleanTask; 89 import org.objectweb.jonas_lib.deployment.work.WorkCleaner; 90 import org.objectweb.jonas_lib.files.FileUtils; 91 import org.objectweb.jonas_lib.loader.EjbJarClassLoader; 92 import org.objectweb.jonas_lib.version.Version; 93 94 import org.objectweb.jonas_jms.api.JmsManager; 95 96 import org.objectweb.jonas.common.JModule; 97 import org.objectweb.jonas.common.JProp; 98 import org.objectweb.jonas.common.Log; 99 import org.objectweb.jonas.ear.EarServiceImpl; 100 import org.objectweb.jonas.jms.JmsService; 101 import org.objectweb.jonas.jmx.J2eeObjectName; 102 import org.objectweb.jonas.jmx.JmxService; 103 import org.objectweb.jonas.jmx.JonasObjectName; 104 import org.objectweb.jonas.jtm.TransactionService; 105 import org.objectweb.jonas.management.JonasMBeanTools; 106 import org.objectweb.jonas.naming.CompNamingContext; 107 import org.objectweb.jonas.naming.NamingManager; 108 import org.objectweb.jonas.security.SecurityService; 109 import org.objectweb.jonas.server.LoaderManager; 110 import org.objectweb.jonas.server.WorkManagerMBean; 111 import org.objectweb.jonas.service.AbsServiceImpl; 112 import org.objectweb.jonas.service.ServiceException; 113 import org.objectweb.jonas.service.ServiceManager; 114 115 import org.objectweb.util.monolog.api.BasicLevel; 116 import org.objectweb.util.monolog.api.Logger; 117 118 131 public class EJBServiceImpl extends AbsServiceImpl implements EJBService, EJBServiceImplMBean { 132 133 134 private static Logger servlog = null; 135 136 137 private static Logger loaderlog = null; 138 139 143 private TransactionManager tm = null; 144 145 146 private JmsManager jms = null; 147 148 149 private MBeanServer mbeanServer = null; 150 151 152 private SecurityService securityService = null; 153 154 157 private static WorkCleaner workCleaner = null; 158 159 private Registry oRegistry = null; 160 161 164 private Vector ejbNames = new Vector (); 165 166 167 private Vector containers = new Vector (); 168 169 170 public static final String MINWORKTHREADS = "jonas.service.ejb.minworkthreads"; 171 private static final int DEFAULT_MINWORKTHREADS = 3; 172 public static final String MAXWORKTHREADS = "jonas.service.ejb.maxworkthreads "; 173 private static final int DEFAULT_MAXWORKTHREADS = 80; 174 public static final String THREADWAITTIMEOUT = "jonas.service.ejb.threadwaittimeout"; 175 private static final int DEFAULT_THREADWAITTIMEOUT = 60; 176 private JWorkManager workManager; 177 178 181 protected static final String JONAS_BASE = JProp.getJonasBase(); 182 183 186 protected static final String EJBJARS_DIR = JONAS_BASE + File.separator + "ejbjars"; 187 188 191 private ArrayList autoloadDirectories = new ArrayList (); 192 193 194 public static final String JONAS_EJB = "jonas.service.ejb"; 195 196 197 public static final String AUTOLOADDIR = JONAS_EJB + ".autoloaddir"; 198 199 200 public static final String PARSINGWITHVALIDATION = JONAS_EJB + ".parsingwithvalidation"; 201 202 203 public static final String DESCRIPTORS = JONAS_EJB + ".descriptors"; 204 205 206 public static final String CLASS = JONAS_EJB + ".class"; 207 208 209 public static final String BMP = "Bean-Managed"; 210 211 212 public static final String CMP = "Container-Managed"; 213 214 215 private ClassLoader appsClassLoader = null; 216 217 220 private static final String WORK_DIR = JProp.getWorkDir(); 221 222 225 private static final String WORK_EJBJARS_DIR = WORK_DIR + File.separator + "ejbjars"; 226 227 230 private static String ejbjarsDir = null; 231 232 236 private DeployerLog jarDeployerLog = null; 237 238 242 246 public void doInit(Context ctx) throws ServiceException { 247 servlog = Log.getLogger(Log.JONAS_SERVER_PREFIX); 248 loaderlog = Log.getLogger(Log.JONAS_LOADER_PREFIX); 249 250 if (servlog.isLoggable(BasicLevel.DEBUG)) { 251 servlog.log(BasicLevel.DEBUG, ""); 252 } 253 254 try { 256 LoaderManager lm = LoaderManager.getInstance(); 257 appsClassLoader = lm.getAppsLoader(); 258 } catch (Exception e) { 259 servlog.log(BasicLevel.ERROR, "Cannot get the Applications ClassLoader from EJB Container Service"); 260 throw new ServiceException("Cannot get the Applications ClassLoader from EJB Container Service", e); 261 } 262 263 ServiceManager serviceManager = null; 264 try { 265 serviceManager = ServiceManager.getInstance(); 266 } catch (Exception e) { 267 servlog.log(BasicLevel.ERROR, "Cannot initialize the EJB Container Service"); 268 throw new ServiceException("Cannot initialize the EJB Container Service", e); 269 } 270 try { 272 TransactionService jtmService = (TransactionService) serviceManager.getTransactionService(); 274 tm = jtmService.getTransactionManager(); 275 } catch (ServiceException e) { 276 servlog.log(BasicLevel.ERROR, "Cannot initialize the EJB Container Service"); 277 throw new ServiceException("Cannot initialize the EJB Container Service", e); 278 } 279 280 try { 281 securityService = (SecurityService) serviceManager.getSecurityService(); 283 } catch (ServiceException se) { 284 securityService = null; 286 } 287 288 try { 289 JmsService jmsService = (JmsService) serviceManager.getJmsService(); 291 jms = jmsService.getJmsManager(); 292 } catch (ServiceException e) { 293 jms = null; 295 } 296 297 try { 298 JmxService jmxService = (JmxService) serviceManager.getJmxService(); 300 mbeanServer = jmxService.getJmxServer(); 301 } catch (ServiceException e) { 302 mbeanServer = null; 304 } 305 oRegistry = JonasMBeanTools.getRegistry(); 306 307 String parsingMode; 309 try { 310 parsingMode = (String ) ctx.lookup(PARSINGWITHVALIDATION); 311 } catch (NamingException e) { 312 parsingMode = "false"; 315 } 316 if ("false".equalsIgnoreCase(parsingMode)) { 317 EjbManagerWrapper.setParsingWithValidation(false); 318 if (servlog.isLoggable(BasicLevel.DEBUG)) { 319 servlog.log(BasicLevel.DEBUG, "XML parsing without validation"); 320 } 321 } else { 322 if (servlog.isLoggable(BasicLevel.DEBUG)) { 323 servlog.log(BasicLevel.DEBUG, "XML parsing with validation"); 324 } 325 } 326 327 String descsValue; 329 try { 330 descsValue = (String ) ctx.lookup(DESCRIPTORS); 331 } catch (NamingException e) { 332 descsValue = null; 335 } 336 if (descsValue != null) { 337 StringTokenizer st = new StringTokenizer (descsValue, ","); 338 while (st.hasMoreTokens()) { 339 String fileName = st.nextToken().trim(); 340 ejbNames.add(fileName); 341 } 342 } 343 344 String dirValue; 346 ArrayList autoDirs = new ArrayList (); 347 try { 348 dirValue = (String ) ctx.lookup(AUTOLOADDIR); 349 } catch (NamingException e) { 350 dirValue = null; 353 } 354 if (dirValue != null) { 355 StringTokenizer st = new StringTokenizer (dirValue, ","); 356 while (st.hasMoreTokens()) { 357 String dirName = st.nextToken().trim(); 358 addEjbjars(dirName); 359 autoDirs.add(dirName); 360 } 361 } 362 File oFile; 364 for (int i = 0; i < autoDirs.size(); i++) { 365 try { 366 oFile = new File (EJBJARS_DIR, autoDirs.get(i).toString()); 367 if (oFile.exists()) { 368 autoloadDirectories.add(oFile.getCanonicalPath()); 369 } else { 370 oFile = new File (autoDirs.get(i).toString()); 371 } 372 } catch (Exception e) { 373 String err = "Error when trying to verify Ejbjar autoload directory : " + autoDirs.get(i); 374 servlog.log(BasicLevel.ERROR, err, e); 375 } 376 } 377 378 int minworkthreads = DEFAULT_MINWORKTHREADS; 380 try { 381 String plz = (String ) ctx.lookup(MINWORKTHREADS); 382 minworkthreads = (new Integer (plz)).intValue(); 383 } catch (NamingException e) { 384 } 386 int maxworkthreads = DEFAULT_MAXWORKTHREADS; 387 try { 388 String mxplz = (String ) ctx.lookup(MAXWORKTHREADS); 389 maxworkthreads = (new Integer (mxplz)).intValue(); 390 } catch (NamingException e) { 391 } 393 int threadwaittimeout = DEFAULT_THREADWAITTIMEOUT; 394 try { 395 String tto = (String ) ctx.lookup(THREADWAITTIMEOUT); 396 threadwaittimeout = (new Integer (tto)).intValue(); 397 } catch (NamingException e) { 398 } 400 workManager = new JWorkManager(minworkthreads, maxworkthreads, tm, threadwaittimeout); 401 402 ObjectName mbn; 404 try { 405 mbn = JonasObjectName.workManager(); 406 ManagedBean oManaged = oRegistry.findManagedBean("WorkManager"); 407 ModelMBean oMBean = oManaged.createMBean(new WorkManagerMBean(workManager)); 408 mbeanServer.registerMBean(oMBean, mbn); 409 } catch (Exception e) { 410 servlog.log(BasicLevel.ERROR, "Cannot create MBean", e); 411 } 412 413 if (servlog.isLoggable(BasicLevel.DEBUG)) { 414 servlog.log(BasicLevel.DEBUG, "EJB Container Service initialized"); 415 } 416 } 417 418 public JWorkManager getWorkManager() { 419 return workManager; 420 } 421 422 425 public void doStart() throws ServiceException { 426 427 ejbjarsDir = WORK_EJBJARS_DIR + File.separator + getJonasServerName(); 428 429 URL ejbjarsUrl = null; 430 try { 431 ejbjarsUrl = new File (ejbjarsDir).toURL(); 432 } catch (MalformedURLException mue) { 433 throw new ServiceException("Error when trying to get the URL of the jonasroot/apps directory", mue); 434 } 435 436 File fLog = new File (ejbjarsUrl.getFile() + File.separator + getJonasServerName() + ".log"); 437 if (!fLog.exists()) { 438 try { 439 fLog.getParentFile().mkdirs(); 441 fLog.createNewFile(); 442 } catch (IOException e) { 443 throw new ServiceException("cannot create the log file" + fLog, e); 444 } 445 } 446 447 try { 449 jarDeployerLog = new DeployerLog(fLog); 450 } catch (DeployerLogException e) { 451 throw new ServiceException("Can not get an EarDeployerLog", e); 452 } 453 454 JarCleanTask jarCleanTask = new JarCleanTask(jarDeployerLog); 456 457 workCleaner = WorkCleaner.getInstance(); 459 460 try { 462 workCleaner.registerTask(jarCleanTask); 463 } catch (CleanerException ce) { 464 throw new ServiceException("Cannot register the JAR clean task", ce); 465 466 } 467 468 workCleaner.executeTasks(); 470 471 String fileName = null; 474 Context contctx = null; 475 for (int i = 0; i < ejbNames.size(); i++) { 476 fileName = (String ) ejbNames.elementAt(i); 477 try { 478 contctx = new CompNamingContext(fileName); 479 contctx.rebind("filename", fileName); 480 } catch (NamingException ne) { 481 servlog.log(BasicLevel.WARN, "Cannot create container for " + fileName 482 + " because of a NamingException : " + ne.toString()); 483 } 484 485 try { 486 createContainer(contctx); 487 } catch (Exception e) { 488 servlog.log(BasicLevel.WARN, "Cannot create container for " + fileName, e); 489 try { 491 contctx.close(); 492 } catch (NamingException nne) { 493 if (servlog.isLoggable(BasicLevel.DEBUG)) { 494 servlog.log(BasicLevel.DEBUG, "Cannot close deploy context for " + fileName, nne); 495 } 496 } 497 } 498 } 499 500 if (mbeanServer != null) { 502 try { 503 mbeanServer.registerMBean(this, JonasObjectName.ejbService()); 504 } catch (MBeanException mbe) { 505 servlog.log(BasicLevel.WARN, "Cannot register the EJB Container Service in the MBean Server."); 507 servlog.log(BasicLevel.WARN, "Regstration failure cause : " + mbe.getTargetException().toString()); 508 } catch (OperationsException me) { 509 servlog.log(BasicLevel.WARN, "Cannot register the EJB Container Service in the MBean Server.", me); 512 } 513 } 514 } 515 516 520 public void doStop() { 521 522 Enumeration lc = containers.elements(); 523 while (lc.hasMoreElements()) { 524 Container cont = (Container) lc.nextElement(); 525 removeContainer(cont); 526 } 527 if (mbeanServer != null) { 528 try { 529 mbeanServer.unregisterMBean(JonasObjectName.ejbService()); 531 } catch (Exception e) { 532 servlog.log(BasicLevel.ERROR, "Cannot stop the EJB Container Service", e); 533 } 534 } 535 536 if (servlog.isLoggable(BasicLevel.DEBUG)) { 537 servlog.log(BasicLevel.DEBUG, "EJB Container Service stopped"); 538 } 539 } 540 541 545 552 public String createContainer(Context ctx) throws Exception { 553 if (servlog.isLoggable(BasicLevel.DEBUG)) { 554 servlog.log(BasicLevel.DEBUG, ""); 555 } 556 557 String fileName = (String ) ctx.lookup("filename"); 559 File f = new File (fileName).getCanonicalFile(); 560 561 boolean isEjbJar = fileName.toLowerCase().endsWith(".jar"); 562 563 try { 567 if (!f.exists() && isEjbJar) { 568 String ejbjarFileName = EJBJARS_DIR + File.separator + fileName; 569 f = new File (ejbjarFileName).getCanonicalFile(); 570 if (!f.exists()) { 571 servlog.log(BasicLevel.ERROR, "createContainer: " + fileName + " not found"); 572 throw new NamingException (fileName + " not found"); 573 } 574 } 575 } catch (IOException e) { 576 String err = "Invalid ejbjar file name '" + fileName; 577 servlog.log(BasicLevel.ERROR, err); 578 throw new Exception (err, e); 579 } 580 boolean isEjbJarFile = isEjbJar && f.isFile(); 581 boolean isEjbJarXml = fileName.toLowerCase().endsWith(".xml") && f.isFile(); 582 583 try { 586 fileName = f.toURL().getPath(); 587 } catch (MalformedURLException e) { 588 servlog.log(BasicLevel.ERROR, "Invalid ejb-jar file name '" + fileName + "'", e); 589 } 590 591 if (f.isFile()) { 592 if (!isEjbJar && !isEjbJarXml) { 593 throw new ServiceException("The ejbjar to deploy is not a jar file nor an xml file"); 594 } 595 } 596 597 if (getContainer(fileName) != null) { 599 servlog.log(BasicLevel.ERROR, "createContainer: " + fileName + " already exists"); 600 throw new Exception ("Container already exists"); 601 } 602 603 boolean isInEar = true; 607 try { 608 ctx.lookup("earClassLoader"); 609 } catch (NamingException ne) { 610 isInEar = false; 611 } 612 613 if (!isInEar) { 616 checkGenIC(fileName); 617 } 618 619 620 String wkFileName = null; 621 622 if (!isInEar && isEjbJarFile) { 623 wkFileName = ejbjarsDir + File.separator + FileManager.fileToTimeStampDir(f.toURL(), ".jar"); 625 626 if (servlog.isLoggable(BasicLevel.DEBUG)) { 627 servlog.log(BasicLevel.DEBUG, "filename=" + fileName); 628 servlog.log(BasicLevel.DEBUG, "wkFilename=" + wkFileName); 629 } 630 631 FileUtils.copyFile(fileName, wkFileName); 633 634 try { 636 jarDeployerLog.addEntry(f, new File (wkFileName)); 637 } catch (DeployerLogException e) { 638 String err = "Error while adding the " + fileName + " entry in the log file"; 639 servlog.log(BasicLevel.ERROR, err + " : " + e.getMessage()); 640 throw new Exception (err, e); 641 } 642 643 if (servlog.isLoggable(BasicLevel.DEBUG)) { 644 servlog.log(BasicLevel.DEBUG, "Create wk file :" + wkFileName); 645 } 646 647 } else { 648 wkFileName = fileName; 650 if (servlog.isLoggable(BasicLevel.DEBUG)) { 651 servlog.log(BasicLevel.DEBUG, "No needs wk file :" + wkFileName); 652 } 653 } 654 655 URL [] url = null; 657 try { 658 url = new URL [1]; 659 url[0] = (new File (wkFileName)).toURL(); 660 } catch (MalformedURLException e) { 661 servlog.log(BasicLevel.ERROR, "Invalid ejb-jar file name '" + wkFileName + "'", e); 662 } 663 664 URLClassLoader ejbClassLoader = null; 666 URLClassLoader earClassLoader = null; 667 try { 668 earClassLoader = (URLClassLoader ) ctx.lookup("earClassLoader"); 669 ejbClassLoader = (URLClassLoader ) ctx.lookup("ejbClassLoader"); 670 if (loaderlog.isLoggable(BasicLevel.DEBUG)) { 671 loaderlog.log(BasicLevel.DEBUG, "earClassLoader=" + earClassLoader); 672 } 673 } catch (NamingException ne) { 674 if (isEjbJar) { 676 ejbClassLoader = new EjbJarClassLoader(url, appsClassLoader); 677 } else { 678 ejbClassLoader = (URLClassLoader ) appsClassLoader; 679 } 680 if (loaderlog.isLoggable(BasicLevel.DEBUG)) { 681 loaderlog.log(BasicLevel.DEBUG, "parent Loader=" + appsClassLoader); 682 } 683 } 684 if (loaderlog.isLoggable(BasicLevel.DEBUG)) { 685 loaderlog.log(BasicLevel.DEBUG, "ejbClassLoader=" + ejbClassLoader); 686 } 687 688 DeploymentDesc dd = null; 690 try { 691 dd = EjbManagerWrapper.getDeploymentDesc(url[0], ejbClassLoader, earClassLoader); 693 } catch (DeploymentDescException e) { 694 String err = "Cannot read the deployment descriptors '" + fileName + "'"; 695 servlog.log(BasicLevel.ERROR, err); 696 throw new ServiceException(err, e); 697 } 698 699 String cname = buildEJBModuleName(fileName); 701 if (cname == null) { 702 cname = "EJB container "; 704 if (dd.getDisplayName() != null) { 705 cname += dd.getDisplayName(); 706 } 707 } 708 709 JContainer cont = new JContainer(cname, fileName, wkFileName, ejbClassLoader); 711 cont.setContainerNaming(NamingManager.getInstance()); 712 cont.setTransactionManager(tm); 713 cont.setPrincipalFactory(new PrincipalFactoryImpl()); 714 cont.setJmsManager(jms); 715 716 String earFileName; 719 try { 720 earFileName = (String ) ctx.lookup("earFileName"); 721 cont.setEarFileName(earFileName); 722 } catch (NamingException ne) { 723 earFileName = null; 724 } 725 726 if (securityService == null) { 728 if (servlog.isLoggable(BasicLevel.DEBUG)) { 729 servlog.log(BasicLevel.DEBUG, "EJB Container Service: working without Security Service"); 730 } 731 cont.setSecurity(false); 732 } else { 733 PermissionManager permissionManager = null; 734 try { 735 permissionManager = new PermissionManager(dd, cont.getContextId()); 736 permissionManager.translateEjbDeploymentDescriptor(); 737 if (!isInEar) { 741 permissionManager.commit(); 742 } 743 } catch (Exception e) { 744 servlog.log(BasicLevel.ERROR, "Can't build permission manager object for the ejbjar '" + fileName + "'", e); 745 } 746 cont.setPermissionManager(permissionManager); 747 } 748 749 cont.setWorkManager(workManager); 751 752 String domainName = getDomainName(); 753 String serverName = getJonasServerName(); 754 String j2eeAppName = EarServiceImpl.buildJ2eeApplicationName(earFileName); 755 EJBModule ejbModuleMBean = null; 756 ObjectName onEjbModule = null; 757 758 Map mbeansToRegister = new HashMap (); 760 761 if (mbeanServer != null) { 763 onEjbModule = J2eeObjectName.getEJBModule(domainName, serverName, j2eeAppName, cname); 767 768 ejbModuleMBean = new EJBModule(onEjbModule.toString(), cont, fileName, cname); 769 ejbModuleMBean.setDeploymentDescriptor(dd.getXmlContent()); 770 ejbModuleMBean.setJonasDeploymentDescriptor(dd.getJOnASXmlContent()); 771 772 ManagedBean oManaged = oRegistry.findManagedBean("EJBModule"); 774 ModelMBean oMBean = oManaged.createMBean(ejbModuleMBean); 775 mbeansToRegister.put(oMBean, onEjbModule); 776 } 777 778 BeanDesc[] beans = dd.getBeanDesc(); 780 for (int i = 0; i < beans.length; i++) { 781 BeanFactory bf = cont.addBean(beans[i]); 782 beans[i].setBeanFactory(bf); 783 if (mbeanServer != null) { 784 try { 785 String beanName = beans[i].getEjbName(); 787 if ((beans[i] instanceof EntityBmpDesc) || (beans[i] instanceof EntityCmpDesc)) { 788 JEntityFactory jef = (JEntityFactory) bf; 789 ObjectName onEntityBean = J2eeObjectName.getEntityBean(domainName, cname, serverName, 790 j2eeAppName, beanName); 791 EntityBean entityBeanMBean; if (beans[i] instanceof EntityBmpDesc) { 794 entityBeanMBean = new EntityBean(onEntityBean.toString(), jef, BMP); 795 } else { 796 entityBeanMBean = new EntityBean(onEntityBean.toString(), jef, CMP); 797 } 798 ManagedBean oManaged = oRegistry.findManagedBean("EntityBean"); 799 ModelMBean oMBean = oManaged.createMBean(entityBeanMBean); 800 mbeansToRegister.put(oMBean, onEntityBean); 801 ejbModuleMBean.addEjb(onEntityBean.toString()); 803 } else if (beans[i] instanceof SessionStatefulDesc) { 804 JSessionFactory jsf = (JSessionFactory) bf; 805 ObjectName onStatefulSessionBean = J2eeObjectName.getStatefulSessionBean(domainName, cname, 806 serverName, j2eeAppName, beanName); 807 StatefulSessionBean sessionBeanMBean = new StatefulSessionBean( 808 onStatefulSessionBean.toString(), jsf); 809 ManagedBean oManaged = oRegistry.findManagedBean("StatefulSessionBean"); 810 ModelMBean oMBean = oManaged.createMBean(sessionBeanMBean); 811 mbeansToRegister.put(oMBean, onStatefulSessionBean); 812 ejbModuleMBean.addEjb(onStatefulSessionBean.toString()); 814 } else if (beans[i] instanceof SessionStatelessDesc) { 815 JStatelessFactory jsf = (JStatelessFactory) bf; 816 ObjectName onStatelessSessionBean = J2eeObjectName.getStatelessSessionBean(domainName, cname, 817 serverName, j2eeAppName, beanName); 818 StatelessSessionBean sessionBeanMBean = new StatelessSessionBean(onStatelessSessionBean 819 .toString(), jsf); 820 ManagedBean oManaged = oRegistry.findManagedBean("StatelessSessionBean"); 821 ModelMBean oMBean = oManaged.createMBean(sessionBeanMBean); 822 mbeansToRegister.put(oMBean, onStatelessSessionBean); 823 ejbModuleMBean.addEjb(onStatelessSessionBean.toString()); 825 } else { 826 ObjectName onMessageDrivenBean = J2eeObjectName.getMessageDrivenBean(domainName, cname, 827 serverName, j2eeAppName, beanName); 828 MessageDrivenBean messageDrivenBeanMBean = null; 829 if (bf instanceof JMdbFactory) { 830 JMdbFactory jmf = (JMdbFactory) bf; 831 messageDrivenBeanMBean = new MessageDrivenBean(onMessageDrivenBean.toString(), jmf); 832 } else { 833 JMdbEndpointFactory jmf = (JMdbEndpointFactory) bf; 834 messageDrivenBeanMBean = new MessageDrivenBean(onMessageDrivenBean.toString(), jmf); 835 } 836 ManagedBean oManaged = oRegistry.findManagedBean("MessageDrivenBean"); 837 ModelMBean oMBean = oManaged.createMBean(messageDrivenBeanMBean); 838 mbeansToRegister.put(oMBean, onMessageDrivenBean); 839 ejbModuleMBean.addEjb(onMessageDrivenBean.toString()); 841 } 842 } catch (Exception e) { 843 servlog.log(BasicLevel.ERROR, "Cannot create container", e); 844 } 845 } 846 } 847 for (int i = 0; i < beans.length; i++) { 850 BeanFactory bf = beans[i].getBeanFactory(); 851 bf.initInstancePool(); 852 } 853 854 containers.addElement(cont); 857 for (Iterator it = mbeansToRegister.keySet().iterator(); it.hasNext();) { 858 ModelMBean mbean = (ModelMBean ) it.next(); 859 ObjectName oName = (ObjectName ) mbeansToRegister.get(mbean); 860 mbeanServer.registerMBean(mbean, oName); 861 862 } 863 864 if (servlog.isLoggable(BasicLevel.DEBUG)) { 865 servlog.log(BasicLevel.DEBUG, "created container for " + fileName); 866 } 867 return onEjbModule.toString(); 869 } 870 871 876 public Container getContainer(String fileName) { 877 if (servlog.isLoggable(BasicLevel.DEBUG)) { 878 servlog.log(BasicLevel.DEBUG, fileName); 879 } 880 881 884 String ejbjarFileName = EJBJARS_DIR + File.separator + fileName; 885 File f = null; 886 String pathEjbJarDirFile; 887 String pathFile = ""; 888 try { 889 f = new File (ejbjarFileName).getCanonicalFile(); 890 pathEjbJarDirFile = f.toURL().getPath(); 893 } catch (Exception e) { 894 pathEjbJarDirFile = ""; 897 } 898 try { 899 f = new File (fileName).getCanonicalFile(); 900 pathFile = f.toURL().getPath(); 903 } catch (Exception e) { 904 String err = "Error while trying to get canonical file '" + fileName + "'"; 905 servlog.log(BasicLevel.ERROR, err); 906 return null; 907 } 908 909 Enumeration lc = containers.elements(); 911 while (lc.hasMoreElements()) { 912 Container cont = (JContainer) lc.nextElement(); 913 String contName = cont.getExternalFileName(); 914 915 if (contName.equals(pathFile)) { 917 return cont; 918 } else if (contName.equals(pathEjbJarDirFile)) { 919 return cont; 921 } else { 922 List lAlDirs = getAutoloadDirectories(); 924 for (int i = 0; i < lAlDirs.size(); i++) { 925 String alDir = (String ) lAlDirs.get(i); 926 927 String alFileName = alDir + File.separator + fileName; 928 try { 929 f = new File (alFileName).getCanonicalFile(); 930 alFileName = f.toURL().getPath(); 933 } catch (Exception e) { 934 alFileName = alDir + File.separator + fileName; 937 } 938 if (servlog.isLoggable(BasicLevel.DEBUG)) { 939 servlog.log(BasicLevel.DEBUG, "alFileName= " + alFileName); 940 } 941 942 if (contName.equals(alFileName)) { 943 return cont; 944 } 945 } 946 } 947 } 948 949 return null; 951 } 952 953 956 public void removeContainer(Container cont) { 957 if (servlog.isLoggable(BasicLevel.DEBUG)) { 958 servlog.log(BasicLevel.DEBUG, cont.getName()); 959 } 960 961 if (mbeanServer != null) { 962 String moduleName = cont.getName(); 963 String earFileName = cont.getEarFileName(); 964 String earName = null; 965 if (earFileName != null) { 966 earName = EarServiceImpl.buildJ2eeApplicationName(earFileName); 967 } 968 String domainName = getDomainName(); 969 String serverName = getJonasServerName(); 970 ObjectName onEjbModule = J2eeObjectName.getEJBModule(domainName, serverName, earName, moduleName); 971 972 ObjectName onEjb = null; 974 try { 975 String [] onEjbs = (String []) mbeanServer.getAttribute(onEjbModule, "ejbs"); 976 for (int i = 0; i < onEjbs.length; i++) { 977 onEjb = new ObjectName (onEjbs[i]); 978 mbeanServer.unregisterMBean(onEjb); 979 } 980 } catch (Exception e) { 981 servlog.log(BasicLevel.ERROR, "Problem when trying to unregsiter MBean " + onEjb.toString(), e); 982 } 983 984 try { 986 mbeanServer.unregisterMBean(onEjbModule); 987 if (servlog.isLoggable(BasicLevel.DEBUG)) { 988 servlog.log(BasicLevel.DEBUG, "unregistered MBean: " + onEjbModule.toString()); 989 } 990 } catch (Exception e) { 991 servlog.log(BasicLevel.ERROR, "Problem when trying to unregsiter MBean " + onEjbModule.toString(), e); 992 } 993 } 994 cont.remove(); 995 containers.removeElement(cont); 996 997 Runtime.getRuntime().gc(); 999 1000 } 1001 1002 1005 public Container[] listContainers() { 1006 if (servlog.isLoggable(BasicLevel.DEBUG)) { 1007 servlog.log(BasicLevel.DEBUG, "size= " + containers.size()); 1008 } 1009 1010 Container[] ret = new Container[containers.size()]; 1011 containers.copyInto(ret); 1012 return ret; 1013 } 1014 1015 1019 public void syncAllEntities(boolean passivate) { 1020 if (servlog.isLoggable(BasicLevel.DEBUG)) { 1021 servlog.log(BasicLevel.DEBUG, ""); 1022 } 1023 1024 Enumeration lc = containers.elements(); 1025 while (lc.hasMoreElements()) { 1026 JContainer cont = (JContainer) lc.nextElement(); 1027 cont.syncAll(passivate); 1028 } 1029 } 1030 1031 1032 1033 1037 public Integer getCurrentNumberOfContainer() { 1038 return new Integer (containers.size()); 1039 } 1040 1041 1045 public Integer getTotalCurrentNumberOfBeanType() { 1046 int count = 0; 1047 Enumeration lc = containers.elements(); 1048 while (lc.hasMoreElements()) { 1049 JContainer cont = (JContainer) lc.nextElement(); 1050 count += cont.getBeanNb(); 1051 } 1052 return new Integer (count); 1053 } 1054 1055 1059 public Integer getTotalCurrentNumberOfBMPType() { 1060 int count = 0; 1061 Enumeration lc = containers.elements(); 1062 while (lc.hasMoreElements()) { 1063 JContainer cont = (JContainer) lc.nextElement(); 1064 count += cont.getEntityBMPNb(); 1065 } 1066 return new Integer (count); 1067 } 1068 1069 1073 public Integer getTotalCurrentNumberOfCMPType() { 1074 int count = 0; 1075 Enumeration lc = containers.elements(); 1076 while (lc.hasMoreElements()) { 1077 JContainer cont = (JContainer) lc.nextElement(); 1078 count += cont.getEntityCMPNb(); 1079 } 1080 return new Integer (count); 1081 } 1082 1083 1087 public Integer getTotalCurrentNumberOfSBFType() { 1088 int count = 0; 1089 Enumeration lc = containers.elements(); 1090 while (lc.hasMoreElements()) { 1091 JContainer cont = (JContainer) lc.nextElement(); 1092 count += cont.getStatefulSessionNb(); 1093 } 1094 return new Integer (count); 1095 } 1096 1097 1101 public Integer getTotalCurrentNumberOfSBLType() { 1102 int count = 0; 1103 Enumeration lc = containers.elements(); 1104 while (lc.hasMoreElements()) { 1105 JContainer cont = (JContainer) lc.nextElement(); 1106 count += cont.getStatelessSessionNb(); 1107 } 1108 return new Integer (count); 1109 } 1110 1111 1115 public Integer getTotalCurrentNumberOfMDBType() { 1116 int count = 0; 1117 Enumeration lc = containers.elements(); 1118 while (lc.hasMoreElements()) { 1119 JContainer cont = (JContainer) lc.nextElement(); 1120 count += cont.getMessageDrivenNb(); 1121 } 1122 return new Integer (count); 1123 } 1124 1125 public void removeContainer(String fileName) throws Exception { 1126 removeContainerMBean(fileName); 1127 } 1128 1129 1133 public void removeContainerMBean(String fileName) throws Exception { 1134 Container cont = null; 1135 try { 1136 cont = getContainer(fileName); 1137 } catch (Exception e) { 1138 String err = "Error while trying to find file '" + fileName + "'"; 1139 servlog.log(BasicLevel.ERROR, err); 1140 throw new Exception (err, e); 1141 } 1142 1143 if (cont != null) { 1144 removeContainer(cont, false); 1145 } else { 1146 String err = "Cannot remove the non-existant container '" + fileName + "'"; 1147 servlog.log(BasicLevel.ERROR, err); 1148 throw new Exception (err); 1149 } 1150 } 1151 1152 public String createContainer(String file) throws Exception { 1153 return createContainerMBean(file); 1154 } 1155 1156 1163 public String createContainerMBean(String file) throws Exception { 1164 String ejbModuleObjectName = null; 1165 try { 1166 Context contctx = new CompNamingContext(file); 1167 contctx.rebind("filename", file); 1168 ejbModuleObjectName = createContainer(contctx); 1169 } catch (Exception e) { 1170 throw new Exception ("Cannot create Container", e); 1171 } 1172 return ejbModuleObjectName; 1173 } 1174 1175 1181 public Boolean isJarDeployed(String fileName) { 1182 return new Boolean (isJarLoaded(fileName)); 1183 } 1184 1185 1191 public boolean isJarDeployedByWorkName(String workFileName) { 1192 if (servlog.isLoggable(BasicLevel.DEBUG)) { 1193 servlog.log(BasicLevel.DEBUG, workFileName); 1194 } 1195 1196 Enumeration lc = containers.elements(); 1198 while (lc.hasMoreElements()) { 1199 Container cont = (JContainer) lc.nextElement(); 1200 1201 String contName = new File (cont.getFileName()).getName(); 1204 if (contName.equals(workFileName)) { 1205 return true; 1206 } 1207 } 1208 1209 return false; 1211 } 1212 1213 static final int DATASOURCE = 1; 1215 1216 static final int JMS_DESTINATION = 2; 1217 1218 static final int JMS_FACTORY = 3; 1219 1220 static final int MAIL_FACTORY = 4; 1221 1222 1229 Set getDependence(String name, int type) { 1230 Set resultObjectName = null; Set resultProperties = new HashSet (); Enumeration lc = containers.elements(); 1233 try { 1234 Context ctx = new InitialContext (); 1235 ctx.lookup(name); 1236 ctx.close(); 1237 while (lc.hasMoreElements()) { 1239 JContainer cont = (JContainer) lc.nextElement(); 1240 Set depProps = null; switch (type) { 1243 1244 case DATASOURCE: 1245 depProps = cont.getDataSourceDependence(name); 1246 break; 1247 1248 case JMS_DESTINATION: 1249 depProps = cont.getJmsDestinationDependence(name); 1250 break; 1251 1252 case JMS_FACTORY: 1253 depProps = cont.getJmsConnectionFactoryDependence(name); 1254 break; 1255 1256 case MAIL_FACTORY: 1257 depProps = cont.getMailFactoryDependence(name); 1258 break; 1259 1260 } 1261 resultProperties.addAll(depProps); 1262 try { 1264 resultObjectName = convertToObjectNames(resultProperties); 1265 } catch (Exception e) { 1266 servlog.log(BasicLevel.ERROR, "EjbServiceImpl: Object Name Error", e); 1267 } 1268 } 1269 } catch (NamingException ne) { 1270 resultObjectName = new HashSet (); 1272 } 1273 return resultObjectName; 1274 } 1275 1276 1281 private Set convertToObjectNames(Set resultProperties) { 1282 Set resultObjectName = new HashSet (); 1283 Iterator it = resultProperties.iterator(); 1284 String domainName = getDomainName(); 1285 String serverName = getJonasServerName(); 1286 Properties item = null; String ejbType = null; 1288 String ejbName = null; 1289 String fileName = null; 1290 String earFileName = null; 1291 String moduleName = null; 1292 String j2eeAppName = null; 1293 while (it.hasNext()) { 1294 item = (Properties ) it.next(); 1295 ObjectName ejbObjectName = null; 1296 ejbType = item.getProperty("type"); 1299 ejbName = item.getProperty("name"); 1300 fileName = item.getProperty("fname"); 1301 earFileName = item.getProperty("earFileName"); 1302 moduleName = item.getProperty("cname"); 1304 if (earFileName != null) { 1305 j2eeAppName = EarServiceImpl.buildJ2eeApplicationName(earFileName); 1306 } 1307 1308 if (ejbType.equals("ejbbmp") || ejbType.equals("ejbcmp")) { 1309 ejbObjectName = J2eeObjectName.getEntityBean(domainName, moduleName, serverName, j2eeAppName, ejbName); 1310 } else if (ejbType.equals("ejbsbf")) { 1311 ejbObjectName = J2eeObjectName.getStatefulSessionBean(domainName, moduleName, serverName, j2eeAppName, 1312 ejbName); 1313 } else if (ejbType.equals("ejbsbl")) { 1314 ejbObjectName = J2eeObjectName.getStatelessSessionBean(domainName, moduleName, serverName, j2eeAppName, 1315 ejbName); 1316 } else if (ejbType.equals("ejbmdb")) { 1317 ejbObjectName = J2eeObjectName.getMessageDrivenBean(domainName, moduleName, serverName, j2eeAppName, 1318 ejbName); 1319 } 1320 if (ejbObjectName != null) { 1321 resultObjectName.add(ejbObjectName); 1322 } 1323 } 1324 return resultObjectName; 1325 } 1326 1327 1331 public Set getDataSourceDependence(String dsName) { 1332 return getDependence(dsName, DATASOURCE); 1333 } 1334 1335 1339 public Set getJmsDestinationDependence(String destName) { 1340 return getDependence(destName, JMS_DESTINATION); 1341 } 1342 1343 1347 public Set getJmsConnectionFactoryDependence(String cfName) { 1348 return getDependence(cfName, JMS_FACTORY); 1349 } 1350 1351 1355 public Set getMailFactoryDependence(String mfName) { 1356 return getDependence(mfName, MAIL_FACTORY); 1357 } 1358 1359 1367 public List getInstalledJars() throws Exception { 1368 ArrayList al = JModule.getInstalledContainersInDir(EJBJARS_DIR, JModule.EJBJAR_EXTENSION, 1370 JModule.EJBJAR_CHILD_DIR, JModule.EJBJAR_CONFIRM_FILE); 1371 for (int i = 0; i < autoloadDirectories.size(); i++) { 1373 al.addAll(JModule.getInstalledContainersInDir(autoloadDirectories.get(i).toString(), 1374 JModule.EJBJAR_EXTENSION, JModule.EJBJAR_CHILD_DIR, JModule.EJBJAR_CONFIRM_FILE)); 1375 } 1376 return al; 1377 } 1378 1379 1393 public void deployJars(Context ctx) throws ServiceException { 1394 1395 URL earRootUrl = null; 1402 URL earUrl = null; 1403 ClassLoader earClassLoader = null; 1404 ClassLoader ejbClassLoader = null; 1405 URL [] jarURLs = null; 1406 String [] roleNames = null; 1407 try { 1408 earRootUrl = (URL ) ctx.lookup("earRootUrl"); 1409 earUrl = (URL ) ctx.lookup("earUrl"); 1410 earClassLoader = (ClassLoader ) ctx.lookup("earClassLoader"); 1411 ejbClassLoader = (ClassLoader ) ctx.lookup("ejbClassLoader"); 1412 jarURLs = (URL []) ctx.lookup("jarURLs"); 1413 roleNames = (String []) ctx.lookup("roleNames"); 1414 } catch (NamingException e) { 1415 String err = "Error while getting parameter from context param :" + e.getMessage(); 1416 servlog.log(BasicLevel.ERROR, err); 1417 throw new ServiceException(err, e); 1418 } 1419 1420 for (int i = 0; i < jarURLs.length; i++) { 1422 1423 String fileName = jarURLs[i].getFile(); 1425 if (servlog.isLoggable(BasicLevel.DEBUG)) { 1426 servlog.log(BasicLevel.DEBUG, "Deploy '" + fileName + "' for the ear service."); 1427 } 1428 1429 Context contctx = null; 1432 try { 1433 contctx = new CompNamingContext(fileName); 1434 contctx.rebind("filename", fileName); 1435 contctx.rebind("earClassLoader", earClassLoader); 1436 contctx.rebind("ejbClassLoader", ejbClassLoader); 1437 contctx.rebind("earRoot", earRootUrl.getFile()); 1438 contctx.rebind("earFileName", earUrl.getFile()); 1439 contctx.rebind("roleNames", roleNames); 1440 createContainer(contctx); 1441 } catch (Exception e) { 1442 servlog.log(BasicLevel.ERROR, "Error when deploying '" + fileName + "'", e); 1445 servlog.log(BasicLevel.ERROR, "Undeploy ejb-jar of the ear application"); 1446 1447 for (int j = 0; j <= i; j++) { 1448 Container cont = getContainer(jarURLs[j].getFile()); 1449 if (cont != null) { 1450 removeContainer(cont, true); 1451 } else { 1452 servlog.log(BasicLevel.ERROR, "Cannot remove the non-existant container '" + fileName + "'"); 1453 } 1454 } 1455 throw new ServiceException("Error during the deployment", e); 1456 } 1457 } 1458 } 1460 1461 1466 public void unDeployJars(URL [] urls) { 1467 for (int i = 0; i < urls.length; i++) { 1468 String fileName = urls[i].getFile(); 1469 Container cont = getContainer(urls[i].getFile()); 1470 if (cont != null) { 1471 removeContainer(cont, true); 1472 } else { 1473 servlog.log(BasicLevel.ERROR, "Cannot remove the non-existant container '" + fileName + "'"); 1474 } 1475 } 1476 } 1477 1478 1484 public void removeContainer(Container cont, boolean isEarCase) { 1485 if (isEarCase == (cont.getEarFileName() != null)) { 1486 removeContainer(cont); 1487 } else { 1488 String err = "Cannot remove container '" + cont.getName() 1489 + "' it is in an ear application. You must undeploy the ear associated."; 1490 servlog.log(BasicLevel.ERROR, err); 1491 } 1492 } 1493 1494 1501 public void removeCache(ClassLoader earClassLoader) { 1502 EjbManagerWrapper.removeCache(earClassLoader); 1503 } 1504 1505 1512 private void addEjbjars(String dirPath) { 1513 boolean found = false; 1514 1515 File dir = new File (EJBJARS_DIR + File.separator + dirPath); 1517 found = dir.isDirectory(); 1518 1519 if (found) { 1520 addEjbjarsFrom(dir); 1521 } else { 1522 String err = "Warning: Cannot load dir: '" + dirPath + "' "; 1523 err += "is not a directory or directory doesn't exist"; 1524 servlog.log(BasicLevel.WARN, err); 1525 } 1526 } 1527 1528 1533 private void addEjbjarsFrom(File dir) throws ServiceException { 1534 1535 try { 1536 if (dir.isDirectory()) { 1537 File [] files = dir.listFiles(); 1538 for (int i = 0; i < files.length; i++) { 1539 if (files[i].getPath().toLowerCase().endsWith(".jar")) { 1540 ejbNames.add(files[i].getCanonicalPath()); 1541 } else if (files[i].isDirectory()) { 1542 addEjbjarsFrom(files[i]); 1543 } 1544 } 1545 } else { 1546 String err = "Cannot load dir: '" + dir.getPath(); 1547 err += "' is not a directory"; 1548 servlog.log(BasicLevel.ERROR, err); 1549 throw new ServiceException(err); 1550 } 1551 } catch (IOException e) { 1552 String err = "Invalid file name '" + dir.getPath(); 1553 servlog.log(BasicLevel.ERROR, err); 1554 throw new ServiceException(err, e); 1555 } 1556 } 1557 1558 1563 public boolean isJarLoaded(String fileName) { 1564 return (getContainer(fileName) != null); 1565 } 1566 1567 1571 public List getDeployedJars() { 1572 ArrayList al = new ArrayList (); 1573 Container oContainer; 1574 for (Enumeration jars = containers.elements(); jars.hasMoreElements();) { 1575 oContainer = (Container) jars.nextElement(); 1576 try { 1577 al.add((new File (oContainer.getExternalFileName())).toURL().getPath()); 1578 } catch (Exception e) { 1579 } 1581 } 1582 return al; 1583 } 1584 1585 1590 public List getDeployableJars() throws Exception { 1591 List al = getInstalledJars(); 1592 al.removeAll(getDeployedJars()); 1593 return al; 1594 } 1595 1596 1600 public List getAutoloadDirectories() { 1601 ArrayList al = new ArrayList (); 1602 for (int i = 0; i < autoloadDirectories.size(); i++) { 1603 try { 1604 al.add((new File (autoloadDirectories.get(i).toString())).toURL().getPath()); 1605 } catch (Exception e) { 1606 } 1608 } 1609 return al; 1610 } 1611 1612 1616 public String getEjbjarsDirectory() { 1617 String sRet; 1618 try { 1619 sRet = (new File (EJBJARS_DIR)).toURL().getPath(); 1620 } catch (Exception e) { 1621 sRet = null; 1622 } 1623 return sRet; 1624 } 1625 1626 1631 public static String buildEJBModuleName(URL pUrl) { 1632 String sName; 1633 try { 1634 sName = new File (pUrl.getFile()).getName(); 1635 if ("file".equals(pUrl.getProtocol())) { 1636 sName = buildEJBModuleName(sName); 1637 } 1638 } catch (NullPointerException e) { 1639 sName = null; 1640 } 1641 return sName; 1642 } 1643 1644 1649 public static String buildEJBModuleName(String pFilename) { 1650 String sName; 1651 try { 1652 sName = new File (pFilename).getName(); 1653 int iPos = sName.lastIndexOf('.'); 1654 if (iPos > -1) { 1655 sName = sName.substring(0, iPos); 1656 } 1657 } catch (NullPointerException e) { 1658 sName = null; 1659 } 1660 return sName; 1661 } 1662 1663 1669 private static boolean checkCurrentProtocolIncludeIntoGenerated(String listProtocolGenerated, String listCurrentProtocol) { 1670 boolean find = true; 1671 int i = 0; 1672 1673 if (listProtocolGenerated == null) 1674 return false; 1675 1676 Vector listGenerate = new Vector (); 1677 Vector listCurrent = new Vector (); 1678 1679 StringTokenizer st = new StringTokenizer (listProtocolGenerated, ","); 1680 while (st.hasMoreTokens()) { 1681 listGenerate.add(st.nextToken()); 1682 } 1683 1684 st = new StringTokenizer (listCurrentProtocol, ","); 1685 while (st.hasMoreTokens()) { 1686 listCurrent.add(st.nextToken()); 1687 } 1688 1689 while (i < listCurrent.size() && find) { 1690 if (!listGenerate.contains(listCurrent.get(i))) 1691 find = false; 1692 i++; 1693 } 1694 1695 return find; 1696 } 1697 1698 1704 private static String getAttributInManifest(String jarName, String attributName) { 1705 try { 1706 File jarFile = new File (jarName); 1707 JarFile jar = new JarFile (jarFile); 1708 Manifest man = jar.getManifest(); 1709 Attributes atts = man.getMainAttributes(); 1710 return atts.getValue(attributName); 1711 } catch (Exception e) { 1712 return null; 1713 } 1714 } 1715 1716 1721 public void checkGenIC(String fileName) { 1722 ProtocolConfiguration[] listCurrentProtocol = ConfigurationRepository.getConfigurations(); 1724 1725 String [] genicArgsString = new String [2]; 1726 genicArgsString[0] = "-protocols"; 1727 String listProtocols = ""; 1728 for (int i = 0; i < listCurrentProtocol.length; i++) { 1729 listProtocols = listProtocols + listCurrentProtocol[i].getName(); 1730 if (i != (listCurrentProtocol.length - 1)) 1731 listProtocols = listProtocols + ","; 1732 } 1733 genicArgsString[1] = listProtocols; 1734 String jonasVersionGenic = getAttributInManifest(fileName, "Genic-Jonas-Version"); 1735 String listProtocolGenerated = getAttributInManifest(fileName, "Genic-Jonas-protocols"); 1736 1737 boolean isCurrentProtocolIncludeIntoGenerated = checkCurrentProtocolIncludeIntoGenerated(listProtocolGenerated, listProtocols); 1738 1739 if ((jonasVersionGenic == null) || !jonasVersionGenic.equals(Version.NUMBER) 1740 || !isCurrentProtocolIncludeIntoGenerated) { 1741 if (jonasVersionGenic == null) 1743 servlog.log(BasicLevel.INFO, "JOnAS version is not find into " + fileName + " manifest file. Try to generate container classes..."); 1744 else if (!jonasVersionGenic.equals(Version.NUMBER)) 1745 servlog.log(BasicLevel.INFO, "JOnAS version find into " + fileName + " manifest file :" + jonasVersionGenic + " is different for the current JOnAS version : " + Version.NUMBER + ". Try to generate container classes..."); 1746 else if (!isCurrentProtocolIncludeIntoGenerated) 1747 servlog.log(BasicLevel.INFO, "Current Carol protocol is not include into those find into" + fileName + " manifest file. Try to generate container classes..."); 1748 1749 Object [] param = {fileName, genicArgsString}; 1750 String [] signature = {"java.lang.String", "[Ljava.lang.String;"}; 1751 try { 1753 ObjectName j2eeServerON = J2eeObjectName.J2EEServer(this.getDomainName(), this.getJonasServerName()); 1754 mbeanServer.invoke(j2eeServerON, "deployLocalFile", param, signature); 1755 1756 } catch (Exception e) { 1757 servlog.log(BasicLevel.WARN, "createContainer: " + fileName + " can't create generated classes", e); 1758 } 1759 } 1760 } 1761} | Popular Tags |