随机的HttpHostConnectException连接被拒绝

问题描述

我正在从Windows文件系统中读取一些文件,并将它们上传到Cloudsystem中。 jar文件是由Windows Task-Scheduler触发的,Windows Task-Scheduler执行一个小的Batch-Skript来运行jar文件

java -jar JarFileName

那没什么花哨的。

有时会抛出一个异常,但它是随机发生的,当之前成功执行了某些调用(GET请求)时,也会发生该异常。例如:我有10个GET-Request。前三个请求已成功执行,但第四个GET-Request抛出异常。

IO Exception occured while attempting to get thing configurationorg.apache.http.conn.HttpHostConnectException: Connect to http-proxy-2.name.com:3128 [http-proxy-2.name.com/12.345.678.4] Failed: Connection refused: connect org.apache.http.conn.HttpHostConnectException: Connect to http-proxy-2.name.com:3128 [http-proxy-2.name.com/12.345.678.4] Failed: Connection refused: connect

这是引发异常的函数

    public static String getThingConfiguration(String thingId) {

    String responseAsstring = null;
    String configuration_URI = AeConstants.APP_IOT_mds + "/Things('" + thingId + "')/Configuration";
    logger.info("##### final getThingConfiguration URI: " + configuration_URI);

    Response response = null;

    try {
        if (SharedConfigFile.proxy_ip != null && SharedConfigFile.proxy_port != null) {
            logger.info("found proxy,connecting via proxy");
            response = Request.Get(configuration_URI).addHeader("Content-Type","application/json")
                    .addHeader("Authorization",token)
                    .viaProxy(
                            new HttpHost(SharedConfigFile.proxy_ip,Integer.parseInt(SharedConfigFile.proxy_port)))
                    .execute();
        } else {
            logger.info("no proxy found,connecting without proxy");
            response = Request.Get(configuration_URI).addHeader("Content-Type",token).execute();
        }

        responseAsstring = response.returnContent().asstring();
    } catch (ClientProtocolException e) {
        e.printstacktrace(printWriter);
        logger.fatal("Failed to get thing configuration: " + e + " " + stringWriter.toString());
        System.exit(1);
    } catch (IOException e) {
        e.printstacktrace(printWriter);
        logger.fatal("IO Exception occured while attempting to get thing configuration" + e + " "
                + stringWriter.toString());
        System.exit(1);
    }

    return responseAsstring;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)