Search in sources :

Example 1 with CreateException

use of javax.ejb.CreateException in project spring-framework by spring-projects.

the class SimpleRemoteStatelessSessionProxyFactoryBeanTests method testCreateException.

@Test
public void testCreateException() throws Exception {
    final String jndiName = "foo";
    final CreateException cex = new CreateException();
    final MyHome home = mock(MyHome.class);
    given(home.create()).willThrow(cex);
    JndiTemplate jt = new JndiTemplate() {

        @Override
        public Object lookup(String name) {
            // parameterize
            assertTrue(name.equals(jndiName));
            return home;
        }
    };
    SimpleRemoteStatelessSessionProxyFactoryBean fb = new SimpleRemoteStatelessSessionProxyFactoryBean();
    fb.setJndiName(jndiName);
    // rely on default setting of resourceRef=false, no auto addition of java:/comp/env prefix
    fb.setBusinessInterface(MyBusinessMethods.class);
    assertEquals(fb.getBusinessInterface(), MyBusinessMethods.class);
    fb.setJndiTemplate(jt);
    // Need lifecycle methods
    fb.afterPropertiesSet();
    MyBusinessMethods mbm = (MyBusinessMethods) fb.getObject();
    assertTrue(Proxy.isProxyClass(mbm.getClass()));
    try {
        mbm.getValue();
        fail("Should have failed to create EJB");
    } catch (RemoteException ex) {
    // expected
    }
}
Also used : JndiTemplate(org.springframework.jndi.JndiTemplate) RemoteException(java.rmi.RemoteException) CreateException(javax.ejb.CreateException) Test(org.junit.Test)

Example 2 with CreateException

use of javax.ejb.CreateException in project opennms by OpenNMS.

the class AlarmListJ2eeConnectionManagerThread method lookupBean.

/**
	 *  Method to find and connect to the remote bean.
	 */
private void lookupBean() throws NamingException, RemoteException {
    /* Create a new InitialContext with the properties paramters - 
		 * The starting point of naming resolution
		 */
    LOG.info("AlarmListJ2eeConnectionManagerThread.lookupBean() Looking up QoS bean");
    InitialContext ic = new InitialContext(env);
    LOG.info("AlarmListJ2eeConnectionManagerThread.lookupBean() InitialContext created");
    try {
        ref = ic.lookup(props.getProperty("org.openoss.opennms.spring.qosd.jvthome"));
        LOG.info("AlarmListJ2eeConnectionManagerThread.lookupBean() QoS Bean found");
        JVTAlarmMonitorHome home = (JVTAlarmMonitorHome) PortableRemoteObject.narrow(ref, JVTAlarmMonitorHome.class);
        LOG.debug("AlarmListJ2eeConnectionManagerThread.lookupBean() home initialised");
        session = home.create();
        LOG.debug("AlarmListJ2eeConnectionManagerThread.lookupBean() Session created");
        alarmInternals = (AlarmMonitor) PortableRemoteObject.narrow(session.getHandle().getEJBObject(), AlarmMonitor.class);
        if (alarmInternals == null)
            LOG.error("AlarmListJ2eeConnectionManagerThread.lookupBean() AlarmMonitor alarmInternals is null line 244");
    } catch (IllegalArgumentException iae_ex) {
        LOG.error("AlarmListJ2eeConnectionManagerThread.lookupBean() jvthome property does not exist", iae_ex);
    }/*catch(RemoteException remote_ex)
		 {
		 log.error("Cannot connect to bean", remote_ex);
		 status = DISCONNECTED;
		 
		 }*/
     catch (CreateException create_ex) {
        LOG.error("AlarmListJ2eeConnectionManagerThread.lookupBean() Cannot create new session", create_ex);
    } catch (NullPointerException np_ex) {
        LOG.error("AlarmListJ2eeConnectionManagerThread.lookupBean() NullPointerException caught", np_ex);
    } finally {
        ic.close();
    }
    LOG.info("AlarmListJ2eeConnectionManagerThread.lookupBean() New bean session started");
}
Also used : JVTAlarmMonitorHome(javax.oss.fm.monitor.JVTAlarmMonitorHome) CreateException(javax.ejb.CreateException) InitialContext(javax.naming.InitialContext)

Example 3 with CreateException

use of javax.ejb.CreateException in project adempiere by adempiere.

the class ServerBean method ejbCreate.

//	toString
/**************************************************************************
	 * 	Create the Session Bean
	 */
@PostConstruct
public void ejbCreate() {
    m_no = ++s_no;
    try {
        if (!Adempiere.startup(false))
            throw new CreateException("Adempiere could not start");
    } catch (Exception ex) {
        log.log(Level.SEVERE, "ejbCreate", ex);
    //	throw new CreateException ();
    }
    log.info("#" + getStatus());
}
Also used : CreateException(javax.ejb.CreateException) CreateException(javax.ejb.CreateException) PostConstruct(javax.annotation.PostConstruct)

Example 4 with CreateException

use of javax.ejb.CreateException in project adempiere by adempiere.

the class StatusBean method ejbCreate.

//	toString
/**************************************************************************
	 * 	Create the Session Bean
	 */
@PostConstruct
public void ejbCreate() {
    m_no = ++s_no;
    try {
        if (!Adempiere.startup(false))
            throw new CreateException("Compiere could not start");
    } catch (Exception ex) {
        log.log(Level.SEVERE, "", ex);
    //	throw new CreateException ();
    }
    log.info("#" + m_no + " - " + getStatus());
}
Also used : CreateException(javax.ejb.CreateException) CreateException(javax.ejb.CreateException) PostConstruct(javax.annotation.PostConstruct)

Example 5 with CreateException

use of javax.ejb.CreateException in project wildfly by wildfly.

the class StatefulInitMethodInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
    final Method method = SessionBeanHomeInterceptorFactory.INIT_METHOD.get();
    final Object[] params = SessionBeanHomeInterceptorFactory.INIT_PARAMETERS.get();
    //we remove them immediately, so they are not set for the rest of the invocation
    //TODO: find a better way to handle this
    SessionBeanHomeInterceptorFactory.INIT_METHOD.remove();
    SessionBeanHomeInterceptorFactory.INIT_PARAMETERS.remove();
    if (method != null) {
        final InvocationType invocationType = context.getPrivateData(InvocationType.class);
        try {
            context.putPrivateData(InvocationType.class, InvocationType.SFSB_INIT_METHOD);
            method.invoke(context.getTarget(), params);
        } catch (InvocationTargetException e) {
            if (CreateException.class.isAssignableFrom(e.getCause().getClass())) {
                EjbExceptionTransformingInterceptorFactories.setCreateException((CreateException) e.getCause());
            }
            throw Interceptors.rethrow(e.getCause());
        } finally {
            context.putPrivateData(InvocationType.class, invocationType);
        }
    }
    return context.proceed();
}
Also used : InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) Method(java.lang.reflect.Method) CreateException(javax.ejb.CreateException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

CreateException (javax.ejb.CreateException)8 Test (org.junit.Test)3 JndiTemplate (org.springframework.jndi.JndiTemplate)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 PostConstruct (javax.annotation.PostConstruct)2 RemoteException (java.rmi.RemoteException)1 EJBLocalObject (javax.ejb.EJBLocalObject)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 JVTAlarmMonitorHome (javax.oss.fm.monitor.JVTAlarmMonitorHome)1 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)1 RemoteAccessException (org.springframework.remoting.RemoteAccessException)1