异常java.net.SocketException:连接重置

时间:2017-07-20 14:13:05

标签: java

我编写了一个代码来解析来自代理服务器的csv文件。但是在一段特定的时间间隔之后(在解析一些csv行之后),它会给出这个错误:

DEBUG [csvFile-267] Successfully parsed usage CSV file for 30 rows
ERROR  [csvFile-271] Exception occurred in csvFile() 
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)  

当我在该服务器上ping时,我得到了#34;请求超时"在某些情况下。这是服务器配置问题,网络还是编码?

我的代码:

    while ((line = reader.readLine()) != null) {
            UsageResponse usageResponse = new UsageResponse();
            ErrorDetails errorDetails = new ErrorDetails();
            try {
                //fileData = line.split(splitby);
                fileData = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");

                if (isheaderReadable) {

                    for (int headerCounter = 0; headerCounter < fileData.length; headerCounter++) {
                        if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_REPORT_START_DATE)) {
                            usageStartDateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_REPORT_END_DATE)) {
                            usageEndDateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_ACCOUNT_ID)) {
                            linkedAccountLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_CODE)) {
                            productCodeLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_USAGE_TYPE)) {
                            usageTypeLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_USAGE_AMOUNT)) {
                            usageAmountLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_UNBLENDED_RATE)) {
                            unBlendedrateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_UNBLENDED_COST)) {
                            unBlendedCostLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_BLENDED_RATE)) {
                            blendedrateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_BLENDED_COST)) {
                            blendedCostLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_ITEM_DESCRIPTION)) {
                            lineItemDescriptionLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_LOCATION)) {
                            productLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_SKU)) {
                            productSKULocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_NAME)) {
                            productNameLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_GROUP)) {
                            productGroupLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_LINE_ITEM_TYPE)) {
                            lineTypeLocation = headerCounter;
                        }
                    }
                    isheaderReadable = false;
                } else {

                    if (!fileData[lineTypeLocation].equalsIgnoreCase("Tax") && !fileData[lineTypeLocation].equalsIgnoreCase("DiscountedUsage")) {
                        usageResponse.setProductCode(fileData[productCodeLocation]);
                        usageResponse.setUsageStartDate(fileData[usageStartDateLocation]);
                        usageResponse.setUsageEndDate(fileData[usageEndDateLocation]);

                        if (fileData[blendedCostLocation] != null && !fileData[blendedCostLocation].isEmpty()) {
                            usageResponse.setBlendedCost(Double.parseDouble(fileData[blendedCostLocation]));
                        }
                        if (fileData[unBlendedCostLocation] != null && !fileData[unBlendedCostLocation].isEmpty()) {
                            usageResponse.setUnblendedCost((Double.parseDouble(fileData[unBlendedCostLocation])));
                        }
                        if (fileData[blendedrateLocation] != null && !fileData[blendedrateLocation].isEmpty()) {
                            usageResponse.setBlendedRate(Double.parseDouble(fileData[blendedrateLocation]));
                        }
                        if (fileData[unBlendedrateLocation] != null && !fileData[unBlendedrateLocation].isEmpty()) {
                            usageResponse.setUnblendedRate((Double.parseDouble(fileData[unBlendedrateLocation])));
                        }

                        usageResponse.setItemDescription(fileData[lineItemDescriptionLocation]);

                        if (fileData[usageAmountLocation] != null && !fileData[usageAmountLocation].isEmpty()) {
                            usageResponse.setUsageAmount(Double.parseDouble(fileData[usageAmountLocation]));
                        }
                        usageResponse.setUsageType(fileData[usageTypeLocation]);
                        usageResponse.setLocation(fileData[productLocation]);
                        usageResponse.setLinkedAccountId(fileData[linkedAccountLocation]);
                        usageResponse.setProductSKU(fileData[productSKULocation]);
                        usageResponse.setProductName(fileData[productNameLocation]);
                        usageResponse.setProductGroup(fileData[productGroupLocation]);
                        usageResponseList.add(usageResponse);
                    }
                }
            } catch (AWSCostAndUsageReportException e) {
                logger.error("Error is occurred during retrieving usage amounts ", e);
                errorDetails.setCode(e.getErrorCode());
                errorDetails.setMessage(e.getMessage());
                usageResponse.setErrorDetails(errorDetails);
            }
            listUsage.setUsageResponses(usageResponseList);

        }

1 个答案:

答案 0 :(得分:1)

如果您正在ping服务器并且请求超时意味着您正在ping的内容没有收到ping。此外,由于错误消息指出Connection已重置,这可能表示服务器失去与应用程序的连接。简而言之,建立了与服务器的连接,但是当您开始与服务器通信时,它会重置连接。

因为您提供的代码似乎不是处理套接字本身的原始代码,所以我不能代表代码发言。

Tldr; 服务器超时,因此连接正在重置。也可能是实际处理套接字的代码