示例#1
0
  private void initInterceptors(final EjbModule jar, final EjbJarInfo ejbJar)
      throws OpenEJBException {
    if (jar.getEjbJar().getInterceptors().length == 0) {
      return;
    }
    if (jar.getEjbJar().getAssemblyDescriptor() == null) {
      return;
    }
    if (jar.getEjbJar().getAssemblyDescriptor().getInterceptorBinding() == null) {
      return;
    }

    for (final Interceptor s : jar.getEjbJar().getInterceptors()) {
      final InterceptorInfo info = new InterceptorInfo();

      info.clazz = s.getInterceptorClass();

      copyCallbacks(s.getAroundInvoke(), info.aroundInvoke);

      copyCallbacks(s.getPostConstruct(), info.postConstruct);
      copyCallbacks(s.getPreDestroy(), info.preDestroy);

      copyCallbacks(s.getPostActivate(), info.postActivate);
      copyCallbacks(s.getPrePassivate(), info.prePassivate);

      copyCallbacks(s.getAfterBegin(), info.afterBegin);
      copyCallbacks(s.getBeforeCompletion(), info.beforeCompletion);
      copyCallbacks(s.getAfterCompletion(), info.afterCompletion);

      copyCallbacks(s.getAroundTimeout(), info.aroundTimeout);

      ejbJar.interceptors.add(info);
    }

    for (final InterceptorBinding binding :
        jar.getEjbJar().getAssemblyDescriptor().getInterceptorBinding()) {
      final InterceptorBindingInfo info = new InterceptorBindingInfo();
      info.ejbName = binding.getEjbName();
      info.excludeClassInterceptors = binding.getExcludeClassInterceptors();
      info.excludeDefaultInterceptors = binding.getExcludeDefaultInterceptors();
      info.interceptors.addAll(binding.getInterceptorClass());
      if (binding.getInterceptorOrder() != null) {
        info.interceptorOrder.addAll(binding.getInterceptorOrder().getInterceptorClass());
      }

      info.method = toInfo(binding.getMethod());
      info.className = binding.getClassName();
      ejbJar.interceptorBindings.add(info);
    }
  }
示例#2
0
  public synchronized AppModule deploy(final AppModule appModule) throws OpenEJBException {

    final Set<String> abstractSchemaNames = new HashSet<String>();
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
      for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        if (isCmpEntity(bean)) {
          final EntityBean entity = (EntityBean) bean;
          final String name = entity.getAbstractSchemaName();
          if (name != null) {
            abstractSchemaNames.add(name);
          }
        }
      }
    }

    final Map<String, String> contextData = new HashMap<String, String>();
    contextData.put("appId", appModule.getModuleId());

    for (final EjbModule ejbModule : appModule.getEjbModules()) {
      contextData.put("ejbJarId", ejbModule.getModuleId());
      deploy(ejbModule, contextData, abstractSchemaNames);
    }
    contextData.clear();
    return appModule;
  }
  public AppModule fillInMissingType(AppModule appModule) throws OpenEJBException {

    for (ClientModule module : appModule.getClientModules()) {
      final JndiConsumer consumer = module.getApplicationClient();
      if (consumer == null) continue;

      fillInMissingType(consumer, module);
    }

    for (WebModule module : appModule.getWebModules()) {
      final JndiConsumer consumer = module.getWebApp();
      if (consumer == null) continue;

      fillInMissingType(consumer, module);
    }

    for (EjbModule module : appModule.getEjbModules()) {
      final EjbJar ejbJar = module.getEjbJar();
      if (ejbJar == null) continue;

      for (EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
        fillInMissingType(consumer, module);
      }
    }

    return appModule;
  }
  public AppModule removeUnsetEnvEntries(AppModule appModule) throws OpenEJBException {

    for (ClientModule module : appModule.getClientModules()) {
      final JndiConsumer consumer = module.getApplicationClient();
      if (consumer == null) continue;

      removeUnsetEnvEntries(consumer);
    }

    for (WebModule module : appModule.getWebModules()) {
      final JndiConsumer consumer = module.getWebApp();
      if (consumer == null) continue;

      removeUnsetEnvEntries(consumer);
    }

    for (EjbModule module : appModule.getEjbModules()) {
      final EjbJar ejbJar = module.getEjbJar();
      if (ejbJar == null) continue;

      for (EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) {
        removeUnsetEnvEntries(consumer);
      }
    }

    return appModule;
  }
示例#5
0
  private void initExcludesList(final EjbModule jar, final Map ejbds, final EjbJarInfo ejbJarInfo) {

    final ExcludeList methodPermissions = jar.getEjbJar().getAssemblyDescriptor().getExcludeList();

    for (final Method excludedMethod : methodPermissions.getMethod()) {
      ejbJarInfo.excludeList.add(getMethodInfo(excludedMethod, ejbds));
    }
  }
示例#6
0
 private void initApplicationExceptions(final EjbModule jar, final EjbJarInfo ejbJarInfo) {
   for (final ApplicationException applicationException :
       jar.getEjbJar().getAssemblyDescriptor().getApplicationException()) {
     final ApplicationExceptionInfo info = new ApplicationExceptionInfo();
     info.exceptionClass = applicationException.getExceptionClass();
     info.rollback = applicationException.isRollback();
     info.inherited = applicationException.isInherited();
     ejbJarInfo.applicationException.add(info);
   }
 }
  @Override
  protected void setUp() throws Exception {
    Assembler assembler = new Assembler();
    config = new ConfigurationFactory();

    ejbModule = new EjbModule(new EjbJar());
    ejbModule.setOpenejbJar(new OpenejbJar());
    ejbJar = ejbModule.getEjbJar();

    strict(false);
  }
示例#8
0
  private void initMethodTransactions(
      final EjbModule jar, final Map ejbds, final EjbJarInfo ejbJarInfo) {
    final List<ContainerTransaction> containerTransactions =
        jar.getEjbJar().getAssemblyDescriptor().getContainerTransaction();
    for (final ContainerTransaction cTx : containerTransactions) {
      final MethodTransactionInfo info = new MethodTransactionInfo();

      info.description = cTx.getDescription();
      info.transAttribute = cTx.getTransAttribute().toString();
      info.methods.addAll(getMethodInfos(cTx.getMethod(), ejbds));
      ejbJarInfo.methodTransactions.add(info);
    }
  }
示例#9
0
  private void initRelationships(final EjbModule jar, final Map<String, EnterpriseBeanInfo> infos)
      throws OpenEJBException {
    for (final EjbRelation ejbRelation : jar.getEjbJar().getRelationships().getEjbRelation()) {
      final Iterator<EjbRelationshipRole> iterator =
          ejbRelation.getEjbRelationshipRole().iterator();
      final EjbRelationshipRole left = iterator.next();
      final EjbRelationshipRole right = iterator.next();

      // left role info
      final CmrFieldInfo leftCmrFieldInfo = initRelationshipRole(left, right, infos);
      final CmrFieldInfo rightCmrFieldInfo = initRelationshipRole(right, left, infos);
      leftCmrFieldInfo.mappedBy = rightCmrFieldInfo;
      rightCmrFieldInfo.mappedBy = leftCmrFieldInfo;
    }
  }
示例#10
0
  private void initMethodPermissions(
      final EjbModule jar, final Map ejbds, final EjbJarInfo ejbJarInfo) {

    final List<MethodPermission> methodPermissions =
        jar.getEjbJar().getAssemblyDescriptor().getMethodPermission();

    for (final MethodPermission mp : methodPermissions) {
      final MethodPermissionInfo info = new MethodPermissionInfo();

      info.description = mp.getDescription();
      info.roleNames.addAll(mp.getRoleName());
      info.methods.addAll(getMethodInfos(mp.getMethod(), ejbds));
      info.unchecked = mp.getUnchecked();

      ejbJarInfo.methodPermissions.add(info);
    }
  }
示例#11
0
  private void initMethodConcurrency(
      final EjbModule jar, final Map ejbds, final EjbJarInfo ejbJarInfo) {
    final List<ContainerConcurrency> containerConcurrency =
        jar.getEjbJar().getAssemblyDescriptor().getContainerConcurrency();
    for (final ContainerConcurrency att : containerConcurrency) {
      final MethodConcurrencyInfo info = new MethodConcurrencyInfo();

      info.description = att.getDescription();
      if (att.getLock() != null) {
        info.concurrencyAttribute = att.getLock().toString();
      }
      info.accessTimeout = toInfo(att.getAccessTimeout());

      info.methods.addAll(getMethodInfos(att.getMethod(), ejbds));
      ejbJarInfo.methodConcurrency.add(info);
    }
  }
示例#12
0
  private void initSecurityRoles(final EjbModule jar, final EjbJarInfo ejbJarInfo) {

    final List<SecurityRole> roles = jar.getEjbJar().getAssemblyDescriptor().getSecurityRole();

    for (final SecurityRole sr : roles) {
      final SecurityRoleInfo info = new SecurityRoleInfo();

      info.description = sr.getDescription();
      info.roleName = sr.getRoleName();

      if (securityRoles.contains(sr.getRoleName())) {
        ConfigUtils.logger.warning("conf.0102", jar.getJarLocation(), sr.getRoleName());
      } else {
        securityRoles.add(sr.getRoleName());
      }
      ejbJarInfo.securityRoles.add(info);
    }
  }
示例#13
0
  private EjbModule deploy(
      final EjbModule ejbModule,
      final Map<String, String> contextData,
      final Set<String> abstractSchemaNames)
      throws OpenEJBException {
    contextData.put("moduleId", ejbModule.getModuleId());
    contextData.put("moduleUri", ejbModule.getModuleUri().toString());

    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
      openejbJar = ejbModule.getOpenejbJar();
    } else {
      openejbJar = new OpenejbJar();
      ejbModule.setOpenejbJar(openejbJar);
    }

    StringTemplate deploymentIdTemplate = this.deploymentIdTemplate;
    if (openejbJar.getProperties().containsKey(DEPLOYMENT_ID_FORMAT)) {
      final String format = openejbJar.getProperties().getProperty(DEPLOYMENT_ID_FORMAT);
      logger.info("Using " + DEPLOYMENT_ID_FORMAT + " '" + format + "'");
      deploymentIdTemplate = new StringTemplate(format);
    }

    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
      StringTemplate template = deploymentIdTemplate;

      final org.apache.openejb.api.EjbDeployment annotation =
          getEjbDeploymentAnnotation(ejbModule, bean);

      EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
      if (ejbDeployment == null) {

        ejbDeployment = new EjbDeployment();

        ejbDeployment.setEjbName(bean.getEjbName());

        if (annotation != null && isDefined(annotation.id())) {
          template = new StringTemplate(annotation.id());
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
        } else {
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
          if (!(bean instanceof ManagedBean) || !((ManagedBean) bean).isHidden()) {
            logger.info(
                "Auto-deploying ejb "
                    + bean.getEjbName()
                    + ": EjbDeployment(deployment-id="
                    + ejbDeployment.getDeploymentId()
                    + ")");
          }
        }

        openejbJar.getEjbDeployment().add(ejbDeployment);
      } else if (ejbDeployment.getDeploymentId() == null) {
        if (annotation != null && isDefined(annotation.id())) {
          template = new StringTemplate(annotation.id());
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
        } else {
          ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
          logger.info(
              "Auto-assigning deployment-id for ejb "
                  + bean.getEjbName()
                  + ": EjbDeployment(deployment-id="
                  + ejbDeployment.getDeploymentId()
                  + ")");
        }
      }

      if (ejbDeployment.getContainerId() == null
          && annotation != null
          && isDefined(annotation.container())) {
        ejbDeployment.setContainerId(annotation.container());
      }

      if (isCmpEntity(bean)) {
        final EntityBean entity = (EntityBean) bean;
        if (entity.getAbstractSchemaName() == null) {
          String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");

          // The AbstractSchemaName must be unique, we should check that it is
          if (abstractSchemaNames.contains(abstractSchemaName)) {
            int i = 2;
            while (abstractSchemaNames.contains(abstractSchemaName + i)) {
              i++;
            }
            abstractSchemaName = abstractSchemaName + i;
          }

          abstractSchemaNames.add(abstractSchemaName);
          entity.setAbstractSchemaName(abstractSchemaName);
        }
      }
    }

    return ejbModule;
  }
示例#14
0
  public EjbJarInfo buildInfo(final EjbModule jar) throws OpenEJBException {
    deploymentIds.clear();
    securityRoles.clear();

    final Map<String, EjbDeployment> ejbds = jar.getOpenejbJar().getDeploymentsByEjbName();
    final int beansDeployed = jar.getOpenejbJar().getEjbDeploymentCount();
    final int beansInEjbJar = jar.getEjbJar().getEnterpriseBeans().length;

    if (beansInEjbJar != beansDeployed) {

      for (final EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
        if (!ejbds.containsKey(bean.getEjbName())) {
          ConfigUtils.logger.warning("conf.0018", bean.getEjbName(), jar.getJarLocation());
        }
      }

      final String message =
          messages.format(
              "conf.0008",
              jar.getJarLocation(),
              String.valueOf(beansInEjbJar),
              String.valueOf(beansDeployed));
      logger.warning(message);
      throw new OpenEJBException(message);
    }

    final Map<String, EnterpriseBeanInfo> infos = new HashMap<String, EnterpriseBeanInfo>();
    final Map<String, EnterpriseBean> items = new HashMap<String, EnterpriseBean>();

    final EjbJarInfo ejbJar = new EjbJarInfo();
    ejbJar.path = jar.getJarLocation();
    ejbJar.moduleUri = jar.getModuleUri();
    ejbJar.moduleId = jar.getModuleId();
    if (jar.getEjbJar() != null && jar.getEjbJar().getModuleName() != null) {
      ejbJar.moduleName = jar.getEjbJar().getModuleName();
    } else {
      ejbJar.moduleName = jar.getModuleId();
    }

    ejbJar.watchedResources.addAll(jar.getWatchedResources());

    ejbJar.properties.putAll(jar.getProperties());
    ejbJar.properties.putAll(jar.getOpenejbJar().getProperties());

    for (final EnterpriseBean bean : jar.getEjbJar().getEnterpriseBeans()) {
      final EnterpriseBeanInfo beanInfo;
      if (bean instanceof SessionBean) {
        beanInfo = initSessionBean((SessionBean) bean, ejbJar, ejbds);
      } else if (bean instanceof EntityBean) {
        beanInfo = initEntityBean((EntityBean) bean, ejbds);
      } else if (bean instanceof MessageDrivenBean) {
        beanInfo = initMessageBean((MessageDrivenBean) bean, ejbds);
      } else {
        throw new OpenEJBException("Unknown bean type: " + bean.getClass().getName());
      }
      ejbJar.enterpriseBeans.add(beanInfo);

      if (deploymentIds.contains(beanInfo.ejbDeploymentId)) {
        final String message =
            messages.format(
                "conf.0100", beanInfo.ejbDeploymentId, jar.getJarLocation(), beanInfo.ejbName);
        logger.warning(message);
        throw new OpenEJBException(message);
      }

      deploymentIds.add(beanInfo.ejbDeploymentId);

      beanInfo.codebase = jar.getJarLocation();
      infos.put(beanInfo.ejbName, beanInfo);
      items.put(beanInfo.ejbName, bean);

      if (bean.getSecurityIdentity() != null) {
        beanInfo.runAs = bean.getSecurityIdentity().getRunAs();

        final EjbDeployment deployment = ejbds.get(beanInfo.ejbName);
        if (deployment != null) {
          for (final RoleMapping mapping : deployment.getRoleMapping()) {
            if (mapping.getRoleName().equals(beanInfo.runAs)) {
              beanInfo.runAsUser = mapping.getPrincipalName();
              break;
            }
          }
        }
      }

      initJndiNames(ejbds, beanInfo);
    }

    if (jar.getEjbJar().getAssemblyDescriptor() != null) {
      initInterceptors(jar, ejbJar);
      initSecurityRoles(jar, ejbJar);
      initMethodPermissions(jar, ejbds, ejbJar);
      initExcludesList(jar, ejbds, ejbJar);
      initMethodTransactions(jar, ejbds, ejbJar);
      initMethodConcurrency(jar, ejbds, ejbJar);
      initApplicationExceptions(jar, ejbJar);

      for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
        resolveRoleLinks(bean, items.get(bean.ejbName));
      }
    }

    if (jar.getEjbJar().getRelationships() != null) {
      initRelationships(jar, infos);
    }

    final Beans beans = jar.getBeans();
    if (beans != null) {
      ejbJar.beans = new BeansInfo();
      ejbJar.beans.version = beans.getVersion();
      ejbJar.beans.discoveryMode = beans.getBeanDiscoveryMode();
      if (beans.getScan() != null) {
        for (final Beans.Scan.Exclude exclude : beans.getScan().getExclude()) {
          final ExclusionInfo exclusionInfo = new ExclusionInfo();
          for (final Object config :
              exclude.getIfClassAvailableOrIfClassNotAvailableOrIfSystemProperty()) {
            if (Beans.Scan.Exclude.IfAvailableClassCondition.class.isInstance(config)) {
              exclusionInfo.availableClasses.add(
                  Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
            } else if (Beans.Scan.Exclude.IfNotAvailableClassCondition.class.isInstance(config)) {
              exclusionInfo.notAvailableClasses.add(
                  Beans.Scan.Exclude.ClassCondition.class.cast(config).getName());
            } else if (Beans.Scan.Exclude.IfSystemProperty.class.isInstance(config)) {
              final Beans.Scan.Exclude.IfSystemProperty systemProperty =
                  Beans.Scan.Exclude.IfSystemProperty.class.cast(config);
              if (systemProperty.getValue() == null) {
                exclusionInfo.systemPropertiesPresence.add(systemProperty.getName());
              } else {
                exclusionInfo.systemProperties.put(
                    systemProperty.getName(), systemProperty.getValue());
              }
            } else {
              throw new IllegalArgumentException("Not supported: " + config);
            }
          }

          final BeansInfo.ExclusionEntryInfo exclusionEntryInfo =
              new BeansInfo.ExclusionEntryInfo();
          exclusionEntryInfo.name = exclude.getName();
          exclusionEntryInfo.exclusion = exclusionInfo;
          ejbJar.beans.excludes.add(exclusionEntryInfo);
        }
      }

      ejbJar.beans.interceptors.addAll(beans.getInterceptors());
      ejbJar.beans.decorators.addAll(beans.getDecorators());
      ejbJar.beans.alternativeClasses.addAll(beans.getAlternativeClasses());
      ejbJar.beans.alternativeStereotypes.addAll(beans.getAlternativeStereotypes());

      ejbJar.beans.duplicatedAlternativeClasses.addAll(
          beans.getDuplicatedAlternatives().getClasses());
      ejbJar.beans.duplicatedAlternativeStereotypes.addAll(
          beans.getDuplicatedAlternatives().getStereotypes());
      ejbJar.beans.duplicatedInterceptors.addAll(beans.getDuplicatedInterceptors());
      ejbJar.beans.duplicatedDecorators.addAll(beans.getDuplicatedDecorators());

      ejbJar.beans.startupClasses.addAll(beans.getStartupBeans());

      final Map<URL, String> discoveryModeByUrl = new HashMap<>();
      if (CompositeBeans.class.isInstance(beans)) {
        discoveryModeByUrl.putAll(CompositeBeans.class.cast(beans).getDiscoveryByUrl());
      } else {
        discoveryModeByUrl.put(null, beans.getBeanDiscoveryMode());
      }
      for (final Map.Entry<URL, List<String>> next : beans.getManagedClasses().entrySet()) {
        final URL key = next.getKey();

        final BeansInfo.BDAInfo bdaInfo = new BeansInfo.BDAInfo();
        bdaInfo.managedClasses.addAll(next.getValue());
        bdaInfo.discoveryMode = discoveryModeByUrl.get(key);
        try {
          bdaInfo.uri = key == null ? null : key.toURI();
        } catch (final URISyntaxException e) {
          bdaInfo.uri = null;
        }
        ejbJar.beans.bdas.add(bdaInfo);
      }
    }

    return ejbJar;
  }