use of org.apache.openejb.jee.Interceptor in project tomee by apache.
the class EjbJarInfoBuilder method initInterceptors.
private void initInterceptors(final EjbModule jar, final EjbJarInfo ejbJar) throws OpenEJBException {
if (jar.getEjbJar().getInterceptors().length == 0) {
return;
}
if (jar.getEjbJar().getAssemblyDescriptor() == null) {
return;
}
if (jar.getEjbJar().getAssemblyDescriptor().getInterceptorBinding() == null) {
return;
}
for (final Interceptor s : jar.getEjbJar().getInterceptors()) {
final InterceptorInfo info = new InterceptorInfo();
info.clazz = s.getInterceptorClass();
copyCallbacks(s.getAroundInvoke(), info.aroundInvoke);
copyCallbacks(s.getPostConstruct(), info.postConstruct);
copyCallbacks(s.getPreDestroy(), info.preDestroy);
copyCallbacks(s.getPostActivate(), info.postActivate);
copyCallbacks(s.getPrePassivate(), info.prePassivate);
copyCallbacks(s.getAfterBegin(), info.afterBegin);
copyCallbacks(s.getBeforeCompletion(), info.beforeCompletion);
copyCallbacks(s.getAfterCompletion(), info.afterCompletion);
copyCallbacks(s.getAroundTimeout(), info.aroundTimeout);
ejbJar.interceptors.add(info);
}
for (final InterceptorBinding binding : jar.getEjbJar().getAssemblyDescriptor().getInterceptorBinding()) {
final InterceptorBindingInfo info = new InterceptorBindingInfo();
info.ejbName = binding.getEjbName();
info.excludeClassInterceptors = binding.getExcludeClassInterceptors();
info.excludeDefaultInterceptors = binding.getExcludeDefaultInterceptors();
info.interceptors.addAll(binding.getInterceptorClass());
if (binding.getInterceptorOrder() != null) {
info.interceptorOrder.addAll(binding.getInterceptorOrder().getInterceptorClass());
}
info.method = toInfo(binding.getMethod());
info.className = binding.getClassName();
ejbJar.interceptorBindings.add(info);
}
}
use of org.apache.openejb.jee.Interceptor in project tomee by apache.
the class DebuggableVmHackery method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
ejbJar.setRelationships(null);
final List<String> removed = new ArrayList<>();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
pruneRefs(bean, ejbDeployment);
// }
if (!(bean instanceof MessageDrivenBean) && !(bean instanceof EntityBean)) {
continue;
}
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
removed.add(ejbName);
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Drop any ejb ref to with an ejb-link to a removed ejb
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
bean.getEjbLocalRefMap().keySet().removeAll(removed);
bean.getEjbRefMap().keySet().removeAll(removed);
}
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
pruneRefs(interceptor, new EjbDeployment());
}
}
return appModule;
}
use of org.apache.openejb.jee.Interceptor in project tomee by apache.
the class RemoveWebServices method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
// Clear any <service-ref> references from ejbs
bean.getServiceRef().clear();
if (!(bean instanceof SessionBean)) {
continue;
}
final SessionBean sessionBean = (SessionBean) bean;
if (sessionBean.getServiceEndpoint() == null) {
continue;
}
sessionBean.setServiceEndpoint(null);
// if not, then we should just delete it
if (sessionBean.getHome() != null) {
continue;
}
if (sessionBean.getLocalHome() != null) {
continue;
}
if (sessionBean.getBusinessLocal().size() > 0) {
continue;
}
if (sessionBean.getBusinessRemote().size() > 0) {
continue;
}
// Ok, delete away...
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
// As well, let's get rid of any transaction or security attributes
// associated with the bean we just deleted.
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Clear any <service-ref> references from interceptors
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
interceptor.getServiceRef().clear();
}
}
return appModule;
}
use of org.apache.openejb.jee.Interceptor in project tomee by apache.
the class CheckClasses method validate.
public void validate(final EjbModule ejbModule) {
final ClassLoader loader = ejbModule.getClassLoader();
for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
try {
final Class<?> beanClass = check_hasEjbClass(loader, bean);
// All the subsequent checks require the bean class
if (beanClass == null) {
continue;
}
if (!(bean instanceof RemoteBean)) {
continue;
}
if (bean instanceof SessionBean && ((SessionBean) bean).getProxy() != null) {
continue;
}
final RemoteBean b = (RemoteBean) bean;
check_isEjbClass(b);
check_hasDependentClasses(b, b.getEjbClass(), "ejb-class");
check_hasInterface(b);
if (b.getRemote() != null) {
checkInterface(loader, b, beanClass, "remote", b.getRemote());
}
if (b.getHome() != null) {
checkInterface(loader, b, beanClass, "home", b.getHome());
}
if (b.getLocal() != null) {
checkInterface(loader, b, beanClass, "local", b.getLocal());
}
if (b.getLocalHome() != null) {
checkInterface(loader, b, beanClass, "local-home", b.getLocalHome());
}
if (b instanceof SessionBean) {
final SessionBean sessionBean = (SessionBean) b;
for (final String interfce : sessionBean.getBusinessLocal()) {
checkInterface(loader, b, beanClass, "business-local", interfce);
}
for (final String interfce : sessionBean.getBusinessRemote()) {
checkInterface(loader, b, beanClass, "business-remote", interfce);
}
}
} catch (final RuntimeException e) {
throw new OpenEJBRuntimeException(bean.getEjbName(), e);
}
}
for (final Interceptor interceptor : ejbModule.getEjbJar().getInterceptors()) {
check_hasInterceptorClass(loader, interceptor);
}
}
use of org.apache.openejb.jee.Interceptor in project tomee by apache.
the class CheckInvalidInterceptorTest method test1.
@Keys({ @Key(value = "interceptor.unused", count = 2, type = KeyType.WARNING), @Key("aroundInvoke.invalidArguments") })
public EjbJar test1() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(BarBean.class));
final Interceptor unused = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(UnusedInterceptor.class));
final Interceptor unused1 = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(UnusedInterceptor1.class));
final Interceptor used = ejbJar.addInterceptor(new org.apache.openejb.jee.Interceptor(UsedInterceptor.class));
final List<InterceptorBinding> interceptorBindings = ejbJar.getAssemblyDescriptor().getInterceptorBinding();
final InterceptorBinding binding = new InterceptorBinding("BarBean", used);
interceptorBindings.add(binding);
return ejbJar;
}
Aggregations