use of com.pamirs.pradar.internal.config.MatchConfig in project LinkAgent by shulieTech.
the class HttpURLConnectionGetInputStreamInterceptor method beforeLast.
@Override
public void beforeLast(Advice advice) throws ProcessControlException {
if (!Pradar.isClusterTest()) {
return;
}
Object target = advice.getTarget();
final HttpURLConnection request = (HttpURLConnection) target;
final URL url = request.getURL();
String fullPath = getService(url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
String whiteList = request.getRequestProperty(PradarService.PRADAR_WHITE_LIST_CHECK);
MatchConfig config = ClusterTestUtils.httpClusterTest(fullPath);
ExecutionStrategy strategy = config.getStrategy();
// 仅mock在getInputStream里执行
if (!(strategy instanceof JsonMockStrategy) && !(strategy instanceof MockStrategy)) {
return;
}
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, whiteList);
// 白名单需要的信息
config.addArgs("url", fullPath);
// mock转发需要信息
config.addArgs("request", request);
config.addArgs("method", "url");
config.addArgs("isInterface", Boolean.FALSE);
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config);
}
use of com.pamirs.pradar.internal.config.MatchConfig in project LinkAgent by shulieTech.
the class HttpURLConnectionInterceptor method beforeLast.
@Override
public void beforeLast(Advice advice) throws ProcessControlException {
if (!Pradar.isClusterTest()) {
return;
}
/**
* 保持trace一致
*/
boolean connecting = advice.hasMark(MARK_CONNECTING);
boolean connected = advice.hasMark(MARK_CONNECTED);
if (connected || connecting) {
return;
}
Object target = advice.getTarget();
final HttpURLConnection request = (HttpURLConnection) target;
final URL url = request.getURL();
String fullPath = getService(url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
String whiteList = request.getRequestProperty(PradarService.PRADAR_WHITE_LIST_CHECK);
MatchConfig config = ClusterTestUtils.httpClusterTest(fullPath);
ExecutionStrategy strategy = config.getStrategy();
// mock不在connect里执行
if (strategy instanceof JsonMockStrategy || strategy instanceof MockStrategy) {
return;
}
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, whiteList);
// 白名单需要的信息
config.addArgs("url", fullPath);
// mock转发需要信息
config.addArgs("request", request);
config.addArgs("method", "url");
config.addArgs("isInterface", Boolean.FALSE);
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config);
}
use of com.pamirs.pradar.internal.config.MatchConfig in project LinkAgent by shulieTech.
the class ClientInterceptor method beforeFirst.
@Override
public void beforeFirst(Advice advice) throws ProcessControlException, MalformedURLException {
Object[] args = advice.getParameterArray();
if (!(args[0] instanceof ClientRequest)) {
return;
}
final ClientRequest clientRequest = (ClientRequest) args[0];
final String url = clientRequest.getUri().toURL().toString();
final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, clientRequest.getHeaderString(PradarService.PRADAR_WHITE_LIST_CHECK));
config.addArgs("url", url);
config.addArgs("isInterface", Boolean.FALSE);
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {
@Override
public Object forward(Object param) {
clientRequest.setUri(URI.create(config.getForwarding()));
return null;
}
@Override
public Object call(Object param) {
return new ClientResponse(clientRequest, Response.ok(param).build());
}
});
}
use of com.pamirs.pradar.internal.config.MatchConfig in project LinkAgent by shulieTech.
the class DubboConsumerInterceptor method beforeLast.
@Override
public void beforeLast(Advice advice) throws ProcessControlException {
final RpcInvocation invocation = (RpcInvocation) advice.getParameterArray()[0];
String interfaceName = getInterfaceName(invocation);
String methodName = invocation.getMethodName();
MatchConfig config = ClusterTestUtils.rpcClusterTest(interfaceName, methodName);
invocation.setAttachment(PradarService.PRADAR_WHITE_LIST_CHECK, String.valueOf(config.isSuccess()));
config.addArgs("args", advice.getParameterArray());
config.addArgs("url", interfaceName.concat("#").concat(methodName));
config.addArgs("isInterface", Boolean.TRUE);
config.addArgs("class", interfaceName);
config.addArgs("method", methodName);
config.addArgs("invocation", invocation);
if (isShentongEvent(interfaceName)) {
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, "true");
}
if (config.getStrategy() instanceof JsonMockStrategy) {
fixJsonStrategy.processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config);
}
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionCall() {
@Override
public Object call(Object param) {
try {
// for 2.8.4
return Reflect.on("org.apache.dubbo.rpc.RpcResult").create(param).get();
} catch (Exception e) {
if (logger.isInfoEnabled()) {
logger.info("find dubbo 2.8.4 class org.apache.dubbo.rpc.RpcResult fail, find others!", e);
}
//
}
try {
Reflect reflect = Reflect.on("org.apache.dubbo.rpc.AsyncRpcResult");
try {
// for 2.7.5
java.util.concurrent.CompletableFuture<AppResponse> future = new java.util.concurrent.CompletableFuture<AppResponse>();
future.complete(new AppResponse(param));
Reflect result = reflect.create(future, invocation);
return result.get();
} catch (ReflectException e) {
// for 2.7.3
Reflect result = reflect.create(invocation);
return result.get();
}
} catch (Exception e) {
logger.error("fail to load dubbo 2.7.x class org.apache.dubbo.rpc.AsyncRpcResult", e);
throw new ReflectException("fail to load dubbo 2.7.x class org.apache.dubbo.rpc.AsyncRpcResult", e);
}
}
});
}
use of com.pamirs.pradar.internal.config.MatchConfig in project LinkAgent by shulieTech.
the class ArbiterHttpExit method matching.
/**
* Internal matching recursive function.
*/
private static MatchConfig matching(String string, MatchConfig matchConfig, int stringStartNdx, int patternStartNdx) {
String wildcard = matchConfig.getUrl();
int pNdx = patternStartNdx;
int sNdx = stringStartNdx;
int pLen = wildcard.length();
if (pLen == 1) {
if (wildcard.charAt(0) == '*') {
// speed-up
return matchConfig;
}
}
int sLen = string.length();
boolean nextIsNotWildcard = false;
MatchConfig config = failure();
while (true) {
// check if end of string and/or pattern occurred
if ((sNdx >= sLen)) {
// end of string still may have pending '*' callback pattern
while ((pNdx < pLen) && (wildcard.charAt(pNdx) == '*')) {
pNdx++;
}
return pNdx >= pLen ? matchConfig : null;
}
if (pNdx >= pLen) {
// end of pattern, but not end of the string
return config;
}
// pattern char
char p = wildcard.charAt(pNdx);
// perform logic
if (!nextIsNotWildcard) {
if (p == '\\') {
pNdx++;
nextIsNotWildcard = true;
continue;
}
if (p == '?') {
sNdx++;
pNdx++;
continue;
}
if (p == '*') {
// next pattern char
char pnext = 0;
if (pNdx + 1 < pLen) {
pnext = wildcard.charAt(pNdx + 1);
}
if (pnext == '*') {
// double '*' have the same effect as one '*'
pNdx++;
continue;
}
int i;
pNdx++;
// line that matches the rest of the pattern !!!
for (i = string.length(); i >= sNdx; i--) {
if (null != matching(string, matchConfig, i, pNdx)) {
return matchConfig;
}
}
return config;
}
} else {
nextIsNotWildcard = false;
}
// check if pattern char and string char are equals
if (p != string.charAt(sNdx)) {
return config;
}
// everything matches for now, continue
sNdx++;
pNdx++;
}
}
Aggregations