2

編集:このコードはすべて外部環境では正常に動作します (つまり、DEA12 では完全に動作します) が、展開すると bufferedreader で停止します。

編集 2:したがって、問題は確かに bufferedreader にあります。URL を少量のテキスト ( https://www.google.comなど) に変更すると、すべてが完璧に機能します。私が使用しなければならない URL には多くのテキストがあります (例: http://www.otc.edu/GEN/schedule/all_classes_fall.txt )。誰もこれを回避する方法を知っていますか?

サーブレットがタイムアウトになり、ログを介して、それが発生している行を絞り込みました。サーブレットは URL を介してデータを読み取り、それらを解析しますが、バッファリングリーダーに到達するとタイムアウトします (コードのどこにコメントしたか、スイッチの直後です)。

private void loadAllClasses()
        throws IOException
{
    //Log beginning of load
    logger.info("Started loading classes at " + new Date());

    URLConnection connection = null;
    LinkedList<ClassInfo> currentList = null;
    final int NUMBEROFSEMESTERS = 3;
    final String SPLITONTAB = "\\t";
    final int STARTINDEX = 0;

    for(int counter = STARTINDEX; counter < NUMBEROFSEMESTERS; counter++)
    {
        //Change local fields for whatever semester we are in, there will always only be three semesters
        switch(counter)
        {
            //Build out the Fall classes
            case 0:
                currentList = null;
                try{
                    connection = this.urlFall.openConnection();
                    logger.info("Opened up Fall URL at " + new Date());
                }
                catch (Exception ex)
                {
                    logger.fatal("FATAL! COULD NOT OPEN GIVEN URL FOR FALL CLASSES!");
                }
                currentList = fallClassListings;
                break;
            //Build out the Spring classes
            case 1:
                currentList = null;
                try{
                    connection = this.urlSpring.openConnection();
                    logger.info("Opened up Spring URL at " + new Date());
                }
                catch (Exception ex)
                {
                    logger.fatal("FATAL! COULD NOT OPEN GIVEN URL FOR SPRING CLASSES!");
                }
                currentList = springClassListings;
                break;
            //Build out the Summer classes
            case 2:
                currentList = null;
                try{
                    connection = this.urlSummer.openConnection();
                    logger.info("Opened up Summer URL at " + new Date());
                }
                catch (Exception ex)
                {
                    logger.fatal("FATAL! COULD NOT OPEN GIVEN URL FOR SUMMER CLASSES!");
                }
                currentList = summerClassListings;
                break;
        }//end switch

        //Opening a URL Successful
        logger.info("Successfully opened URL, beginning parse at " + new Date());

        //!!!!IT HAPPENS HERE AS THE LOG BELOW WILL NEVER BE REACHED!!!!
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        logger.info("Bufferedreader opened at " + new Date());

        String line = reader.readLine();

        //This is what is reading through and parsing all of the text from the URL
        while(line != null)
        {
            //Log beginning of parse
            logger.info("Parsing next text line of current URL at " + new Date());

            //Keeps track of how big the array is
            int index = Integer.parseInt(properties.getProperty("FIRSTINDEX"));

            //Split data on tab character
            String[] data = line.split(SPLITONTAB);

            //Strip all the white space so everything doesn't turn out poorly formatted
            for(int arrayCounter = Integer.parseInt(properties.getProperty("FIRSTINDEX")); arrayCounter < data.length; arrayCounter++)
            {
                data[arrayCounter] = data[arrayCounter].trim();

                index++;
            }

            //ADD THE DATA TO THE ACTUAL CLASS INFO OBJECTS
            if(index == Integer.parseInt(properties.getProperty("MAXSIZEARRAY")))//Size of array was 14, which has all of the class information
            {
                //TEST CONDITION TO FIND A LAB, if the name is empty this is a new class. If it isn't it is
                //Supplementary data to the last class created.
                if(!data[Integer.parseInt(properties.getProperty("NAME"))].isEmpty())//REGULAR CLASS IF TRUE
                {
                    //Strip out empty space and make it say "N/A"
                    data = convertEmptySpace(data);

                    currentList.add(new ClassInfo(data));
                    logger.info("Added a class.");
                }
                else//THESE ARE LABS OR ADDITIONAL LECTURE TIMES, so add all the last information from the last class since it's the same.
                {
                    ClassInfo classForLab = new ClassInfo(data);

                    //Lab details are already set from the array, so fill the empty data correctly
                    classForLab.setSectionName(currentList.get(currentList.size()- Integer.parseInt(properties.getProperty("SUBTRACTTOP"))).getSectionName());
                    classForLab.setSectionSynonym(currentList.get(currentList.size()- Integer.parseInt(properties.getProperty("SUBTRACTTOP"))).getSectionSynonym());
                    classForLab.setSectionCredits(properties.getProperty("ZERO_OUT_INFO"));
                    classForLab.setSectionTitle(currentList.get(currentList.size()- Integer.parseInt(properties.getProperty("SUBTRACTTOP"))).getSectionTitle());
                    classForLab.setSectionCapacity(currentList.get(currentList.size()- Integer.parseInt(properties.getProperty("SUBTRACTTOP"))).getSectionCapacity());
                    classForLab.setSectionAvailableSeats(properties.getProperty("ZERO_OUT_INFO"));
                    classForLab.setSectionInstructor(currentList.get(currentList.size()- Integer.parseInt(properties.getProperty("SUBTRACTTOP"))).getSectionInstructor());
                    classForLab.setSectionMysteryVariable(currentList.get(currentList.size()- Integer.parseInt(properties.getProperty("SUBTRACTTOP"))).getSectionMysteryVariable());

                    //After everything is set, add lab to the class listings
                    currentList.add(classForLab);
                    logger.info("Added a lab.");
                }
            }

            //Log classes added
            logger.info("Done parsing text at " + new Date());

            //End of the current line.
            line = reader.readLine();
        }

        //Close the reader
        reader.close();
    }//All semester are loaded, add them to the master list as well

    logger.info("All classes were successfully retrieved via parsing at " + new Date());

    allClassListings.addAll(fallClassListings);
    allClassListings.addAll(springClassListings);
    allClassListings.addAll(summerClassListings);

}

私のログ:

13:30:38,145 [TP-Processor18] INFO  Properties file was loaded successfully.
13:30:38,146 [TP-Processor18] INFO  URLs were successfully loaded at Thu Mar 07  13:30:38 CST 2013
13:30:38,146 [TP-Processor18] INFO  Started loading classes at Thu Mar 07 13:30:38 CST 2013
13:30:38,146 [TP-Processor18] INFO  Opened up Fall URL at Thu Mar 07 13:30:38 CST 2013
13:30:38,146 [TP-Processor18] INFO  Successfully opened URL, beginning parse at Thu Mar 07 13:30:38 CST 2013

なぜこれが起こっているのか、またはどのようにトラブルシューティングを行えばよいのでしょうか?

4

1 に答える 1

1

URLConnetion は、この行より前の接続から読み取り (ストリーミング データ) を開始しません。

BufferedReader reader = new BufferedReader(new 
              InputStreamReader(connection.getInputStream()));

connection.getInputStream()接続オブジェクトが URL からのデータの読み取りを開始します。

サーバーが URL にアクセスできず、タイムアウトしているようです。

呼び出してタイムアウトを変更することができますconnection.setTimeOut()

PING,TRACEサーバーからそれらの URL にアクセスして、それらの URL にアクセスできることと、ファイアウォールのブロックがないことを確認してください。

JavaDocs から -

>     openConnection()
>     ----------------------------> 
>     The connection object is created by invoking the openConnection method on a URL.
> 
>     getInputStream()
>     ---------------------------->
>     Returns an input stream that reads from this open connection.
于 2013-03-07T19:46:37.600 に答える