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
}
}
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");
}
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());
}
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());
}
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();
}
Aggregations