Search in sources :

Example 31 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor 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 32 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class AuthenticationMechanismHandler method processAnnotation.

public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = element.getProcessingContext().getHandler();
    AuthenticationMechanism authMechanism = (AuthenticationMechanism) element.getAnnotation();
    if (aeHandler instanceof RarBundleContext) {
        boolean isConnectionDefinition = hasConnectorAnnotation(element);
        if (isConnectionDefinition) {
            RarBundleContext rarContext = (RarBundleContext) aeHandler;
            ConnectorDescriptor desc = rarContext.getDescriptor();
            if (!desc.getOutBoundDefined()) {
                OutboundResourceAdapter ora = new OutboundResourceAdapter();
                desc.setOutboundResourceAdapter(ora);
            }
            OutboundResourceAdapter ora = desc.getOutboundResourceAdapter();
            String[] description = authMechanism.description();
            int authMechanismValue = getAuthMechVal(authMechanism.authMechanism());
            AuthenticationMechanism.CredentialInterface ci = authMechanism.credentialInterface();
            String credentialInterface = ora.getCredentialInterfaceName(ci);
            // XXX: Siva: For now use the first description
            String firstDesc = "";
            if (description.length > 0) {
                firstDesc = description[0];
            }
            AuthMechanism auth = new AuthMechanism(firstDesc, authMechanismValue, credentialInterface);
            ora.addAuthMechanism(auth);
        } else {
            getFailureResult(element, "Not a @Connector annotation : @AuthenticationMechanism must " + "be specified along with @Connector annotation", true);
        }
    } else {
        getFailureResult(element, "Not a rar bundle context", true);
    }
    return getDefaultProcessedResult();
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) AuthMechanism(com.sun.enterprise.deployment.AuthMechanism) AuthenticationMechanism(javax.resource.spi.AuthenticationMechanism) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext) OutboundResourceAdapter(com.sun.enterprise.deployment.OutboundResourceAdapter)

Example 33 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class ConnectionDefinitionHandler method handleAnnotation.

private void handleAnnotation(AnnotatedElementHandler aeHandler, ConnectionDefinition connDefn, AnnotationInfo element) {
    RarBundleContext rarContext = (RarBundleContext) aeHandler;
    ConnectorDescriptor desc = rarContext.getDescriptor();
    Class c = (Class) element.getAnnotatedElement();
    String targetClassName = c.getName();
    if (ManagedConnectionFactory.class.isAssignableFrom(c)) {
        if (!desc.getOutBoundDefined()) {
            OutboundResourceAdapter ora = new OutboundResourceAdapter();
            desc.setOutboundResourceAdapter(ora);
        }
        OutboundResourceAdapter ora = desc.getOutboundResourceAdapter();
        if (!ora.hasConnectionDefDescriptor(connDefn.connectionFactory().getName())) {
            ConnectionDefDescriptor cdd = new ConnectionDefDescriptor();
            cdd.setConnectionFactoryImpl(connDefn.connectionFactoryImpl().getName());
            cdd.setConnectionFactoryIntf(connDefn.connectionFactory().getName());
            cdd.setConnectionIntf(connDefn.connection().getName());
            cdd.setConnectionImpl(connDefn.connectionImpl().getName());
            cdd.setManagedConnectionFactoryImpl(targetClassName);
            ora.addConnectionDefDescriptor(cdd);
        }
    // else {
    // ignore the duplicates
    // duplicates can be via :
    // (i) connection-definition defined in DD
    // (ii) as part of this particular annotation processing,
    // already this connection-definition is defined
    // TODO V3 how to handle (ii)
    // }
    } else {
        getFailureResult(element, "Cant handle ConnectionDefinition annotation as the annotated class does not" + "implement ManagedConnectionFactory", true);
    }
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext) OutboundResourceAdapter(com.sun.enterprise.deployment.OutboundResourceAdapter)

Example 34 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class ConnectorNode method setElementValue.

/**
 * receives notification of the value for a particular tag
 *
 * @param element the xml element
 * @param value it's associated value
 */
@Override
public void setElementValue(XMLElement element, String value) {
    getDescriptor();
    if (descriptor == null) {
        throw new RuntimeException("Trying to set values on a null descriptor");
    }
    if (ConnectorTagNames.SPEC_VERSION.equals(element.getQName())) {
        descriptor.setSpecVersion(value);
        specVersion = value;
    // the version element value is the resourve adapter version
    // and it's only available from dtd based xml
    } else if (ConnectorTagNames.VERSION.equals(element.getQName())) {
        descriptor.setResourceAdapterVersion(value);
    } else if (TagNames.MODULE_NAME.equals(element.getQName())) {
        ConnectorDescriptor bundleDesc = getDescriptor();
        bundleDesc.getModuleDescriptor().setModuleName(value);
    /*
            bundleDesc.setModuleNameSet(true);
*/
    } else {
        super.setElementValue(element, value);
    }
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor)

Example 35 with ConnectorDescriptor

use of com.sun.enterprise.deployment.ConnectorDescriptor in project Payara by payara.

the class RANode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node for the DOM tree
 * @param the descriptor to write
 * @return the DOM tree top node
 */
public Node writeDescriptor(Node connectorNode, Descriptor descriptor) {
    if (!(descriptor instanceof ConnectorDescriptor)) {
        throw new IllegalArgumentException(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
    }
    ConnectorDescriptor conDesc = (ConnectorDescriptor) descriptor;
    Node raNode = appendChild(connectorNode, ConnectorTagNames.RESOURCE_ADAPTER);
    appendTextChild(raNode, ConnectorTagNames.RESOURCE_ADAPTER_CLASS, conDesc.getResourceAdapterClass());
    // config-property
    ConfigPropertyNode config = new ConfigPropertyNode();
    raNode = config.writeDescriptor(raNode, conDesc);
    if (conDesc.getOutBoundDefined() == true) {
        // outbound RA info
        OutBoundRANode obNode = new OutBoundRANode();
        raNode = obNode.writeDescriptor(raNode, conDesc);
    }
    if (conDesc.getInBoundDefined() == true) {
        // inbound RA info
        InBoundRANode inNode = new InBoundRANode();
        raNode = inNode.writeDescriptor(raNode, conDesc);
    }
    // adminobject
    AdminObjectNode admin = new AdminObjectNode();
    raNode = admin.writeDescriptor(raNode, conDesc);
    // }
    // security-permission*
    SecurityPermissionNode secPerm = new SecurityPermissionNode();
    raNode = secPerm.writeDescriptor(raNode, conDesc);
    return connectorNode;
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) Node(org.w3c.dom.Node) DeploymentDescriptorNode(com.sun.enterprise.deployment.node.DeploymentDescriptorNode)

Aggregations

ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)40 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)11 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)9 RarBundleContext (com.sun.enterprise.deployment.annotation.context.RarBundleContext)8 OutboundResourceAdapter (com.sun.enterprise.deployment.OutboundResourceAdapter)5 Iterator (java.util.Iterator)5 AuthMechanism (com.sun.enterprise.deployment.AuthMechanism)4 URISyntaxException (java.net.URISyntaxException)4 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)3 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)3 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 ActiveResourceAdapter (com.sun.enterprise.connectors.ActiveResourceAdapter)2 ConnectorDescriptorInfo (com.sun.enterprise.connectors.ConnectorDescriptorInfo)2 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)2 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)2 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)2 JmsRaUtil (com.sun.enterprise.connectors.jms.util.JmsRaUtil)2 MessageListener (com.sun.enterprise.deployment.MessageListener)2 AdministeredObjectResource (com.sun.enterprise.resource.beans.AdministeredObjectResource)2 URI (java.net.URI)2