use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class HessianProxyWrapper method exceptionTrace.
public SpanRecord exceptionTrace(Object target, String methodName, Method method, Object[] args, Throwable throwable) {
if (args == null || args.length == 0) {
return null;
}
Class<?> type = getType(target, method, args);
if (type == null) {
return null;
}
SpanRecord spanRecord = new SpanRecord();
spanRecord.setService(type.getName());
spanRecord.setMethod(method.getName());
spanRecord.setRequest(args);
spanRecord.setResponse(throwable);
spanRecord.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
URL url = null;
try {
url = Reflect.on(target).get(HessianConstants.DYNAMIC_FIELD_URL);
} catch (ReflectException e) {
}
if (url != null) {
String host = url.getHost();
int port = url.getPort();
if (port == 80 || port == -1) {
host = host + ":" + port;
}
spanRecord.setRemoteIp(host);
}
return spanRecord;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class HessianProxyWrapper method beforeTrace.
public SpanRecord beforeTrace(Object target, String methodName, Method method, Object[] args) {
if (args == null || args.length == 0) {
return null;
}
Class<?> type = getType(target, method, args);
if (type == null) {
return null;
}
manager.setDynamicField(target, HessianConstants.DYNAMIC_FIELD_METHOD, method);
SpanRecord spanRecord = new SpanRecord();
spanRecord.setService(type.getName());
spanRecord.setMethod(method.getName());
spanRecord.setRequest(args);
URL url = null;
try {
url = Reflect.on(target).get(HessianConstants.DYNAMIC_FIELD_URL);
} catch (ReflectException e) {
}
if (url != null) {
String host = url.getHost();
int port = url.getPort();
if (port == 80 || port == -1) {
host = host + ":" + port;
}
spanRecord.setRemoteIp(host);
}
return spanRecord;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class HessianProxyWrapper method afterTrace.
public SpanRecord afterTrace(Object target, String methodName, Method method, Object[] args, Object result) {
if (args == null || args.length == 0) {
return null;
}
Class<?> type = getType(target, method, args);
if (type == null) {
return null;
}
SpanRecord spanRecord = new SpanRecord();
spanRecord.setService(type.getName());
spanRecord.setMethod(method.getName());
spanRecord.setRequest(args);
spanRecord.setResponse(result);
URL url = null;
try {
url = Reflect.on(target).get(HessianConstants.DYNAMIC_FIELD_URL);
} catch (ReflectException e) {
}
if (url != null) {
String host = url.getHost();
int port = url.getPort();
if (port == 80 || port == -1) {
host = host + ":" + port;
}
spanRecord.setRemoteIp(host);
}
return spanRecord;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class RealCallEnqueueV2Interceptor 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);
}
final 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 {
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.reflect.ReflectException in project LinkAgent by shulieTech.
the class RealCallEnqueueV2Interceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
InnerWhiteListCheckUtil.check();
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);
}
SpanRecord record = new SpanRecord();
record.setRemoteIp(request.url().getHost());
record.setPort(request.url().getPort());
record.setService(request.url().getPath());
record.setMethod(StringUtils.upperCase(request.method()));
record.setRequest(request.url().getQuery());
String header = request.header("content-length");
if (StringUtils.isNotBlank(header) && NumberUtils.isDigits(header)) {
try {
record.setRequestSize(Integer.valueOf(header));
} catch (NumberFormatException e) {
}
}
return record;
}
Aggregations