IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

MethodInterceptor avec JSF et Spring


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 92
    Par défaut MethodInterceptor avec JSF et Spring
    Bonjour,

    Je veux calculer la durée de toutes mes méthodes. Pour cela j'ai voulu intégrer Spring dans mon application en JSF et j'ai mis un interceptor.

    Voici ce que j'ai fait:
    1) J'ai ajouté la librairie spring.jar et aopalliance.jar
    2) J'ai créer une classe Java pour l'interception
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
     
    package fr.ademe.evalad.util.PerformanceAudit;
     
    import java.lang.reflect.Method;
    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;
    import org.apache.commons.lang.time.StopWatch;
    import org.apache.log4j.Logger;
     
     
     
     
     
    /**
     * Class interceptant n'importe quelle m�thode et mesure la dur�e de son
     * ex�cution.
     * @author Thomas Noirez
     */
     
    public class PerformanceInterceptor implements MethodInterceptor {
     
    	/*** Le log. */
    	private final Logger log = Logger.getLogger(this.getClass());
     
    	/*** Temps max d'execution avant le log d'un message warning. */
    	private final long warningTimeInMs;
     
    	/*** Temps max d'execution avant le log d'un message warning. */
    	private final static long WARNING_TIME_IN_MS = 300;
     
     
     
    	/**
             * Creates a new PerformanceInterceptor object.
             */
    	public PerformanceInterceptor() {
    		super();
    		this.warningTimeInMs = WARNING_TIME_IN_MS;
    		log.info("PerformanceInterceptor initialisé");
    	}
     
    	/**
             * Creates a new PerformanceInterceptor object.
             */
    	public PerformanceInterceptor(long warningTimeInMs) {
    		super();
    		this.warningTimeInMs = warningTimeInMs;
    		log.info("PerformanceInterceptor initialisé");
    	}
     
     
     
    	/**
             * Mesure du temps d'execution d'une methode.
             * @param methodInvocation
             * @return
             * @throws Throwable
             */
    	public final Object invoke(final MethodInvocation methodInvocation)
     
    	throws Throwable {
    		log.debug("invoke - IN");
    		StopWatch sw = new StopWatch();
    		sw.start();
    		Object o = methodInvocation.proceed();
    		sw.stop();
    		this.logDebug(methodInvocation, sw.getTime());
    		log.debug("invoke - OUT");
    		return o;
    	}
     
     
     
    	/**
             * Log des infos de la duree d'execution d'une methode
             * @param methodInvocation 
             * @param ms 
             */
    	private void logDebug (final MethodInvocation methodInvocation, long ms) {
    		log.debug("logDebug - IN");
    		Method m = methodInvocation.getMethod();
    		Object t = methodInvocation.getThis();
    		String tmp = "Dur. : " + ms + " ms " + t.getClass().getName() + " " + m.getName();
    		log.debug(tmp);
    		log.debug("logDebug - OUT");
    	}
    }
    3) J'ai créer un fichier applicationContext.xml qui contient:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <beans>
    	<bean id="performanceInterceptor" class="fr.ademe.evalad.util.PerformanceAudit.PerformanceInterceptor"/>
    	<bean id="performanceAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    		<property name="advice" ref="performanceInterceptor"/>
    		<property name="patterns">
    			<list>
    				<value>.*</value>
    			</list>
    		</property>
    	</bean>
    	<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
    </beans>
    4) Et dans mon web.wml j'ai ajouté un listenner:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    <!-- Spring -->
     <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
     </listener>
    Suite à tous j'ai démarrer mon serveur qui m'as indiquer que tous était initialisé:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    18:31:14,165  INFO ContextLoader:189 - Root WebApplicationContext: initialization started
    18:31:14,227  INFO XmlWebApplicationContext:412 - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@15c2843: display name [Root WebApplicationContext]; startup date [Wed Mar 25 18:31:14 CET 2009]; root of context hierarchy
    18:31:14,352  INFO XmlBeanDefinitionReader:323 - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    18:31:14,555  INFO XmlWebApplicationContext:427 - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@15c2843]: org.springframework.beans.factory.support.DefaultListableBeanFactory@c19fbf
    18:31:14,789  INFO DefaultListableBeanFactory:414 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c19fbf: defining beans [performanceInterceptor,performanceAdvisor,autoProxyCreator]; root of factory hierarchy
    18:31:14,789  INFO PerformanceInterceptor:38 - PerformanceInterceptor initialisé
    18:31:14,867  INFO ContextLoader:209 - Root WebApplicationContext: initialization completed in 702 ms
    Mais pourtant rien ne se logue, pouvez vous me dire poourquoi?

    Merci

  2. #2
    Membre expérimenté
    Profil pro
    Dev NodeJS
    Inscrit en
    Août 2006
    Messages
    177
    Détails du profil
    Informations personnelles :
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev NodeJS

    Informations forums :
    Inscription : Août 2006
    Messages : 177
    Par défaut
    As-tu configuré log4j pour afficher le niveau de log debug?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 92
    Par défaut
    Oui, car je l'utilise dans toutes mon application.
    Le problème vient du fait que l'on ne rentre jamais dans la fonction invoke.
    J'ai essayé en mode debug en mettant un point d'arrêt et il ne passe jamais par la fonction.

    Sur un projet entièrement Srping cela marche. Mais pourquoi cela ne marche pas avec JSF?

    Merci pour ton aide

Discussions similaires

  1. différence entre Spring MVC et Spring intégré avec JSF
    Par marwa_eniso dans le forum Spring Web
    Réponses: 5
    Dernier message: 15/11/2016, 11h16
  2. Différence entre Spring MVC et Spring intégré avec JSF
    Par marwa_eniso dans le forum Frameworks Web
    Réponses: 3
    Dernier message: 31/08/2010, 07h16
  3. [Framework] Spring avec JSF et Hibernate
    Par wajdopovitch dans le forum Spring
    Réponses: 0
    Dernier message: 11/12/2009, 12h49
  4. Utilisation spring avec jsf
    Par rushtakn dans le forum JSF
    Réponses: 9
    Dernier message: 16/06/2009, 09h30
  5. Implémentation Spring Avec JSF-Hibernate
    Par wajdopovitch dans le forum Spring
    Réponses: 2
    Dernier message: 04/04/2009, 21h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo