Search in sources :

Example 1 with ResourceProperty

use of com.sun.enterprise.repository.ResourceProperty in project Payara by payara.

the class JavaEEResourceBase method getPropsString.

/**
 * Gets a the of properties as a JSON array
 * i.e. [ propname1=value , propname2=othervalue ]
 * <p>
 * If there are no properties an empty string is returned.
 * @return
 */
protected String getPropsString() {
    StringBuffer propsBuffer = new StringBuffer();
    Set props = getProperties();
    if (!props.isEmpty()) {
        for (Iterator iter = props.iterator(); iter.hasNext(); ) {
            if (propsBuffer.length() == 0) {
                propsBuffer.append("[ ");
            } else {
                propsBuffer.append(" , ");
            }
            ResourceProperty next = (ResourceProperty) iter.next();
            propsBuffer.append(next.getName()).append("=").append(next.getValue());
        }
        propsBuffer.append(" ]");
    }
    return propsBuffer.toString();
}
Also used : ResourceProperty(com.sun.enterprise.repository.ResourceProperty)

Example 2 with ResourceProperty

use of com.sun.enterprise.repository.ResourceProperty in project Payara by payara.

the class JavaEEResourceBase method makeClone.

@Override
public JavaEEResource makeClone(ResourceInfo resourceInfo) {
    JavaEEResource clone = doClone(resourceInfo);
    Set entrySet = properties_.entrySet();
    for (Iterator iter = entrySet.iterator(); iter.hasNext(); ) {
        Map.Entry next = (Map.Entry) iter.next();
        ResourceProperty propClone = new ResourcePropertyImpl((String) next.getKey());
        propClone.setValue(next.getValue());
        clone.addProperty(propClone);
    }
    // START OF IASRI #4626188
    clone.setEnabled(isEnabled());
    clone.setDescription(getDescription());
    // END OF IASRI #4626188
    return clone;
}
Also used : ResourceProperty(com.sun.enterprise.repository.ResourceProperty)

Example 3 with ResourceProperty

use of com.sun.enterprise.repository.ResourceProperty in project Payara by payara.

the class ExternalJndiResourceDeployer method installExternalJndiResource.

/**
 * Installs the given external jndi resource. This method gets called
 * during server initialization and from external jndi resource
 * deployer to handle resource events.
 *
 * @param extJndiRes external jndi resource
 * @param resourceInfo Information about the resource
 */
public void installExternalJndiResource(org.glassfish.resources.beans.ExternalJndiResource extJndiRes, ResourceInfo resourceInfo) {
    try {
        // create the external JNDI factory, its initial context and
        // pass them as references.
        String factoryClass = extJndiRes.getFactoryClass();
        String jndiLookupName = extJndiRes.getJndiLookupName();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "installExternalJndiResources resourceName " + resourceInfo + " factoryClass " + factoryClass + " jndiLookupName = " + jndiLookupName);
        }
        Object factory = ResourceUtil.loadObject(factoryClass);
        if (factory == null) {
            _logger.log(Level.WARNING, "jndi.factory_load_error", factoryClass);
            return;
        } else if (!(factory instanceof javax.naming.spi.InitialContextFactory)) {
            _logger.log(Level.WARNING, "jndi.factory_class_unexpected", factoryClass);
            return;
        }
        // Get properties to create the initial naming context
        // for the target JNDI factory
        Hashtable env = new Hashtable();
        for (Iterator props = extJndiRes.getProperties().iterator(); props.hasNext(); ) {
            ResourceProperty prop = (ResourceProperty) props.next();
            env.put(prop.getName(), prop.getValue());
        }
        Context context = null;
        try {
            context = ((InitialContextFactory) factory).getInitialContext(env);
        } catch (NamingException ne) {
            _logger.log(Level.SEVERE, "jndi.initial_context_error", factoryClass);
            _logger.log(Level.SEVERE, "jndi.initial_context_error_excp", ne.getMessage());
        }
        if (context == null) {
            _logger.log(Level.SEVERE, "jndi.factory_create_error", factoryClass);
            return;
        }
        // Bind a Reference to the proxy object factory; set the
        // initial context factory.
        // JndiProxyObjectFactory.setInitialContext(bindName, context);
        Reference ref = new Reference(extJndiRes.getResType(), "org.glassfish.resources.naming.JndiProxyObjectFactory", null);
        // unique JNDI name within server runtime
        ref.add(new SerializableObjectRefAddr("resourceInfo", resourceInfo));
        // target JNDI name
        ref.add(new StringRefAddr("jndiLookupName", jndiLookupName));
        // target JNDI factory class
        ref.add(new StringRefAddr("jndiFactoryClass", factoryClass));
        // add Context info as a reference address
        ref.add(new ProxyRefAddr(extJndiRes.getResourceInfo().getName(), env));
        // Publish the reference
        namingService.publishObject(resourceInfo, ref, true);
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "customrsrc.create_ref_error", resourceInfo);
        _logger.log(Level.SEVERE, "customrsrc.create_ref_error_excp", ex);
    }
}
Also used : Context(javax.naming.Context) Hashtable(java.util.Hashtable) Reference(javax.naming.Reference) SerializableObjectRefAddr(org.glassfish.resources.naming.SerializableObjectRefAddr) NamingException(javax.naming.NamingException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException) InitialContextFactory(javax.naming.spi.InitialContextFactory) ResourceProperty(com.sun.enterprise.repository.ResourceProperty) StringRefAddr(javax.naming.StringRefAddr) Iterator(java.util.Iterator) NamingException(javax.naming.NamingException) ProxyRefAddr(org.glassfish.resources.naming.ProxyRefAddr)

Example 4 with ResourceProperty

use of com.sun.enterprise.repository.ResourceProperty in project Payara by payara.

the class MailConfiguration method loadMailResources.

/**
 * Load all configuration information from the mail resource node in
 * domain.xml for the JavaMail Session object within Java EE.
 */
private void loadMailResources(MailResourceIntf mailResource) throws Exception {
    if (mailResource == null) {
        _logger.log(Level.FINE, "MailConfiguration: no MailResource object. mailResource=null");
        return;
    }
    jndiName = mailResource.getName();
    description = mailResource.getDescription();
    enabled = mailResource.isEnabled();
    storeProtocol = mailResource.getStoreProtocol();
    storeProtocolClass = mailResource.getStoreProtocolClass();
    transportProtocol = mailResource.getTransportProtocol();
    transportProtocolClass = mailResource.getTransportProtocolClass();
    mailHost = mailResource.getMailHost();
    username = mailResource.getUsername();
    password = mailResource.getPassword();
    auth = mailResource.getAuth();
    mailFrom = mailResource.getMailFrom();
    debug = mailResource.isDebug();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("storeProtocol " + storeProtocol);
        _logger.fine("storeProtocolClass " + storeProtocolClass);
        _logger.fine("transportProtocol " + transportProtocol);
        _logger.fine("transportProtocolClass " + transportProtocolClass);
        _logger.fine("mailHost " + mailHost);
        _logger.fine("username " + username);
        // Not displayed
        _logger.fine("password has been set.");
        _logger.fine("auth" + auth);
        _logger.fine("mailFrom " + mailFrom);
        _logger.fine("debug " + debug);
    }
    // JavaMail doesn't default this one properly
    if (transportProtocol == null) {
        transportProtocol = "smtp";
    }
    // Save to Property list
    put(MAIL_HOST, mailHost);
    put(MAIL_USER, username);
    put(MAIL_PASSWORD, password);
    put(MAIL_STORE_PROTOCOL, storeProtocol);
    put(MAIL_TRANSPORT_PROTOCOL, transportProtocol);
    if (storeProtocol != null) {
        put(MAIL_PREFIX + storeProtocol + MAIL_SUFFIX_CLASS, storeProtocolClass);
    }
    if (transportProtocol != null) {
        put(MAIL_PREFIX + transportProtocol + MAIL_SUFFIX_CLASS, transportProtocolClass);
        put(MAIL_PREFIX + transportProtocol + MAIL_SUFFIX_AUTH, Boolean.toString(auth));
    }
    put(MAIL_FROM, mailFrom);
    put(MAIL_DEBUG, (debug ? "true" : "false"));
    // Get the properties and save to Property list
    Set properties = mailResource.getProperties();
    for (Iterator it = properties.iterator(); it.hasNext(); ) {
        ResourceProperty property = (ResourceProperty) it.next();
        String name = property.getName();
        String value = (String) property.getValue();
        if (name.startsWith(PROP_NAME_PREFIX_LEGACY)) {
            name = name.replace(PROP_NAME_DELIM_LEGACY, MAIL_DELIM);
        }
        put(name, value);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("mail property: " + name + " = " + value);
        }
    }
}
Also used : ResourceProperty(com.sun.enterprise.repository.ResourceProperty) Set(java.util.Set) Iterator(java.util.Iterator)

Example 5 with ResourceProperty

use of com.sun.enterprise.repository.ResourceProperty in project Payara by payara.

the class CustomResourceDeployer method installCustomResource.

/**
 * Installs the given custom resource. It publishes the resource as a
 * javax.naming.Reference with the naming manager (jndi). This method gets
 * called during server initialization and custom resource deployer to
 * handle custom resource events.
 *
 * @param customRes custom resource
 * @param resourceInfo
 */
public void installCustomResource(org.glassfish.resources.beans.CustomResource customRes, ResourceInfo resourceInfo) {
    try {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "installCustomResource by jndi-name : " + resourceInfo);
        }
        // bind a Reference to the object factory
        Reference ref = new Reference(customRes.getResType(), customRes.getFactoryClass(), null);
        // add resource properties as StringRefAddrs
        for (Iterator props = customRes.getProperties().iterator(); props.hasNext(); ) {
            ResourceProperty prop = (ResourceProperty) props.next();
            ref.add(new StringRefAddr(prop.getName(), (String) prop.getValue()));
        }
        // publish the reference
        cns.publishObject(resourceInfo, ref, true);
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "customrsrc.create_ref_error", resourceInfo);
        _logger.log(Level.SEVERE, "customrsrc.create_ref_error_excp", ex);
    }
}
Also used : ResourceProperty(com.sun.enterprise.repository.ResourceProperty) StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) Iterator(java.util.Iterator) NamingException(javax.naming.NamingException) ResourceConflictException(org.glassfish.resourcebase.resources.api.ResourceConflictException)

Aggregations

ResourceProperty (com.sun.enterprise.repository.ResourceProperty)10 Iterator (java.util.Iterator)3 Property (org.jvnet.hk2.config.types.Property)3 NamingException (javax.naming.NamingException)2 Reference (javax.naming.Reference)2 StringRefAddr (javax.naming.StringRefAddr)2 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)2 Hashtable (java.util.Hashtable)1 Set (java.util.Set)1 Context (javax.naming.Context)1 InitialContextFactory (javax.naming.spi.InitialContextFactory)1 CustomResource (org.glassfish.resources.config.CustomResource)1 ExternalJndiResource (org.glassfish.resources.config.ExternalJndiResource)1 MailBean (org.glassfish.resources.javamail.beans.MailBean)1 ProxyRefAddr (org.glassfish.resources.naming.ProxyRefAddr)1 SerializableObjectRefAddr (org.glassfish.resources.naming.SerializableObjectRefAddr)1