[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[ajdt-dev] AspectJ applied to EJBs, JNDI issues / Example TestCase/ pretty urgent
|
hello all,
has anyone ever tried to use AspectJ with EJBs?
Here's my testcase
public aspect SequenceRetrievalAspect {
private SequenceSessionLocal sequenceSession;
public SequenceRetrievalAspect() {
try {
// can't look it up using JNDI. intercepted bean should have a reference to SequenceSessionBean
// can't look it up neither using SequenceSession JNDI, since its JNDI is resolved to localhost/cell1/server1/myapp/SequenceSessionLocalHome
// and that will make my code host-dependent
} catch (Exception exc) {
....
}
}
pointcut getSequence(DTO dto) : execution (* com.myapp.ejb.MyBean.methodX(DTO)) && args(dto);
before(DTO dto) : getSequence(dto) {
if(dto.getID() == null)
dto.setID(sequenceSession.getNextIndex());
}
}
}
I had plenty of problems in looking up the EJB that needs to be used by the Aspect.
i could not use EJB-REF in the form java:/comp/env/ejb , not even the full JNDI name
of the EJB, since my server resolves full jndi name to some sort of host/cell/server/ plus JNDI Name of the EJB
I ran short of alternatives:
- either write a pointcut that intercept calls to SequenceSession and cache the SequenceSession in the aspect (but this could potentially fail if i need
to get sequence before even calling SequenceSession..)
- or intercepts calls where EJBs are being put into JNDI tree.....
can anyone suggest me something?
obviously i coudl avoid using aspects, but in that case i'll need to duplicate the Sequecne retrieval code in all places where i need the sequence
thanks and regards
marco