-
1. Re: the intercept component don't work!
pmuir Aug 28, 2007 5:23 AM (in response to chlol)Use [ code ] tags
-
2. Re: the intercept component don't work!
chlol Aug 29, 2007 2:07 AM (in response to chlol)my test intercept:
@Name("interceptsTest") @Interceptor public class InterceptsTest { @Logger Log log; @AroundInvoke public Object doLogs(InvocationContext inv) throws Exception { int methodModify = inv.getMethod().getModifiers(); String methodName = inv.getMethod().getName(); if (methodModify == Modifier.PUBLIC && (methodName.startsWith("create") || methodName.startsWith("update") || methodName.startsWith("persist") || methodName.startsWith("remove"))) { Map data = inv.getContextData(); Object target = inv.getTarget(); log.debug("ContextData:" + data); log.debug("Target:" + target); } return inv.proceed(); } }
my invoke intercept class:@Name("useIntercept") @Interceptors(InterceptsTest.class) public class UseIntercept { public void persist() { System.out.println("&&&&&&&&&&&& do persist() &&&&&&&&&&&&"); } }
help me,please
thank you -
3. Re: the intercept component don't work!
matt.drees Aug 29, 2007 2:13 AM (in response to chlol)What's the code that calls persist()?
-
4. Re: the intercept component don't work!
chlol Aug 29, 2007 6:02 AM (in response to chlol)thank your reply!
i use a test case to call the persist method,the following is code:@Test public void testIntercept() throws Exception { new ComponentTest() { protected void testComponents() throws Exception { invokeMethod("#{useIntercept.persist}"); } }.run(); }
-
5. Re: the intercept component don't work!
matt.drees Aug 29, 2007 11:19 AM (in response to chlol)I think because your component is a javabean component, you can't use @Interceptors directly on it. Instead, you do something like:
@Name("useIntercept") @LogCrudOperations public class UseIntercept { public void persist() { System.out.println("&&&&&&&&&&&& do persist() &&&&&&&&&&&&"); } } @Interceptors(InterceptsTests.class) @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface LogCrudOperations { }
-
6. Re: the intercept component don't work!
matt.drees Aug 29, 2007 11:19 AM (in response to chlol)Also, your interceptor (InterceptsTest) doesn't get to be a Seam component. So @Logger won't work.
-
7. Re: the intercept component don't work!
chlol Aug 30, 2007 2:03 AM (in response to chlol)that's ok,thank you!
but how to define a seam component? Is not it to use @Name to define?
pardon my prolixity! -
8. Re: the intercept component don't work!
matt.drees Aug 30, 2007 2:14 AM (in response to chlol)Yes, you use @Name to define a seam component. So, if you called Component.getInstance("interceptsTest"), the @Logger field would be filled.
But when Seam instantiates an interceptor from the class you specify, it just treats it like a normal object. It doesn't inject @Loggers or give it interceptors for bijection, etc. -
9. Re: the intercept component don't work!
chlol Aug 30, 2007 9:29 PM (in response to chlol)i understand
thank you very much again!