0

I have written a code to parse a csv file from a proxy server.But after a specific time interval (after parsing some csv lines), it is giving this error:

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)  

When I am pinging on that server I am getting "request timeout" in some cases. Is that a server configuration problem, or network, or coding?

My Code:

    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);

        }
2
  • 3
    please post your code Commented Jul 20, 2017 at 14:14
  • Yeah posted, Some problems had occurred regarding line indents. Commented Jul 20, 2017 at 14:22

1 Answer 1

1

If you are pinging the server and getting a request time out that means that what ever you are pinging is not receiving your ping. Also, since the error message states that the Connection has reset that could be indicative of the server loosing connection to your application. In short, the connection to the server is made, but when you start to talk to the server it resets the connection.

Take that with a grain of salt because the code you have supplied does not seem to be the raw code that is handling the socket itself, so I cannot speak on the behalf of the code.

Tldr; Server is timing out so the connection is resetting. Could also be the code actually handling the socket

Sign up to request clarification or add additional context in comments.

3 Comments

I think this too..but everytime it is giving me a same result, connection timeout/ socket time exceptions should not be given repeatedly . Is it for any internal memory overflow related problem??..because the file size is big...
I think it is more like you are hitting the server multiple times, which if you are hitting it more than it can handle it will eventually go down. Like how DDoS attacks work. Now, this could account why it happens around the same time. If we want to rule out the code itself we either need the source handling the socket (which I do not know if you have access to) or try a different server (if possible)
I am using buffered reader, which is mapped with a csv file(located in a proxy server), and reading each line at a time . The connection is builded for once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.