use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class AutoConfig method getResourceId.
private String getResourceId(final String beanName, String resourceId, final String type, final Properties required, AppResources appResources) throws OpenEJBException {
resourceId = normalizeResourceId(resourceId);
if (resourceId == null) {
return null;
}
if (appResources == null) {
appResources = EMPTY_APP_RESOURCES;
}
// skip references such as URL which are automatically handled by the server
if (type != null && ignoredReferenceTypes.contains(type)) {
return null;
}
// check for existing resource with specified resourceId and type and properties
// check first in app namespace
String id = findResourceId(beanName + '/' + resourceId, type, required, appResources);
if (id != null) {
return id;
}
id = findResourceId(resourceId, type, required, appResources);
if (id != null) {
return id;
}
// expand search to any type -- may be asking for a reference to a sub-type
id = findResourceId(resourceId, null, required, appResources);
if (id != null) {
return id;
}
// app resources
if (appResources.appId != null && !appResources.appId.isEmpty() && resourceId.startsWith(appResources.appId + '/')) {
id = findResourceId(resourceId.substring(appResources.appId.length() + 1), type, required, appResources);
if (id != null) {
return id;
}
}
// throw an exception or log an error
final String shortName = toShortName(resourceId);
final String message = "No existing resource found while attempting to Auto-link unmapped resource-ref '" + resourceId + "' of type '" + type + "' for '" + beanName + "'. Looked for Resource(id=" + resourceId + ") and Resource(id=" + shortName + ")";
if (!autoCreateResources) {
throw new OpenEJBException(message);
}
logger.debug(message);
// if there is a provider with the specified name. use it
if (ServiceUtils.hasServiceProvider(resourceId)) {
final ResourceInfo resourceInfo = configFactory.configureService(resourceId, ResourceInfo.class);
return installResource(beanName, resourceInfo);
} else if (ServiceUtils.hasServiceProvider(shortName)) {
final ResourceInfo resourceInfo = configFactory.configureService(shortName, ResourceInfo.class);
return installResource(beanName, resourceInfo);
}
// if there are any resources of the desired type, use the first one
id = firstMatching(beanName, type, required, appResources);
if (id != null) {
return id;
}
// Auto create a resource using the first provider that can supply a resource of the desired type
return autoCreateResource(type, required, beanName);
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class AutoConfig method checkUnitDataSourceRefs.
private void checkUnitDataSourceRefs(final PersistenceUnit unit) throws OpenEJBException {
final Properties required = new Properties();
// check that non-jta-data-source does NOT point to a JtaManaged=true datasource
required.put("JtaManaged", "true");
final String invalidNonJta = findResourceId(unit.getNonJtaDataSource(), "DataSource", required, null);
if (invalidNonJta != null) {
throw new OpenEJBException("PeristenceUnit " + unit.getName() + " <non-jta-data-source> points to a jta managed Resource. Update Resource \"" + invalidNonJta + "\" to \"JtaManaged=false\", use a different Resource, or delete the <non-jta-data-source> element and a default will be supplied if possible.");
}
// check that jta-data-source does NOT point to a JtaManaged=false datasource
required.put("JtaManaged", "false");
final String invalidJta = findResourceId(unit.getJtaDataSource(), "DataSource", required, null);
if (invalidJta != null) {
throw new OpenEJBException("PeristenceUnit " + unit.getName() + " <jta-data-source> points to a non jta managed Resource. Update Resource \"" + invalidJta + "\" to \"JtaManaged=true\", use a different Resource, or delete the <jta-data-source> element and a default will be supplied if possible.");
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class CmpContainer method undeploy.
@Override
public void undeploy(final BeanContext beanContext) throws OpenEJBException {
synchronized (this) {
deploymentsById.remove(beanContext.getDeploymentID());
beansByClass.remove(beanContext.getCmpImplClass());
try {
final Field field = beanContext.getCmpImplClass().getField("deploymentInfo");
field.set(null, null);
} catch (final Exception e) {
// ignore
}
beanContext.setContainer(null);
beanContext.setContainerData(null);
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class EntityContainer method invoke.
@Override
public Object invoke(final Object deployID, InterfaceType type, final Class callInterface, final Method callMethod, final Object[] args, final Object primKey) throws OpenEJBException {
final BeanContext beanContext = this.getBeanContext(deployID);
if (beanContext == null) {
throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
}
// Use the backup way to determine call type if null was supplied.
if (type == null) {
type = beanContext.getInterfaceType(callInterface);
}
final ThreadContext callContext = new ThreadContext(beanContext, primKey);
final ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
final boolean authorized = type == InterfaceType.TIMEOUT || getSecurityService().isCallerAuthorized(callMethod, type);
if (!authorized) {
throw new ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
}
final Class declaringClass = callMethod.getDeclaringClass();
final String methodName = callMethod.getName();
if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
if (declaringClass != EJBHome.class && declaringClass != EJBLocalHome.class) {
if (methodName.startsWith("create")) {
return createEJBObject(callMethod, args, callContext, type);
} else if (methodName.startsWith("find")) {
return findMethod(callMethod, args, callContext, type);
} else {
return homeMethod(callMethod, args, callContext, type);
}
} else if (methodName.equals("remove")) {
removeEJBObject(callMethod, args, callContext, type);
return null;
}
} else if ((EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) && methodName.equals("remove")) {
removeEJBObject(callMethod, args, callContext, type);
return null;
}
callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
callContext.set(Method.class, runMethod);
return invoke(type, callMethod, runMethod, args, callContext);
} finally {
ThreadContext.exit(oldCallContext);
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class EjbHomeProxyHandler method _invoke.
@Override
protected Object _invoke(final Object proxy, final Class interfce, final Method method, final Object[] args) throws Throwable {
final String methodName = method.getName();
if (logger.isDebugEnabled()) {
logger.debug("EjbHomeProxyHandler: invoking method " + methodName + " on " + deploymentID);
}
try {
final Object retValue;
final MethodType operation = dispatchTable.get(methodName);
if (operation == null) {
retValue = homeMethod(interfce, method, args, proxy);
} else {
switch(operation) {
/*-- CREATE ------------- <HomeInterface>.create(<x>) ---*/
case CREATE:
retValue = create(interfce, method, args, proxy);
break;
case FIND:
retValue = findX(interfce, method, args, proxy);
break;
/*-- GET EJB METADATA ------ EJBHome.getEJBMetaData() ---*/
case META_DATA:
retValue = getEJBMetaData(method, args, proxy);
break;
/*-- GET HOME HANDLE -------- EJBHome.getHomeHandle() ---*/
case HOME_HANDLE:
retValue = getHomeHandle(method, args, proxy);
break;
/*-- REMOVE ------------------------ EJBHome.remove() ---*/
case REMOVE:
{
final Class type = method.getParameterTypes()[0];
/*-- HANDLE ------- EJBHome.remove(Handle handle) ---*/
if (Handle.class.isAssignableFrom(type)) {
retValue = removeWithHandle(interfce, method, args, proxy);
} else {
/*-- PRIMARY KEY ----- EJBHome.remove(Object key) ---*/
retValue = removeByPrimaryKey(interfce, method, args, proxy);
}
break;
}
default:
throw new OpenEJBRuntimeException("Inconsistent internal state: value " + operation + " for operation " + methodName);
}
}
if (logger.isDebugEnabled()) {
logger.debug("EjbHomeProxyHandler: finished invoking method " + method.getName() + ". Return value:" + retValue);
}
return retValue;
/*
* The ire is thrown by the container system and propagated by
* the server to the stub.
*/
} catch (final RemoteException re) {
if (interfaceType.isLocal()) {
throw new EJBException(re.getMessage()).initCause(re.detail);
} else {
throw re;
}
} catch (final InvalidateReferenceException ire) {
Throwable cause = ire.getRootCause();
if (cause instanceof RemoteException && interfaceType.isLocal()) {
final RemoteException re = (RemoteException) cause;
final Throwable detail = re.detail != null ? re.detail : re;
cause = new EJBException(re.getMessage()).initCause(detail);
}
throw cause;
/*
* Application exceptions must be reported dirctly to the client. They
* do not impact the viability of the proxy.
*/
} catch (final ApplicationException ae) {
final Throwable exc = ae.getRootCause() != null ? ae.getRootCause() : ae;
if (exc instanceof EJBAccessException) {
if (interfaceType.isBusiness()) {
throw exc;
} else {
if (interfaceType.isLocal()) {
throw (AccessLocalException) new AccessLocalException(exc.getMessage()).initCause(exc);
} else {
try {
throw new AccessException(exc.getMessage()).initCause(exc);
} catch (final IllegalStateException vmbug) {
// bug affects using initCause on any RemoteException subclasses in Sun 1.5_07 or lower
throw new AccessException(exc.getMessage(), (Exception) exc);
}
}
}
}
throw exc;
/*
* A system exception would be highly unusual and would indicate a sever
* problem with the container system.
*/
} catch (final SystemException se) {
if (interfaceType.isLocal()) {
throw new EJBException("Container has suffered a SystemException").initCause(se.getRootCause());
} else {
throw new RemoteException("Container has suffered a SystemException", se.getRootCause());
}
} catch (final OpenEJBException oe) {
if (interfaceType.isLocal()) {
throw new EJBException("Unknown Container Exception").initCause(oe.getRootCause());
} else {
throw new RemoteException("Unknown Container Exception", oe.getRootCause());
}
} catch (final Throwable t) {
logger.debug("EjbHomeProxyHandler: finished invoking method " + method.getName() + " with exception:" + t, t);
throw t;
}
}
Aggregations