Search in sources :

Example 16 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class PoolManagerImpl method getResourceReference.

public ResourceReferenceDescriptor getResourceReference(String jndiName, String logicalName) {
    Set descriptors = getConnectorRuntime().getResourceReferenceDescriptor();
    List matchingRefs = new ArrayList();
    if (descriptors != null) {
        for (Object descriptor : descriptors) {
            ResourceReferenceDescriptor ref = (ResourceReferenceDescriptor) descriptor;
            String name = ref.getJndiName();
            if (jndiName.equals(name)) {
                matchingRefs.add(ref);
            }
        }
    }
    if (matchingRefs.size() == 1) {
        return (ResourceReferenceDescriptor) matchingRefs.get(0);
    } else if (matchingRefs.size() > 1) {
        Iterator it = matchingRefs.iterator();
        while (it.hasNext()) {
            ResourceReferenceDescriptor rrd = (ResourceReferenceDescriptor) it.next();
            String refName = rrd.getName();
            if (refName != null && logicalName != null) {
                refName = getJavaName(refName);
                if (refName.equals(getJavaName(logicalName))) {
                    return rrd;
                }
            }
        }
    }
    return null;
}
Also used : ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor)

Example 17 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class EjbBundleTracerVisitor method accept.

protected void accept(EjbDescriptor ejb) {
    logInfo("==================");
    logInfo(ejb.getType() + " Bean " + ejb.getName());
    logInfo("\thomeClassName " + ejb.getHomeClassName());
    logInfo("\tremoteClassName " + ejb.getRemoteClassName());
    logInfo("\tlocalhomeClassName " + ejb.getLocalHomeClassName());
    logInfo("\tlocalClassName " + ejb.getLocalClassName());
    logInfo("\tremoteBusinessIntfs " + ejb.getRemoteBusinessClassNames());
    logInfo("\tlocalBusinessIntfs " + ejb.getLocalBusinessClassNames());
    logInfo("\tjndiName " + ejb.getJndiName());
    logInfo("\tejbClassName " + ejb.getEjbClassName());
    logInfo("\ttransactionType " + ejb.getTransactionType());
    if (ejb.getUsesCallerIdentity() == false) {
        logInfo("\trun-as role " + ejb.getRunAsIdentity());
    } else {
        logInfo("\tuse-caller-identity " + ejb.getUsesCallerIdentity());
    }
    for (EjbReference aRef : ejb.getEjbReferenceDescriptors()) {
        accept(aRef);
    }
    for (Iterator e = ejb.getPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
        MethodPermission mp = (MethodPermission) e.next();
        Set methods = (Set) ejb.getPermissionedMethodsByPermission().get(mp);
        accept(mp, methods);
    }
    if (ejb.getStyledPermissionedMethodsByPermission() != null) {
        for (Iterator e = ejb.getStyledPermissionedMethodsByPermission().keySet().iterator(); e.hasNext(); ) {
            MethodPermission mp = (MethodPermission) e.next();
            Set methods = (Set) ejb.getStyledPermissionedMethodsByPermission().get(mp);
            accept(mp, methods);
        }
    }
    for (RoleReference roleRef : ejb.getRoleReferences()) {
        accept(roleRef);
    }
    for (Iterator e = ejb.getMethodContainerTransactions().keySet().iterator(); e.hasNext(); ) {
        MethodDescriptor md = (MethodDescriptor) e.next();
        ContainerTransaction ct = (ContainerTransaction) ejb.getMethodContainerTransactions().get(md);
        accept(md, ct);
    }
    for (EnvironmentProperty envProp : ejb.getEnvironmentProperties()) {
        accept(envProp);
    }
    for (ResourceReferenceDescriptor next : ejb.getResourceReferenceDescriptors()) {
        accept(next);
    }
    for (ResourceEnvReferenceDescriptor next : ejb.getResourceEnvReferenceDescriptors()) {
        accept(next);
    }
    for (MessageDestinationReferencer next : ejb.getMessageDestinationReferenceDescriptors()) {
        accept(next);
    }
    // referencer as well.
    if (ejb.getType().equals(EjbMessageBeanDescriptor.TYPE)) {
        MessageDestinationReferencer msgDestReferencer = (MessageDestinationReferencer) ejb;
        if (msgDestReferencer.getMessageDestinationLinkName() != null) {
            accept(msgDestReferencer);
        }
    }
    for (ServiceReferenceDescriptor sref : ejb.getServiceReferenceDescriptors()) {
        accept(sref);
    }
    if (ejb instanceof EjbCMPEntityDescriptor) {
        EjbCMPEntityDescriptor cmp = (EjbCMPEntityDescriptor) ejb;
        PersistenceDescriptor persistenceDesc = cmp.getPersistenceDescriptor();
        for (Object fd : persistenceDesc.getCMPFields()) {
            accept((FieldDescriptor) fd);
        }
        for (Object o : persistenceDesc.getQueriedMethods()) {
            if (o instanceof MethodDescriptor) {
                QueryDescriptor qd = persistenceDesc.getQueryFor((MethodDescriptor) o);
                accept(qd);
            }
        }
    }
}
Also used : Set(java.util.Set) ServiceReferenceDescriptor(com.sun.enterprise.deployment.ServiceReferenceDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission) EjbReference(com.sun.enterprise.deployment.types.EjbReference) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) MessageDestinationReferencer(com.sun.enterprise.deployment.types.MessageDestinationReferencer) QueryDescriptor(org.glassfish.ejb.deployment.descriptor.QueryDescriptor) RoleReference(com.sun.enterprise.deployment.RoleReference) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) Iterator(java.util.Iterator) ResourceEnvReferenceDescriptor(com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)

Example 18 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class EjbBundleValidator method accept.

/**
 * visits an ejb descriptor
 * @param ejb descriptor
 */
@Override
public void accept(EjbDescriptor ejb) {
    // application
    if (ejb instanceof DummyEjbDescriptor) {
        throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.exceptionbeanbundle", "Referencing error: this bundle has no bean of name: {0}", new Object[] { ejb.getName() }));
    }
    this.ejb = ejb;
    setDOLDefault(ejb);
    computeRuntimeDefault(ejb);
    checkDependsOn(ejb);
    validateConcurrencyMetadata(ejb);
    validateStatefulTimeout(ejb);
    validatePassivationConfiguration(ejb);
    try {
        ClassLoader cl = ejb.getEjbBundleDescriptor().getClassLoader();
        Class ejbClass = cl.loadClass(ejb.getEjbClassName());
        if (Globals.getDefaultHabitat() == null) {
            return;
        }
        if (ejb instanceof EjbSessionDescriptor) {
            EjbSessionDescriptor desc = (EjbSessionDescriptor) ejb;
            if (desc.isClustered()) {
                if (!desc.isSingleton()) {
                    throw new IllegalArgumentException("Only Sinlgeton beans can be Clustered: " + desc.getName());
                }
                if (!Serializable.class.isAssignableFrom(ejbClass)) {
                    throw new IllegalStateException(String.format("Clustered Singleton %s must be Serializable", desc.getName()));
                }
                if (desc.getClusteredLockType() == DistributedLockType.LOCK) {
                    throw new IllegalStateException(String.format("Clustered Singleton %s - incompatible lock type LOCK", desc.getName()));
                }
            }
        }
        // Perform 2.x style TimedObject processing if the class
        // hasn't already been identified as a timed object.
        AnnotationTypesProvider provider = Globals.getDefaultHabitat().getService(AnnotationTypesProvider.class, "EJB");
        if (provider == null) {
            throw new RuntimeException("Cannot find AnnotationTypesProvider named 'EJB'");
        }
        if (ejb.getEjbTimeoutMethod() == null && provider.getType("javax.ejb.TimedObject").isAssignableFrom(ejbClass)) {
            MethodDescriptor timedObjectMethod = new MethodDescriptor("ejbTimeout", "TimedObject timeout method", new String[] { "javax.ejb.Timer" }, MethodDescriptor.TIMER_METHOD);
            ejb.setEjbTimeoutMethod(timedObjectMethod);
        } else if (ejb.getEjbTimeoutMethod() != null) {
            // If timeout-method was only processed from the descriptor,
            // we need to create a MethodDescriptor using the actual
            // Method object corresponding to the timeout method.  The
            // timeout method can have any access type and be anywhere
            // in the bean class hierarchy.
            MethodDescriptor timeoutMethodDescOrig = ejb.getEjbTimeoutMethod();
            MethodDescriptor timeoutMethodDesc = processTimeoutMethod(ejb, timeoutMethodDescOrig, provider, ejbClass);
            ejb.setEjbTimeoutMethod(timeoutMethodDesc);
        }
        for (ScheduledTimerDescriptor sd : ejb.getScheduledTimerDescriptors()) {
            try {
                // This method creates new schedule and attempts to calculate next timeout.
                // The second part ensures that all values that are not verified up-front
                // are also validated.
                // It does not check that such timeout date is a valid date.
                EJBTimerSchedule.isValid(sd);
            } catch (Exception e) {
                throw new RuntimeException(ejb.getName() + ": Invalid schedule " + "defined on method " + sd.getTimeoutMethod().getFormattedString() + ": " + e.getMessage());
            }
            MethodDescriptor timeoutMethodDescOrig = sd.getTimeoutMethod();
            MethodDescriptor timeoutMethodDesc = processTimeoutMethod(ejb, timeoutMethodDescOrig, provider, ejbClass);
            sd.setTimeoutMethod(timeoutMethodDesc);
        }
    } catch (Exception e) {
        RuntimeException re = new RuntimeException("Error processing EjbDescriptor");
        re.initCause(e);
        throw re;
    }
    // has to be derived from target inject method or inject field.
    for (InjectionCapable injectable : ejb.getEjbBundleDescriptor().getInjectableResources(ejb)) {
        accept(injectable);
    }
    for (Iterator itr = ejb.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
        EjbReference aRef = (EjbReference) itr.next();
        accept(aRef);
    }
    for (Iterator it = ejb.getResourceReferenceDescriptors().iterator(); it.hasNext(); ) {
        ResourceReferenceDescriptor next = (ResourceReferenceDescriptor) it.next();
        accept(next);
    }
    for (Iterator it = ejb.getResourceEnvReferenceDescriptors().iterator(); it.hasNext(); ) {
        ResourceEnvReferenceDescriptor next = (ResourceEnvReferenceDescriptor) it.next();
        accept(next);
    }
    for (Iterator it = ejb.getMessageDestinationReferenceDescriptors().iterator(); it.hasNext(); ) {
        MessageDestinationReferencer next = (MessageDestinationReferencer) it.next();
        accept(next);
    }
    // referencer as well.
    if (ejb.getType().equals(EjbMessageBeanDescriptor.TYPE)) {
        if (ejb instanceof MessageDestinationReferencer) {
            MessageDestinationReferencer msgDestReferencer = (MessageDestinationReferencer) ejb;
            if (msgDestReferencer.getMessageDestinationLinkName() != null) {
                accept(msgDestReferencer);
            }
        }
    }
    Set serviceRefs = ejb.getServiceReferenceDescriptors();
    for (Iterator itr = serviceRefs.iterator(); itr.hasNext(); ) {
        accept((ServiceReferenceDescriptor) itr.next());
    }
    if (ejb instanceof EjbCMPEntityDescriptor) {
        EjbCMPEntityDescriptor cmp = (EjbCMPEntityDescriptor) ejb;
        PersistenceDescriptor persistenceDesc = cmp.getPersistenceDescriptor();
        for (Iterator e = persistenceDesc.getCMPFields().iterator(); e.hasNext(); ) {
            FieldDescriptor fd = (FieldDescriptor) e.next();
            accept(fd);
        }
    }
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) DummyEjbDescriptor(org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor) ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbReference(com.sun.enterprise.deployment.types.EjbReference) PersistenceDescriptor(org.glassfish.ejb.deployment.descriptor.PersistenceDescriptor) MessageDestinationReferencer(com.sun.enterprise.deployment.types.MessageDestinationReferencer) InjectionCapable(com.sun.enterprise.deployment.InjectionCapable) Iterator(java.util.Iterator) ResourceEnvReferenceDescriptor(com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) AnnotationTypesProvider(org.glassfish.internal.deployment.AnnotationTypesProvider)

Example 19 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class EjbDescriptor method addResourceReferenceDescriptor.

/**
 * Adds a resource reference to me.
 * @param resourceReference
 */
@Override
public final void addResourceReferenceDescriptor(ResourceReferenceDescriptor resourceReference) {
    try {
        ResourceReferenceDescriptor existing = getResourceReferenceByName(resourceReference.getName());
        for (InjectionTarget next : resourceReference.getInjectionTargets()) {
            existing.addInjectionTarget(next);
        }
    } catch (IllegalArgumentException e) {
        if (env != null)
            env.addResourceReferenceDescriptor(resourceReference);
        else
            resourceReferences.add(resourceReference);
    }
}
Also used : InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor)

Example 20 with ResourceReferenceDescriptor

use of com.sun.enterprise.deployment.ResourceReferenceDescriptor in project Payara by payara.

the class ResourceAuth method check.

/**
 * Resource authority exists test.  Must be Container or Servlet.
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Set resourceRefs;
    ResourceReferenceDescriptor resrefDes;
    Iterator itr;
    String resAuth;
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    if (!descriptor.getResourceReferenceDescriptors().isEmpty()) {
        // get the Resource Reference Descriptors set
        resourceRefs = descriptor.getResourceReferenceDescriptors();
        itr = resourceRefs.iterator();
        // test the Resource Reference Descriptor
        while (itr.hasNext()) {
            resrefDes = (ResourceReferenceDescriptor) itr.next();
            resAuth = resrefDes.getAuthorization();
            if (resAuth.equals("Application") || resAuth.equals("Container")) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Resource reference has valid authorization."));
            } else {
                oneFailed = true;
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Resource reference auth has to be either Container or Application."));
            }
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no resource references defined within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else {
        result.setStatus(Result.PASSED);
    }
    return result;
}
Also used : ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor)

Aggregations

ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)24 Iterator (java.util.Iterator)11 Set (java.util.Set)8 Result (com.sun.enterprise.tools.verifier.Result)6 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)6 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)5 EjbReference (com.sun.enterprise.deployment.types.EjbReference)4 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)3 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 MessageDestinationRuntimeNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRuntimeNode)2 RuntimeDescriptorNode (com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode)2 WebServiceRuntimeNode (com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode)2 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)2 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)2