use of com.mopub.volley.Request in project prebid-mobile-android by prebid.
the class AdServerTest method processMoPubRequest.
private void processMoPubRequest(Request request) {
Networking.getRequestQueue(mContext).removeRequestFinishedListener(mMoPubRequestFinishedListener);
try {
String url = request.getUrl();
if (!TextUtils.isEmpty(url) && request.getBody() != null) {
ByteArrayInputStream postBodyStream = new ByteArrayInputStream(request.getBody());
String postBody = IOUtil.getStringFromStream(postBodyStream);
postBodyStream.close();
checkRequestForKeywords(url, postBody);
OkHttpClient client = new OkHttpClient.Builder().build();
RequestBody body = RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody);
okhttp3.Request httpRequest = new okhttp3.Request.Builder().url(url).post(body).build();
client.newCall(httpRequest).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, e.getMessage());
invokeContainsPrebidCreative(false);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.body() != null) {
InputStream inputStream = response.body().byteStream();
mAdServerResponse = IOUtil.getStringFromStream(inputStream);
inputStream.close();
checkResponseForPrebidCreative();
} else {
invokeContainsPrebidCreative(false);
}
}
});
}
} catch (Exception exception) {
Log.e(TAG, exception.getMessage());
}
}
use of com.mopub.volley.Request in project prebid-mobile-android by prebid.
the class SdkTest method processMoPubRequest.
private void processMoPubRequest(Request request) {
Networking.getRequestQueue(mContext).removeRequestFinishedListener(mMoPubRequestFinishedListener);
try {
String url = request.getUrl();
if (!TextUtils.isEmpty(url) && request.getBody() != null) {
ByteArrayInputStream postBodyStream = new ByteArrayInputStream(request.getBody());
String postBody = IOUtil.getStringFromStream(postBodyStream);
postBodyStream.close();
OkHttpClient client = new OkHttpClient.Builder().build();
RequestBody body = RequestBody.create(MediaType.parse(request.getBodyContentType()), postBody);
okhttp3.Request httpRequest = new okhttp3.Request.Builder().url(url).post(body).build();
client.newCall(httpRequest).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e(TAG, e.getMessage());
invokeContainsPrebidCreative(false);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.body() != null) {
InputStream inputStream = response.body().byteStream();
mAdServerResponse = IOUtil.getStringFromStream(inputStream);
inputStream.close();
checkResponseForPrebidCreative();
} else {
invokeContainsPrebidCreative(false);
}
}
});
mContext.runOnUiThread(() -> {
if (mListener != null) {
mListener.requestSentToAdServer(url, postBody);
}
});
}
} catch (Exception exception) {
Log.e(TAG, exception.getMessage());
}
}
Aggregations