use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class EjbObjectProxyHandler method _invoke.
@Override
public Object _invoke(final Object p, final Class interfce, final Method m, final Object[] a) throws Throwable {
Object retValue = null;
Throwable exc = null;
final String methodName = m.getName();
try {
if (logger.isDebugEnabled()) {
logger.debug("EjbObjectProxyHandler: invoking method " + methodName + " on " + deploymentID + " with identity " + primaryKey);
}
Integer operation = dispatchTable.get(methodName);
if (operation != null) {
if (operation == 3) {
if (m.getParameterTypes()[0] != EJBObject.class && m.getParameterTypes()[0] != EJBLocalObject.class) {
operation = null;
}
} else {
operation = m.getParameterTypes().length == 0 ? operation : null;
}
}
if (operation == null || !interfaceType.isComponent()) {
retValue = businessMethod(interfce, m, a, p);
} else {
switch(operation) {
case 1:
retValue = getHandle(m, a, p);
break;
case 2:
retValue = getPrimaryKey(m, a, p);
break;
case 3:
retValue = isIdentical(m, a, p);
break;
case 4:
retValue = remove(interfce, m, a, p);
break;
case 5:
retValue = getEJBHome(m, a, p);
break;
case 6:
retValue = getEJBLocalHome(m, a, p);
break;
default:
throw new OpenEJBRuntimeException("Inconsistent internal state");
}
}
return retValue;
/*
* The ire is thrown by the container system and propagated by
* the server to the stub.
*/
} catch (final InvalidateReferenceException ire) {
invalidateAllHandlers(getRegistryId());
exc = ire.getRootCause() != null ? ire.getRootCause() : new RemoteException("InvalidateReferenceException: " + ire);
throw exc;
/*
* Application exceptions must be reported dirctly to the client. They
* do not impact the viability of the proxy.
*/
} catch (final ApplicationException ae) {
exc = ae.getRootCause() != null ? ae.getRootCause() : ae;
if (exc instanceof EJBAccessException) {
if (interfaceType.isBusiness()) {
throw exc;
} else {
if (interfaceType.isLocal()) {
throw new AccessLocalException(exc.getMessage()).initCause(exc.getCause());
} else {
throw new AccessException(exc.getMessage());
}
}
}
throw exc;
/*
* A system exception would be highly unusual and would indicate a sever
* problem with the container system.
*/
} catch (final SystemException se) {
invalidateReference();
exc = se.getRootCause() != null ? se.getRootCause() : se;
logger.debug("The container received an unexpected exception: ", exc);
throw new RemoteException("Container has suffered a SystemException", exc);
} catch (final OpenEJBException oe) {
exc = oe.getRootCause() != null ? oe.getRootCause() : oe;
logger.debug("The container received an unexpected exception: ", exc);
throw new RemoteException("Unknown Container Exception", oe.getRootCause());
} finally {
if (logger.isDebugEnabled()) {
if (exc == null) {
String ret = "void";
if (null != retValue) {
try {
ret = retValue.toString();
} catch (final Exception e) {
ret = "toString() failed on (" + e.getMessage() + ")";
}
}
logger.debug("EjbObjectProxyHandler: finished invoking method " + methodName + ". Return value:" + ret);
} else {
logger.debug("EjbObjectProxyHandler: finished invoking method " + methodName + " with exception " + exc);
}
}
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class ServiceJarXmlLoader method parse.
private void parse(final String namespace) {
try {
// Load and try again
final ServicesJar servicesJar = JaxbOpenejb.readServicesJar(namespace);
for (final ServiceProvider provider : servicesJar.getServiceProvider()) {
final ID found = new ID(namespace, provider.getId());
loaded.put(found, provider);
}
} catch (final OpenEJBException e) {
throw new IllegalStateException(e);
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class CheckAsynchronous method getMethod.
private Method getMethod(final Class<?> clazz, final AsyncMethod asyncMethod) {
try {
final MethodParams methodParams = asyncMethod.getMethodParams();
final Class<?>[] parameterTypes;
if (methodParams != null) {
parameterTypes = new Class[methodParams.getMethodParam().size()];
int arrayIndex = 0;
for (final String parameterType : methodParams.getMethodParam()) {
parameterTypes[arrayIndex++] = loadClass(parameterType);
}
} else {
parameterTypes = new Class[0];
}
return clazz.getMethod(asyncMethod.getMethodName(), parameterTypes);
} catch (final NoSuchMethodException e) {
return null;
} catch (final OpenEJBException e) {
throw new OpenEJBRuntimeException(e);
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class CheckMethods method check_unusedPostCreateMethods.
public void check_unusedPostCreateMethods(final RemoteBean b) {
Class bean = null;
try {
bean = loadClass(b.getEjbClass());
} catch (final OpenEJBException e) {
return;
}
for (final Method postCreate : bean.getMethods()) {
if (!postCreate.getName().startsWith("ejbPostCreate")) {
continue;
}
final StringBuilder ejbCreate = new StringBuilder(postCreate.getName());
ejbCreate.replace(0, "ejbPostCreate".length(), "ejbCreate");
try {
bean.getMethod(ejbCreate.toString(), postCreate.getParameterTypes());
} catch (final NoSuchMethodException e) {
final String paramString = getParameters(postCreate);
warn(b, "unused.ejbPostCreate", b.getEjbClass(), postCreate.getName(), paramString, ejbCreate.toString());
}
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class WebContext method newWeakableInstance.
public <T> Instance newWeakableInstance(final Class<T> beanClass) throws OpenEJBException {
final WebBeansContext webBeansContext = getWebBeansContext();
final ConstructorInjectionBean<Object> beanDefinition = getConstructorInjectionBean(beanClass, webBeansContext);
CreationalContext<Object> creationalContext;
final Object o;
if (webBeansContext == null) {
creationalContext = null;
try {
o = beanClass.newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
throw new OpenEJBException(e);
}
} else {
creationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(beanDefinition);
o = beanDefinition.create(creationalContext);
}
// Create bean instance
final Context unwrap = InjectionProcessor.unwrap(getInitialContext());
final InjectionProcessor injectionProcessor = new InjectionProcessor(o, injections, unwrap);
final Object beanInstance;
try {
beanInstance = injectionProcessor.createInstance();
if (webBeansContext != null) {
final InjectionTargetBean<Object> bean = InjectionTargetBean.class.cast(beanDefinition);
bean.getInjectionTarget().inject(beanInstance, creationalContext);
if (shouldBeReleased(bean.getScope())) {
creationalContexts.put(beanInstance, creationalContext);
}
}
} catch (final OpenEJBException oejbe) {
if (creationalContext != null) {
creationalContext.release();
}
throw oejbe;
}
return new Instance(beanInstance, creationalContext);
}
Aggregations