-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAxwayAspect.java
More file actions
136 lines (119 loc) · 5.91 KB
/
Copy pathAxwayAspect.java
File metadata and controls
136 lines (119 loc) · 5.91 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.axway.apim.aspects;
import com.axway.apim.opentelemetry.ConnectToUrl;
import com.axway.apim.opentelemetry.HttpServer;
import com.axway.apim.opentelemetry.Telemetry;
import com.axway.apim.opentelemetry.Utils;
import com.vordel.circuit.InvocationContext;
import com.vordel.circuit.Message;
import com.vordel.circuit.MessageProcessor;
import com.vordel.config.Circuit;
import com.vordel.coreapireg.runtime.PathResolverResult;
import com.vordel.coreapireg.runtime.broker.ApiShunt;
import com.vordel.coreapireg.runtime.broker.InvokableMethod;
import com.vordel.dwe.http.ServerTransaction;
import com.vordel.mime.Body;
import com.vordel.mime.HeaderSet;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class AxwayAspect {
private HttpServer httpServer = new HttpServer();
private ConnectToUrl connectToUrl = new ConnectToUrl();
@Pointcut("execution(* com.vordel.circuit.SyntheticCircuitChainProcessor.invoke(..)) && args (m, lastChanceHandler, context)")
public void invokeGateway(Message m, MessageProcessor lastChanceHandler, Object context) {
}
/**
* Captures policies exposed via Listener and API manager UI traffics, it does not capture servlet traffic like api manger REST API
*
* @param m m
* @param lastChanceHandler currentApiCallStatus
* @param context context
* @return context object
* @throws Throwable
*/
@Around("invokeGateway(m, lastChanceHandler, context)")
public Object invokePointcutGateway(ProceedingJoinPoint pjp, Message m, MessageProcessor lastChanceHandler, Object context) throws Throwable {
String apiName;
String httpVerb;
try {
String requestPath = (String) m.get("http.request.path");
String[] uriSplit = requestPath.split("/");
apiName = uriSplit.length > 1 ? uriSplit[1] : "/";
httpVerb = Utils.getHttpMethod(m);
} catch (Throwable e) {
Telemetry.disable("gateway advice setup", e);
return pjp.proceed();
}
return httpServer.aroundHttpServer(pjp, m, apiName, httpVerb);
}
@Pointcut("execution(* com.vordel.circuit.net.ConnectionProcessor.invoke(..)) && args (c, m, headers, verb, body)")
public void invokeConnectToUrl(Circuit c, Message m, HeaderSet headers, String verb, Body body) {
}
@Around("invokeConnectToUrl(c, m, headers, verb, body)")
public Object invokeConnectToUrlAroundAdvice(ProceedingJoinPoint pjp, Circuit c, Message m, HeaderSet headers, String verb, Body body) throws Throwable {
return connectToUrl.httpClient(pjp, m, c, headers, verb);
}
@Pointcut("execution(* com.vordel.coreapireg.runtime.CoreApiBroker.invokeMethod(..)) && args (txn, m, lastChanceHandler, runMethod, resolvedMethod, matchCount, httpMethod, currentApiCallStatus)")
public void invokeMethodPointcut(ServerTransaction txn, Message m,
MessageProcessor lastChanceHandler, InvokableMethod runMethod,
final PathResolverResult resolvedMethod, final int matchCount,
String httpMethod, ApiShunt currentApiCallStatus) {
}
/**
* Captures api manager traffic
*
* @param pjp pjp
* @param txn txt
* @param m message
* @param lastChanceHandler lastChanceHandler
* @param runMethod runMethod
* @param resolvedMethod resolvedMethod
* @param matchCount matchCount
* @param httpMethod httpMethod
* @param currentApiCallStatus currentApiCallStatus
* @return pjp object
* @throws Throwable
*/
@Around("invokeMethodPointcut(txn, m, lastChanceHandler, runMethod, resolvedMethod, matchCount, httpMethod, currentApiCallStatus)")
public Object invokeMethodAroundAdvice(ProceedingJoinPoint pjp, ServerTransaction txn, Message m,
MessageProcessor lastChanceHandler, InvokableMethod runMethod,
final PathResolverResult resolvedMethod, final int matchCount,
String httpMethod, ApiShunt currentApiCallStatus) throws Throwable {
String apiName;
try {
String[] uriSplit = Utils.getRequestURL(m).split("/");
String defaultApiName = uriSplit.length > 1 ? uriSplit[1] : "/";
apiName = (String) m.getOrDefault("api.name", defaultApiName);
} catch (Throwable e) {
Telemetry.disable("API Manager advice setup", e);
return pjp.proceed();
}
return httpServer.aroundHttpServer(pjp, m, apiName, httpMethod);
}
@Pointcut("execution(* com.vordel.coreapireg.runtime.CoreApiBroker.invokeFaultHandler(..)) && args (shuntReason, m, ctx)")
public void apiManagerFaultHandler(ApiShunt shuntReason, Message m, InvocationContext ctx) {
}
@Around("apiManagerFaultHandler(shuntReason, m, ctx)")
public Object handleApiManagerFaultHandler(ProceedingJoinPoint pjp, ApiShunt shuntReason, Message m, InvocationContext ctx) throws Throwable {
boolean traceNotFound;
try {
traceNotFound = shuntReason.getStatusCode() == 404;
} catch (Throwable e) {
Telemetry.disable("API Manager fault advice setup", e);
return pjp.proceed();
}
if (traceNotFound) {
String httpMethod;
try {
httpMethod = Utils.getHttpMethod(m);
} catch (Throwable e) {
Telemetry.disable("API Manager fault advice setup", e);
return pjp.proceed();
}
return httpServer.aroundHttpServer(pjp, m, "NotFound", httpMethod);
}
return pjp.proceed();
}
}