[jboss-user] [JBoss AOP] - Passing MetaData through Invocations

Steven Op de beeck do-not-reply at jboss.com
Thu May 5 10:27:28 EDT 2011


Steven Op de beeck [http://community.jboss.org/people/stevenodb] created the discussion

"Passing MetaData through Invocations"

To view the discussion, visit: http://community.jboss.org/message/603708#603708

--------------------------------------------------------------
I'm trying to use the JBoss AOP *Invocation structure to pass metadata between two advices on the same Jointpoint (one call, the other exection). I read this in the documentation of JBossAOP:

You can attach untyped metadata to the invocation object, or even to the response. This allows advices to pass contextual data to one another in the incoming invocation or outgoing response for instance if you had advices running on a remote client that wanted to pass contextual data to server-side aspects. This method on invocation gets you access to a org.jboss.aop.metadata.SimpleMetaData instance so that you can attach or read data. SimpleMetaData getMetaData()

So I was hopeful that I could push some metadata on in one advice, and pull it of in a later advice. However, I don't seem to be able to get it to work. All I'm pulling off at the receiving end are null-pointers.

Some example code:

Caller side aspect:

@Aspect(scope=Scope.+PER_INSTANCE+)
*public* *class* HelloWorldCaller {

  @PointcutDef("call(java.lang.String $instanceof{backend.HelloBackEndRemote}->getValue(..))")
  *public* *static* Pointcut +getValueCallerPointcut+;


  @Bind(pointcut="hello.HelloWorldCaller.getValueCallerPointcut", type=AdviceType.+AROUND+)
*public* Object helloAdv(CallerInvocation invocation) *throws* Throwable {

                    Object invResult = *null*;

SimpleMetaData md = invocation.getMetaData();
  md.addMetaData("pom", "appel", "peer", PayloadKey.AS_IS);

*try* {
                                   invResult = invocation.invokeNext();
                    } *catch* (Exception e) {
                              e.printStackTrace();
                    }


*return* "[caller " + invResult + "]";
          }
}

Callee side aspect:

@Aspect(scope=Scope.+PER_INSTANCE+)
*public* *class* HelloWorldCallee {

  @PointcutDef("execution(java.lang.String $instanceof{backend.HelloBackEndRemote}->getValue(..))")
  *public* *static* Pointcut +getValueCalleePointcut+;

  @Bind(pointcut="hellocruel.HelloWorldCallee.getValueCalleePointcut", type=AdviceType.+AROUND+)
*public* Object helloAdv(MethodInvocation invocation) *throws* Throwable {

                    Object invResult = *null*;

                    SimpleMetaData md = invocation.getMetaData();
                    Object obj = invocation.getMetaData("pom", "appel");

                    Object obj2 = invocation.getResponseAttachment("appel");

*try* {
                              invResult = invocation.invokeNext();
                    } *catch* (Exception e) {
                              e.printStackTrace();
                    }

                    String result = "";
*if* (invResult != *null*) {
                              result = (String)invResult;
                    }

  *return* result + " [callee Goodbye World.]";
          }
}

Even when I'm debugging the respectitive MetaData fields in the MethodInvocation object are null. 

Is this supported behaviour? Am I doing something wrong?

Thanks in advance.
Steven.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/603708#603708]

Start a new discussion in JBoss AOP at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2027]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110505/defc7323/attachment-0001.html 


More information about the jboss-user mailing list