Example usage for org.apache.http.client.methods CloseableHttpResponse getClass

List of usage examples for org.apache.http.client.methods CloseableHttpResponse getClass

Introduction

In this page you can find the example usage for org.apache.http.client.methods CloseableHttpResponse getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.artifactory.util.HttpUtils.java

public static String resolveResponseRemoteAddress(CloseableHttpResponse response) {
    try {/*from w w  w . ja  v  a  2s  .co  m*/
        Field connHolderField = response.getClass().getDeclaredField("connHolder");
        connHolderField.setAccessible(true);
        Object connHolder = connHolderField.get(response);

        Field managedConnField = connHolder.getClass().getDeclaredField("managedConn");
        managedConnField.setAccessible(true);
        ManagedHttpClientConnection managedConn = (ManagedHttpClientConnection) managedConnField
                .get(connHolder);
        String hostAddress = managedConn.getSocket().getInetAddress().getHostAddress();
        return hostAddress == null ? StringUtils.EMPTY : hostAddress;
    } catch (Throwable throwable) {
        return StringUtils.EMPTY;
    }
}