You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by Thomas Herzog <t....@curecomp.com> on 2013/05/12 16:33:30 UTC
CDI Extension AnnotatedTypeBuilder
Hello guys
I want to add a @Transactional annotation which has an interceptor binding to our services within our JUnit test (Deltaspike openEjb), so that the interceptor will take place when a service method get invoked.
The problem is that I can add the annotation to our EjbService annotation (Stereotype) but the interceptor does not take place when a service method gets invoked.
Do I miss something or is this not possible??
public void handleEjbServiceannotation(@Observes ProcessAnnotatedType<EjbService> annotatedType) {
AnnotatedTypeBuilder<EjbService> builder = new AnnotatedTypeBuilder<EjbService>();
builder.readFromType(annotatedType.getAnnotatedType().getJavaClass());
builder.addToClass(new TransactionalLiteral());
annotatedType.setAnnotatedType(builder.create());
}
public class TransactionalLiteral extends AnnotationLiteral<Transactional> {
private static final long serialVersionUID = -5729507529445029857L;
}
@Stereotype
@InterceptorBinding
@Inherited
@TransactionAware
@Target({
TYPE,
METHOD })
@Retention(RUNTIME)
@Documented
public @interface Transactional {
}
@Inherited
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionAware
@Stereotype
@Logging
@ExceptionWrapping({
@ExceptionWrap(
wrapper = ConcurrentEntityUpdateException.class,
sources = OptimisticLockException.class),
@ExceptionWrap(
wrapper = CoreException.class) })
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EjbService {
}
When I try to add the annotation on the supertype of our service the interceptor does not take place either.
Thanks in advance.
Mit freundlichen Grüßen
Thomas Herzog
Softwareentwicklung
curecomp Software Services GmbH
Hafenstrasse 47-51
4020 Linz
web: www.curecomp.com <http://www.curecomp.com/>
e-Mail: t.herzog@curecomp.com <ma...@curecomp.com>
tel: +43 (0)732 9015-5563
mobile: +43 (0)664 8867 9829
Re: CDI Extension AnnotatedTypeBuilder
Posted by Mark Struberg <st...@yahoo.de>.
Hi Thomas!
Did you also add the <interceptors> section to your beans.xml?
LieGrue,
strub
>________________________________
> From: Thomas Herzog <t....@curecomp.com>
>To: deltaspike-users@incubator.apache.org
>Sent: Sunday, 12 May 2013, 16:33
>Subject: CDI Extension AnnotatedTypeBuilder
>
>
>
>Hello guys
>
>I want to add a @Transactional annotation which has an interceptor binding to our services within our JUnit test (Deltaspike openEjb), so that the interceptor will take place when a service method get invoked.
>The problem is that I can add the annotation to our EjbService annotation (Stereotype) but the interceptor does not take place when a service method gets invoked.
>Do I miss something or is this not possible??
>
> publicvoidhandleEjbServiceannotation(@ObservesProcessAnnotatedType<EjbService> annotatedType) {
> AnnotatedTypeBuilder<EjbService> builder = newAnnotatedTypeBuilder<EjbService>();
> builder.readFromType(annotatedType.getAnnotatedType().getJavaClass());
> builder.addToClass(newTransactionalLiteral());
> annotatedType.setAnnotatedType(builder.create());
> }
>
>publicclassTransactionalLiteral extendsAnnotationLiteral<Transactional> {
>
> privatestaticfinallongserialVersionUID= -5729507529445029857L;
>
>}
>
>@Stereotype
>@InterceptorBinding
>@Inherited
>@TransactionAware
>@Target({
> TYPE,
> METHOD})
>@Retention(RUNTIME)
>@Documented
>public@interfaceTransactional{
>
>}
>
>@Inherited
>@TransactionManagement(TransactionManagementType.CONTAINER)
>@TransactionAttribute(TransactionAttributeType.REQUIRED)
>@TransactionAware
>@Stereotype
>@Logging
>@ExceptionWrapping({
> @ExceptionWrap(
> wrapper = ConcurrentEntityUpdateException.class,
> sources = OptimisticLockException.class),
> @ExceptionWrap(
> wrapper = CoreException.class) })
>@Retention(RetentionPolicy.RUNTIME)
>@Target(ElementType.TYPE)
>public@interfaceEjbService{
>}
>
>When I try to add the annotation on the supertype of our service the interceptor does not take place either.
>
>Thanks in advance.
>
>Mit freundlichen Grüßen
>
>Thomas Herzog
>Softwareentwicklung
>
>curecomp Software Services GmbH
>Hafenstrasse 47-51
>4020 Linz
>
>web: www.curecomp.com
>e-Mail: t.herzog@curecomp.com
>tel: +43 (0)732 9015-5563
>mobile: +43 (0)664 8867 9829
>
>
>
>
>