Search in sources :

Example 1 with HttpRequest

use of com.megaease.easeagent.plugin.tools.trace.HttpRequest in project easeagent by megaease.

the class OkHttpTracingInterceptor method getRequest.

@Override
protected HttpRequest getRequest(MethodInfo methodInfo, Context context) {
    Object realCall = methodInfo.getInvoker();
    Request originalRequest = AgentFieldReflectAccessor.getFieldValue(realCall, "originalRequest");
    if (originalRequest == null) {
        return null;
    }
    context.put(METHOD_KEY, originalRequest.method());
    Request.Builder requestBuilder = originalRequest.newBuilder();
    context.put(REQUEST_BUILDER_KEY, requestBuilder);
    return new InternalRequest(originalRequest, requestBuilder);
}
Also used : HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) Request(okhttp3.Request)

Example 2 with HttpRequest

use of com.megaease.easeagent.plugin.tools.trace.HttpRequest in project easeagent by megaease.

the class DoFilterForwardedInterceptor method doBefore.

@Override
public void doBefore(MethodInfo methodInfo, Context context) {
    HttpServletRequest httpServletRequest = (HttpServletRequest) methodInfo.getArgs()[0];
    HttpRequest httpRequest = new HttpServerRequest(httpServletRequest);
    Cleaner cleaner = context.importForwardedHeaders(httpRequest);
    context.put(FORWARDED_KEY, cleaner);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) Cleaner(com.megaease.easeagent.plugin.api.Cleaner)

Example 3 with HttpRequest

use of com.megaease.easeagent.plugin.tools.trace.HttpRequest in project easeagent by megaease.

the class HttpClientDoExecuteInterceptorTest method getRequest.

@Test
public void getRequest() {
    Context context = EaseAgent.getContext();
    HttpGet httpGet = new HttpGet();
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).build();
    HttpClientDoExecuteInterceptor httpClientDoExecuteInterceptor = new HttpClientDoExecuteInterceptor();
    HttpRequest request = httpClientDoExecuteInterceptor.getRequest(methodInfo, context);
    assertEquals(com.megaease.easeagent.plugin.api.trace.Span.Kind.CLIENT, request.kind());
    assertEquals("GET", request.method());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) HttpGet(org.apache.http.client.methods.HttpGet) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

Example 4 with HttpRequest

use of com.megaease.easeagent.plugin.tools.trace.HttpRequest in project easeagent by megaease.

the class ClientHttpRequestInterceptorTest method getRequest.

@Test
public void getRequest() throws URISyntaxException, IOException {
    ClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    ClientHttpRequest request = requestFactory.createRequest(new URI("http://127.0.0.1:8080/test"), HttpMethod.GET);
    MethodInfo methodInfo = MethodInfo.builder().invoker(request).build();
    Context context = EaseAgent.getContext();
    ClientHttpRequestInterceptor clientHttpRequestInterceptor = new ClientHttpRequestInterceptor();
    HttpRequest httpRequest = clientHttpRequestInterceptor.getRequest(methodInfo, context);
    assertEquals(com.megaease.easeagent.plugin.api.trace.Span.Kind.CLIENT, httpRequest.kind());
    assertEquals("GET", httpRequest.method());
    assertEquals("/test", httpRequest.path());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) URI(java.net.URI) Test(org.junit.Test)

Example 5 with HttpRequest

use of com.megaease.easeagent.plugin.tools.trace.HttpRequest in project easeagent by megaease.

the class WebClientFilterTracingInterceptorTest method getRequest.

@Test
public void getRequest() throws URISyntaxException {
    URI uri = new URI(url);
    ClientRequest clientRequest = MockClientRequest.build(uri);
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { clientRequest }).build();
    WebClientFilterTracingInterceptor interceptor = new WebClientFilterTracingInterceptor();
    HttpRequest httpRequest = interceptor.getRequest(methodInfo);
    check(httpRequest);
    String key = "testKey";
    String value = "testValue";
    httpRequest.setHeader(key, value);
    assertNull(httpRequest.header(key));
    assertEquals(value, Objects.requireNonNull(((ClientRequest) methodInfo.getArgs()[0]).headers().get(key)).get(0));
}
Also used : HttpRequest(com.megaease.easeagent.plugin.tools.trace.HttpRequest) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) URI(java.net.URI) ClientRequest(org.springframework.web.reactive.function.client.ClientRequest) MockClientRequest(org.springframework.web.reactive.function.client.MockClientRequest) Test(org.junit.Test)

Aggregations

HttpRequest (com.megaease.easeagent.plugin.tools.trace.HttpRequest)10 MethodInfo (com.megaease.easeagent.plugin.interceptor.MethodInfo)6 Test (org.junit.Test)6 Context (com.megaease.easeagent.plugin.api.Context)5 RequestContext (com.megaease.easeagent.plugin.api.context.RequestContext)2 URI (java.net.URI)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Cleaner (com.megaease.easeagent.plugin.api.Cleaner)1 Span (com.megaease.easeagent.plugin.api.trace.Span)1 Request (feign.Request)1 Call (okhttp3.Call)1 Request (okhttp3.Request)1 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)1 HttpGet (org.apache.http.client.methods.HttpGet)1 ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)1 MockClientRequest (org.springframework.web.reactive.function.client.MockClientRequest)1