[JBoss AOP] - Re: Dynamic AOP and User-Defined Class Loader
by flavia.rainone@jboss.com
The problem with your example is that, while the joinpoint has been loaded by the system class loader (Test.class), the interceptor was loaded by a different, unrelated, class loader.
For Test instances to be intercepted by an interceptor, this interceptor must be visible to the Test.class. Otherwise, it won't be possible of inserting calls to the interceptor at the Test.class.
Look at the example below:
| public class Test
| {
| public void print()
| {
| ...
| (new GrettingInterceptor()).invoke(...);
| ...
| }
| }
|
This a simplified view of what JBoss AOP does. It will insert a call to the interceptor. However, Test.class cannot see GreetingInterceptor.class, because its class loader cannot find this class.
The solution to make the code above work is to make GreetingInterceptor visible to Test.class. For this, either GreetingInterceptor class loader is a parent of the Test class loader, and Test class loader delegates to its parent... or they must be loaded by the same class loader. So, the code below should work:
| ClassLoader loader = new ... // my class loader
| Thread.currentThread().setContextClassLoader(loader);
| Class clazz = Class.forName("aspect.GreetingInterceptor", false, loader);
|
| AdviceBinding binding = new AdviceBinding();
| binding.setPointcutExpression("execution(* *.Test->*(..))");
| binding.addInterceptor(clazz);
| AspectManager.instance().addBinding(binding);
|
| Class testClass = Class.forName(Test.class.getName(), false, loader);
| Object testInstance = testClass.newInstance();
| Method printMethod = testClass.getDeclaredMethod("print", new Class[0]);
| printMethod.invoke(testInstance, new Object[0]);
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148852#4148852
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148852
16 years, 4 months
[EJB/JBoss] - EJB3 and CORBA clients
by arv
Hello,
could somebody explain me, how to connect a ejb3 bean deployed in jboss-5.0.0.Beta4 from a CORBA client (Java and/or C++) ?
Here is the bean code:
Bean Interface:
| package arv;
|
| import java.rmi.RemoteException;
| import javax.ejb.EJBObject;
|
| public interface HelloInterface extends EJBObject
| {
| void helloWorld() throws RemoteException;
| }
|
Bean Implementation:
| import javax.ejb.Remote;
| import javax.ejb.Stateless;
|
| import org.jboss.ejb3.annotation.IIOP;
| import org.jboss.ejb3.annotation.RemoteBinding;
| import org.jboss.ejb3.annotation.defaults.RemoteBindingDefaults;
|
| import java.rmi.RemoteException;
|
| @Stateless
| @Remote(HelloInterface.class)
| @RemoteBinding(factory=RemoteBindingDefaults.PROXY_FACTORY_IMPLEMENTATION_IOR)
| @IIOP(interfaceRepositorySupported=false)
| public class HelloWorldBean {
|
| public HelloWorldBean() throws Exception {}
|
| public void helloWorld() throws RemoteException {
| System.out.println("Hello");
| }
|
| }
|
|
I compiled both classes and packaged them in a jar-file HelloWorld.jar.
I copied the jar file into jboss-5.0.0.Beta4/server/all/deploy and
got following jboss output:
|
| 13:44:02,426 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:jar=HelloWorld.jar,name=HelloWorldBean,service=EJB3 with dependencies:
| 13:44:02,457 INFO [MCKernelAbstraction] and demands:
| 13:44:02,457 INFO [MCKernelAbstraction] jboss.ejb:service=EJBTimerService
| 13:44:02,457 INFO [MCKernelAbstraction] and supplies:
| 13:44:06,263 INFO [EJBContainer] STARTED EJB: arv.HelloWorldBean ejbName: HelloWorldBean
|
|
JNDIView shows following entries:
| java:comp namespace of the component jboss.j2ee:jar=HelloWorld.jar,name=HelloWorldBean,service=EJB3 :
|
| +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)
| +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef)
| +- EJBContext (class: javax.ejb.EJBContext)
| +- env (class: org.jnp.interfaces.NamingContext)
| +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)
|
|
Thank you very much !
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148851#4148851
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148851
16 years, 4 months
[JBoss AOP] - About multiple introductions and mixins
by elysch
Hi all.
I hope my question is not too dumb.
I have a project in which I need to specify via AOP all the functionalities of each use case by it self.
So, I have an almost empty structure with hibernate, spring, and struts (an AndroMDA structure with jbpm, etc).
In it's various layers I need to add new methods and attributes using introductions.
My problem is that, for example, I add a new "find" method in the Dao object and when I add a method that uses it in a service object I get an error on compilation, because this new method can't be found.
I hope I can explain it clearly with code:
For example, the jboss-aop.xml has:
<introduction class="com.mitalteli.bolsaDeTrabajo.domain.VacanteDao">
| <mixin>
| <interfaces>
| com.mitalteli.bolsaDeTrabajo.useCaseSlices.specific.consultarVacantes.IAspectoVacanteDao
| </interfaces>
| <class>com.mitalteli.bolsaDeTrabajo.useCaseSlices.specific.consultarVacantes.MixinAspectoVacanteDao</class>
| <construction>new com.mitalteli.bolsaDeTrabajo.useCaseSlices.specific.consultarVacantes.MixinAspectoVacanteDao(this)</construction>
| </mixin>
| </introduction>
and
<introduction class="com.mitalteli.bolsaDeTrabajo.service.ServicioConsultarVacantesBase">
| <mixin>
| <interfaces>
| com.mitalteli.bolsaDeTrabajo.useCaseSlices.specific.consultarVacantes.IAspectoServicioConsultarVacantesBase
| </interfaces>
| <class>com.mitalteli.bolsaDeTrabajo.useCaseSlices.specific.consultarVacantes.MixinAspectoServicioConsultarVacantesBase</class>
| <construction>new com.mitalteli.bolsaDeTrabajo.useCaseSlices.specific.consultarVacantes.MixinAspectoServicioConsultarVacantesBase(this)</construction>
| </mixin>
| </introduction>
and their respective mixins contain:
/**
| * @see com.mitalteli.bolsaDeTrabajo.domain.VacanteDao#encuentraConCriterios(com.mitalteli.bolsaDeTrabajo.vo.CriteriosBusquedaConsultarVacantesVO)
| */
| public java.util.List encuentraConCriterios(final com.mitalteli.bolsaDeTrabajo.vo.CriteriosBusquedaConsultarVacantesVO criteria)
| {
| if (criteria == null)
| {
| throw new IllegalArgumentException(
| "com.mitalteli.bolsaDeTrabajo.domain.VacanteDao.encuentraConCriterios(com.mitalteli.bolsaDeTrabajo.vo.CriteriosBusquedaConsultarVacantesVO criteria) - 'criteria' can not be null");
| }
| try
| {
| return this.handleEncuentraConCriterios(criteria);
| }
| catch (Throwable th)
| {
| throw new java.lang.RuntimeException(
| "Error performing 'com.mitalteli.bolsaDeTrabajo.domain.VacanteDao.encuentraConCriterios(com.mitalteli.bolsaDeTrabajo.vo.CriteriosBusquedaConsultarVacantesVO criteria)' --> " + th,
| th);
| }
| }
and
/**
| * @see com.mitalteli.bolsaDeTrabajo.service.ServicioConsultarVacantes#encuentraVacantes(com.mitalteli.bolsaDeTrabajo.vo.CriteriosBusquedaConsultarVacantesVO)
| */
| public /*protected*/ com.mitalteli.bolsaDeTrabajo.vo.ResumenVacanteVO[] handleEncuentraVacantes(com.mitalteli.bolsaDeTrabajo.vo.CriteriosBusquedaConsultarVacantesVO criteria)
| throws java.lang.Exception
| {
| //List vacantes = servicioConsultarVacantesBase.getVacanteDao().encuentraConCriterios(criteria);
| List vacantes = getVacanteDao().encuentraConCriterios(criteria);
| getVacanteDao().toResumenVacanteVOCollection(vacantes);
| return (ResumenVacanteVO[])vacantes.toArray(new ResumenVacanteVO[0]);
| }
So, as I told before, the Dao class should have now a find method called: encuentraConCriterios, so the call to getVacanteDao().encuentraConCriterios(criteria); should be found, but that's not the case. I get the error message:
...\useCaseSlices\specific\consultarVacantes\MixinAspectoServicioConsultarVacantesB
| ase.java:[162,39] cannot find symbol
| symbol : method encuentraConCriterios(com.mitalteli.bolsaDeTrabajo.vo.Criterios
| BusquedaConsultarVacantesVO)
| location: interface com.mitalteli.bolsaDeTrabajo.domain.VacanteDao
I'm trying to do loadtime waving on a jboss-4.2.1.GA with jboss-aop-1.5.6 with jdk 6 update 3, and jre 6 update 5 on my WinXP pro Service pack2 computer.
So I'm not waving the classes yet, just compiling them. I guess I'm doing some thing wrong.
Is this even possible? Maybe If I compile and wave the first mixin, and then compile and wave the second one, instead of doing loadtime waving?
Any Ideas?
I'm very very new to all this AOP technology, so maybe I don't understand something right.
Thank you all in advance.
Ely.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4148849#4148849
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4148849
16 years, 4 months