use of com.shulie.instrument.simulator.api.ProcessControlException in project LinkAgent by shulieTech.
the class RealCallExecuteV2Interceptor method beforeFirst.
@Override
public void beforeFirst(Advice advice) throws ProcessControlException {
Object target = advice.getTarget();
Request request = null;
try {
request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_REQUEST);
} catch (ReflectException e) {
request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_ORIGINAL_REQUEST);
}
String url = request.urlString();
final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
String check = request.header(OKHttpConstants.DYNAMIC_FIELD_HEADER);
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, check);
config.addArgs("url", url);
config.addArgs("isInterface", Boolean.FALSE);
final Request finalRequest = request;
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {
@Override
public Object forward(Object param) throws ProcessControlException {
HttpUrl httpUrl = HttpUrl.parse(config.getForwarding());
Reflect.on(finalRequest).set("url", httpUrl);
return null;
}
@Override
public Object call(Object param) {
Headers header = Headers.of(new String[0]);
Buffer buffer = new Buffer();
try {
byte[] bytes = null;
if (param instanceof String) {
buffer.write(String.valueOf(param).getBytes("UTF-8"));
} else {
buffer.write(JSONObject.toJSONBytes(param));
}
} catch (IOException e) {
}
return new Response.Builder().code(200).body(new RealResponseBody(header, buffer)).request(finalRequest).protocol(Protocol.HTTP_1_0).message("OK").build();
}
});
}
use of com.shulie.instrument.simulator.api.ProcessControlException in project LinkAgent by shulieTech.
the class RealCallEnqueueV3Interceptor method beforeFirst.
@Override
public void beforeFirst(Advice advice) throws ProcessControlException {
Object target = advice.getTarget();
final Call call = (Call) target;
HttpUrl httpUrl = call.request().url();
String url = OKHttpConstants.getService(httpUrl.scheme(), httpUrl.host(), httpUrl.port(), httpUrl.encodedPath());
final MatchConfig config = ClusterTestUtils.httpClusterTest(url);
String check = call.request().header(OKHttpConstants.DYNAMIC_FIELD_HEADER);
config.addArgs(PradarService.PRADAR_WHITE_LIST_CHECK, check);
config.addArgs("url", url);
config.addArgs("isInterface", Boolean.FALSE);
if (config.getStrategy() instanceof JsonMockStrategy) {
config.addArgs("call", call);
MockReturnUtils.fixJsonStrategy.processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config);
}
config.getStrategy().processBlock(advice.getBehavior().getReturnType(), advice.getClassLoader(), config, new ExecutionForwardCall() {
@Override
public Object forward(Object param) throws ProcessControlException {
HttpUrl httpUrl = HttpUrl.parse(config.getForwarding());
Reflect.on(call.request()).set("url", httpUrl);
return null;
}
@Override
public Object call(Object param) {
Headers header = new Headers.Builder().build();
Buffer buffer = new Buffer();
try {
if (param instanceof String) {
buffer.write(String.valueOf(param).getBytes("UTF-8"));
} else {
buffer.write(JSONObject.toJSONBytes(param));
}
} catch (IOException e) {
}
return new Response.Builder().code(200).body(new RealResponseBody(header, buffer)).request(call.request()).protocol(Protocol.HTTP_1_0).message("OK").build();
}
});
}
use of com.shulie.instrument.simulator.api.ProcessControlException in project LinkAgent by shulieTech.
the class ScopedTraceInterceptor method doBefore.
@Override
public void doBefore(Advice advice) throws Throwable {
final InterceptorScopeInvocation transaction = getScope(advice).getCurrentInvocation();
final boolean success = transaction.tryEnter(policy);
boolean processControlException = false;
if (success) {
try {
interceptor.doBefore(advice);
} catch (ProcessControlException p) {
processControlException = true;
throw p;
} finally {
if (processControlException) {
transaction.leave(policy);
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("tryBefore() returns false: interceptorScopeTransaction: {}, executionPoint: {}. Skip interceptor {}", transaction, policy, interceptor.getClass());
}
}
}
Aggregations