Example usage for org.apache.commons.httpclient HttpException getMessage

List of usage examples for org.apache.commons.httpclient HttpException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java

/**
 * Bach Nguyen - 01/05/2012 - Created SingleLoginForm to use for all login
 * If success then replace all login classes above
 * Attempts a login using the given PostMethod by adding the needed form parameters.
 * //from  w  w  w .j  a v a  2  s  .com
 * @param postMethod
 *            - the PostMethod with all other needed params already
 *            inserted.
 * @return the response as a String.
 */
public StatusString SingleLogInForm(PostMethod postMethod) {

    String html = null;
    Status iStatus = new Status();
    StatusString loginStatus = new StatusString();

    try {
        int statusCode = client.executeMethod(postMethod);
        //LOG.debug("statusCode: " + statusCode);
        if (statusCode == 200) {
            LOG.debug("SingleLogInForm - statusCode(" + statusCode + ") - Success received Login page");
            html = postMethod.getResponseBodyAsString();
            //LOG.debug("LoginWebForm - html.length: " + html.length());
            iStatus.returnStatus = true;
            iStatus.returnMsg = "MillenniumRemoteServiceManager-SingleLogInForm - Success";
            loginStatus.recordStatus = iStatus;
            loginStatus.statusValue = html;

        } else if (statusCode == 301) {
            LOG.debug("SingleLogInForm - statusCode(" + statusCode + ") - Link moved permanently");
            String redirectLocation = postMethod.getResponseHeader("Location").getValue();
            LOG.debug("MillenniumRemoteServiceManager-SingleLogInForm - redirectLocation: '" + redirectLocation
                    + "'");

            if (redirectLocation.length() > 0) {
                //LOG.debug("SingleLogInForm - Found Redirect Url");
                iStatus.returnStatus = true;
                iStatus.returnMsg = "MillenniumRemoteServiceManager-SingleLogInForm - (Handshake-301)";
                loginStatus.recordStatus = iStatus;
                loginStatus.statusValue = redirectLocation;
            } else {
                //LOG.debug("SingleLogInForm - Error in finding Redirct Url");
                iStatus.returnStatus = false;
                iStatus.returnMsg = "SingleLogInForm - Error in finding Redirct Url";
                loginStatus.recordStatus = iStatus;
                loginStatus.statusValue = html;
            }

        } else if (statusCode == 302) {
            String redirectLocation = postMethod.getResponseHeader("Location").getValue();
            //LOG.debug("LoginWebForm (Handshake-302) - redirectLocation: " + redirectLocation);
            //LOG.debug("LoginWebForm - HostName: " + postMethod.getURI().getHost());
            String url = "http://" + postMethod.getURI().getHost() + redirectLocation;
            if (redirectLocation.contains(postMethod.getURI().getHost())) {
                url = redirectLocation;
            }
            LOG.debug("SingleLogInForm-url(302): " + url);
            GetMethod getMethod = new GetMethod(url);

            statusCode = client.executeMethod(getMethod);
            //LOG.debug("SingleLogInForm-statusCode of getPost: " + statusCode);

            if (statusCode == 200) {
                LOG.debug("SingleLogInForm - (postMethod(302)-GetMethod (Handshake-200)");
                html = getMethod.getResponseBodyAsString();
                iStatus.returnStatus = true;
                iStatus.returnMsg = "MillenniumRemoteServiceManager-SingleLogInForm - (postMethod(302)-GetMethod (Handshake-200)";
                loginStatus.recordStatus = iStatus;
                loginStatus.statusValue = html;
            } else {
                LOG.debug("SingleLogInForm - Error in (postMethod(302)-getMethod(" + statusCode + ")");
                iStatus.returnStatus = false;
                iStatus.returnMsg = "SingleLogInForm - Error in (postMethod(302)-getMethod(" + statusCode + ")";
                loginStatus.recordStatus = iStatus;
                loginStatus.statusValue = html;
            }
            if (getMethod != null) {
                getMethod.releaseConnection();
            }
        } else {
            LOG.debug("SingleLogInForm - statusCode(" + statusCode + ") - false received Login page");
            iStatus.returnStatus = false;
            iStatus.returnMsg = "MillenniumRemoteServiceManager-SingleLogInForm - statusCode(" + statusCode
                    + "). " + errorCodeMsg.ErrorMessage(470);
            loginStatus.recordStatus = iStatus;
            loginStatus.statusValue = html;
        }

    } catch (HttpException e1) {
        LOG.error("SingleLogInForm - Error! HttpException.");
        //e1.printStackTrace();

        iStatus.returnStatus = false;
        iStatus.returnMsg = "MillenniumRemoteServiceManager-SingleLogInForm - "
                + errorCodeMsg.ErrorMessage(490);
        loginStatus.recordStatus = iStatus;
        loginStatus.statusValue = html;

    } catch (IOException e1) {
        LOG.error("SingleLogInForm - Error! IOException.");
        if (e1.getMessage().contains("unable to find valid certification path")) {
            LOG.debug("SingleLoginForm - Error! IOException - SSL-Unable to find valid certification path!");
            iStatus.returnStatus = false;
            iStatus.returnMsg = "MillenniumRemoteServiceManager-SingleLogInForm - "
                    + errorCodeMsg.ErrorMessage(482);
            ;
            loginStatus.recordStatus = iStatus;
            loginStatus.statusValue = html;
        } else {
            iStatus.returnStatus = false;
            iStatus.returnMsg = "MillenniumRemoteServiceManager-SingleLogInForm - "
                    + errorCodeMsg.ErrorMessage(480);
            ;
            loginStatus.recordStatus = iStatus;
            loginStatus.statusValue = html;
        }
        //e1.printStackTrace();
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
    }
    return loginStatus;
}

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 w w w. j  ava  2 s  .  com
  *  
  * @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;
}

From source file:org.fao.geonet.kernel.harvest.harvester.webdav.WAFRemoteFile.java

public Element getMetadata(SchemaManager schemaMan) throws Exception {
    try {//from   w  ww . jav a 2  s. c o  m
        String type = WAFRetriever.getFileType(this.path);
        if (type.equals(WAFRetriever.type_GetCapabilities))
            return getMdFromService(path, schemaMan);
        else if (type.equals(WAFRetriever.type_xml))
            return Xml.loadFile(new URL(path));
        else
            return null;
    } catch (HttpException x) {
        throw new Exception("HTTPException : " + x.getMessage());
    }
}

From source file:org.fao.geonet.kernel.harvest.harvester.webdav.WAFRemoteFile.java

private Element getMdFromService(String url, SchemaManager schemaMan) throws Exception {
    Element el = null;/*from  w  w  w.  jav  a  2s  .  c  om*/
    String styleSheet = getStyleSheet(url, schemaMan);
    if (styleSheet == null)
        return null;
    try {
        Element xml = Xml.loadFile(new URL(url));

        // md5 the full capabilities URL
        String uuid = Sha1Encoder.encodeString(url); // is the service identifier

        Map<String, String> param = new HashMap<String, String>();
        param.put("uuid", uuid);

        el = Xml.transform(xml, styleSheet, param);
    } catch (HttpException x) {
        // TODO Auto-generated catch block
        throw new Exception("HTTPException : " + x.getMessage());
    }
    return el;
}

From source file:org.fao.geonet.kernel.harvest.harvester.webdav.WebDavRemoteFile.java

public Element getMetadata(SchemaManager schemaMan) throws Exception {
    try {/*  ww w . ja v  a  2s.co  m*/
        wr.setPath(path);
        return Xml.loadStream(wr.getMethodData());
    } catch (HttpException x) {
        throw new Exception("HTTPException : " + x.getMessage());
    }
}

From source file:org.fao.geonet.kernel.harvest.harvester.webdav.WebDavRetriever.java

private WebdavResource open(String url) throws Exception {
    if (log.isDebugEnabled())
        log.debug("opening webdav resource with URL: " + url);
    if (!url.endsWith("/")) {
        if (log.isDebugEnabled())
            log.debug("URL " + url + "does not end in slash -- will be appended");
        url += "/";
    }/*from  w ww.j a  v  a2 s.  c  o  m*/
    try {
        if (log.isDebugEnabled())
            log.debug("Connecting to webdav url for node : " + params.name + " URL: " + params.url);
        WebdavResource wr = createResource(url);
        if (log.isDebugEnabled())
            log.debug("Connected to webdav resource at : " + url);

        //--- we are interested only in folders
        // heikki: somehow this works fine here, but see retrieveFiles()
        if (!wr.isCollection()) {
            log.error("Resource url is not a collection : " + url);
            wr.close();
            throw new Exception("Resource url is not a collection : " + url);
        } else {
            log.info("Resource path is : " + wr.getPath());
            return wr;
        }
    } catch (HttpException e) {
        throw new Exception("HTTPException: " + e.getMessage());
    }
}

From source file:org.geworkbench.engine.ccm.ComponentConfigurationManagerWindow2.java

private void findAvailableUpdatesFromTomcat() {

    installedRow = initialRow;/*from  w  w  w  .j  av  a 2s  .com*/
    //      String url = System.getProperty("remote_components_config_url");
    //remote_components_config_url=http://califano11.cgc.cpmc.columbia.edu:8080/componentRepository/deploycomponents.txt

    GlobalPreferences prefs = GlobalPreferences.getInstance();
    String url = prefs.getRCM_URL().trim();
    if (url == null || url == "") {
        log.info("No Remote Component Manager URL configured.");
        return;
    }
    url += "/deploycomponents.txt";

    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(3000);
    GetMethod method = new GetMethod(url);
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));
    method.setFollowRedirects(true);

    try {
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            JOptionPane.showMessageDialog(null,
                    "No updates are available at this time.\nPlease try again later.",
                    "Remote Component Update", JOptionPane.PLAIN_MESSAGE);
            return;
        }

        String deploycomponents = method.getResponseBodyAsString();
        //         String[] rows = deploycomponents.split("\\r\\n");
        String[] folderNameVersions = deploycomponents.split("\\r\\n");

        for (int i = 0; i < ccmTableModel.getModelRowCount(); i++) {
            String localFolderName = ccmTableModel.getResourceFolder(i);

            String localVersion = ((String) ccmTableModel.getModelValueAt(i, CCMTableModel2.VERSION_INDEX));
            Double dLocalVersion = new Double(localVersion);

            for (int j = 0; j < folderNameVersions.length; j++) {
                String[] cols = folderNameVersions[j].split(",");
                String remoteFolderName = cols[0];
                String remoteVersion = cols[1];
                Double dRemoteVersion = new Double(remoteVersion);

                if (localFolderName.equalsIgnoreCase(remoteFolderName)) {
                    if (dRemoteVersion.compareTo(dLocalVersion) > 0) {
                        ccmTableModel.setModelValueAt(remoteVersion, i, CCMTableModel2.AVAILABLE_UPDATE_INDEX,
                                CCMTableModel2.NO_VALIDATION);
                    }
                }
            }
        }
    } catch (HttpException e) {
        JOptionPane.showMessageDialog(null, "No updates are available at this time.\nPlease try again later.",
                "Remote Component Update", JOptionPane.PLAIN_MESSAGE);
        //e.printStackTrace();
        return;
    } catch (IOException e) {
        JOptionPane.showMessageDialog(null,
                e.getMessage() + ".\n(" + e.getClass().getName() + ")\nPlease try again later.",
                "No Update Available", JOptionPane.PLAIN_MESSAGE);
        //e.printStackTrace();
        return;
    } catch (Exception e) { // IllegalArgumentException
        JOptionPane.showMessageDialog(null, e.getMessage() + ".", "No Update Available",
                JOptionPane.PLAIN_MESSAGE);
    }
}

From source file:org.gss_project.gss.web.client.TestClient.java

public static void main(String[] args) {
    String user = "ebstest@grnet-hq.admin.grnet.gr";
    String token = "PcxaZ/4oIqCqIvCYgsUcKr1hAFcsW40G3kcWJSRPJV5GjzoNuo8RsA==";
    String host = "pithos.grnet.gr";
    String restPath = "/pithos/rest";
    String path = "/" + user + "/files/";
    String now = DateUtil.formatDate(new Date());
    String signature = sign("GET", now, path, token);
    HttpClient client = new HttpClient();
    HostConfiguration hostconfig = new HostConfiguration();
    hostconfig.setHost(host);//w w w.ja va2 s  .c om
    HttpMethod method = new GetMethod(restPath + path);
    Collection<Header> headers = new ArrayList<Header>();
    Header auth = new Header("Authorization", user + " " + signature);
    headers.add(auth);
    Header date = new Header("X-GSS-Date", now);
    headers.add(date);
    System.out.println(headers.toString());
    hostconfig.getParams().setParameter("http.default-headers", headers);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(hostconfig, method);

        if (statusCode != HttpStatus.SC_OK)
            System.err.println("Method failed: " + method.getStatusLine());

        // Read the response body.
        byte[] responseBody = method.getResponseBody();

        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary data
        System.out.println(new String(responseBody));
    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:org.iavante.sling.gad.hospies.impl.HospiesImpl.java

/**
 * download the current manifest and get the upgrade code
 * // w w w  .  ja  v  a 2 s .c  o m
 * @return the code of the actual upgrade
 * 
 */
private String getActualUpgradeCode(String profile) {
    /* make http connection */
    if (!checkProfileExist(profile))
        return null;

    /* get the document from S3 */
    InputStream body = null;

    HttpClient client = new HttpClient();
    GetMethod getm = new GetMethod("http://" + hospbucket + ".s3.amazonaws.com/" + base_current + profile);
    try {
        client.executeMethod(getm);
    } catch (HttpException e) {
        log.error("HttpException getting actual upgrade code: " + e.getMessage());
        return null;
    } catch (IOException e) {
        log.error("IOException getting actual upgrade code: " + e.getMessage());
        return null;
    }

    try {
        body = getm.getResponseBodyAsStream();
    } catch (IOException e) {
        log.error("IOException getting actual upgrade body code: " + e.getMessage());
        return null;
    }

    /* parse the xml document and get the upgrade tag */
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db;
    try {
        db = dbf.newDocumentBuilder();
        Document doc = db.parse(body);
        doc.getDocumentElement().normalize();
        NodeList nodeLst = doc.getElementsByTagName("upgrade");
        getm.releaseConnection();

        if (nodeLst.getLength() != 1) {
            log.error("nodeLst.getLength() != 1  , aborting...");
            return null;
        }

        Element ele = (Element) nodeLst.item(0);
        getm.releaseConnection();
        return ele.getTextContent();

    } catch (ParserConfigurationException e) {
        log.error("ParserConfigurationException parsing actual upgrade body code: " + e.getMessage());

    } catch (IOException e) {
        log.error("IOException parsing actual upgrade body code: " + e.getMessage());

    } catch (SAXException e) {
        log.error("SAXException parsing actual upgrade body code: " + e.getMessage());

    }
    getm.releaseConnection();
    return null;
}

From source file:org.infoglue.igide.helper.HTTPClientHelper.java

public String getContent(URL url) {
    GetMethod method = new GetMethod(url.toExternalForm());
    method.setDoAuthentication(true);// w  w  w.ja  v  a 2 s . c  o  m
    method.setFollowRedirects(true);

    String response = null;

    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + method.getStatusLine() + "code;" + method.getStatusCode());
            if (method.getStatusCode() == 302) {
                // Infoglue special!!

            }

        }

        // Read the response body.
        byte[] responseBody = method.getResponseBody();

        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary data
        response = new String(responseBody);

    } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return response;
}