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

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.fao.geonet.kernel.harvest.harvester.ogcwxs.Harvester.java

/** 
  * Load thumbnails making a GetMap operation.
  * Width is 300px. Ratio is computed for height using LatLongBoundingBoxElement.
  *  /*from   ww w. j  a v a 2  s . c  o  m*/
  *  
  * @param layer   layer for which the thumbnail needs to be generated
  *                   
  */
private String getMapThumbnail(WxSLayerRegistry layer) {
    String filename = layer.uuid + ".png";
    String dir = context.getUploadDir();
    Double r = WIDTH / (layer.maxx - layer.minx) * (layer.maxy - layer.miny);

    // Usual GetMap url tested with mapserver and geoserver
    // http://localhost:8080/geoserver/wms?service=WMS&request=GetMap&VERSION=1.1.1&
    //       LAYERS=gn:world&WIDTH=200&HEIGHT=200&FORMAT=image/png&BBOX=-180,-90,180,90&STYLES=
    String url = getBaseUrl(params.url) + "&SERVICE=" + params.ogctype.substring(0, 3) + "&VERSION="
            + params.ogctype.substring(3) + "&REQUEST=" + GETMAP + "&FORMAT=" + IMAGE_FORMAT + "&WIDTH=" + WIDTH
            + "&SRS=EPSG:4326" + "&HEIGHT=" + r.intValue() + "&LAYERS=" + layer.name + "&STYLES=" + "&BBOX="
            + layer.minx + "," + layer.miny + "," + layer.maxx + "," + layer.maxy;
    // All is in Lat/Long epsg:4326

    HttpClient httpclient = new HttpClient();
    GetMethod req = new GetMethod(url);

    if (log.isDebugEnabled())
        log.debug("Retrieving remote document: " + url);

    // set proxy from settings manager
    Lib.net.setupProxy(context, httpclient);

    try {
        // Connect
        int result = httpclient.executeMethod(req);
        if (log.isDebugEnabled())
            log.debug("   Get " + result);

        if (result == 200) {
            // Save image document to temp directory
            // TODO: Check OGC exception
            OutputStream fo = new FileOutputStream(dir + filename);
            BinaryFile.copy(req.getResponseBodyAsStream(), fo, true, true);
        } else {
            log.info(" Http error connecting");
            return null;
        }
    } catch (HttpException he) {
        log.info(" Http error connecting to '" + httpclient.toString() + "'");
        log.info(he.getMessage());
        return null;
    } catch (IOException ioe) {
        log.info(" Unable to connect to '" + httpclient.toString() + "'");
        log.info(ioe.getMessage());
        return null;
    } finally {
        // Release current connection to the connection pool once you are done
        req.releaseConnection();
    }

    return filename;
}