Hi Jonathan,
comments inline...
On 01. 06. 21 20:50, Jonathan Vila wrote:
> Hi
>
> I need to create an interceptor for my custom annotation, and for every
> method (setter) annotated it will change the value being passed.
>
> *My annotation :*
>
> @Inherited
> @InterceptorBinding
> @Target({ElementType.METHOD, ElementType.TYPE})
> @Retention(RetentionPolicy.RUNTIME)
> public @interface Translate {}
>
> *My Interceptor : *
>
> @Translate
> @Interceptor
> public class TranslateProcessor {
> @AroundInvoke
> public Object invoke(InvocationContext context) throws Exception {
> // here I should modify the value being passed to the method
> return context.proceed();
> }
> }
>
> *My class : *
>
> public class MyDto {
> private String title;
>
> @Translate
> public void setTitle(String title) {
> this.title = title;
> }
> }
>
> But basically I have the problem that the code in the interceptor is
> never called.
> Is there anything I'm missing to enable the interceptor ? I assume
> Quarkus doesn't need the beans.xml file,
It depends. The descriptor is not needed for application classes, i.e.
if the interceptor is located in src/main/java you don't need to do
anything. However, if you place the interceptor in a dependency jar then
it has to contain a beans.xml (content is ignored) or a Jandex index
(META-INF/jandex.idx). If you can’t modify the dependency, you can still
index it by adding quarkus.index-dependency entries to your
application.properties.
See also
https://quarkus.io/guides/cdi-reference#bean_discovery
> and also I don't see the need
> to set the priority to the interceptor.
If you don't set the priority the value of 0 is used.
>
> Jonathan Vila
> --
> Barcelona Java Users Group Leader
> <
https://mailtrack.io/trace/link/08d3f1e6c014f590aff2afd17e958e88db6fb281?url=http%3A%2F%2Fbarcelonajug.org%2F&userId=3660166&signature=73316107bc54e7fa>
> <
https://mailtrack.io/trace/link/ad6f0f889ec8dcbb4f25aaa5847e842158a4d444?url=http%3A%2F%2Fwww.meetup.com%2FBarcelonaJUG&userId=3660166&signature=a96f8c2b0a28f696><
https://mailtrack.io/trace/link/5aa57dd59f5505843f93dbbaf0ce91bd51294eed?url=http%3A%2F%2Fbit.ly%2FBarcelonaJUG&userId=3660166&signature=418b74d5262398f5><
https://mailtrack.io/trace/link/dcc88f5ec352179bac960039049488924d6b51e8?url=http%3A%2F%2Ftwitter.com%2FBarcelonaJUG&userId=3660166&signature=6cce41d2c6a11a81><
https://mailtrack.io/trace/link/57f3a2e0f9d0098941123c31b6af1e2fd3753977?url=http%3A%2F%2Fwww.facebook.com%2FBarcelonaJUG&userId=3660166&signature=5903945ae91f3672><
https://mailtrack.io/trace/link/a3755d537ba0595c80c50694091dcbb6b6525398?url=http%3A%2F%2Fj.mp%2FbarcelonaJUG&userId=3660166&signature=c27d3af352c53a28><
https://mailtrack.io/trace/link/edd4592231d3bcadfdf7cb9a30534bbcfaf08f9c?url=http%3A%2F%2Fbit.ly%2FBCNjug&userId=3660166&signature=0141c50419a1d093>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
quarkus-dev...@googlegroups.com
> <mailto:
quarkus-dev...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/quarkus-dev/CABNTrS_yachzFdbmai0t2tdBFt5HXxMuueOYEpBd2OF_X8NHiw%40mail.gmail.com
> <
https://groups.google.com/d/msgid/quarkus-dev/CABNTrS_yachzFdbmai0t2tdBFt5HXxMuueOYEpBd2OF_X8NHiw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
--
Martin Kouba
Software Engineer
Red Hat, Czech Republic