Bonjour,
J'ai besoin d'un peu d'aide pour expliquer une petite anomalie, j'essaie d'expliquer le souci puis je détaillerai plus loin dans mon post.
Je fais de l'AOP sur une méthode en utilisant AspectJ et les annotations, la méthode ciblée s’exécute qu'une seule fois, alors les méthodes @Before et @After s’exécutent deux fois (par le même thread)![]()
J'utilise une gateway webservice dans un context Spring-Integration, avec un intercepteur comme suit :
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 .................. <aop:aspectj-autoproxy /> <bean id="MailWSInterceptor" class="com.test.integration.archive.ws.ArchiveWSInterceptor" /> <int:chain input-channel="toArchiveWS" output-channel="archived"> <int:header-enricher> <int:header name="serviceName" value="addMail" overwrite="true" /> </int:header-enricher> <int-ws:outbound-gateway id="addMailWS" interceptor="MailWSInterceptor" uri="${archive.endpoint}" marshaller="marshaller" unmarshaller="marshaller" message-sender="${archive.ws.sender}" ignore-empty-responses="false" > <int:poller task-executor="pooledTaskExecutor" /> </int-ws:outbound-gateway> </int:chain> <task:executor id="pooledTaskExecutor" pool-size="${archive.maxthreads}" />
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 package com.test.integration.monitoring.soa; import java.util.ArrayList; import java.util.List; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.oxm.Unmarshaller; import org.springframework.stereotype.Component; import org.springframework.ws.context.MessageContext; @Aspect @Component public class ArchiveBCMonitor { private Unmarshaller unmarshaller; public Unmarshaller getUnmarshaller() { return unmarshaller; } public void setUnmarshaller(Unmarshaller unmarshaller) { this.unmarshaller = unmarshaller; } @Before("execution(* com.test.integration.archive.ws.ArchiveWSInterceptor.handleRequest(..))") public void logRequest(JoinPoint joinPoint) { MessageContext messageContext = (MessageContext) joinPoint.getArgs()[0]; ............................... } @Before("execution(* com.test.integration.archive.ws.ArchiveWSInterceptor.handleResponse(..))") public void logResponse(JoinPoint joinPoint) { MessageContext messageContext = (MessageContext) joinPoint.getArgs()[0]; ............................. } @Before("execution(* com.test.integration.archive.ws.ArchiveWSInterceptor.handleFault(..))") public void logFailure(JoinPoint joinPoint) { MessageContext messageContext = (MessageContext) joinPoint.getArgs()[0]; ...................... } }Pour résumer :
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 package com.test.integration.archive.ws; import java.io.ByteArrayOutputStream; import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ws.client.WebServiceClientException; import org.springframework.ws.context.MessageContext; import org.springframework.xml.transform.TransformerObjectSupport; import com.ft.webdoc.gedcli.gedcliservices.AddMailingDocumentException; import com.ft.webdoc.gedcli.gedcliservices.fault.func.FaultType; public class ArchiveWSInterceptorextends TransformerObjectSupport implements org.springframework.ws.client.support.interceptor.ClientInterceptor { ............................. private org.springframework.oxm.Unmarshaller unmarsheller; public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException { ................................... return true; } public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException { ................................ return true; } public boolean handleFault(MessageContext messageContext) throws WebServiceClientException { .................................. return false; } public org.springframework.oxm.Unmarshaller getUnmarsheller() { return unmarsheller; } public void setUnmarsheller( org.springframework.oxm.Unmarshaller unmarshaller) { this.unmarsheller = unmarshaller; }
Une exécution com.test.integration.archive.ws.ArchiveWSInterceptor.handleRequest => deux exécutions de com.test.integration.monitoring.soa.logRequest
Une exécution com.test.integration.archive.ws.ArchiveWSInterceptor.handleResponse => deux exécutions de com.test.integration.monitoring.soa.logResponse
Une exécution com.test.integration.archive.ws.ArchiveWSInterceptor.handleFailure => deux exécutions de com.test.integration.monitoring.soa.logFailure
Je suis sur ce problème depuis deux jours, SVP, si quelqu'un a une idée, je suis preneur. Merci par avance.
Dépendances Maven :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.11</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.11</version> </dependency>
Partager