From 9fc5cee6fe10943965d67e9aab59d5f5a582d6ea Mon Sep 17 00:00:00 2001 From: Risto Kankkunen Date: Mon, 20 May 2013 22:10:44 +0300 Subject: [PATCH 1/3] Avoid a NPE if the public URL is not set. --HG-- extra : rebase_source : 9b98f856d10dff6cb19bbaf90fb7eb22336aea7f --- .../commafeed/backend/services/FeedSubscriptionService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java b/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java index 00ba09ed..54c342f7 100644 --- a/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java +++ b/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java @@ -41,7 +41,11 @@ public class FeedSubscriptionService { public Feed subscribe(User user, String url, String title, FeedCategory category) { - if (url.startsWith(applicationSettingsService.get().getPublicUrl())) { + final String pubUrl = applicationSettingsService.get().getPublicUrl(); + if (pubUrl == null) { + throw new RuntimeException("Public URL of this CommaFeed is unset"); + } + if (url.startsWith(pubUrl)) { throw new RuntimeException( "Could not subscribe to a feed from this CommaFeed instance"); } From 8f9e8fd2ea6d893fa09e4986ad6b6b2cbf8aad22 Mon Sep 17 00:00:00 2001 From: Risto Kankkunen Date: Mon, 20 May 2013 22:14:56 +0300 Subject: [PATCH 2/3] Make subscription failures visible. --HG-- extra : rebase_source : 9e7232b821665d9a6342c928d0b17ac3bdd9e6e7 --- .../commafeed/frontend/rest/resources/FeedREST.java | 10 ++++++++-- src/main/webapp/js/controllers.js | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java b/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java index 68394500..3b4c9b03 100644 --- a/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java +++ b/src/main/java/com/commafeed/frontend/rest/resources/FeedREST.java @@ -224,9 +224,15 @@ public class FeedREST extends AbstractResourceREST { FeedCategory category = CategoryREST.ALL.equals(req.getCategoryId()) ? null : feedCategoryDAO.findById(Long.valueOf(req.getCategoryId())); FeedInfo info = (FeedInfo) fetchFeed(url).getEntity(); - feedSubscriptionService.subscribe(getUser(), info.getUrl(), + try { + feedSubscriptionService.subscribe(getUser(), info.getUrl(), req.getTitle(), category); - + } catch (Exception e) { + log.info("Failed to subscribe to URL {}: {}", url, e.getMessage()); + return Response.status(Status.SERVICE_UNAVAILABLE).entity( + "Failed to subscribe to URL " + url + ": " + e.getMessage() + ).build(); + } return Response.ok(Status.OK).build(); } diff --git a/src/main/webapp/js/controllers.js b/src/main/webapp/js/controllers.js index b635265f..fc46eb18 100644 --- a/src/main/webapp/js/controllers.js +++ b/src/main/webapp/js/controllers.js @@ -75,8 +75,11 @@ function($scope, FeedService, CategoryService) { } FeedService.subscribe($scope.sub, function() { CategoryService.init(); + $scope.close(); + }, function(data) { + $scope.state = 'failed'; + $scope.sub.title = 'ERROR: ' + data.data; }); - $scope.close(); }; $scope.openImport = function() { From ab621e9c5fb9b6ec558fc46dd8c9a45f8ff1dd4a Mon Sep 17 00:00:00 2001 From: Risto Kankkunen Date: Mon, 20 May 2013 22:33:45 +0300 Subject: [PATCH 3/3] Make the error message prettier by avoiding a nested exception. --HG-- extra : rebase_source : 8c33ce8a8a6ae92fcc1e46a7b416e1c9802bf726 --- .../backend/services/FeedSubscriptionService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java b/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java index 54c342f7..566368c2 100644 --- a/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java +++ b/src/main/java/com/commafeed/backend/services/FeedSubscriptionService.java @@ -3,6 +3,7 @@ package com.commafeed.backend.services; import java.util.List; import javax.ejb.Stateless; +import javax.ejb.ApplicationException; import javax.inject.Inject; import com.commafeed.backend.dao.FeedEntryDAO; @@ -19,6 +20,12 @@ import com.google.api.client.util.Lists; @Stateless public class FeedSubscriptionService { + @ApplicationException + public class FeedSubscriptionException extends RuntimeException { + public FeedSubscriptionException(String msg) { + super(msg); + } + } @Inject FeedService feedService; @@ -43,7 +50,8 @@ public class FeedSubscriptionService { final String pubUrl = applicationSettingsService.get().getPublicUrl(); if (pubUrl == null) { - throw new RuntimeException("Public URL of this CommaFeed is unset"); + throw new FeedSubscriptionException( + "Public URL of this CommaFeed is unset"); } if (url.startsWith(pubUrl)) { throw new RuntimeException(