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:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java

/**
 * ?//from   w  w  w  .j ava2 s. co m
 * 
 * @param serverId
 * @param id
 * @return
 */
private ContextResult processDelete(String serverId, long id) {
    ContextResult response = new ContextResult();
    // 
    if (!login(serverId)) {
        response.setSuccess(false);
        response.setStatusMsg(",??serverId?");
        return response;
    }
    log.info("processDelete(" + serverId + "," + id);
    String url = "/diamond-server/admin.do?method=deleteConfig&id=" + id;
    GetMethod method = new GetMethod(url);
    configureGetMethod(method);
    try {

        int status = client.executeMethod(method);
        response.setStatusCode(status);
        switch (status) {
        case HttpStatus.SC_OK:
            response.setSuccess(true);
            response.setReceiveResult(getContent(method));
            response.setStatusMsg("?, url=" + url);
            log.warn("???, url=" + url);
            break;
        case HttpStatus.SC_REQUEST_TIMEOUT:
            response.setSuccess(false);
            response.setStatusMsg("?" + require_timeout + "");
            log.error("?:" + require_timeout + ", id=" + id
                    + ",serverId=" + serverId);
            break;
        default:
            response.setSuccess(false);
            response.setStatusMsg("????" + status);
            log.error("???" + status + ", id=" + id + ",serverId=" + serverId);
            break;
        }

    } catch (HttpException e) {
        response.setSuccess(false);
        response.setStatusMsg("?,?" + e.getMessage());
        log.error("?, id=" + id + ",serverId=" + serverId, e);
    } catch (IOException e) {
        response.setSuccess(false);
        response.setStatusMsg("?,?" + e.getMessage());
        log.error("?, id=" + id + ",serverId=" + serverId, e);
    } finally {
        // ?
        method.releaseConnection();
    }

    return response;
}

From source file:com.taobao.diamond.sdkapi.impl.DiamondSDKManagerImpl.java

private ContextResult processPulishAfterModifiedByDefinedServerId(String dataId, String groupName,
        String context, String serverId) {
    ContextResult response = new ContextResult();
    // /*from   ww  w .  jav  a 2 s. c  om*/
    if (!login(serverId)) {
        response.setSuccess(false);
        response.setStatusMsg(",serverId");
        return response;
    }
    if (log.isDebugEnabled())
        log.debug("processPulishAfterModifiedByDefinedServerId(" + dataId + "," + groupName + "," + context
                + "," + serverId + ")");
    // dataId,groupName
    ContextResult result = null;
    result = queryByDataIdAndGroupName(dataId, groupName, serverId);
    if (null == result || !result.isSuccess()) {
        response.setSuccess(false);
        response.setStatusMsg("!");
        log.warn("! dataId=" + dataId + ",group=" + groupName + ",serverId="
                + serverId);
        return response;
    }
    // 
    else {
        String postUrl = "/diamond-server/admin.do?method=updateConfig";
        PostMethod post = new PostMethod(postUrl);
        // 
        post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout);
        try {
            NameValuePair dataId_value = new NameValuePair("dataId", dataId);
            NameValuePair group_value = new NameValuePair("group", groupName);
            NameValuePair content_value = new NameValuePair("content", context);
            // 
            post.setRequestBody(new NameValuePair[] { dataId_value, group_value, content_value });
            // 
            ConfigInfo configInfo = new ConfigInfo();
            configInfo.setDataId(dataId);
            configInfo.setGroup(groupName);
            configInfo.setContent(context);
            if (log.isDebugEnabled())
                log.debug("ConfigInfo: " + configInfo);
            // 
            response.setConfigInfo(configInfo);
            // http
            int status = client.executeMethod(post);
            response.setReceiveResult(post.getResponseBodyAsString());
            response.setStatusCode(status);
            log.info("" + status + "," + post.getResponseBodyAsString());
            if (status == HttpStatus.SC_OK) {
                response.setSuccess(true);
                response.setStatusMsg("");
                log.info("");
            } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) {
                response.setSuccess(false);
                response.setStatusMsg(":" + require_timeout + "");
                log.error(":" + require_timeout + ", dataId=" + dataId
                        + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId);
            } else {
                response.setSuccess(false);
                response.setStatusMsg(
                        ",ContextResultgetReceiveResult()");
                log.error(":" + response.getReceiveResult() + ",dataId=" + dataId + ",group="
                        + groupName + ",content=" + context + ",serverId=" + serverId);
            }

        } catch (HttpException e) {
            response.setSuccess(false);
            response.setStatusMsg("HttpException" + e.getMessage());
            log.error(
                    "processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context,String serverId)HttpExceptiondataId="
                            + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId,
                    e);
            return response;
        } catch (IOException e) {
            response.setSuccess(false);
            response.setStatusMsg("IOException" + e.getMessage());
            log.error(
                    "processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context,String serverId)IOExceptiondataId="
                            + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId,
                    e);
            return response;
        } finally {
            // 
            post.releaseConnection();
        }

        return response;
    }
}

From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java

private ContextResult processPulishAfterModifiedByDefinedServerId(String dataId, String groupName,
        String context, String serverId) {
    ContextResult response = new ContextResult();
    // //from  w  w  w. j a va2s .co m
    if (!login(serverId)) {
        response.setSuccess(false);
        response.setStatusMsg(",??serverId");
        return response;
    }
    if (log.isDebugEnabled())
        log.debug("processPulishAfterModifiedByDefinedServerId(" + dataId + "," + groupName + ","
                + context + "," + serverId + ")?");
    // ?dataId,groupName?
    ContextResult result = null;
    result = queryByDataIdAndGroupName(dataId, groupName, serverId);
    if (null == result || !result.isSuccess()) {
        response.setSuccess(false);
        response.setStatusMsg("????!");
        log.warn("????! dataId=" + dataId + ",group="
                + groupName + ",serverId=" + serverId);
        return response;
    }
    // ?
    else {
        String postUrl = "/diamond-server/admin.do?method=updateConfig";
        PostMethod post = new PostMethod(postUrl);
        // 
        post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout);
        try {
            NameValuePair dataId_value = new NameValuePair("dataId", dataId);
            NameValuePair group_value = new NameValuePair("group", groupName);
            NameValuePair content_value = new NameValuePair("content", context);
            // ?
            post.setRequestBody(new NameValuePair[] { dataId_value, group_value, content_value });
            // ?
            ConfigInfo configInfo = new ConfigInfo();
            configInfo.setDataId(dataId);
            configInfo.setGroup(groupName);
            configInfo.setContent(context);
            if (log.isDebugEnabled())
                log.debug("?ConfigInfo: " + configInfo);
            // ??
            response.setConfigInfo(configInfo);
            // http??
            int status = client.executeMethod(post);
            response.setReceiveResult(post.getResponseBodyAsString());
            response.setStatusCode(status);
            log.info("??" + status + ",?" + post.getResponseBodyAsString());
            if (status == HttpStatus.SC_OK) {
                response.setSuccess(true);
                response.setStatusMsg("???");
                log.info("???");
            } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) {
                response.setSuccess(false);
                response.setStatusMsg(
                        "??:" + require_timeout + "");
                log.error("??:" + require_timeout
                        + ", dataId=" + dataId + ",group=" + groupName + ",content=" + context
                        + ",serverId=" + serverId);
            } else {
                response.setSuccess(false);
                response.setStatusMsg(
                        "??,ContextResultgetReceiveResult()");
                log.error("??:" + response.getReceiveResult() + ",dataId=" + dataId
                        + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId);
            }

        } catch (HttpException e) {
            response.setSuccess(false);
            response.setStatusMsg("??HttpException" + e.getMessage());
            log.error(
                    "?processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context,String serverId)?HttpExceptiondataId="
                            + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId,
                    e);
            return response;
        } catch (IOException e) {
            response.setSuccess(false);
            response.setStatusMsg("??IOException" + e.getMessage());
            log.error(
                    "?processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context,String serverId)?IOExceptiondataId="
                            + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId,
                    e);
            return response;
        } finally {
            // ?
            post.releaseConnection();
        }

        return response;
    }
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private Asociacion buscarAsociacion(int code) {
    HttpClient httpclient = getHttpClient();
    GetMethod get = new GetMethod(restUrl.getAssociationUrl());
    get.addRequestHeader("Accept", "application/xml");
    Asociacion ret = null;//from w ww .j  av  a  2  s . co m
    try {
        int result = httpclient.executeMethod(get);
        logger.info("Response status code: " + result);
        String xmlString = get.getResponseBodyAsString();
        logger.info("Response body: " + xmlString);

        ret = importAsociacion(xmlString, code);
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } finally {
        get.releaseConnection();
    }
    return ret;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private FormaJuridica findRestFormaJuridica(Integer id) {
    HttpClient httpclient = getHttpClient();
    GetMethod get = new GetMethod(restUrl.getFormaJuridicaUrl());
    get.addRequestHeader("Accept", "application/xml");
    FormaJuridica ret = null;/*from w  w  w.  ja v  a  2  s  . c o  m*/
    try {
        int result = httpclient.executeMethod(get);
        logger.info("Response status code: " + result);
        String xmlString = get.getResponseBodyAsString();
        logger.info("Response body: " + xmlString);

        ret = importFormaJuridica(xmlString, id);
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } finally {
        get.releaseConnection();
    }
    return ret;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private ClasificacionOrganizacion findRestClasificacionOrganizacion(Integer id) {
    HttpClient httpclient = getHttpClient();
    GetMethod get = new GetMethod(restUrl.getClassOrganizacionUrl());
    get.addRequestHeader("Accept", "application/xml");
    ClasificacionOrganizacion ret = null;
    try {//from   www  .j  a  va 2  s .c om
        int result = httpclient.executeMethod(get);
        logger.info("Response status code: " + result);
        String xmlString = get.getResponseBodyAsString();
        logger.info("Response body: " + xmlString);

        ret = importClasificacionOrganizacion(xmlString, id);
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } finally {
        get.releaseConnection();
    }
    return ret;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private Sector buscarSector(int sectorCode) {
    HttpClient httpclient = getHttpClient();
    GetMethod get = new GetMethod(restUrl.getSectorUrl());
    get.addRequestHeader("Accept", "application/xml");
    Sector ret = null;/*  w  ww. j av a2  s .c o m*/
    try {
        int result = httpclient.executeMethod(get);
        logger.info("Response status code: " + result);
        String xmlString = get.getResponseBodyAsString();
        logger.info("Response body: " + xmlString);

        ret = importSector(xmlString, sectorCode);
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } finally {
        get.releaseConnection();
    }
    return ret;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private Capacidad buscarCapacidad(int capacityCode) {
    HttpClient httpclient = getHttpClient();
    GetMethod get = new GetMethod(restUrl.getCapacidadUrl());
    get.addRequestHeader("Accept", "application/xml");
    Capacidad ret = null;/*ww w.  ja v a2 s . c o  m*/
    try {
        int result = httpclient.executeMethod(get);
        if (logger.isTraceEnabled())
            logger.trace("Response status code: " + result);
        String xmlString = get.getResponseBodyAsString();
        if (logger.isTraceEnabled())
            logger.trace("Response body: " + xmlString);

        ret = importCapacidad(xmlString, capacityCode);
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } finally {
        get.releaseConnection();
    }
    return ret;
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private String getXmlToken() {
    String token = null;//  ww w  .j a v  a2s.  c  o  m
    HttpClient httpclient = getHttpClient();
    GetMethod get = new GetMethod(restUrl.getTokenUrl());
    get.addRequestHeader("Accept", "application/xml");

    NameValuePair userParam = new NameValuePair(USERNAME_PARAM, satelite.getUser());
    NameValuePair passwordParam = new NameValuePair(PASSWORD_PARAM, satelite.getPassword());
    NameValuePair[] params = new NameValuePair[] { userParam, passwordParam };

    get.setQueryString(params);
    try {
        int statusCode = httpclient.executeMethod(get);
        if (statusCode != HttpStatus.SC_OK) {
            logger.error("Method failed: " + get.getStatusLine());
        }
        token = parseToken(get.getResponseBodyAsString());
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } finally {
        get.releaseConnection();
    }

    return token;
}

From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.navegacao_cego.PainelSimuladorNavegacao.java

public void avaliaUrl(String url) {
    if (url.startsWith("http")) {
        PegarPaginaWEB ppw = new PegarPaginaWEB();
        if (url != null) {
            try {
                String codHtml = ppw.getContent(url);
                System.out.println(codHtml);
                parentFrame.showPainelSimuladorNavegacaoPArq(codHtml);
                parentFrame.setTitle(url + " - " + TradSimuladorNavegacao.TITULO_SIMULADOR_CEGO);
            } catch (HttpException e1) {
                JOptionPane.showMessageDialog(this, TradPainelAvaliacao.AVISO_NAO_CONECTOU,
                        TradPainelAvaliacao.AVISO, JOptionPane.WARNING_MESSAGE);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(this, TradPainelAvaliacao.AVISO_VERIFIQUE_URL,
                        TradPainelAvaliacao.AVISO, JOptionPane.WARNING_MESSAGE);
                e.printStackTrace();// w ww . j  a va2s  .c o m
            } catch (Exception e1) {
                JOptionPane.showMessageDialog(this, e1.getMessage(), e1.getMessage(),
                        JOptionPane.WARNING_MESSAGE);
                e1.printStackTrace();
            }
        }
    } else {
        G_File temp = new G_File(url);
        if (temp.exists()) {
            parentFrame.showPainelSimuladorNavegacaoPArq(temp.read());
            parentFrame
                    .setTitle(temp.getFile().getName() + " - " + TradSimuladorNavegacao.TITULO_SIMULADOR_CEGO);
        } else {
            JOptionPane.showMessageDialog(this, TradPainelAvaliacao.AVISO_VERIFIQUE_URL,
                    TradPainelAvaliacao.AVISO, JOptionPane.WARNING_MESSAGE);
        }
    }
}