[jboss-user] [JBoss AOP] - How to access intercepted methods in JSF?

ykrishnaprasad do-not-reply at jboss.com
Wed Dec 27 17:54:58 EST 2006


1) If there is a return in the intercepted method(call or execution), the interceptor doesn't work.
Is there anything i am missing?

2) I have an AOP "Project1" with interceptor on a method in a class.
I do not have a problem running the Project1 by itself(unless i use a return in my intercepted method).
But if a take the Project1 jar(without jboss-aop.xml in the jar) file for 
this project along with its jboss-aop.xml(2 files in total)
and drop it in JBoss deploy directory, and try to use the intercepted method of Project1 class
in JSF of "Project2", it doesn't intercept.
Am i deploying correctly?

Project1:
Calltest.java
HelloAOPInterceptor.java
jboss-aop.xml

Project2:
JSF, faces-config.xml and web.xml

(The reason for seperating the jar and jboss-aop.xml(of Project1) 
is that i can reference the deploy directory project1.jar in my Project2 library 
list to use its classes.If i include the jboss-aop.xml 
in the jar itself, then it has to be named as project1.jar.aop(according to JBoss AOP framework doc chapter 10)
which i cannot add to my library list in Project 2.)

My mbean(faces-config.xml) in project2 looks like this:

  |   </managed-bean>
  |      <managed-bean>
  |        <managed-bean-name>
  |            callTest
  |        </managed-bean-name>
  |        <managed-bean-class>
  |            jbossaop.callTest
  |        </managed-bean-class>
  |        <managed-bean-scope>
  |            request
  |        </managed-bean-scope>
  |    </managed-bean>
  | 

where i declared callTest class in my jbossaop package( which i got from Project1).

My jsf(jsp) in project 2 looks like:

  |     <f:view>
  |     <h:form id="helloForm" >
  |                 <%@ page import="jbossaop.*" %>
  |   		<h2>Hi. My name is Duke. I'm thinking of a number from
  | 		<h:outputText value="#{callTest.callme1}"/> to 
  | 		<h:outputText value="#{UserNumberBean.maximum}"/>.
  |                          Can you guess it?
  | 		</h2>
  | ............
  |    </h:form>
  |    </f:view>
  | 

UserNumberBean is a bean within Project 2 and callTest is from the aop jar i added to the library list of Project2.
The callTest.callme1 corresponds to the getCallme1() method in callTest class.

The callTest class in Project1 looks like:


  | package jbossaop;
  | 
  | public class callTest {
  |         private long callme = 1;
  |         private long callme1 = 2;
  |         public callTest(){
  |           
  |         }
  | 	public void getCallme() {
  |            //return (this.callme);
  | 	}
  | 	public void setCallme(long callme) {
  |            this.callme = callme;
  |         }      
  |         
  |         public long getCallme1(){
  |          getCallme();
  |          return callme1;
  |         }
  | }
  | 

The interceptor is on getCallme() method and jboss-aop.xml looks like:

  | <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  | <aop>
  |     <bind pointcut="call(public void jbossaop.callTest->getCallme())">
  |         <interceptor class="jbossaop.HelloAOPInterceptor"/>
  |     </bind>
  |     <bind pointcut="execution(public void jbossaop.callTest->getCallme())">
  |         <interceptor class="jbossaop.HelloAOPInterceptor"/>
  |     </bind>
  | </aop>
  | 

The interceptor class is:

  | public class HelloAOPInterceptor implements Interceptor{
  | 	public String getName(){
  | 		return "HelloAOPInterceptor";
  | 	}
  | 	public Object invoke(Invocation invocation) throws Throwable{
  |             FileWriter writer = new FileWriter( "c:/temp/log.txt", true );          
  |           
  |           if (invocation instanceof MethodCalledByMethodInvocation){
  |               writer.write( "Method Called By Method Invocation " + new Date() + "\n");  
  | 	  } else {
  |               writer.write( "JSF Invocation " + new Date()+ "\n");
  |           }  
  |           
  |           writer.close();
  |           
  |           return invocation.invokeNext();
  | 	}
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996538#3996538

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996538



More information about the jboss-user mailing list