Search in sources :

Example 1 with HttpResponse

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());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) BasicHttpResponse(org.apache.hc.core5.http.message.BasicHttpResponse) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 2 with HttpResponse

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);
    }
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) PathPattern(org.springframework.web.util.pattern.PathPattern) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) RequestContext(com.megaease.easeagent.plugin.api.context.RequestContext) Cleaner(com.megaease.easeagent.plugin.api.Cleaner)

Example 3 with HttpResponse

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());
}
Also used : Response(feign.Response) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) Request(feign.Request) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 4 with HttpResponse

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());
}
Also used : HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) URI(java.net.URI) Test(org.junit.Test)

Example 5 with HttpResponse

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);
}
Also used : Response(feign.Response) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) Request(feign.Request)

Aggregations

HttpResponse (com.megaease.easeagent.plugin.tools.trace.HttpResponse)7 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)6 Test (org.junit.Test)5 Context (com.megaease.easeagent.plugin.api.Context)2 HttpRequest (com.megaease.easeagent.plugin.tools.trace.HttpRequest)2 Request (feign.Request)2 Response (feign.Response)2 Cleaner (com.megaease.easeagent.plugin.api.Cleaner)1 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)1 URI (java.net.URI)1 Call (okhttp3.Call)1 Response (okhttp3.Response)1 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)1 BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)1 ProtocolVersion (org.apache.http.ProtocolVersion)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1 PathPattern (org.springframework.web.util.pattern.PathPattern)1