use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.
the class CallbackMethodException method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
ClassLoader cl = getVerifierContext().getClassLoader();
Set<LifecycleCallbackDescriptor> callbackDescs = new HashSet<LifecycleCallbackDescriptor>();
for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
callbackDescs.addAll(interceptor.getPostConstructDescriptors());
callbackDescs.addAll(interceptor.getPreDestroyDescriptors());
callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
}
if (descriptor.hasPostConstructMethod())
callbackDescs.addAll(descriptor.getPostConstructDescriptors());
if (descriptor.hasPreDestroyMethod())
callbackDescs.addAll(descriptor.getPreDestroyDescriptors());
// session descriptor has two extra interceptor methods.
if (descriptor instanceof EjbSessionDescriptor) {
EjbSessionDescriptor ejbSessionDescriptor = ((EjbSessionDescriptor) descriptor);
if (ejbSessionDescriptor.hasPostActivateMethod())
callbackDescs.addAll(ejbSessionDescriptor.getPostActivateDescriptors());
if (ejbSessionDescriptor.hasPrePassivateMethod())
callbackDescs.addAll(ejbSessionDescriptor.getPrePassivateDescriptors());
}
for (LifecycleCallbackDescriptor callbackDesc : callbackDescs) {
try {
Method method = callbackDesc.getLifecycleCallbackMethodObject(cl);
Class[] excepClasses = method.getExceptionTypes();
for (Class exception : excepClasses) {
if (!(RuntimeException.class.isAssignableFrom(exception) || java.rmi.RemoteException.class.isAssignableFrom(exception))) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Method [ {0} ] throws an application exception.", new Object[] { method }));
}
}
}// will be caught in other tests
catch (Exception e) {
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Callback methods."));
}
return result;
}
use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.
the class CallbacksOnBeanClass method check.
public Result check(EjbDescriptor descriptor) {
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
Set<EjbInterceptor> interceptors = descriptor.getInterceptorClasses();
for (EjbInterceptor interceptor : interceptors) {
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE);
reportError(callBackDescs, "ejbActivate", interceptor.getInterceptorClassName());
}
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE);
reportError(callBackDescs, "ejbPassivate", interceptor.getInterceptorClassName());
}
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT);
reportError(callBackDescs, "ejbCreate", interceptor.getInterceptorClassName());
}
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY);
reportError(callBackDescs, "ejbRemove", interceptor.getInterceptorClassName());
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid lifecycle callback method(s)"));
}
return result;
}
use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.
the class InterceptorNoArgConstructor method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
Set<EjbInterceptor> interceptors = descriptor.getInterceptorClasses();
for (EjbInterceptor interceptor : interceptors) {
try {
Class interceptorClass = Class.forName(interceptor.getInterceptorClassName(), false, getVerifierContext().getClassLoader());
try {
interceptorClass.getConstructor(new Class[] {});
} catch (NoSuchMethodException e) {
result.getFaultLocation().setFaultyClass(interceptorClass);
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Interceptor class [ {0} ] does not have a " + "public constructor with no arguments.", new Object[] { interceptorClass }));
}
}// will be caught in other tests
catch (ClassNotFoundException e) {
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Interceptor(s) used."));
}
return result;
}
use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.
the class InterceptorMethodException method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
Set<Method> interceptorMethods = new HashSet<Method>();
if (descriptor.hasAroundInvokeMethod()) {
// XXX
/*
Method method = descriptor.getAroundInvokeMethod().getMethod(descriptor);
interceptorMethods.add(method);
*/
}
List<EjbInterceptor> interceptors = descriptor.getInterceptorChain();
for (EjbInterceptor interceptor : interceptors) {
try {
Class interceptorClass = Class.forName(interceptor.getInterceptorClassName(), false, getVerifierContext().getClassLoader());
// XXX
/*
Method method = interceptor.getAroundInvokeMethod().getMethod(interceptorClass);
interceptorMethods.add(method);
*/
} catch (ClassNotFoundException e) {
Verifier.debug(e);
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "[ {0} ] not found.", new Object[] { interceptor.getInterceptorClassName() }));
}
}
for (Method method : interceptorMethods) {
Class[] exceptions = method.getExceptionTypes();
for (Class excepClass : exceptions) {
if (java.rmi.RemoteException.class.isAssignableFrom(excepClass)) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Method [ {0} ] throws java.rmi.RemoteException.", new Object[] { method }));
}
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Interceptor methods."));
}
return result;
}
use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.
the class EjbServicesImpl method registerInterceptors.
@Override
public void registerInterceptors(EjbDescriptor<?> ejbDesc, InterceptorBindings interceptorBindings) {
com.sun.enterprise.deployment.EjbDescriptor glassfishEjbDesc = (com.sun.enterprise.deployment.EjbDescriptor) ((EjbDescriptorImpl<?>) ejbDesc).getEjbDescriptor();
// First create master list of EjbInterceptor descriptors
for (Interceptor<?> next : interceptorBindings.getAllInterceptors()) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, TRYING_TO_REGISTER_INTERCEPTOR, new Object[] { next });
}
// Add interceptor to list all interceptors in ejb descriptor
if (!(glassfishEjbDesc.hasInterceptorClass(next.getBeanClass().getName()))) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, ADDING_INTERCEPTOR_FOR_EJB, new Object[] { next.getBeanClass().getName(), glassfishEjbDesc.getEjbClassName() });
}
EjbInterceptor ejbInt = makeEjbInterceptor(next, glassfishEjbDesc.getEjbBundleDescriptor());
ejbInt.setInterceptorClass(next.getBeanClass());
glassfishEjbDesc.addInterceptorClass(ejbInt);
}
}
// Create ordered list of EjbInterceptor for each lifecycle interception type and append to
// EjbDescriptor.
// JSR 299 (CDI) interceptors are always added after any interceptors defined via
// EJB-defined metadata, so the ordering will be correct since all the ejb interceptors
// have already been processed.
glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(AROUND_CONSTRUCT, interceptorBindings.getLifecycleInterceptors(AROUND_CONSTRUCT), glassfishEjbDesc));
glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(POST_CONSTRUCT, interceptorBindings.getLifecycleInterceptors(POST_CONSTRUCT), glassfishEjbDesc));
glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(PRE_DESTROY, interceptorBindings.getLifecycleInterceptors(PRE_DESTROY), glassfishEjbDesc));
glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(PRE_PASSIVATE, interceptorBindings.getLifecycleInterceptors(PRE_PASSIVATE), glassfishEjbDesc));
glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(POST_ACTIVATE, interceptorBindings.getLifecycleInterceptors(POST_ACTIVATE), glassfishEjbDesc));
// JSR 299-provided list is organized as per-method. Append each method chain to EjbDescriptor.
Class<?> ejbBeanClass = null;
try {
ClassLoader cl = glassfishEjbDesc.getEjbBundleDescriptor().getClassLoader();
ejbBeanClass = cl.loadClass(glassfishEjbDesc.getEjbClassName());
} catch (ClassNotFoundException cnfe) {
throw new IllegalStateException("Cannot load bean class " + glassfishEjbDesc.getEjbClassName(), cnfe);
}
Class<?> ejbBeanSuperClass = ejbBeanClass;
while (!ejbBeanSuperClass.equals(java.lang.Object.class)) {
for (Method m : ejbBeanSuperClass.getDeclaredMethods()) {
if (!methodOverridden(ejbBeanClass, m)) {
List<EjbInterceptor> aroundInvokeChain = makeInterceptorChain(InterceptionType.AROUND_INVOKE, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, m), glassfishEjbDesc);
glassfishEjbDesc.addMethodLevelChain(aroundInvokeChain, m, true);
List<EjbInterceptor> aroundTimeoutChain = makeInterceptorChain(InterceptionType.AROUND_TIMEOUT, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, m), glassfishEjbDesc);
glassfishEjbDesc.addMethodLevelChain(aroundTimeoutChain, m, false);
}
}
ejbBeanSuperClass = ejbBeanSuperClass.getSuperclass();
}
}
Aggregations