Search in sources :

Example 1 with SetMethodAction

use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.

the class ConnectorMessageBeanClient method getActivationSpec.

private ActivationSpec getActivationSpec(ActiveInboundResourceAdapter aira, String activationSpecClassName) throws Exception {
    ClassLoader cl = aira.getClassLoader();
    Class aClass = cl.loadClass(activationSpecClassName);
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "classloader = " + aClass.getClassLoader());
        logger.log(Level.FINEST, "classloader parent = " + aClass.getClassLoader().getParent());
    }
    ActivationSpec activationSpec = (ActivationSpec) aClass.newInstance();
    Set props = ConnectorsUtil.getMergedActivationConfigProperties(getDescriptor());
    AccessController.doPrivileged(new SetMethodAction(activationSpec, props));
    return activationSpec;
}
Also used : Set(java.util.Set) ActivationSpec(javax.resource.spi.ActivationSpec) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 2 with SetMethodAction

use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.

the class ActiveJmsResourceAdapter method createManagedConnectionFactory.

/**
 * Creates ManagedConnection Factory instance. For any property that is
 * for supporting AS7 imq properties, resource adapter has a set method
 * setProperty(String,String). All as7 properties starts with "imq".
 * MQ Adapter supports this only for backward compatibility.
 *
 * @param cpr <code>ConnectorConnectionPool</code> object
 * @param loader Class Loader.
 * @return
 */
@Override
public ManagedConnectionFactory createManagedConnectionFactory(com.sun.enterprise.connectors.ConnectorConnectionPool cpr, ClassLoader loader) {
    ManagedConnectionFactory mcf = super.createManagedConnectionFactory(cpr, loader);
    if (mcf != null) {
        Set s = cpr.getConnectorDescriptorInfo().getMCFConfigProperties();
        Iterator it = s.iterator();
        while (it.hasNext()) {
            ConnectorConfigProperty prop = (ConnectorConfigProperty) it.next();
            String propName = prop.getName();
            // setProperty(String,String) method.
            if (propName.startsWith("imq") && !"".equals(prop.getValue())) {
                try {
                    Method meth = mcf.getClass().getMethod(SETTER, new Class[] { java.lang.String.class, java.lang.String.class });
                    meth.invoke(mcf, new Object[] { prop.getName(), prop.getValueObject() });
                } catch (NoSuchMethodException ex) {
                    if (_logger.isLoggable(Level.WARNING)) {
                        _logger.log(Level.WARNING, JMSLoggerInfo.NO_SUCH_METHOD, new Object[] { SETTER, mcf.getClass().getName() });
                    }
                } catch (Exception ex) {
                    LogHelper.log(_logger, Level.SEVERE, JMSLoggerInfo.ERROR_EXECUTE_METHOD, ex, SETTER, mcf.getClass().getName());
                }
            }
        }
        // CR 6591307- Fix for properties getting overridden when setRA is called. Resetting the  properties if the RA is the JMS RA
        String moduleName = this.getModuleName();
        if (ConnectorAdminServiceUtils.isJMSRA(moduleName)) {
            try {
                Set configProperties = cpr.getConnectorDescriptorInfo().getMCFConfigProperties();
                Object[] array = configProperties.toArray();
                for (int i = 0; i < array.length; i++) {
                    if (array[i] instanceof ConnectorConfigProperty) {
                        ConnectorConfigProperty property = (ConnectorConfigProperty) array[i];
                        if (ActiveJmsResourceAdapter.ADDRESSLIST.equals(property.getName())) {
                            if (property.getValue() == null || "".equals(property.getValue()) || "localhost".equals(property.getValue())) {
                                _logger.log(Level.FINE, "raraddresslist.default.value : " + property.getValue());
                                configProperties.remove(property);
                            }
                        }
                    }
                }
                SetMethodAction setMethodAction = new SetMethodAction(mcf, configProperties);
                setMethodAction.run();
            } catch (Exception Ex) {
                final String mcfClass = cpr.getConnectorDescriptorInfo().getManagedConnectionFactoryClass();
                if (_logger.isLoggable(Level.WARNING)) {
                    _logger.log(Level.WARNING, JMSLoggerInfo.RARDEPLOYMENT_MCF_ERROR, new Object[] { mcfClass, Ex.getMessage() });
                }
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "rardeployment.mcfcreation_error", Ex);
                }
            }
        }
    }
    return mcf;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Method(java.lang.reflect.Method) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) Iterator(java.util.Iterator) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 3 with SetMethodAction

use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.

the class ActiveJmsResourceAdapter method createManagedConnectionFactories.

/**
 * This is a temporay solution for obtaining all the MCFs
 * corresponding to a JMS RA pool, this is to facilitate the
 * recovery process where the XA resources of all RMs in the
 * broker cluster are required. Should be removed when a permanent
 * solutuion is available from the broker.
 * @param cpr <code>ConnectorConnectionPool</code> object
 * @param loader Class Loader.
 * @return
 */
@Override
public ManagedConnectionFactory[] createManagedConnectionFactories(com.sun.enterprise.connectors.ConnectorConnectionPool cpr, ClassLoader loader) {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "RECOVERY : Entering createMCFS in AJMSRA");
    }
    ArrayList mcfs = new ArrayList();
    if (getAddressListCount() < 2) {
        mcfs.add(createManagedConnectionFactory(cpr, loader));
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Brokers are not clustered,So doing normal recovery");
        }
    } else {
        String addlist = null;
        Set s = cpr.getConnectorDescriptorInfo().getMCFConfigProperties();
        Iterator tmpit = s.iterator();
        while (tmpit.hasNext()) {
            ConnectorConfigProperty prop = (ConnectorConfigProperty) tmpit.next();
            String propName = prop.getName();
            if (propName.equalsIgnoreCase("imqAddressList") || propName.equalsIgnoreCase("Addresslist")) {
                addlist = prop.getValue();
            }
        }
        StringTokenizer tokenizer = null;
        if ((addlist == null) || (addlist.trim().equalsIgnoreCase("localhost"))) {
            tokenizer = new StringTokenizer(addressList, ",");
        } else {
            tokenizer = new StringTokenizer(addlist, ",");
        }
        _logger.log(Level.FINE, "No of addresses found " + tokenizer.countTokens());
        while (tokenizer.hasMoreTokens()) {
            String brokerurl = tokenizer.nextToken();
            ManagedConnectionFactory mcf = super.createManagedConnectionFactory(cpr, loader);
            Iterator it = s.iterator();
            while (it.hasNext()) {
                ConnectorConfigProperty prop = (ConnectorConfigProperty) it.next();
                String propName = prop.getName();
                String propValue = prop.getValue();
                if (propName.startsWith("imq") && !"".equals(propValue)) {
                    try {
                        Method meth = mcf.getClass().getMethod(SETTER, new Class[] { java.lang.String.class, java.lang.String.class });
                        if (propName.trim().equalsIgnoreCase("imqAddressList")) {
                            meth.invoke(mcf, new Object[] { prop.getName(), brokerurl });
                        } else {
                            meth.invoke(mcf, new Object[] { prop.getName(), prop.getValueObject() });
                        }
                    } catch (NoSuchMethodException ex) {
                        if (_logger.isLoggable(Level.WARNING)) {
                            _logger.log(Level.WARNING, JMSLoggerInfo.NO_SUCH_METHOD, new Object[] { SETTER, mcf.getClass().getName() });
                        }
                    } catch (Exception ex) {
                        LogHelper.log(_logger, Level.SEVERE, JMSLoggerInfo.ERROR_EXECUTE_METHOD, ex, SETTER, mcf.getClass().getName());
                    }
                }
            }
            ConnectorConfigProperty addressProp3 = new ConnectorConfigProperty(ADDRESSLIST, brokerurl, "Address List", "java.lang.String");
            // todo: need to remove log statement
            if (_logger.isLoggable(Level.INFO)) {
                _logger.log(Level.INFO, JMSLoggerInfo.ADDRESSLIST, new Object[] { brokerurl });
            }
            HashSet addressProp = new HashSet();
            addressProp.add(addressProp3);
            SetMethodAction setMethodAction = new SetMethodAction(mcf, addressProp);
            try {
                setMethodAction.run();
            } catch (Exception e) {
                ;
            }
            mcfs.add(mcf);
        }
    }
    return (ManagedConnectionFactory[]) mcfs.toArray(new ManagedConnectionFactory[mcfs.size()]);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) StringTokenizer(java.util.StringTokenizer) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) Iterator(java.util.Iterator) HashSet(java.util.HashSet) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 4 with SetMethodAction

use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.

the class InboundRecoveryHandler method recoverInboundTransactions.

private void recoverInboundTransactions(List<XAResource> xaresList) {
    List<Application> applications = deployedApplications.getApplications();
    try {
        _logger.log(Level.INFO, "Recovery of Inbound Transactions started.");
        if (applications.size() == 0) {
            _logger.log(Level.FINE, "No applications deployed.");
            return;
        }
        // List of CMT enabled MDB descriptors on the application server instance.
        List<EjbDescriptor> xaEnabledMDBList = new ArrayList<EjbDescriptor>();
        // Done so as to initialize connectors-runtime before loading inbound active RA. need a better way ?
        ConnectorRuntime cr = connectorRuntimeProvider.get();
        for (Application application : applications) {
            Vector ejbDescVec = getEjbDescriptors(application, appsRegistry);
            for (int j = 0; j < ejbDescVec.size(); j++) {
                EjbDescriptor desc = (EjbDescriptor) ejbDescVec.elementAt(j);
                // add it to the list of xaEnabledMDBList.
                if (desc instanceof EjbMessageBeanDescriptor && desc.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
                    xaEnabledMDBList.add(desc);
                    _logger.log(Level.FINE, "Found a CMT MDB: " + desc.getEjbClassName());
                }
            }
        }
        if (xaEnabledMDBList.size() == 0) {
            _logger.log(Level.FINE, "Found no CMT MDBs in all applications");
            return;
        }
        ConnectorRegistry creg = ConnectorRegistry.getInstance();
        // for each RA (key in the map) get the list (value) of MDB Descriptors
        Map<String, List<EjbDescriptor>> mappings = createRAEjbMapping(xaEnabledMDBList);
        // For each RA
        for (Map.Entry entry : mappings.entrySet()) {
            String raMid = (String) entry.getKey();
            List<EjbDescriptor> respectiveDesc = mappings.get(raMid);
            try {
                createActiveResourceAdapter(raMid);
            } catch (Exception ex) {
                _logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", raMid);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, ex.toString(), ex);
                }
            }
            ActiveInboundResourceAdapter activeInboundRA = (ActiveInboundResourceAdapter) creg.getActiveResourceAdapter(raMid);
            // assert activeInboundRA instanceof ActiveInboundResourceAdapter;
            boolean isSystemJmsRA = false;
            if (ConnectorsUtil.isJMSRA(activeInboundRA.getModuleName())) {
                isSystemJmsRA = true;
            }
            javax.resource.spi.ResourceAdapter resourceAdapter = activeInboundRA.getResourceAdapter();
            // activationSpecList represents the ActivationSpec[] that would be
            // sent to the getXAResources() method.
            ArrayList<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
            try {
                for (int i = 0; i < respectiveDesc.size(); i++) {
                    try {
                        // Get a MessageBeanDescriptor from respectiveDesc ArrayList
                        EjbMessageBeanDescriptor descriptor = (EjbMessageBeanDescriptor) respectiveDesc.get(i);
                        // to be updated J2EE 1.4 style props.
                        if (isSystemJmsRA) {
                            // XXX: Find out the pool descriptor corres to MDB and update
                            // MDBRuntimeInfo with that.
                            activeInboundRA.updateMDBRuntimeInfo(descriptor, null);
                        }
                        // Get the ActivationConfig Properties from the MDB Descriptor
                        Set activationConfigProps = RARUtils.getMergedActivationConfigProperties(descriptor);
                        // get message listener type
                        String msgListenerType = descriptor.getMessageListenerType();
                        // start resource adapter and get ActivationSpec class for
                        // the given message listener type from the ConnectorRuntime
                        ActivationSpec aspec = (ActivationSpec) (Class.forName(cr.getActivationSpecClass(raMid, msgListenerType), false, resourceAdapter.getClass().getClassLoader()).newInstance());
                        aspec.setResourceAdapter(resourceAdapter);
                        // Populate ActivationSpec class with ActivationConfig properties
                        SetMethodAction sma = new SetMethodAction(aspec, activationConfigProps);
                        sma.run();
                        activationSpecList.add(aspec);
                    } catch (Exception e) {
                        _logger.log(Level.WARNING, "error.creating.activationspec", e.getMessage());
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, e.toString(), e);
                        }
                    }
                }
                // Get XA resources from RA.
                ActivationSpec[] activationSpecArray = activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]);
                XAResource[] xar = resourceAdapter.getXAResources(activationSpecArray);
                // Add the resources to the xaresList which is used by the RecoveryManager
                if (xar != null) {
                    for (int p = 0; p < xar.length; p++) {
                        xaresList.add(xar[p]);
                    }
                }
            // Catch UnsupportedOperationException if a RA does not support XA
            // which is fine.
            } catch (UnsupportedOperationException uoex) {
                _logger.log(Level.FINE, uoex.getMessage());
            // otherwise catch the unexpected exception
            } catch (Exception e) {
                _logger.log(Level.SEVERE, "exception.during.inbound.resource.acqusition", e);
            }
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, "exception.during.inbound.recovery", e);
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ConnectorRegistry(com.sun.enterprise.connectors.ConnectorRegistry) Vector(java.util.Vector) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) XAResource(javax.transaction.xa.XAResource) EjbMessageBeanDescriptor(com.sun.enterprise.deployment.EjbMessageBeanDescriptor) ActivationSpec(javax.resource.spi.ActivationSpec) Application(com.sun.enterprise.config.serverbeans.Application) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Example 5 with SetMethodAction

use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.

the class ActiveResourceAdapterImpl method createManagedConnectionFactory.

/**
 * Creates managed Connection factory instance.
 *
 * @param ccp Connector connection pool which contains the pool properties
 *            and ra.xml values pertaining to managed connection factory
 *            class. These values are used in MCF creation.
 * @param jcl Classloader used to managed connection factory class.
 * @return ManagedConnectionFactory created managed connection factory
 *         instance
 */
public ManagedConnectionFactory createManagedConnectionFactory(ConnectorConnectionPool ccp, ClassLoader jcl) {
    final String mcfClass = ccp.getConnectorDescriptorInfo().getManagedConnectionFactoryClass();
    try {
        ManagedConnectionFactory mcf = null;
        mcf = instantiateMCF(mcfClass, jcl);
        if (mcf instanceof ConfigurableTransactionSupport) {
            TransactionSupport ts = ConnectionPoolObjectsUtils.getTransactionSupport(ccp.getTransactionSupport());
            ((ConfigurableTransactionSupport) mcf).setTransactionSupport(ts);
        }
        SetMethodAction setMethodAction = new SetMethodAction(mcf, ccp.getConnectorDescriptorInfo().getMCFConfigProperties());
        setMethodAction.run();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Created MCF object : ", mcfClass);
        }
        return mcf;
    } catch (ClassNotFoundException Ex) {
        _logger.log(Level.SEVERE, "rardeployment.class_not_found", new Object[] { mcfClass, Ex.getMessage() });
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "rardeployment.class_not_found", Ex);
        }
        return null;
    } catch (InstantiationException Ex) {
        _logger.log(Level.SEVERE, "rardeployment.class_instantiation_error", new Object[] { mcfClass, Ex.getMessage() });
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "rardeployment.class_instantiation_error", Ex);
        }
        return null;
    } catch (IllegalAccessException Ex) {
        _logger.log(Level.SEVERE, "rardeployment.illegalaccess_error", new Object[] { mcfClass, Ex.getMessage() });
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "rardeployment.illegalaccess_error", Ex);
        }
        return null;
    } catch (Exception Ex) {
        _logger.log(Level.SEVERE, "rardeployment.mcfcreation_error", new Object[] { mcfClass, Ex.getMessage() });
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "rardeployment.mcfcreation_error", Ex);
        }
        return null;
    }
}
Also used : ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) ConfigurableTransactionSupport(com.sun.appserv.connectors.spi.ConfigurableTransactionSupport) TransactionSupport(com.sun.appserv.connectors.spi.TransactionSupport) ConfigurableTransactionSupport(com.sun.appserv.connectors.spi.ConfigurableTransactionSupport) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) SetMethodAction(com.sun.enterprise.connectors.util.SetMethodAction)

Aggregations

SetMethodAction (com.sun.enterprise.connectors.util.SetMethodAction)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)5 Set (java.util.Set)4 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)3 PrivilegedActionException (java.security.PrivilegedActionException)3 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)3 Method (java.lang.reflect.Method)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 ExecutionException (java.util.concurrent.ExecutionException)2 ResourceException (javax.resource.ResourceException)2 ActivationSpec (javax.resource.spi.ActivationSpec)2 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)2 MultiException (org.glassfish.hk2.api.MultiException)2 ConnectorRuntime (com.sun.appserv.connectors.internal.api.ConnectorRuntime)1 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)1 ConfigurableTransactionSupport (com.sun.appserv.connectors.spi.ConfigurableTransactionSupport)1 TransactionSupport (com.sun.appserv.connectors.spi.TransactionSupport)1