Results 1 to 7 of 7

Thread: Simple Interception

  1. #1

    Default Simple Interception

    Hi everyone,

    I tried to realize a very simple interception. My interceptor bean is created
    but my interceptor is never call. I want to intercept , with a before advice method, any to call to

    Code:
    void onClickOnPushMe(ActionEvent e) 
    void setText(String text)
    My regex pattern is :
    Code:
    <value>.*setText*</value>
    <value>.*onClickOnPushMe*</value>
    but it failed to do the trick.

    I add my config.xml's file just below with my interceptor code wich is pretty hallow.

    Code:
    <bean id="textInterceptor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
            <property name="advice" ref="userInterceptorImpl"/>
            <property name="patterns">
                <list>
                    <value>.*setText*</value> 
                	<value>.*onClickOnPushMe*</value>
                </list>
            </property>
        </bean> 
    	<bean id="userInterceptorImpl" class="com.AO.SpringAppContext.app.TextInterceptor"/>
    Code:
    public class TextInterceptor implements MethodBeforeAdvice
    &#123;
    	private static Logger _log = Logger.getLogger&#40;"INTERCEPTOR&#58;"&#41;;
    	public TextInterceptor&#40;&#41;
    	&#123;
    		_log.info&#40;"Creating UserInterceptor"&#41;;
    	&#125;
    	public void before&#40;Method arg0, Object&#91;&#93; arg1, Object arg2&#41; throws Throwable 
    	&#123;
    		_log.info&#40;"INTERCEPTION !"&#41;;
    	&#125;
    &#125;
    Thanks !

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default Re: Simple Interception

    Quote Originally Posted by belaran
    My regex pattern is :
    Code:
    <value>.*setText*</value>
    <value>.*onClickOnPushMe*</value>
    but it failed to do the trick.
    Try this:

    Code:
    .*?setText.*
    .*?onClickOnPushMe.*
    Regards,
    Andreas

  3. #3

    Default

    That failed too... There must something wrong...

    My spring core build the following beans :

    Code:
    <bean id="gui" class="com.AO.SpringAppContext.GUI.HelloWorldClass" autowire="byType"/>
    	<bean id="Treatement" class="com.AO.SpringAppContext.bus.Treatement"/>
    "gui" has a method setText and Treatement has a method doJob, so the following pattern should work :

    Code:
     <list>
    <value>.*?setText.*</value> 
    <value>.*onClickOnPushMe</value>
    <value>.*doJob.*</value>
    </list>

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Maybe you should provide the full configuration of the beans. For example the ProxyFactoryBean proxying your bean would be interesting.

    Regards,
    Andreas

  5. #5

    Default

    Okay.

    I used AppContext to build my beans :

    Code:
    public static void main&#40;String&#91;&#93; args&#41; 
    	&#123;
    		ApplicationContext cxt = new   FileSystemXmlApplicationContext&#40;configFile&#41;;
    		IGUI winApp = &#40;IGUI&#41; cxt.getBean&#40;"gui"&#41;;
    		winApp.setCtx&#40;cxt&#41;;
                    winApp.setText&#40;cxt.getMessage&#40;"NewText",null,"NoBundle",null&#41;&#41;;
    	&#125;

    As specified, my interceptor should be triggered when winApp.setText(...) is called.

    My config.xml :

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<bean id="gui" class="com.AO.SpringAppContext.GUI.HelloWorldClass" autowire="byType"/>
    	<bean id="Treatement" class="com.AO.SpringAppContext.bus.Treatement"/>
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basenames">
    			<list>
    				<value>AO</value>
    			</list>
    		</property>
    	</bean>	
    	<bean id="textInterceptor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
            <property name="advice" ref="userInterceptorImpl"/>
            <property name="patterns">
                <list>
                    <value>.*?setText.*</value> 
                	<value>.*onClickOnPushMe</value>
                	<value>.*doJob.*</value>
                </list>
            </property>
        </bean> 
    	<bean id="userInterceptorImpl" class="com.AO.SpringAppContext.app.TextInterceptor"/>
    </beans>
    That's everything that seemed meaningfull.
    Thanks for any help you can provide...

  6. #6
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    In fact I cannot see, why the interceptor should kick in, when you access your bean.

    You have to specify a ProxyFactoryBean that creates a proxy with your bean as target and your interceptor inbetween.

    See the reference for details

    Regards,
    Andreas

  7. #7

    Default

    Ok.

    To realize an interception i should have done this:

    Code:
    <beans>
            <!-- my simple an naive bean, unaware of the fact that it's going to be intercepted. -->
    	<bean id="guiImpl" class="com.AO.SpringAppContext.GUI.HelloWorldClass" autowire="byType"/>
    
    	<!--Proxying the simple and naive bean -->
    	<bean id="gui" class="org.springframework.aop.framework.ProxyFactoryBean">
        	<property name="proxyInterfaces"><value>com.AO.SpringAppContext.GUI.IGUI</value></property>
        	<property name="target"><ref local="guiImpl"/></property>
        	<property name="interceptorNames">
        	    <list>
        	        <value>userInterceptorImpl</value>
        	    </list>
        	</property>
    	</bean>
            <!-- The interceptor class -->
    	<bean id="userInterceptorImpl" class="com.AO.SpringAppContext.app.TextInterceptor"/>
    </beans>
    I've done this and i worked perfectly. No i realize my problem was lexical.
    Actually, i wanted to advice my app, so i used the xml code specified above...
    Now I'm going to try to make the code above work. If i run into any trouble i should create a new post entitled "Simple Advice"

    Thanks for uour help...

Similar Threads

  1. Problem with Simple RMI Sample
    By con19m32 in forum Remoting
    Replies: 2
    Last Post: Jun 27th, 2007, 12:38 AM
  2. simple question
    By yukster in forum Security
    Replies: 6
    Last Post: Sep 19th, 2005, 07:58 AM
  3. Simple cacheing idea
    By jonmor in forum AOP
    Replies: 3
    Last Post: Feb 5th, 2005, 02:57 AM
  4. Replies: 5
    Last Post: Nov 10th, 2004, 01:44 PM
  5. Simple ServletEngine
    By Martin Kersten in forum Web
    Replies: 3
    Last Post: Aug 12th, 2004, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •