Search in sources :

Example 11 with ExternalJndiResource

use of org.glassfish.resources.config.ExternalJndiResource in project Payara by payara.

the class ExternalJndiResourceDeployer method toExternalJndiJavaEEResource.

/**
 * Returns a new instance of j2ee external jndi resource from the given
 * config bean.
 * <p/>
 * This method gets called from the external resource
 * deployer to convert external-jndi-resource config bean into
 * external-jndi  j2ee resource.
 *
 * @param rbean external-jndi-resource config bean
 * @param resourceInfo
 * @return a new instance of j2ee external jndi resource
 */
public static org.glassfish.resources.api.JavaEEResource toExternalJndiJavaEEResource(ExternalJndiResource rbean, ResourceInfo resourceInfo) {
    org.glassfish.resources.beans.ExternalJndiResource jr = new org.glassfish.resources.beans.ExternalJndiResource(resourceInfo);
    // jr.setDescription( rbean.getDescription() ); // FIXME: getting error
    // sets the enable flag
    jr.setEnabled(Boolean.valueOf(rbean.getEnabled()));
    // sets the jndi look up name
    jr.setJndiLookupName(rbean.getJndiLookupName());
    // sets the resource type
    jr.setResType(rbean.getResType());
    // sets the factory class name
    jr.setFactoryClass(rbean.getFactoryClass());
    // sets the properties
    List<Property> properties = rbean.getProperty();
    if (properties != null) {
        for (Property property : properties) {
            ResourceProperty rp = new ResourcePropertyImpl(property.getName(), property.getValue());
            jr.addProperty(rp);
        }
    }
    return jr;
}
Also used : ResourceProperty(com.sun.enterprise.repository.ResourceProperty) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) ResourceProperty(com.sun.enterprise.repository.ResourceProperty) Property(org.jvnet.hk2.config.types.Property)

Example 12 with ExternalJndiResource

use of org.glassfish.resources.config.ExternalJndiResource in project Payara by payara.

the class LegacyJmsRecoveryResourceHandler method loadXAResourcesAndItsConnections.

public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
    try {
        Collection<ExternalJndiResource> jndiResources = resources.getResources(ExternalJndiResource.class);
        InitialContext ic = new InitialContext();
        for (ExternalJndiResource jndiResource : jndiResources) {
            if (isEnabled(jndiResource)) {
                try {
                    ic.lookup(jndiResource.getJndiName());
                    if (!isJMSConnectionFactory(jndiResource)) {
                        continue;
                    }
                    String jndiName = jndiResource.getJndiName();
                    Object jmsXAConnectionFactory;
                    boolean isQueue;
                    Object objext = ic.lookup(jndiName);
                    if (!instanceOf(objext, "ConnectionFactory")) {
                        throw new NamingException(localStrings.getLocalString("recovery.unexpected_objtype", "Unexpected object type " + objext.getClass().getName() + " for " + jndiName, new Object[] { objext.getClass().getName(), jndiName }));
                    }
                    jmsXAConnectionFactory = wrapJMSConnectionFactoryObject(objext);
                    isQueue = instanceOf(objext, "QueueConnectionFactory");
                    recoverJMSXAResource(xaresList, connList, jmsXAConnectionFactory, isQueue);
                // } catch (NamingException ne) {
                // If you are here then it is most probably an embedded RAR resource
                // So we need to explicitly load that rar and create the resources
                } catch (Exception ex) {
                    _logger.log(Level.SEVERE, JMSLoggerInfo.LOAD_RESOURCES_ERROR, new Object[] { jndiResource.getJndiName() });
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, ex.toString(), ex);
                    }
                }
            }
        }
    } catch (NamingException ne) {
        _logger.log(Level.SEVERE, JMSLoggerInfo.LOAD_RESOURCES_ERROR, new Object[] { ne.getMessage() });
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, ne.toString(), ne);
        }
    }
}
Also used : NamingException(javax.naming.NamingException) ExternalJndiResource(org.glassfish.resources.config.ExternalJndiResource) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException)

Aggregations

ExternalJndiResource (org.glassfish.resources.config.ExternalJndiResource)12 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)4 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)2 Resource (com.sun.enterprise.config.serverbeans.Resource)2 ActionReport (org.glassfish.api.ActionReport)2 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)2 Test (org.junit.Test)2 Property (org.jvnet.hk2.config.types.Property)2 ResourceRef (com.sun.enterprise.config.serverbeans.ResourceRef)1 Resources (com.sun.enterprise.config.serverbeans.Resources)1 ResourceProperty (com.sun.enterprise.repository.ResourceProperty)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1