I found my own solution for this.
In my api module I create a new wrapper class called AdvisableDelegatingQueryProcessor which implements the same interface of the service I want to advise but is annotated with the annotation I look for in the pointcut. As you can guess by the name, this class simply wraps and delegates.
Code:
public class AdvisableDelegatingQueryProcessor implements RequestProcessor
Code:
/**
* @param requestProcessor
*/
public AdvisableDelegatingQueryProcessor(final RequestProcessor requestProcessor)
{
this.requestProcessor = requestProcessor;
}
@Override
@QueryProcessor
public boolean process(final ChainRequest request)
{
return requestProcessor.process(request);
}
Likewise, I moved my Aspect to my api module and decoupled the Advice from the advice class. Note the addition of the + in the pointcut in order to recognize subclasses.
Code:
/**
* The around advice to execute
*/
private QpAroundAdvice aroundAdvice;
@SuppressWarnings("unused")
@Pointcut("@annotation(edu.utah.further.ds.api.annotation.QueryProcessor)"
+ " && args(chainRequest) && this(requestProcessor+)")
private void annotatedMethod(final ChainRequest chainRequest,
final RequestProcessor requestProcessor)
{
}
@Around("annotatedMethod(chainRequest, requestProcessor)")
public Object aroundAdvice(final ProceedingJoinPoint pjp,
final ChainRequest chainRequest, final RequestProcessor requestProcessor)
{
return aroundAdvice.doAround(pjp, chainRequest, requestProcessor);
}
I then obtain an OSGi reference to my service and wrap it
Code:
<osgi:reference id="mockInitializer" bean-name="mockInitializer">
<osgi:interfaces>
<value>edu.utah.further.ds.api.service.query.SearchQueryInitializer</value>
<value>edu.utah.further.core.api.chain.RequestProcessor</value>
</osgi:interfaces>
</osgi:reference>
<bean id="wrappedInitializer"
class="edu.utah.further.ds.api.service.query.AdvisableDelegatingQueryProcessor"
p:requestProcessor-ref="mockInitializer" />
this then allows AnnotationAwareAspectJAutoProxyCreator to create a proxy around the method instead of trying to create a proxy for an already final proxy generated from the OSGi service reference.