Search in sources :

Example 1 with NamingObjectProxy

use of org.glassfish.api.naming.NamingObjectProxy in project Payara by payara.

the class ManagedBeanManagerImpl method getManagedBean.

public Object getManagedBean(String globalJndiName) throws Exception {
    NamingObjectProxy proxy = appClientManagedBeans.get(globalJndiName);
    Object managedBean = null;
    if (proxy != null) {
        managedBean = proxy.create(new InitialContext());
    }
    return managedBean;
}
Also used : NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) InitialContext(javax.naming.InitialContext)

Example 2 with NamingObjectProxy

use of org.glassfish.api.naming.NamingObjectProxy in project Payara by payara.

the class GlassfishNamingManagerImpl method lookup.

private Object lookup(String componentId, String name, Context ctx) throws NamingException {
    ComponentIdInfo info = componentIdInfo.get(componentId);
    String logicalJndiName = name;
    boolean replaceName = (info != null) && (info.treatComponentAsModule) && name.startsWith("java:comp");
    if (replaceName) {
        logicalJndiName = logicalCompJndiNameToModule(name);
    }
    Map namespace = getNamespace(componentId, logicalJndiName);
    Object obj = namespace.get(logicalJndiName);
    if (obj == null)
        throw new NameNotFoundException("No object bound to name " + name);
    if (obj instanceof NamingObjectProxy) {
        NamingObjectProxy namingProxy = (NamingObjectProxy) obj;
        obj = namingProxy.create(ctx);
    } else if (obj instanceof Context) {
        // and return that.
        if (replaceName) {
            obj = new JavaURLContext(name, null);
        }
        if (obj instanceof JavaURLContext) {
            if (ctx instanceof SerialContext) {
                obj = new JavaURLContext((JavaURLContext) obj, (SerialContext) ctx);
            } else {
                obj = new JavaURLContext((JavaURLContext) obj, null);
            }
        }
    }
    return obj;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) NameNotFoundException(javax.naming.NameNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with NamingObjectProxy

use of org.glassfish.api.naming.NamingObjectProxy in project Payara by payara.

the class RemoteSerialContextProviderImpl method lookup.

@Override
public Object lookup(String name) throws NamingException, RemoteException {
    Object obj = super.lookup(name);
    // If CORBA object, resolve here in server to prevent a
    // another round-trip to CosNaming.
    ClassLoader originalClassLoader = null;
    try {
        if (obj instanceof Reference) {
            Reference ref = (Reference) obj;
            if (ref.getFactoryClassName().equals(GlassfishNamingManagerImpl.IIOPOBJECT_FACTORY)) {
                // Set CCL to this CL so it's guaranteed to be able to find IIOPObjectFactory
                originalClassLoader = Utility.setContextClassLoader(getClass().getClassLoader());
                Hashtable env = new Hashtable();
                env.put("java.naming.corba.orb", orb);
                obj = javax.naming.spi.NamingManager.getObjectInstance(obj, new CompositeName(name), null, env);
            }
        } else if (obj instanceof NamingObjectProxy) {
            NamingObjectProxy namingProxy = (NamingObjectProxy) obj;
            // this call will make sure that the actual object is initialized
            obj = ((NamingObjectProxy) obj).create(new InitialContext());
            // create() call and re-lookup the name.
            if (namingProxy instanceof NamingObjectProxy.InitializationNamingObjectProxy) {
                return super.lookup(name);
            }
        }
    } catch (Exception e) {
        RemoteException re = new RemoteException("", e);
        throw re;
    } finally {
        if (originalClassLoader != null) {
            Utility.setContextClassLoader(originalClassLoader);
        }
    }
    return obj;
}
Also used : NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) Hashtable(java.util.Hashtable) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException)

Example 4 with NamingObjectProxy

use of org.glassfish.api.naming.NamingObjectProxy in project Payara by payara.

the class GlassfishNamingManagerImpl method lookupFromNamespace.

private Object lookupFromNamespace(String name, Map namespace, Hashtable env) throws NamingException {
    Object o = namespace.get(name);
    if (o == null) {
        throw new NameNotFoundException("No object bound to name " + name);
    } else {
        if (o instanceof NamingObjectProxy) {
            NamingObjectProxy namingProxy = (NamingObjectProxy) o;
            InitialContext ic = initialContext;
            if (env != null) {
                ic = new InitialContext(env);
            }
            o = namingProxy.create(ic);
        } else if (o instanceof Reference) {
            try {
                o = getObjectInstance(name, o, env);
            } catch (Exception e) {
                if (logger.isLoggable(Level.FINEST)) {
                    logger.log(Level.FINEST, "Unable to get Object instance from Reference for name [" + name + "]. " + "Hence returning the Reference object ", e);
                }
            }
        }
        return o;
    }
}
Also used : NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NotContextException(javax.naming.NotContextException) RemoteException(java.rmi.RemoteException)

Example 5 with NamingObjectProxy

use of org.glassfish.api.naming.NamingObjectProxy in project Payara by payara.

the class SerialContext method lookup.

private Object lookup(String name, int level) throws NamingException {
    // Before any lookup bind any NamedNamingObjectProxy
    // Skip if in plain Java SE client
    // TODO this should really be moved somewhere else
    NamedNamingObjectManager.checkAndLoadProxies(services);
    /**
     * In case a user is creating an IC with env passed in constructor; env
     * specifies endpoints in some form in that case, the sticky IC should
     * be stored as a thread local variable.
     */
    final boolean useSticky = myEnv.get(NamingClusterInfo.IIOP_URL_PROPERTY) != null;
    if (useSticky) {
        grabSticky();
    }
    try {
        if (name.isEmpty()) {
            // a new instance with its own independent environment.
            return (new SerialContext(myName, myEnv, services));
        }
        name = (String) TranslatedConfigView.getTranslatedValue(name);
        name = getRelativeName(name);
        if (isjavaURL(name)) {
            // it is possible that the object bound in a java url ("java:") is
            // reference object.
            Object o = javaUrlContext.lookup(name);
            if (o instanceof Reference) {
                o = getObjectInstance(name, o);
            }
            return o;
        } else {
            SerialContextProvider prvdr = getProvider();
            Object obj = prvdr.lookup(name);
            if (obj instanceof NamingObjectProxy) {
                return ((NamingObjectProxy) obj).create(this);
            }
            if (obj instanceof Context) {
                return new SerialContext(name, myEnv, services);
            }
            Object retObj = getObjectInstance(name, obj);
            return retObj;
        }
    } catch (NamingException nnfe) {
        NamingException ne = new NamingException("Lookup failed for '" + name + "' in " + this);
        ne.initCause(nnfe);
        throw ne;
    } catch (Exception ex) {
        // Issue 14732: make this FINE, as a cluster configuration change
        // can send us here in a normal retry scenario.
        logger.log(Level.FINE, EXCEPTION_DURING_LOOKUP, name);
        logger.log(Level.FINE, "", ex);
        final int nextLevel = level + 1;
        // implementation to persistent
        if (ex instanceof java.rmi.MarshalException && ex.getCause() instanceof org.omg.CORBA.COMM_FAILURE && nextLevel < MAX_LEVEL) {
            clearProvider();
            logger.fine("Resetting provider to NULL. Will get new obj ref for provider since previous obj ref was stale...");
            return lookup(name, nextLevel);
        } else {
            CommunicationException ce = new CommunicationException("Communication exception for " + this);
            ce.initCause(ex);
            throw ce;
        }
    } finally {
        if (useSticky) {
            releaseSticky();
        }
    }
}
Also used : NamingContext(org.omg.CosNaming.NamingContext) ServerContext(org.glassfish.internal.api.ServerContext) NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) RemoteException(java.rmi.RemoteException) PortableRemoteObject(javax.rmi.PortableRemoteObject)

Aggregations

NamingObjectProxy (org.glassfish.api.naming.NamingObjectProxy)5 RemoteException (java.rmi.RemoteException)3 InitialContext (javax.naming.InitialContext)3 NameNotFoundException (javax.naming.NameNotFoundException)2 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Context (javax.naming.Context)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1 NotContextException (javax.naming.NotContextException)1 Reference (javax.naming.Reference)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1 ServerContext (org.glassfish.internal.api.ServerContext)1 NamingContext (org.omg.CosNaming.NamingContext)1