Example usage for org.apache.commons.httpclient HttpClient getClass

List of usage examples for org.apache.commons.httpclient HttpClient getClass

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpClient getClass.

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

public void initNetcdfHttpClient() throws MotuException {
    try {//from  ww  w  . j ava  2s  .c o m
        synchronized (this) {
            Field field = NetcdfDataset.class.getDeclaredField("httpClient");
            field.setAccessible(true);
            HttpClient httpClientNetcdfDataset = (HttpClient) field.get(null);
            HttpClientCAS httpClientCAS = null;

            field = DConnect2.class.getDeclaredField("_httpClient");
            field.setAccessible(true);
            HttpClient httpClientDConnect2 = (HttpClient) field.get(null);

            field = HTTPRandomAccessFile.class.getDeclaredField("_client");
            field.setAccessible(true);
            HttpClient httpClientHTTPRandomAccessFile = (HttpClient) field.get(null);

            if ((httpClientNetcdfDataset != null) && (httpClientDConnect2 != null)
                    && (httpClientHTTPRandomAccessFile != null)) {
                return;
            }

            if ((httpClientNetcdfDataset == null) && (httpClientDConnect2 == null)
                    && (httpClientHTTPRandomAccessFile == null)) {

                final int SO_TIMEOUT_VALUE = 180000; // in milliseconds 

                MultiThreadedHttpConnectionManager connectionManager = HttpUtil.createConnectionManager();
                // WARNING: because socket read can raise an infinite time out, set an arbitrary socket read time out
                connectionManager.getParams().setSoTimeout(SO_TIMEOUT_VALUE); // in milliseconds 

                httpClientCAS = new HttpClientCAS(connectionManager);

                HttpClientParams httpClientParams = new HttpClientParams();
                httpClientParams.setParameter("http.protocol.allow-circular-redirects", true);
                httpClientCAS.setParams(httpClientParams);

                NetcdfDataset.setHttpClient(httpClientCAS);

                connectionManager = HttpUtil.createConnectionManager();
                // WARNING: because socket read can raise an infinite time out, set an arbitrary socket read time out
                connectionManager.getParams().setSoTimeout(SO_TIMEOUT_VALUE); // in milliseconds 

                httpClientCAS = new HttpClientCAS(connectionManager);

                httpClientParams = new HttpClientParams();
                httpClientParams.setParameter("http.protocol.allow-circular-redirects", true);
                httpClientCAS.setParams(httpClientParams);

                DConnect2.setHttpClient(httpClientCAS);

                connectionManager = HttpUtil.createConnectionManager();
                // WARNING: because socket read can raise an infinite time out, set an arbitrary socket read time out
                connectionManager.getParams().setSoTimeout(SO_TIMEOUT_VALUE); // in milliseconds 

                httpClientCAS = new HttpClientCAS(connectionManager);

                httpClientParams = new HttpClientParams();
                httpClientParams.setParameter("http.protocol.allow-circular-redirects", true);
                httpClientCAS.setParams(httpClientParams);

                HTTPRandomAccessFile.setHttpClient(httpClientCAS);
            }

            if ((httpClientNetcdfDataset != null) && !(httpClientNetcdfDataset instanceof HttpClientCAS)) {
                throw new MotuException(String.format(
                        "Error in NetCdfReader acquireDataset - httpClientNetcdfDataset has been set but is no an HttpClientCAS object:'%s'",
                        httpClientNetcdfDataset.getClass().getName()));
            }

            if ((httpClientDConnect2 != null) && !(httpClientDConnect2 instanceof HttpClientCAS)) {
                throw new MotuException(String.format(
                        "Error in NetCdfReader acquireDataset - httpClientDConnect2 has been set but is no an HttpClientCAS object:'%s'",
                        httpClientDConnect2.getClass().getName()));
            }

            if ((httpClientHTTPRandomAccessFile != null)
                    && !(httpClientHTTPRandomAccessFile instanceof HttpClientCAS)) {
                throw new MotuException(String.format(
                        "Error in NetCdfReader acquireDataset - httpClientHTTPRandomAccessFile has been set but is no an HttpClientCAS object:'%s'",
                        httpClientHTTPRandomAccessFile.getClass().getName()));
            }

        }
    } catch (MotuException e) {
        throw e;
    } catch (Exception e) {
        throw new MotuException(
                "Error in NetCdfReader initNetcdfHttpClient - Unable to initialize httpClient object", e);
    }

}