Search in sources :

Example 6 with InvocationException

use of org.glassfish.api.invocation.InvocationException in project Payara by payara.

the class AppTest method testNonCachingNamingObjectFactory.

@Test
public void testNonCachingNamingObjectFactory() {
    GlassfishNamingManagerImpl nm = null;
    InvocationManager im = new InvocationManagerImpl();
    ComponentInvocation inv = null;
    try {
        InitialContext ic = newInitialContext();
        triggerLoadingNamedProxies(ic);
        nm = new GlassfishNamingManagerImpl(ic);
        nm.setInvocationManager(im);
        List<Binding> bindings = new ArrayList<Binding>();
        NamingObjectFactory intFactory = new NamingObjectFactory() {

            private int counter = 1;

            public boolean isCreateResultCacheable() {
                return false;
            }

            public Object create(Context ic) {
                return new Integer(++counter);
            }

            public String toString() {
                return "Huh? ";
            }
        };
        bindings.add(new Binding("conf/area", intFactory));
        bindings.add(new Binding("conf/location", "Santa Clara"));
        nm.bindToComponentNamespace("app1", "mod1", "comp1", false, bindings);
        inv = new ComponentInvocation("comp1", ComponentInvocation.ComponentInvocationType.EJB_INVOCATION, null, null, null);
        im.preInvoke(inv);
        System.out.println("**lookup(java:comp/env/conf/area) ==> " + ic.lookup("java:comp/env/conf/area"));
        System.out.println("**lookup(java:comp/env/conf/location) ==> " + ic.lookup("java:comp/env/conf/location"));
        NamingObjectFactory floatFactory = new NamingObjectFactory() {

            private int counter = 1;

            public boolean isCreateResultCacheable() {
                return false;
            }

            public Object create(Context ic) {
                return Float.valueOf(("7" + (++counter)) + "." + 2323);
            }

            public String toString() {
                return "Huh? ";
            }
        };
        List<Binding> bindings2 = new ArrayList<Binding>();
        bindings2.add(new Binding("conf/area", floatFactory));
        bindings2.add(new Binding("conf/location", "Santa Clara[14]"));
        nm.bindToComponentNamespace("app1", "mod1", "comp2", false, bindings2);
        inv = new ComponentInvocation("comp2", ComponentInvocation.ComponentInvocationType.EJB_INVOCATION, null, null, null);
        im.preInvoke(inv);
        System.out.println("**lookup(java:comp/env/conf/area) ==> " + ic.lookup("java:comp/env/conf/area"));
        System.out.println("**lookup(java:comp/env/conf/location) ==> " + ic.lookup("java:comp/env/conf/location"));
        assert (true);
    } catch (InvocationException inEx) {
        inEx.printStackTrace();
        assert (false);
    } catch (Exception ex) {
        ex.printStackTrace();
        assert (false);
    } finally {
        try {
            im.postInvoke(inv);
            nm.unbindComponentObjects("comp1");
        } catch (InvocationException inEx) {
        } catch (Exception ex) {
        }
    }
}
Also used : JNDIBinding(org.glassfish.api.naming.JNDIBinding) InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) ArrayList(java.util.ArrayList) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) InvocationException(org.glassfish.api.invocation.InvocationException) InvocationManagerImpl(org.glassfish.api.invocation.InvocationManagerImpl) InvocationException(org.glassfish.api.invocation.InvocationException) NamingObjectFactory(com.sun.enterprise.naming.spi.NamingObjectFactory)

Example 7 with InvocationException

use of org.glassfish.api.invocation.InvocationException in project Payara by payara.

the class JavaEETransactionManagerSimplified method enlistComponentResources.

private void enlistComponentResources(ComponentInvocation inv) throws InvocationException {
    try {
        Transaction tran = (Transaction) inv.getTransaction();
        if (isTransactionActive(tran)) {
            List l = getExistingResourceList(inv.getInstance(), inv);
            if (l == null || l.size() == 0)
                return;
            Iterator it = l.iterator();
            // END IASRI 4705808 TTT002
            while (it.hasNext()) {
                TransactionalResource h = (TransactionalResource) it.next();
                try {
                    enlistResource(tran, h);
                } catch (Exception ex) {
                    if (_logger.isLoggable(Level.FINE))
                        _logger.log(Level.WARNING, "enterprise_distributedtx.pooling_excep", ex);
                    it.remove();
                    handleResourceError(h, ex, tran);
                }
            }
        // END OF IASRI 4658504
        }
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "enterprise_distributedtx.excep_in_enlist", ex);
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) TransactionalResource(com.sun.enterprise.transaction.spi.TransactionalResource) InvocationException(org.glassfish.api.invocation.InvocationException) WorkException(javax.resource.spi.work.WorkException) RemoteException(java.rmi.RemoteException) XAException(javax.transaction.xa.XAException)

Aggregations

InvocationException (org.glassfish.api.invocation.InvocationException)7 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)4 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)3 RemoteException (java.rmi.RemoteException)3 WorkException (javax.resource.spi.work.WorkException)3 XAException (javax.transaction.xa.XAException)3 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)2 TransactionalResource (com.sun.enterprise.transaction.spi.TransactionalResource)2 InvocationManager (org.glassfish.api.invocation.InvocationManager)2 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)1 NamingObjectFactory (com.sun.enterprise.naming.spi.NamingObjectFactory)1 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)1 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)1 SecurityContext (com.sun.enterprise.security.SecurityContext)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 ResourceException (javax.resource.ResourceException)1