From 9ec62bc1deefef729c302b1a4c1d2c8fbdb467be Mon Sep 17 00:00:00 2001 From: Athou Date: Sat, 13 Aug 2022 18:46:08 +0200 Subject: [PATCH] display error when importing invalid OPML file --- .../com/commafeed/backend/opml/OPMLImporter.java | 16 ++++++---------- .../commafeed/backend/opml/OPMLImporterTest.java | 11 ++++++----- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java b/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java index 8e127c99..e46a6ee1 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java @@ -18,6 +18,7 @@ import com.commafeed.backend.service.FeedSubscriptionService; import com.commafeed.backend.service.FeedSubscriptionService.FeedSubscriptionException; import com.rometools.opml.feed.opml.Opml; import com.rometools.opml.feed.opml.Outline; +import com.rometools.rome.io.FeedException; import com.rometools.rome.io.WireFeedInput; import lombok.RequiredArgsConstructor; @@ -32,19 +33,14 @@ public class OPMLImporter { private final FeedSubscriptionService feedSubscriptionService; private final CacheService cache; - public void importOpml(User user, String xml) { + public void importOpml(User user, String xml) throws IllegalArgumentException, FeedException { xml = xml.substring(xml.indexOf('<')); WireFeedInput input = new WireFeedInput(); - try { - Opml feed = (Opml) input.build(new StringReader(xml)); - List outlines = feed.getOutlines(); - for (int i = 0; i < outlines.size(); i++) { - handleOutline(user, outlines.get(i), null, i); - } - } catch (Exception e) { - log.error(e.getMessage(), e); + Opml feed = (Opml) input.build(new StringReader(xml)); + List outlines = feed.getOutlines(); + for (int i = 0; i < outlines.size(); i++) { + handleOutline(user, outlines.get(i), null, i); } - } private void handleOutline(User user, Outline outline, FeedCategory parent, int position) { diff --git a/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java b/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java index c597b48a..ae89f32e 100644 --- a/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java +++ b/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java @@ -12,30 +12,31 @@ import com.commafeed.backend.dao.FeedCategoryDAO; import com.commafeed.backend.model.FeedCategory; import com.commafeed.backend.model.User; import com.commafeed.backend.service.FeedSubscriptionService; +import com.rometools.rome.io.FeedException; class OPMLImporterTest { @Test - void testOpmlV10() throws IOException { + void testOpmlV10() throws IOException, IllegalArgumentException, FeedException { testOpmlVersion("/opml/opml_v1.0.xml"); } @Test - void testOpmlV11() throws IOException { + void testOpmlV11() throws IOException, IllegalArgumentException, FeedException { testOpmlVersion("/opml/opml_v1.1.xml"); } @Test - void testOpmlV20() throws IOException { + void testOpmlV20() throws IOException, IllegalArgumentException, FeedException { testOpmlVersion("/opml/opml_v2.0.xml"); } @Test - void testOpmlNoVersion() throws IOException { + void testOpmlNoVersion() throws IOException, IllegalArgumentException, FeedException { testOpmlVersion("/opml/opml_noversion.xml"); } - private void testOpmlVersion(String fileName) throws IOException { + private void testOpmlVersion(String fileName) throws IOException, IllegalArgumentException, FeedException { FeedCategoryDAO feedCategoryDAO = Mockito.mock(FeedCategoryDAO.class); FeedSubscriptionService feedSubscriptionService = Mockito.mock(FeedSubscriptionService.class); CacheService cacheService = Mockito.mock(CacheService.class);