append http protocol if missing

This commit is contained in:
Athou
2013-04-08 15:13:32 +02:00
parent 22408abc50
commit 546562c175

View File

@@ -39,11 +39,13 @@ public class SubscriptionsREST extends AbstractREST {
@Path("fetch")
public Feed fetchFeed(@QueryParam("url") String url) {
Preconditions.checkNotNull(url);
url = prependHttp(url);
Feed feed = null;
try {
feed = feedFetcher.fetch(url);
} catch (FeedException e) {
throw new WebApplicationException(Response
throw new WebApplicationException(e, Response
.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build());
}
@@ -57,7 +59,9 @@ public class SubscriptionsREST extends AbstractREST {
Preconditions.checkNotNull(req.getTitle());
Preconditions.checkNotNull(req.getUrl());
Feed fetchedFeed = fetchFeed(req.getUrl());
String url = prependHttp(req.getUrl());
Feed fetchedFeed = fetchFeed(url);
Feed feed = feedService.findByUrl(fetchedFeed.getUrl());
if (feed == null) {
feed = fetchedFeed;
@@ -74,6 +78,13 @@ public class SubscriptionsREST extends AbstractREST {
return Response.ok(Status.OK).build();
}
private String prependHttp(String url) {
if (!url.startsWith("http")) {
url = "http://" + url;
}
return url;
}
@GET
@Path("unsubscribe")
public Response unsubscribe(@QueryParam("id") Long subscriptionId) {