
com.moesif.sdk.okhttp3client.models.OkHttp3ResponseMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moesif-okhttp-interceptor Show documentation
Show all versions of moesif-okhttp-interceptor Show documentation
Moesif Java OkHttp Interceptor SDK
package com.moesif.sdk.okhttp3client.models;
import com.moesif.api.models.EventResponseBuilder;
import com.moesif.api.models.EventResponseModel;
import com.moesif.helpers.CollectionUtils;
import okhttp3.Connection;
import okhttp3.Response;
import java.util.Date;
public class OkHttp3ResponseMapper extends EventResponseModel {
public static EventResponseModel createOkHttp3Response(
Response response,
Date responseDate,
Connection connection
) {
String ipAddress = getIpAddr(connection);
return createOkHttp3Response(response, responseDate, ipAddress);
}
public static EventResponseModel createOkHttp3Response(
Response response,
Date responseDate,
String ipAddress
) {
return new EventResponseBuilder()
.time(responseDate)
.status(response.code())
.headers(CollectionUtils.flattenMultiMap(
response.headers().toMultimap())
)
.ipAddress(ipAddress)
.build();
}
/**
* Obtains socket from Okhttp3 Connection object and runs GetHostByAddress
*
* @param c Connection
* @return null or ipAddress
*/
public static String getIpAddr(Connection c) {
String ipAddress = null;
if (c != null) {
ipAddress = c
.route()
.socketAddress()
.getAddress()
.getHostAddress();
}
return ipAddress;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy