Search in sources :

Example 6 with HttpResponse

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

the class HttpClientDoExecuteInterceptorTest method getResponse.

@Test
public void getResponse() {
    Context context = EaseAgent.getContext();
    HttpGet httpGet = new HttpGet();
    ProtocolVersion protocolVersion = new ProtocolVersion("testProtocol", 10, 1);
    BasicHttpResponse basicHttpResponse = new BasicHttpResponse(protocolVersion, 200, "");
    basicHttpResponse.setHeader("aa", "bb");
    MethodInfo methodInfo = MethodInfo.builder().args(new Object[] { httpGet }).retValue(basicHttpResponse).build();
    HttpClientDoExecuteInterceptor httpClientDoExecuteInterceptor = new HttpClientDoExecuteInterceptor();
    HttpResponse httpResponse = httpClientDoExecuteInterceptor.getResponse(methodInfo, context);
    assertEquals(200, httpResponse.statusCode());
}
Also used : Context(com.megaease.easeagent.plugin.api.Context) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) ProtocolVersion(org.apache.http.ProtocolVersion) Test(org.junit.Test)

Example 7 with HttpResponse

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

the class OkHttpTracingInterceptorTest method getResponse.

@Test
public void getResponse() {
    Call call = OkHttpTestUtils.buildCall();
    Response.Builder builder = OkHttpTestUtils.responseBuilder(call);
    Response response = builder.build();
    MethodInfo.MethodInfoBuilder methodInfoBuilder = MethodInfo.builder().invoker(call).retValue(response);
    MethodInfo methodInfo = methodInfoBuilder.build();
    OkHttpTracingInterceptor okHttpTracingInterceptor = new OkHttpTracingInterceptor();
    EaseAgent.getContext().put(OkHttpTracingInterceptor.METHOD_KEY, call.request().method());
    HttpResponse httpResponse = okHttpTracingInterceptor.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 = okHttpTracingInterceptor.getResponse(methodInfoBuilder.build(), EaseAgent.getContext());
    assertEquals(runtimeException, httpResponse.maybeError());
}
Also used : HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) Response(okhttp3.Response) Call(okhttp3.Call) HttpResponse(com.megaease.easeagent.plugin.tools.trace.HttpResponse) MethodInfo(com.megaease.easeagent.plugin.interceptor.MethodInfo) Test(org.junit.Test)

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