Search in sources :

Example 1 with AdministeredObjectResource

use of com.sun.enterprise.resource.beans.AdministeredObjectResource in project Payara by payara.

the class ActiveOutboundResourceAdapter method addAdminObject.

/**
 * Creates an admin object.
 *
 * @param appName         Name of application, in case of embedded rar.
 * @param connectorName   Module name of the resource adapter.
 * @param jndiName        JNDI name to be registered.
 * @param adminObjectType Interface name of the admin object.
 * @param props           <code>Properties</code> object containing name/value
 *                        pairs of properties.
 */
public void addAdminObject(String appName, String connectorName, ResourceInfo resourceInfo, String adminObjectType, String adminObjectClassName, Properties props) throws ConnectorRuntimeException {
    if (props == null) {
        // empty properties
        props = new Properties();
    }
    ConnectorRegistry registry = ConnectorRegistry.getInstance();
    ConnectorDescriptor desc = registry.getDescriptor(connectorName);
    AdminObject aoDesc = null;
    // or the combination of the both names.
    if (adminObjectClassName == null || adminObjectClassName.trim().equals("")) {
        // get AO through interface name
        List<AdminObject> adminObjects = desc.getAdminObjectsByType(adminObjectType);
        if (adminObjects.size() > 1) {
            String msg = localStrings.getString("aor.could_not_determine_aor_type", adminObjectType);
            throw new ConnectorRuntimeException(msg);
        } else {
            aoDesc = adminObjects.get(0);
        }
    } else if (adminObjectType == null || adminObjectType.trim().equals("")) {
        // get AO through class name
        List<AdminObject> adminObjects = desc.getAdminObjectsByClass(adminObjectClassName);
        if (adminObjects.size() > 1) {
            String msg = localStrings.getString("aor.could_not_determine_aor_class", adminObjectClassName);
            throw new ConnectorRuntimeException(msg);
        } else {
            aoDesc = adminObjects.get(0);
        }
    } else {
        // get AO through interface name and class name
        aoDesc = desc.getAdminObject(adminObjectType, adminObjectClassName);
    }
    if (aoDesc == null) {
        String msg = localStrings.getString("aor.could_not_determine_aor", adminObjectType, adminObjectClassName);
        throw new ConnectorRuntimeException(msg);
    }
    AdministeredObjectResource aor = new AdministeredObjectResource(resourceInfo);
    aor.initialize(aoDesc);
    aor.setResourceAdapter(connectorName);
    Object[] envProps = aoDesc.getConfigProperties().toArray();
    // Override them if same config properties are provided by the user
    for (int i = 0; i < envProps.length; i++) {
        ConnectorConfigProperty envProp = (ConnectorConfigProperty) envProps[i];
        String name = envProp.getName();
        String userValue = (String) props.remove(name);
        if (userValue != null)
            aor.addConfigProperty(new ConnectorConfigProperty(name, userValue, userValue, envProp.getType()));
        else
            aor.addConfigProperty(envProp);
    }
    // Add non-default config properties provided by the user to aor
    Iterator iter = props.keySet().iterator();
    while (iter.hasNext()) {
        String name = (String) iter.next();
        String userValue = props.getProperty(name);
        if (userValue != null)
            aor.addConfigProperty(new ConnectorConfigProperty(name, userValue, userValue));
    }
    // bind to JNDI namespace
    try {
        Reference ref = aor.createAdminObjectReference();
        connectorRuntime_.getResourceNamingService().publishObject(resourceInfo, ref, true);
    } catch (NamingException ex) {
        String i18nMsg = localStrings.getString("aira.cannot_bind_admin_obj");
        throw new ConnectorRuntimeException(i18nMsg, ex);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) Reference(javax.naming.Reference) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) AdminObject(com.sun.enterprise.deployment.AdminObject) NamingException(javax.naming.NamingException) AdministeredObjectResource(com.sun.enterprise.resource.beans.AdministeredObjectResource) AdminObject(com.sun.enterprise.deployment.AdminObject)

Example 2 with AdministeredObjectResource

use of com.sun.enterprise.resource.beans.AdministeredObjectResource in project Payara by payara.

the class AdministeredObjectFactory method getObjectInstance.

public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception {
    Reference ref = (Reference) obj;
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("AdministeredObjectFactory: " + ref + " Name:" + name);
    }
    AdministeredObjectResource aor = (AdministeredObjectResource) ref.get(0).getContent();
    String moduleName = aor.getResourceAdapter();
    // If call fom application client, start resource adapter lazily.
    // todo: Similar code in ConnectorObjectFactory - to refactor.
    ConnectorRuntime runtime = ConnectorNamingUtils.getRuntime();
    if (runtime.isACCRuntime() || runtime.isNonACCRuntime()) {
        ConnectorDescriptor connectorDescriptor = null;
        try {
            Context ic = new InitialContext();
            String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
            connectorDescriptor = (ConnectorDescriptor) ic.lookup(descriptorJNDIName);
        } catch (NamingException ne) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Failed to look up ConnectorDescriptor " + "from JNDI", moduleName);
            }
            throw new ConnectorRuntimeException("Failed to look up " + "ConnectorDescriptor from JNDI");
        }
        runtime.createActiveResourceAdapter(connectorDescriptor, moduleName, null);
    }
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    if (runtime.checkAccessibility(moduleName, loader) == false) {
        throw new NamingException("Only the application that has the embedded resource" + "adapter can access the resource adapter");
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("[AdministeredObjectFactory] ==> Got AdministeredObjectResource = " + aor);
    }
    // all RARs except system RARs should have been available now.
    if (ConnectorsUtil.belongsToSystemRA(moduleName)) {
        // make sure that system rar is started and hence added to connector classloader chain
        if (ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName) == null) {
            String moduleLocation = ConnectorsUtil.getSystemModuleLocation(moduleName);
            runtime.createActiveResourceAdapter(moduleLocation, moduleName, null);
        }
        loader = ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName).getClassLoader();
    } else if (runtime.isServer()) {
        if (ConnectorsUtil.isStandAloneRA(moduleName)) {
            loader = ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName).getClassLoader();
        }
    }
    return aor.createAdministeredObject(loader);
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) AdministeredObjectResource(com.sun.enterprise.resource.beans.AdministeredObjectResource) ConnectorRuntime(com.sun.enterprise.connectors.ConnectorRuntime)

Aggregations

ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)2 AdministeredObjectResource (com.sun.enterprise.resource.beans.AdministeredObjectResource)2 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)1 AdminObject (com.sun.enterprise.deployment.AdminObject)1 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)1 NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1