Example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager shutdown

List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager shutdown

Introduction

In this page you can find the example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager shutdown.

Prototype

boolean shutdown

To view the source code for org.apache.commons.httpclient MultiThreadedHttpConnectionManager shutdown.

Click Source Link

Usage

From source file:org.jetbrains.jet.jvm.compiler.longTest.ResolveDescriptorsFromExternalLibraries.java

private File getFileFromUrl(@NotNull String lib, @NotNull File file, @NotNull String uri) throws IOException {
    if (file.exists()) {
        return file;
    }// ww w  .  ja  v a  2  s .co  m

    JetTestUtils.mkdirs(file.getParentFile());

    File tmp = new File(file.getPath() + "~");

    GetMethod method = new GetMethod(uri);

    FileOutputStream os = null;

    System.out.println("Downloading library " + lib + " to " + file);

    MultiThreadedHttpConnectionManager connectionManager = null;
    try {
        connectionManager = new MultiThreadedHttpConnectionManager();
        HttpClient httpClient = new HttpClient(connectionManager);
        os = new FileOutputStream(tmp);
        String userAgent = ResolveDescriptorsFromExternalLibraries.class.getName() + "/commons-httpclient";
        method.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
        int code = httpClient.executeMethod(method);
        if (code != 200) {
            throw new RuntimeException("failed to execute GET " + uri + ", code is " + code);
        }
        InputStream responseBodyAsStream = method.getResponseBodyAsStream();
        if (responseBodyAsStream == null) {
            throw new RuntimeException("method is executed fine, but response is null");
        }
        ByteStreams.copy(responseBodyAsStream, os);
        os.close();
        if (!tmp.renameTo(file)) {
            throw new RuntimeException("failed to rename file: " + tmp + " to " + file);
        }
        return file;
    } finally {
        if (method != null) {
            try {
                method.releaseConnection();
            } catch (Throwable e) {
            }
        }
        if (connectionManager != null) {
            try {
                connectionManager.shutdown();
            } catch (Throwable e) {
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (Throwable e) {
            }
        }
        tmp.delete();
    }
}

From source file:org.jetbrains.kotlin.jvm.compiler.longTest.ResolveDescriptorsFromExternalLibraries.java

private static File getFileFromUrl(@NotNull String lib, @NotNull File file, @NotNull String uri)
        throws IOException {
    if (file.exists()) {
        return file;
    }/*from www. jav  a2 s . co  m*/

    KotlinTestUtils.mkdirs(file.getParentFile());

    File tmp = new File(file.getPath() + "~");

    GetMethod method = new GetMethod(uri);

    FileOutputStream os = null;

    System.out.println("Downloading library " + lib + " to " + file);

    MultiThreadedHttpConnectionManager connectionManager = null;
    try {
        connectionManager = new MultiThreadedHttpConnectionManager();
        HttpClient httpClient = new HttpClient(connectionManager);
        os = new FileOutputStream(tmp);
        String userAgent = ResolveDescriptorsFromExternalLibraries.class.getName() + "/commons-httpclient";
        method.getParams().setParameter(HttpMethodParams.USER_AGENT, userAgent);
        int code = httpClient.executeMethod(method);
        if (code != 200) {
            throw new RuntimeException("failed to execute GET " + uri + ", code is " + code);
        }
        InputStream responseBodyAsStream = method.getResponseBodyAsStream();
        if (responseBodyAsStream == null) {
            throw new RuntimeException("method is executed fine, but response is null");
        }
        ByteStreams.copy(responseBodyAsStream, os);
        os.close();
        if (!tmp.renameTo(file)) {
            throw new RuntimeException("failed to rename file: " + tmp + " to " + file);
        }
        return file;
    } finally {
        try {
            method.releaseConnection();
        } catch (Throwable e) {
        }
        if (connectionManager != null) {
            try {
                connectionManager.shutdown();
            } catch (Throwable e) {
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (Throwable e) {
            }
        }
        tmp.delete();
    }
}

From source file:org.switchyard.component.test.mixins.http.HTTPMixIn.java

@Override
public void uninitialize() {
    if (_httpClient != null) {
        final HttpConnectionManager connectionManager = _httpClient.getHttpConnectionManager();
        if (connectionManager instanceof MultiThreadedHttpConnectionManager) {
            final MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = (MultiThreadedHttpConnectionManager) connectionManager;
            multiThreadedHttpConnectionManager.shutdown();
        }//from  w  ww. ja v a  2  s. c om
        connectionManager.closeIdleConnections(0);
    }
}