26
26
import org .apache .synapse .core .axis2 .Axis2MessageContext ;
27
27
import org .wso2 .micro .integrator .initializer .handler .DataHolder ;
28
28
import org .wso2 .micro .integrator .initializer .handler .transaction .store .TransactionStore ;
29
+ import org .wso2 .micro .integrator .initializer .utils .Constants ;
29
30
30
31
import java .util .concurrent .ExecutorService ;
31
32
import java .util .concurrent .RejectedExecutionException ;
@@ -45,7 +46,17 @@ public TransactionCountHandler(ExecutorService executor) {
45
46
@ Override
46
47
public boolean handleRequestInFlow (MessageContext messageContext ) {
47
48
try {
48
- transactionCountExecutor .execute (() -> handleTransactionCount (messageContext ));
49
+ org .apache .axis2 .context .MessageContext axis2MessageContext =
50
+ ((Axis2MessageContext ) messageContext ).getAxis2MessageContext ();
51
+
52
+ // Setting this property to identify request-response pairs
53
+ axis2MessageContext .setProperty (Constants .IS_THERE_ASSOCIATED_INCOMING_REQUEST , true );
54
+
55
+ // Counting message received via an open WebSocket
56
+ String transport = axis2MessageContext .getIncomingTransportName ();
57
+ if (transport .equals (Constants .TRANSPORT_WS ) || transport .equals (Constants .TRANSPORT_WSS )){
58
+ transactionCountExecutor .execute (() -> handleTransactionCount (messageContext ));
59
+ }
49
60
} catch (RejectedExecutionException e ) {
50
61
LOG .error ("Transaction could not be counted." , e );
51
62
}
@@ -54,6 +65,19 @@ public boolean handleRequestInFlow(MessageContext messageContext) {
54
65
55
66
@ Override
56
67
public boolean handleRequestOutFlow (MessageContext messageContext ) {
68
+ try {
69
+ org .apache .axis2 .context .MessageContext axis2MessageContext =
70
+ ((Axis2MessageContext ) messageContext ).getAxis2MessageContext ();
71
+ Object isThereAnAssociatedIncomingRequest = axis2MessageContext .getProperty (
72
+ Constants .IS_THERE_ASSOCIATED_INCOMING_REQUEST );
73
+
74
+ // Counting outgoing messages that are not related to any request-response pair
75
+ if (isThereAnAssociatedIncomingRequest == null ) {
76
+ transactionCountExecutor .execute (() -> handleTransactionCount (messageContext ));
77
+ }
78
+ } catch (RejectedExecutionException e ) {
79
+ LOG .error ("Transaction could not be counted." , e );
80
+ }
57
81
return true ;
58
82
}
59
83
@@ -64,6 +88,15 @@ public boolean handleResponseInFlow(MessageContext messageContext) {
64
88
65
89
@ Override
66
90
public boolean handleResponseOutFlow (MessageContext messageContext ) {
91
+ org .apache .axis2 .context .MessageContext axis2MessageContext =
92
+ ((Axis2MessageContext ) messageContext ).getAxis2MessageContext ();
93
+ Object isThereAnAssociatedIncomingRequest = axis2MessageContext .getProperty (
94
+ Constants .IS_THERE_ASSOCIATED_INCOMING_REQUEST );
95
+
96
+ // Counting request-response pairs
97
+ if (isThereAnAssociatedIncomingRequest instanceof Boolean ) {
98
+ transactionCountExecutor .execute (() -> handleTransactionCount (messageContext ));
99
+ }
67
100
return true ;
68
101
}
69
102
0 commit comments