in Education by
I'm new to Java and Spring boot and I am trying to read and Parse RSS feed from a site. What's the issue: I need to read all the data from the feed and it'll be the paginated call. What's my solution: I think, I can achieve it if I read the data in a loop unless I reach the end and there's no more data. My code is as: SyndFeedInput input = new SyndFeedInput(); int pageNumber = 1; do { URL feedSource = new URL("https://altaonline.com/feed?paged=" + pageNumber); SyndFeed feed = input.build(new XmlReader(feedSource)); pageNumber = pageNumber + 1; } while ( pageNumber <= 27); //Need to fix this. I need help with: If there's no data on this URL, it gives me exception. I am not sure, how to check if the URL is valid, or if there's any data to process. How to do it JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You wouldn't know if the URL is valid unless you make the http request. So in this case, it would be ideal to surround the code with a try-catch and handle the exception accordingly. In case the URL isn't valid or returning no data, it can be handled by catching IOException. In case the feed returned cannot be parsed or generated, it can be handled by catching FeedException. SyndFeedInput input = new SyndFeedInput(); int pageNumber = 1; try{ do { URL feedSource = new URL("https://altaonline.com/feed?paged=" + pageNumber); SyndFeed feed = input.build(new XmlReader(feedSource)); pageNumber++; } while (pageNumber <= 27); } catch (IOException ex){ System.out.println("IO exception occurred due to: "+ ex); //Handle this exception accordingly } catch (FeedException ex) { System.out.println("Feed exception occurred due to: "+ ex); //Handle this exception accordingly } You may even catch Exception at the bottom for handling any other unknown exceptions that may occur. Please note that System.out.println is only given as an example and ideally should be replaced by using a logging library.

Related questions

0 votes
    What are the advantages of using Spring Boot?...
asked Jul 5, 2021 in Technology by JackTerrance
0 votes
    Spring Boot is example of __________. A. Service Deployment B. Service registry C. Chassis Framework D. API Gateway...
asked Jan 11, 2023 in Technology by JackTerrance
0 votes
    Spring boot follows Opinionated Defaults Configuration approach to reduce developer effort. A. True B. False...
asked Nov 8, 2022 in Education by JackTerrance
0 votes
    For which of the following criteria can Spring boot auto configuration be done? A. Presence of a System Property B. ... of a particular class in classpath E. All the options...
asked Nov 8, 2022 in Education by JackTerrance
0 votes
    The embedded server that starts up with the Spring boot application is ____________. A. Tomcat server B. Weblogic server C. None of the options D. Server has to be configured...
asked Nov 8, 2022 in Education by JackTerrance
0 votes
    I am using spring boot command line runner app, it hangs at PostGIS dialect, the below stack trace contains ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am using spring-boot latest 2.1.3 release and want to start with testcases, but this is not ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am using spring-boot latest 2.1.3 release and want to start with testcases, but this is not ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I created a microservice project that consist of a few services. In one of these services, I added an ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am trying to make requests to dedicated WSDL server with the help of Apache Camel CXF. I have ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    Which of the following enables production-ready features to the spring boot application? 1. Endpoint 2. Actuators 3. Boot 4. None of the above...
asked Jul 25, 2021 in Technology by JackTerrance
0 votes
    How can we override the default properties of Spring boot projects?...
asked Jul 23, 2021 in Technology by JackTerrance
0 votes
    What is the role of actuator in spring boot?...
asked Jul 23, 2021 in Technology by JackTerrance
0 votes
    Explain about the spring cloud and spring boot?...
asked Jul 23, 2021 in Technology by JackTerrance
0 votes
    Starting points of Spring Boot Application? 1. @Controller 2. @SpringBootApplication 3. @Service 4. None of the Above...
asked Jul 8, 2021 in Education by JackTerrance
...