Search in sources :

Example 1 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project tomee by apache.

the class Assembler method doCreateResource.

private Object doCreateResource(final Collection<ServiceInfo> infos, final ResourceInfo serviceInfo) throws OpenEJBException {
    // do it early otherwise we can loose it
    final String skipPropertiesFallback = (String) serviceInfo.properties.remove("SkipPropertiesFallback");
    final ObjectRecipe serviceRecipe = createRecipe(infos, serviceInfo);
    final boolean properties = PropertiesFactory.class.getName().equals(serviceInfo.className);
    if ("false".equalsIgnoreCase(serviceInfo.properties.getProperty("SkipImplicitAttributes", "false")) && !properties) {
        serviceRecipe.setProperty("transactionManager", transactionManager);
        serviceRecipe.setProperty("ServiceId", serviceInfo.id);
    }
    serviceInfo.properties.remove("SkipImplicitAttributes");
    // if custom instance allow to skip properties fallback to avoid to set unexpectedly it - connectionProps of DBs
    final AtomicReference<Properties> injectedProperties = new AtomicReference<>();
    if (!"true".equalsIgnoreCase(skipPropertiesFallback)) {
        serviceRecipe.setProperty("properties", new UnsetPropertiesRecipe() {

            @Override
            protected Object internalCreate(final Type expectedType, final boolean lazyRefAllowed) throws ConstructionException {
                final Map<String, Object> original = serviceRecipe.getUnsetProperties();
                final Properties properties = new SuperProperties() {

                    @Override
                    public Object remove(final Object key) {
                        // avoid to log them then
                        original.remove(key);
                        return super.remove(key);
                    }
                }.caseInsensitive(// keep our nice case insensitive feature
                true);
                for (final Map.Entry<String, Object> entry : original.entrySet()) {
                    properties.put(entry.getKey(), entry.getValue());
                }
                injectedProperties.set(properties);
                return properties;
            }
        });
    } else {
        // this is not the best fallback we have but since it is super limited it is acceptable
        final Map<String, Object> unsetProperties = serviceRecipe.getUnsetProperties();
        injectedProperties.set(new Properties() {

            @Override
            public String getProperty(final String key) {
                final Object obj = unsetProperties.get(key);
                return String.class.isInstance(obj) ? String.valueOf(obj) : null;
            }

            @Override
            public Set<String> stringPropertyNames() {
                return unsetProperties.keySet();
            }

            @Override
            public Set<Object> keySet() {
                // noinspection unchecked
                return Set.class.cast(unsetProperties.keySet());
            }

            @Override
            public synchronized boolean containsKey(final Object key) {
                return getProperty(String.valueOf(key)) != null;
            }
        });
    }
    if (serviceInfo.types.contains("DataSource") || serviceInfo.types.contains(DataSource.class.getName())) {
        final Properties props = PropertyPlaceHolderHelper.simpleHolds(serviceInfo.properties);
        if (serviceInfo.properties.containsKey("Definition")) {
            final Object encoding = serviceInfo.properties.remove("DefinitionEncoding");
            try {
                // we catch classcast etc..., if it fails it is not important
                final InputStream is = new ByteArrayInputStream(serviceInfo.properties.getProperty("Definition").getBytes(encoding != null ? encoding.toString() : "ISO-8859-1"));
                final Properties p = new SuperProperties();
                IO.readProperties(is, p);
                for (final Entry<Object, Object> entry : p.entrySet()) {
                    final String key = entry.getKey().toString();
                    if (!props.containsKey(key) && !(key.equalsIgnoreCase("url") && props.containsKey("JdbcUrl"))) {
                        // with @DataSource we can get both, see org.apache.openejb.config.ConvertDataSourceDefinitions.rawDefinition()
                        props.put(key, entry.getValue());
                    }
                }
            } catch (final Exception e) {
            // ignored
            }
        }
        serviceRecipe.setProperty("Definition", PropertiesHelper.propertiesToString(props));
    }
    // else: any other kind of resource relying on it? shouldnt be
    replaceResourceAdapterProperty(serviceRecipe);
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    boolean customLoader = false;
    try {
        if (serviceInfo.classpath != null && serviceInfo.classpath.length > 0) {
            final URL[] urls = new URL[serviceInfo.classpath.length];
            for (int i = 0; i < serviceInfo.classpath.length; i++) {
                urls[i] = serviceInfo.classpath[i].toURL();
            }
            loader = new URLClassLoaderFirst(urls, loader);
            customLoader = true;
            serviceRecipe.setProperty("OpenEJBResourceClasspath", "true");
        }
    } catch (final MalformedURLException e) {
        throw new OpenEJBException("Unable to create a classloader for " + serviceInfo.id, e);
    }
    if (!customLoader && serviceInfo.classpathAPI != null) {
        throw new IllegalArgumentException("custom-api provided but not classpath used for " + serviceInfo.id);
    }
    Object service = serviceRecipe.create(loader);
    if (customLoader) {
        final Collection<Class<?>> apis;
        if (serviceInfo.classpathAPI == null) {
            apis = new ArrayList<>(Arrays.asList(service.getClass().getInterfaces()));
        } else {
            final String[] split = serviceInfo.classpathAPI.split(" *, *");
            apis = new ArrayList<>(split.length);
            final ClassLoader apiLoader = Thread.currentThread().getContextClassLoader();
            for (final String fqn : split) {
                try {
                    apis.add(apiLoader.loadClass(fqn));
                } catch (final ClassNotFoundException e) {
                    throw new IllegalArgumentException(fqn + " not usable as API for " + serviceInfo.id, e);
                }
            }
        }
        if (apis.size() - (apis.contains(Serializable.class) ? 1 : 0) - (apis.contains(Externalizable.class) ? 1 : 0) > 0) {
            service = Proxy.newProxyInstance(loader, apis.toArray(new Class<?>[apis.size()]), new ClassLoaderAwareHandler(null, service, loader));
        }
    // else proxy would be useless
    }
    serviceInfo.unsetProperties = injectedProperties.get();
    // Java Connector spec ResourceAdapters and ManagedConnectionFactories need special activation
    if (service instanceof ResourceAdapter) {
        final ResourceAdapter resourceAdapter = (ResourceAdapter) service;
        // Create a thead pool for work manager
        final int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
        final Executor threadPool;
        if (threadPoolSize <= 0) {
            logger.warning("Thread pool for '" + serviceInfo.id + "' is (unbounded), consider setting a size using: " + serviceInfo.id + ".QueueSize=[size]");
            threadPool = Executors.newCachedThreadPool(new DaemonThreadFactory(serviceInfo.id + "-worker-"));
        } else {
            threadPool = new ExecutorBuilder().size(threadPoolSize).prefix(serviceInfo.id).threadFactory(new DaemonThreadFactory(serviceInfo.id + "-worker-")).build(new Options(serviceInfo.properties, SystemInstance.get().getOptions()));
            logger.info("Thread pool size for '" + serviceInfo.id + "' is (" + threadPoolSize + ")");
        }
        // WorkManager: the resource adapter can use this to dispatch messages or perform tasks
        final WorkManager workManager;
        if (GeronimoTransactionManager.class.isInstance(transactionManager)) {
            final GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;
            final TransactionContextHandler txWorkContextHandler = new TransactionContextHandler(geronimoTransactionManager);
            // use id as default realm name if realm is not specified in service properties
            final String securityRealmName = getStringProperty(serviceInfo.properties, "realm", serviceInfo.id);
            final SecurityContextHandler securityContextHandler = new SecurityContextHandler(securityRealmName);
            final HintsContextHandler hintsContextHandler = new HintsContextHandler();
            final Collection<WorkContextHandler> workContextHandlers = new ArrayList<>();
            workContextHandlers.add(txWorkContextHandler);
            workContextHandlers.add(securityContextHandler);
            workContextHandlers.add(hintsContextHandler);
            workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, workContextHandlers);
        } else {
            workManager = new SimpleWorkManager(threadPool);
        }
        // BootstrapContext: wraps the WorkMananger and XATerminator
        final BootstrapContext bootstrapContext;
        if (transactionManager instanceof GeronimoTransactionManager) {
            bootstrapContext = new GeronimoBootstrapContext(GeronimoWorkManager.class.cast(workManager), (GeronimoTransactionManager) transactionManager, (GeronimoTransactionManager) transactionManager);
        } else if (transactionManager instanceof XATerminator) {
            bootstrapContext = new SimpleBootstrapContext(workManager, (XATerminator) transactionManager);
        } else {
            bootstrapContext = new SimpleBootstrapContext(workManager);
        }
        // start the resource adapter
        try {
            logger.debug("createResource.startingResourceAdapter", serviceInfo.id, service.getClass().getName());
            resourceAdapter.start(bootstrapContext);
        } catch (final ResourceAdapterInternalException e) {
            throw new OpenEJBException(e);
        }
        final Map<String, Object> unset = serviceRecipe.getUnsetProperties();
        unset.remove("threadPoolSize");
        logUnusedProperties(unset, serviceInfo);
        registerAsMBean(serviceInfo.id, "ResourceAdapter", resourceAdapter);
        service = new ResourceAdapterReference(resourceAdapter, threadPool, OPENEJB_RESOURCE_JNDI_PREFIX + serviceInfo.id);
    } else if (service instanceof ManagedConnectionFactory) {
        final ManagedConnectionFactory managedConnectionFactory = (ManagedConnectionFactory) service;
        // connection manager is constructed via a recipe so we automatically expose all cmf properties
        final ObjectRecipe connectionManagerRecipe = new ObjectRecipe(GeronimoConnectionManagerFactory.class, "create");
        connectionManagerRecipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
        connectionManagerRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
        connectionManagerRecipe.setAllProperties(serviceInfo.properties);
        connectionManagerRecipe.setProperty("name", serviceInfo.id);
        connectionManagerRecipe.setProperty("mcf", managedConnectionFactory);
        // standard properties
        connectionManagerRecipe.setProperty("transactionManager", transactionManager);
        ClassLoader classLoader = loader;
        if (classLoader == null) {
            classLoader = getClass().getClassLoader();
        }
        if (classLoader == null) {
            classLoader = ClassLoader.getSystemClassLoader();
        }
        connectionManagerRecipe.setProperty("classLoader", classLoader);
        logger.getChildLogger("service").info("createResource.createConnectionManager", serviceInfo.id, service.getClass().getName());
        // create the connection manager
        final ConnectionManager connectionManager = (ConnectionManager) connectionManagerRecipe.create();
        String txSupport = "xa";
        try {
            txSupport = (String) connectionManagerRecipe.getProperty("transactionSupport");
        } catch (Exception e) {
        // ignore
        }
        if (txSupport == null || txSupport.trim().length() == 0) {
            txSupport = "xa";
        }
        if (connectionManager == null) {
            throw new OpenEJBRuntimeException(messages.format("assembler.invalidConnectionManager", serviceInfo.id));
        }
        final Map<String, Object> unsetA = serviceRecipe.getUnsetProperties();
        final Map<String, Object> unsetB = connectionManagerRecipe.getUnsetProperties();
        final Map<String, Object> unset = new HashMap<>();
        for (final Entry<String, Object> entry : unsetA.entrySet()) {
            if (unsetB.containsKey(entry.getKey())) {
                unset.put(entry.getKey(), entry.getValue());
            }
        }
        // service becomes a ConnectorReference which merges connection manager and mcf
        service = new ConnectorReference(connectionManager, managedConnectionFactory);
        // init cm if needed
        final Object eagerInit = unset.remove("eagerInit");
        if (eagerInit != null && eagerInit instanceof String && "true".equalsIgnoreCase((String) eagerInit) && connectionManager instanceof AbstractConnectionManager) {
            try {
                ((AbstractConnectionManager) connectionManager).doStart();
                try {
                    final Object cf = managedConnectionFactory.createConnectionFactory(connectionManager);
                    if (cf instanceof ConnectionFactory) {
                        final Connection connection = ((ConnectionFactory) cf).getConnection();
                        connection.getMetaData();
                        connection.close();
                    }
                } catch (final Exception e) {
                // no-op: just to force eager init of pool
                }
            } catch (final Exception e) {
                logger.warning("Can't start connection manager", e);
            }
        }
        logUnusedProperties(unset, serviceInfo);
    } else if (service instanceof DataSource) {
        ClassLoader classLoader = loader;
        if (classLoader == null) {
            classLoader = getClass().getClassLoader();
        }
        final ImportSql importer = new ImportSql(classLoader, serviceInfo.id, (DataSource) service);
        if (importer.hasSomethingToImport()) {
            importer.doImport();
        }
        final ObjectRecipe recipe = DataSourceFactory.forgetRecipe(service, serviceRecipe);
        if (recipe != serviceRecipe || !serviceInfo.properties.containsKey("XaDataSource")) {
            logUnusedProperties(recipe, serviceInfo);
        }
        // else logged on xadatasource itself
        final Properties prop = serviceInfo.properties;
        String url = prop.getProperty("JdbcUrl", prop.getProperty("url"));
        if (url == null) {
            url = prop.getProperty("jdbcUrl");
        }
        if (url == null) {
            logger.debug("Unable to find url for " + serviceInfo.id + " will not monitor it");
        } else {
            final String host = extractHost(url);
            if (host != null) {
                remoteResourceMonitor.addHost(host);
                remoteResourceMonitor.registerIfNot();
            }
        }
    } else if (!Properties.class.isInstance(service)) {
        if (serviceInfo.unsetProperties == null || isTemplatizedResource(serviceInfo)) {
            logUnusedProperties(serviceRecipe, serviceInfo);
        }
        // else wait post construct
        registerAsMBean(serviceInfo.id, "Resource", service);
    }
    final ResourceCreated event = new ResourceCreated(service, serviceInfo.id);
    SystemInstance.get().fireEvent(event);
    return event.getReplacement() == null ? service : event.getReplacement();
}
Also used : URLClassLoaderFirst(org.apache.openejb.util.classloader.URLClassLoaderFirst) OpenEJBException(org.apache.openejb.OpenEJBException) MalformedURLException(java.net.MalformedURLException) Serializable(java.io.Serializable) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) TransactionContextHandler(org.apache.geronimo.connector.work.TransactionContextHandler) ArrayList(java.util.ArrayList) GeronimoWorkManager(org.apache.geronimo.connector.work.GeronimoWorkManager) SuperProperties(org.apache.openejb.util.SuperProperties) ExecutorBuilder(org.apache.openejb.util.ExecutorBuilder) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) ConnectionManager(javax.resource.spi.ConnectionManager) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) SimpleWorkManager(org.apache.openejb.core.transaction.SimpleWorkManager) WorkManager(javax.resource.spi.work.WorkManager) GeronimoWorkManager(org.apache.geronimo.connector.work.GeronimoWorkManager) ResourceAdapter(javax.resource.spi.ResourceAdapter) SecurityContextHandler(org.apache.openejb.core.security.SecurityContextHandler) UnsetPropertiesRecipe(org.apache.xbean.recipe.UnsetPropertiesRecipe) GeronimoConnectionManagerFactory(org.apache.openejb.resource.GeronimoConnectionManagerFactory) DataSource(javax.sql.DataSource) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) HintsContextHandler(org.apache.geronimo.connector.work.HintsContextHandler) SimpleBootstrapContext(org.apache.openejb.core.transaction.SimpleBootstrapContext) ByteArrayInputStream(java.io.ByteArrayInputStream) PropertiesFactory(org.apache.openejb.resource.PropertiesFactory) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) ConnectorReference(org.apache.openejb.core.ConnectorReference) Options(org.apache.openejb.loader.Options) XATerminator(javax.resource.spi.XATerminator) HashSet(java.util.HashSet) Set(java.util.Set) UrlSet(org.apache.xbean.finder.UrlSet) ClassLoaderAwareHandler(org.apache.openejb.util.classloader.ClassLoaderAwareHandler) DaemonThreadFactory(org.apache.openejb.util.DaemonThreadFactory) SimpleWorkManager(org.apache.openejb.core.transaction.SimpleWorkManager) SimpleBootstrapContext(org.apache.openejb.core.transaction.SimpleBootstrapContext) GeronimoBootstrapContext(org.apache.geronimo.connector.GeronimoBootstrapContext) BootstrapContext(javax.resource.spi.BootstrapContext) AbstractConnectionManager(org.apache.geronimo.connector.outbound.AbstractConnectionManager) SuperProperties(org.apache.openejb.util.SuperProperties) Properties(java.util.Properties) URL(java.net.URL) Entry(java.util.Map.Entry) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) ConnectionFactory(javax.resource.cci.ConnectionFactory) Executor(java.util.concurrent.Executor) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) ResourceCreated(org.apache.openejb.assembler.classic.event.ResourceCreated) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(javax.resource.cci.Connection) AtomicReference(java.util.concurrent.atomic.AtomicReference) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) InvalidObjectException(java.io.InvalidObjectException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ObjectStreamException(java.io.ObjectStreamException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) UndeployException(org.apache.openejb.UndeployException) DefinitionException(javax.enterprise.inject.spi.DefinitionException) ConstructionException(org.apache.xbean.recipe.ConstructionException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ValidationException(javax.validation.ValidationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) DuplicateDeploymentIdException(org.apache.openejb.DuplicateDeploymentIdException) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) DeploymentException(javax.enterprise.inject.spi.DeploymentException) NoSuchApplicationException(org.apache.openejb.NoSuchApplicationException) MalformedURLException(java.net.MalformedURLException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) BeanType(org.apache.openejb.BeanType) Type(java.lang.reflect.Type) TransactionType(org.apache.openejb.core.transaction.TransactionType) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) ConstructionException(org.apache.xbean.recipe.ConstructionException) WorkContextHandler(org.apache.geronimo.connector.work.WorkContextHandler)

Example 2 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project Payara by payara.

the class ConnectorConfigParserUtils method introspectJavaBean.

public Properties introspectJavaBean(String className, Set ddPropsSet, boolean associateResourceAdapter, String resourceAdapterName) throws ConnectorRuntimeException {
    Class loadedClass = loadClass(className, resourceAdapterName);
    Object loadedInstance = instantiate(loadedClass);
    try {
        if (associateResourceAdapter) {
            ActiveResourceAdapter activeRA = ConnectorRegistry.getInstance().getActiveResourceAdapter(resourceAdapterName);
            if (activeRA == null) {
                // Check and Load RAR
                ConnectorRuntime.getRuntime().loadDeferredResourceAdapter(resourceAdapterName);
                activeRA = ConnectorRegistry.getInstance().getActiveResourceAdapter(resourceAdapterName);
            }
            // Associate RAR
            if (activeRA instanceof ActiveOutboundResourceAdapter) {
                ResourceAdapter raInstance = activeRA.getResourceAdapter();
                if (loadedInstance instanceof ResourceAdapterAssociation) {
                    ((ResourceAdapterAssociation) loadedInstance).setResourceAdapter(raInstance);
                }
            }
        }
    } catch (Exception e) {
        _logger.log(Level.WARNING, "rardeployment.error_associating_ra", e);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Exception while associating the resource adapter" + "to the JavaBean", e);
        }
    }
    return introspectJavaBean(loadedInstance, ddPropsSet);
}
Also used : ResourceAdapterAssociation(javax.resource.spi.ResourceAdapterAssociation) ResourceAdapter(javax.resource.spi.ResourceAdapter)

Example 3 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project cxf by apache.

the class ResourceAdapterImplTest method testConstructorWithProperties.

@Test
public void testConstructorWithProperties() throws Exception {
    Properties props = new Properties();
    ResourceAdapterImpl rai = new ResourceAdapterImpl(props);
    assertTrue("constructed with props", rai instanceof ResourceAdapterImpl);
    assertTrue("constructed with props", rai instanceof ResourceBean);
    assertTrue("constructed with props", rai instanceof ResourceAdapter);
    assertTrue("constructed with props", rai instanceof Serializable);
}
Also used : Serializable(java.io.Serializable) ResourceBean(org.apache.cxf.jca.core.resourceadapter.ResourceBean) ResourceAdapter(javax.resource.spi.ResourceAdapter) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project Payara by payara.

the class ConnectorMessageBeanClient method setup.

/**
 * Gets executed as part of message bean deployment. Creates the
 * <code>ActivationSpec</code> javabean and does endpointfactory
 * activation with the resource adapter. This code also converts
 * all J2EE 1.3 MDB properties to MQ resource adapter activation
 * spec properties, if user doesnt specifies resource adapter
 * module name in sun-ejb-jar.xml of the MDB. This is done using
 * <code>com.sun.enterprise.connector.system.ActiveJmsResourceAdapter
 * </code>
 *
 * @param messageBeanPM <code>MessageBeanProtocolManager</code> object.
 */
public void setup(MessageBeanProtocolManager messageBeanPM) throws Exception {
    ClassLoader loader = descriptor_.getEjbBundleDescriptor().getClassLoader();
    if (loader == null) {
        loader = Thread.currentThread().getContextClassLoader();
    }
    beanClass_ = loader.loadClass(descriptor_.getEjbClassName());
    messageBeanPM_ = messageBeanPM;
    String resourceAdapterMid = getResourceAdapterMid(descriptor_);
    ActiveInboundResourceAdapter aira = getActiveResourceAdapter(resourceAdapterMid);
    aira.updateMDBRuntimeInfo(descriptor_, messageBeanPM_.getPoolDescriptor());
    // the resource adapter this MDB client is deployed to
    ResourceAdapter ra = aira.getResourceAdapter();
    if (ra == null) {
        String i18nMsg = localStrings.getString("msg-bean-client.ra.class.not.specified", resourceAdapterMid);
        throw new ConnectorRuntimeException(i18nMsg);
    }
    ConnectorDescriptor desc = aira.getDescriptor();
    MessageListener msgListener = getMessageListener(desc);
    String activationSpecClassName = null;
    if (msgListener != null) {
        activationSpecClassName = msgListener.getActivationSpecClass();
    }
    if (activationSpecClassName != null) {
        if (logger.isLoggable(Level.FINEST)) {
            String msg = "ActivationSpecClassName = " + activationSpecClassName;
            logger.log(Level.FINEST, msg);
        }
        try {
            ActivationSpec activationSpec = getActivationSpec(aira, activationSpecClassName);
            activationSpec.setResourceAdapter(ra);
            // at this stage, activation-spec is created, config properties merged with ejb-descriptor.
            // validate activation-spec now
            ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
            runtime.getConnectorBeanValidator().validateJavaBean(activationSpec, resourceAdapterMid);
            aira.validateActivationSpec(activationSpec);
            myState = BLOCKED;
            ra.endpointActivation(this, activationSpec);
            aira.addEndpointFactoryInfo(beanID_, new MessageEndpointFactoryInfo(this, activationSpec));
        } catch (Exception ex) {
            Object[] args = new Object[] { resourceAdapterMid, activationSpecClassName, ex };
            logger.log(Level.WARNING, "endpoint.activation.failure", args);
            throw (Exception) (new Exception()).initCause(ex);
        }
    } else {
        // FIXME  throw some exception here.
        throw new Exception("Unsupported message listener type");
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ActivationSpec(javax.resource.spi.ActivationSpec) MessageListener(com.sun.enterprise.deployment.MessageListener) ActiveResourceAdapter(com.sun.enterprise.connectors.ActiveResourceAdapter) ResourceAdapter(javax.resource.spi.ResourceAdapter) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) UnavailableException(javax.resource.spi.UnavailableException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Example 5 with ResourceAdapter

use of javax.resource.spi.ResourceAdapter in project Payara by payara.

the class ActiveRAFactory method createActiveResourceAdapter.

/**
 * Creates an active resource adapter.
 *
 * @param cd         Deployment descriptor object for connectors.
 * @param moduleName Module name of the resource adapter.
 * @param loader     Class Loader,
 * @return An instance of <code> ActiveResourceAdapter </code> object.
 * @throws ConnectorRuntimeException when unable to create the runtime for RA
 */
public ActiveResourceAdapter createActiveResourceAdapter(ConnectorDescriptor cd, String moduleName, ClassLoader loader) throws ConnectorRuntimeException {
    ActiveResourceAdapter activeResourceAdapter = null;
    ClassLoader originalContextClassLoader = null;
    ProcessEnvironment.ProcessType processType = ConnectorRuntime.getRuntime().getEnvironment();
    ResourceAdapter ra = null;
    String raClass = cd.getResourceAdapterClass();
    try {
        if (raClass != null && !raClass.equals("")) {
            if (processType == ProcessEnvironment.ProcessType.Server) {
                ra = (ResourceAdapter) loader.loadClass(raClass).newInstance();
            } else {
                // ra = (ResourceAdapter) Class.forName(raClass).newInstance();
                ra = (ResourceAdapter) Thread.currentThread().getContextClassLoader().loadClass(raClass).newInstance();
            }
        }
        originalContextClassLoader = Utility.setContextClassLoader(loader);
        activeResourceAdapter = instantiateActiveResourceAdapter(cd, moduleName, loader, ra);
    } catch (ClassNotFoundException Ex) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
        cre.initCause(Ex);
        _logger.log(Level.SEVERE, "rardeployment.class_not_found", raClass);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    } catch (InstantiationException Ex) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
        cre.initCause(Ex);
        _logger.log(Level.SEVERE, "rardeployment.class_instantiation_error", raClass);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    } catch (IllegalAccessException Ex) {
        ConnectorRuntimeException cre = new ConnectorRuntimeException("Error in creating active RAR");
        cre.initCause(Ex);
        _logger.log(Level.SEVERE, "rardeployment.illegalaccess_error", raClass);
        _logger.log(Level.SEVERE, "", cre);
        throw cre;
    } finally {
        if (originalContextClassLoader != null) {
            Utility.setContextClassLoader(originalContextClassLoader);
        }
    }
    return activeResourceAdapter;
}
Also used : ResourceAdapter(javax.resource.spi.ResourceAdapter) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment)

Aggregations

ResourceAdapter (javax.resource.spi.ResourceAdapter)11 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)3 ActiveJmsResourceAdapter (com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter)3 Method (java.lang.reflect.Method)3 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)2 MQAddressList (com.sun.enterprise.connectors.jms.system.MQAddressList)2 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 ObjectStreamException (java.io.ObjectStreamException)2 Serializable (java.io.Serializable)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 Properties (java.util.Properties)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 DefinitionException (javax.enterprise.inject.spi.DefinitionException)2 DeploymentException (javax.enterprise.inject.spi.DeploymentException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2