Search in sources :

Example 31 with RefAddr

use of javax.naming.RefAddr in project tomee by apache.

the class TomcatEjbFactory method getObjectInstance.

@SuppressWarnings("unchecked")
@Override
public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable environment) throws Exception {
    Object beanObj = null;
    final Class ejbRefClass = Class.forName("org.apache.naming.EjbRef");
    if (ejbRefClass.isAssignableFrom(obj.getClass())) {
        RefAddr refAddr;
        String addrType;
        final Properties env = new Properties();
        String bean = null;
        final Reference ref = (Reference) obj;
        final Enumeration addresses = ref.getAll();
        while (addresses.hasMoreElements()) {
            refAddr = (RefAddr) addresses.nextElement();
            addrType = refAddr.getType();
            if (addrType.startsWith(OPENEJB_PREFIX)) {
                final String value = refAddr.getContent().toString();
                if (addrType.equals(OPENEJB_EJB_LINK)) {
                    bean = value;
                    continue;
                }
                String key = addrType.substring(OPENEJB_PREFIX_LENGTH);
                key = JAVA_PREFIX + key;
                env.put(key, value);
            }
        }
        if (bean != null) {
            beanObj = (new InitialContext(env)).lookup(bean);
        }
    }
    return beanObj;
}
Also used : RefAddr(javax.naming.RefAddr) Enumeration(java.util.Enumeration) Reference(javax.naming.Reference) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext)

Example 32 with RefAddr

use of javax.naming.RefAddr in project tomee by apache.

the class NamingUtil method getProperty.

public static String getProperty(final Reference ref, final String name) {
    final RefAddr addr = ref.get(name);
    if (addr == null) {
        return null;
    }
    final Object value = addr.getContent();
    return (String) value;
}
Also used : RefAddr(javax.naming.RefAddr)

Example 33 with RefAddr

use of javax.naming.RefAddr in project tomee by apache.

the class TomcatJndiBuilder method normalize.

/**
     * LinkRef addresses need to be prefixed with java: or they won't resolve
     *
     * OpenEJB is fine with this, but Tomcat needs them
     *
     * @param value
     * @return
     */
private static Object normalize(final Object value) {
    try {
        if (!(value instanceof LinkRef)) {
            return value;
        }
        final LinkRef ref = (LinkRef) value;
        final RefAddr refAddr = ref.getAll().nextElement();
        final String address = refAddr.getContent().toString();
        if (address.startsWith("openejb:")) {
            return value;
        }
        if (!address.startsWith("java:")) {
            return new LinkRef("java:" + address);
        }
    } catch (final Exception e) {
    // no-op
    }
    return value;
}
Also used : RefAddr(javax.naming.RefAddr) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) NameNotFoundException(javax.naming.NameNotFoundException) MalformedURLException(java.net.MalformedURLException) LinkRef(javax.naming.LinkRef)

Aggregations

RefAddr (javax.naming.RefAddr)33 Reference (javax.naming.Reference)22 Properties (java.util.Properties)8 NamingException (javax.naming.NamingException)6 StringRefAddr (javax.naming.StringRefAddr)6 InitialContext (javax.naming.InitialContext)4 ObjectFactory (javax.naming.spi.ObjectFactory)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 NameNotFoundException (javax.naming.NameNotFoundException)2 DirObjectFactory (javax.naming.spi.DirObjectFactory)2 DruidDataSourceFactory (com.alibaba.druid.pool.DruidDataSourceFactory)1 MongoClient (com.mongodb.MongoClient)1 MongoClientURI (com.mongodb.MongoClientURI)1 MongoException (com.mongodb.MongoException)1 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1