use of com.android.volley.toolbox.HttpResponse in project splunk-otel-android by signalfx.
the class VolleyResponseAttributesExtractorTest method spanDecoration_noLinkingHeader.
@Test
public void spanDecoration_noLinkingHeader() {
ServerTimingHeaderParser headerParser = mock(ServerTimingHeaderParser.class);
when(headerParser.parse(null)).thenReturn(new String[0]);
RequestWrapper fakeRequest = new RequestWrapper(mock(Request.class), Collections.emptyMap());
HttpResponse response = new HttpResponse(200, Collections.emptyList(), "hello".getBytes());
VolleyResponseAttributesExtractor attributesExtractor = new VolleyResponseAttributesExtractor(headerParser);
AttributesBuilder attributesBuilder = Attributes.builder();
attributesExtractor.onEnd(attributesBuilder, null, fakeRequest, response, null);
attributesExtractor.onStart(attributesBuilder, null, fakeRequest);
Attributes attributes = attributesBuilder.build();
assertEquals("http", attributes.get(SplunkRum.COMPONENT_KEY));
assertNull(attributes.get(SplunkRum.LINK_TRACE_ID_KEY));
assertNull(attributes.get(SplunkRum.LINK_SPAN_ID_KEY));
}
use of com.android.volley.toolbox.HttpResponse in project Hentoid by avluis.
the class VolleyOkHttp3Stack method executeRequest.
@Override
public HttpResponse executeRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
okhttp3.Request.Builder okHttpRequestBuilder = new okhttp3.Request.Builder();
okHttpRequestBuilder.url(request.getUrl());
Map<String, String> headers = request.getHeaders();
for (Map.Entry<String, String> entry : headers.entrySet()) {
String value = (null == entry.getValue()) ? "" : entry.getValue();
okHttpRequestBuilder.addHeader(entry.getKey(), value);
}
for (Map.Entry<String, String> entry : additionalHeaders.entrySet()) {
String value = (null == entry.getValue()) ? "" : entry.getValue();
okHttpRequestBuilder.addHeader(entry.getKey(), value);
}
setConnectionParametersForRequest(okHttpRequestBuilder, request);
okhttp3.Request okHttpRequest = okHttpRequestBuilder.build();
Call okHttpCall = client.newCall(okHttpRequest);
Response okHttpResponse = okHttpCall.execute();
int code = okHttpResponse.code();
ResponseBody body = okHttpResponse.body();
InputStream content = body == null ? null : body.byteStream();
int contentLength = body == null ? 0 : (int) body.contentLength();
List<Header> responseHeaders = mapHeaders(okHttpResponse.headers());
return new HttpResponse(code, responseHeaders, contentLength, content);
}
use of com.android.volley.toolbox.HttpResponse in project splunk-otel-android by signalfx.
the class TracingHurlStack method executeRequest.
@Override
public HttpResponse executeRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
HttpResponse response = null;
Throwable throwable = null;
RequestWrapper requestWrapper = new RequestWrapper(request, additionalHeaders);
currentRequestWrapper.set(requestWrapper);
Context parentContext = Context.current();
Context context = null;
Scope scope = null;
if (instrumenter.shouldStart(parentContext, requestWrapper)) {
context = instrumenter.start(parentContext, requestWrapper);
scope = context.makeCurrent();
}
try {
response = super.executeRequest(request, requestWrapper.getAdditionalHeaders());
} catch (Throwable t) {
throwable = t;
throw t;
} finally {
if (scope != null) {
scope.close();
instrumenter.end(context, requestWrapper, response, throwable);
}
currentRequestWrapper.remove();
}
return response;
}
use of com.android.volley.toolbox.HttpResponse in project splunk-otel-android by signalfx.
the class VolleyResponseAttributesExtractorTest method spanDecoration.
@Test
public void spanDecoration() {
ServerTimingHeaderParser headerParser = mock(ServerTimingHeaderParser.class);
when(headerParser.parse("headerValue")).thenReturn(new String[] { "9499195c502eb217c448a68bfe0f967c", "fe16eca542cd5d86" });
List<Header> responseHeaders = Collections.singletonList(new Header("Server-Timing", "headerValue"));
RequestWrapper fakeRequest = new RequestWrapper(mock(Request.class), Collections.emptyMap());
HttpResponse response = new HttpResponse(200, responseHeaders, "hello".getBytes());
VolleyResponseAttributesExtractor attributesExtractor = new VolleyResponseAttributesExtractor(headerParser);
AttributesBuilder attributesBuilder = Attributes.builder();
attributesExtractor.onStart(attributesBuilder, null, fakeRequest);
attributesExtractor.onEnd(attributesBuilder, null, fakeRequest, response, null);
Attributes attributes = attributesBuilder.build();
assertEquals("http", attributes.get(SplunkRum.COMPONENT_KEY));
assertEquals("9499195c502eb217c448a68bfe0f967c", attributes.get(SplunkRum.LINK_TRACE_ID_KEY));
assertEquals("fe16eca542cd5d86", attributes.get(SplunkRum.LINK_SPAN_ID_KEY));
}
Aggregations