use of com.megaease.easeagent.plugin.tools.trace.HttpResponse in project easeagent by megaease.
the class HttpClient5DoExecuteInterceptorTest method getResponse.
@Test
public void getResponse() {
Context context = EaseAgent.getContext();
HttpGet httpGet = new HttpGet("http://127.0.0.1:8080");
BasicHttpResponse basicHttpResponse = new BasicHttpResponse(200);
basicHttpResponse.setHeader("aa", "bb");
MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).retValue(basicHttpResponse).build();
HttpClient5DoExecuteInterceptor httpClientDoExecuteInterceptor = new HttpClient5DoExecuteInterceptor();
HttpResponse httpResponse = httpClientDoExecuteInterceptor.getResponse(methodInfo, context);
assertEquals(200, httpResponse.statusCode());
}
use of com.megaease.easeagent.plugin.tools.trace.HttpResponse in project easeagent by megaease.
the class GatewayServerTracingInterceptor method finishCallback.
void finishCallback(MethodInfo methodInfo, AsyncContext ctx) {
try (Cleaner ignored = ctx.importToCurrent()) {
RequestContext pCtx = EaseAgent.getContext().get(SPAN_CONTEXT_KEY);
ServerWebExchange exchange = (ServerWebExchange) methodInfo.getArgs()[0];
BiConsumer<ServerWebExchange, MethodInfo> consumer = exchange.getAttribute(GatewayCons.CLIENT_RECEIVE_CALLBACK_KEY);
if (consumer != null) {
consumer.accept(exchange, methodInfo);
}
FluxHttpServerRequest httpServerRequest = EaseAgent.getContext().get(FluxHttpServerRequest.class);
PathPattern bestPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
String route = null;
if (bestPattern != null) {
route = bestPattern.getPatternString();
}
HttpResponse response = new FluxHttpServerResponse(httpServerRequest, exchange.getResponse(), route, methodInfo.getThrowable());
HttpUtils.finish(pCtx.span(), response);
exchange.getAttributes().remove(GatewayCons.SPAN_KEY);
}
}
use of com.megaease.easeagent.plugin.tools.trace.HttpResponse in project easeagent by megaease.
the class FeignClientTracingInterceptorTest method getResponse.
@Test
public void getResponse() {
Request request = RequestUtils.buildFeignClient();
Response response = RequestUtils.responseBuilder(request).build();
MethodInfo.MethodInfoBuilder methodInfoBuilder = MethodInfo.builder().args(new Object[] { request }).retValue(response);
MethodInfo methodInfo = methodInfoBuilder.build();
FeignClientTracingInterceptor feignClientTracingInterceptor = new FeignClientTracingInterceptor();
HttpResponse httpResponse = feignClientTracingInterceptor.getResponse(methodInfo, EaseAgent.getContext());
assertEquals("GET", httpResponse.method());
assertNull(httpResponse.route());
assertNull(httpResponse.maybeError());
assertEquals(200, httpResponse.statusCode());
RuntimeException runtimeException = new RuntimeException("test error");
methodInfoBuilder.throwable(runtimeException);
httpResponse = feignClientTracingInterceptor.getResponse(methodInfoBuilder.build(), EaseAgent.getContext());
assertEquals(runtimeException, httpResponse.maybeError());
}
use of com.megaease.easeagent.plugin.tools.trace.HttpResponse in project easeagent by megaease.
the class ClientHttpRequestInterceptorTest method getResponse.
@Test
public void getResponse() throws IOException, URISyntaxException {
String url = "http://127.0.0.1:8080/test";
ClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = requestFactory.createRequest(new URI(url), HttpMethod.GET);
ClientHttpResponse clientHttpResponse = SimpleClientHttpResponseFactory.createMockResponse(url);
MethodInfo.MethodInfoBuilder methodInfoBuilder = MethodInfo.builder().invoker(request).retValue(clientHttpResponse);
MethodInfo methodInfo = methodInfoBuilder.build();
ClientHttpRequestInterceptor clientHttpRequestInterceptor = new ClientHttpRequestInterceptor();
HttpResponse httpResponse = clientHttpRequestInterceptor.getResponse(methodInfo, EaseAgent.getContext());
assertEquals("GET", httpResponse.method());
assertNull(httpResponse.route());
assertNull(httpResponse.maybeError());
assertEquals(200, httpResponse.statusCode());
RuntimeException runtimeException = new RuntimeException("test error");
methodInfoBuilder.throwable(runtimeException);
httpResponse = clientHttpRequestInterceptor.getResponse(methodInfoBuilder.build(), EaseAgent.getContext());
assertEquals(runtimeException, httpResponse.maybeError());
}
use of com.megaease.easeagent.plugin.tools.trace.HttpResponse in project easeagent by megaease.
the class FeignClientTracingInterceptor method getResponse.
@Override
protected HttpResponse getResponse(MethodInfo methodInfo, Context context) {
Request request = (Request) methodInfo.getArgs()[0];
Response response = (Response) methodInfo.getRetValue();
return new FeignClientResponseWrapper(methodInfo.getThrowable(), request, response);
}
Aggregations