Example usage for org.apache.http.impl.client SystemDefaultHttpClient getConnectionManager

List of usage examples for org.apache.http.impl.client SystemDefaultHttpClient getConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.impl.client SystemDefaultHttpClient getConnectionManager.

Prototype

public synchronized final ClientConnectionManager getConnectionManager() 

Source Link

Usage

From source file:de.badw.strauss.glyphpicker.controller.alltab.TeiLoadWorker.java

/**
 * Loads TEI data from a URL./*  w ww  .j  a v  a  2 s . c o  m*/
 *
 * @return the resulting GlyphDefinition list
 */
public List<GlyphDefinition> loadDataFromUrl() {
    SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
    try {
        HttpGet httpGet = new HttpGet(dataSource.getBasePath());
        return httpClient.execute(httpGet, new XMLResponseHandler());
    } catch (IOException e) {
        String message = String.format(i18n.getString("TeiLoadWorker.couldNotLoadData"),
                e.getLocalizedMessage(), dataSource.getBasePath());
        if (e instanceof UnknownHostException) {
            message += " Unknown host";
        }
        JOptionPane.showMessageDialog(null, message, i18n.getString("TeiLoadWorker.error"),
                JOptionPane.ERROR_MESSAGE);
        LOGGER.info(e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    return null;
}

From source file:de.badw.strauss.glyphpicker.controller.bitmap.BitmapUrlLoader.java

/**
 * Gets an image from a URL./*from  w  ww  . j ava  2s .com*/
 *
 * @param url the url
 * @return the image from the url
 */
public BufferedImage getImageFromUrl(String url) {
    SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
    try {
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = httpClient.execute(httpGet);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            byte[] bytes = EntityUtils.toByteArray(entity);
            return ImageIO.read(new ByteArrayInputStream(bytes));
        } else {
            throw new IOException(
                    "Download failed, HTTP response code " + statusCode + " - " + statusLine.getReasonPhrase());
        }
    } catch (IOException e) {
        LOGGER.warn("Error loading image from \"" + url + "\". " + e.getMessage());
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
    return null;
}