Search in sources :

Example 1 with InstrumentableClassLoader

use of org.glassfish.api.deployment.InstrumentableClassLoader in project Payara by payara.

the class DefaultProviderVerification method check.

public Result check(Descriptor descriptor) {
    PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
    Result result = getInitializedResult();
    result.setStatus(Result.PASSED);
    PersistenceProvider provider;
    final String appLocation = getVerifierContext().getAbstractArchive().getURI().getPath();
    final InstrumentableClassLoader cl = InstrumentableClassLoader.class.cast(pu.getParent().getClassLoader());
    PersistenceUnitInfo pi = new AVKPersistenceUnitInfoImpl(pu, appLocation, cl);
    logger.fine("PersistenceInfo for PU is :\n" + pi);
    Properties props = new Properties();
    // This property is set to indicate that TopLink should only
    // validate the descriptors etc. and not try to login to database.
    props.put(PersistenceUnitProperties.VALIDATION_ONLY_PROPERTY, // NOI18N
    "TRUE");
    // This property is used so that TopLink throws validation exceptions
    // as opposed to printing CONFIG level messages to console.
    // e.g. if mapping file does not exist, we will get an exception.
    props.put(PersistenceUnitProperties.THROW_EXCEPTIONS, // NOI18N
    "TRUE");
    // the following property is needed as it initializes the logger in TL
    props.put(PersistenceUnitProperties.TARGET_SERVER, // NOI18N
    "SunAS9");
    // Turn off enhancement during verification. For details,
    // refer to http://glassfish.dev.java.net/issues/show_bug.cgi?id=3295
    props.put(PersistenceUnitProperties.WEAVING, "FALSE");
    provider = new org.eclipse.persistence.jpa.PersistenceProvider();
    EntityManagerFactory emf = null;
    try {
        emf = provider.createContainerEntityManagerFactory(pi, props);
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "emf = {0}", emf);
    } catch (IntegrityException ie) {
        result.setStatus(Result.FAILED);
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        for (Object o : ie.getIntegrityChecker().getCaughtExceptions()) {
            Exception e = Exception.class.cast(o);
            result.addErrorDetails(e.getMessage());
        }
    } catch (ValidationException ve) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(ve.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", ve);
    } catch (DatabaseException de) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(de.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", de);
    } catch (PersistenceException pe) {
        addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
        result.failed(pe.getMessage());
        logger.logp(Level.FINE, "DefaultProviderVerification", "check", "Following exception occurred", pe);
    } finally {
        if (emf != null) {
            emf.close();
        }
    }
    return result;
}
Also used : ValidationException(org.eclipse.persistence.exceptions.ValidationException) InstrumentableClassLoader(org.glassfish.api.deployment.InstrumentableClassLoader) PersistenceProvider(javax.persistence.spi.PersistenceProvider) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) AVKPersistenceUnitInfoImpl(com.sun.enterprise.tools.verifier.persistence.AVKPersistenceUnitInfoImpl) Properties(java.util.Properties) PersistenceUnitProperties(org.eclipse.persistence.config.PersistenceUnitProperties) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) PersistenceException(javax.persistence.PersistenceException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) ValidationException(org.eclipse.persistence.exceptions.ValidationException) Result(com.sun.enterprise.tools.verifier.Result) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceException(javax.persistence.PersistenceException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor)

Example 2 with InstrumentableClassLoader

use of org.glassfish.api.deployment.InstrumentableClassLoader in project Payara by payara.

the class DeploymentContextImpl method addTransformer.

/**
 * Add a new ClassFileTransformer to the context
 *
 * @param transformer the new class file transformer to register to the new application
 * class loader
 * @throws UnsupportedOperationException if the class loader we use does not support the
 * registration of a ClassFileTransformer. In such case, the deployer should either fail
 * deployment or revert to a mode without the byteocode enhancement feature.
 */
public void addTransformer(ClassFileTransformer transformer) {
    InstrumentableClassLoader icl = InstrumentableClassLoader.class.cast(getFinalClassLoader());
    String isComposite = getAppProps().getProperty(ServerTags.IS_COMPOSITE);
    if (Boolean.valueOf(isComposite) && icl instanceof URLClassLoader) {
        URLClassLoader urlCl = (URLClassLoader) icl;
        boolean isAppLevel = (getParentContext() == null);
        if (isAppLevel) {
            // for ear lib PUs, let's install the
            // tranformers with the EarLibClassLoader
            icl = InstrumentableClassLoader.class.cast(urlCl.getParent().getParent());
        } else {
            // for modules inside the ear, let's install the
            // transformers with the EarLibClassLoader in
            // addition to installing them to module classloader
            ClassLoader libCl = urlCl.getParent().getParent();
            if (!(libCl instanceof URLClassLoader)) {
                // web module
                libCl = libCl.getParent();
            }
            if (libCl instanceof URLClassLoader) {
                InstrumentableClassLoader libIcl = InstrumentableClassLoader.class.cast(libCl);
                libIcl.addTransformer(transformer);
            }
        }
    }
    icl.addTransformer(transformer);
}
Also used : InstrumentableClassLoader(org.glassfish.api.deployment.InstrumentableClassLoader) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) InstrumentableClassLoader(org.glassfish.api.deployment.InstrumentableClassLoader)

Aggregations

InstrumentableClassLoader (org.glassfish.api.deployment.InstrumentableClassLoader)2 PersistenceUnitDescriptor (com.sun.enterprise.deployment.PersistenceUnitDescriptor)1 Result (com.sun.enterprise.tools.verifier.Result)1 AVKPersistenceUnitInfoImpl (com.sun.enterprise.tools.verifier.persistence.AVKPersistenceUnitInfoImpl)1 URLClassLoader (java.net.URLClassLoader)1 Properties (java.util.Properties)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 PersistenceException (javax.persistence.PersistenceException)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 PersistenceUnitProperties (org.eclipse.persistence.config.PersistenceUnitProperties)1 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)1 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)1 ValidationException (org.eclipse.persistence.exceptions.ValidationException)1