diff --git a/src/main/java/com/commafeed/CommaFeedApplication.java b/src/main/java/com/commafeed/CommaFeedApplication.java index 8c5c8006..6f05ef76 100644 --- a/src/main/java/com/commafeed/CommaFeedApplication.java +++ b/src/main/java/com/commafeed/CommaFeedApplication.java @@ -55,7 +55,6 @@ import com.commafeed.backend.model.UserRole; import com.commafeed.backend.model.UserSettings; import com.commafeed.backend.opml.OPMLExporter; import com.commafeed.backend.opml.OPMLImporter; -import com.commafeed.backend.service.ApplicationPropertiesService; import com.commafeed.backend.service.DatabaseCleaningService; import com.commafeed.backend.service.FeedEntryContentService; import com.commafeed.backend.service.FeedEntryService; @@ -155,7 +154,6 @@ public class CommaFeedApplication extends Application { FeedQueues queues = new FeedQueues(feedDAO, config, metrics); // Services - ApplicationPropertiesService applicationPropertiesService = new ApplicationPropertiesService(); DatabaseCleaningService cleaningService = new DatabaseCleaningService(sessionFactory, feedDAO, feedEntryDAO, feedEntryContentDAO, feedEntryStatusDAO); FeedEntryContentService feedEntryContentService = new FeedEntryContentService(feedEntryContentDAO); @@ -175,7 +173,7 @@ public class CommaFeedApplication extends Application { OPMLExporter opmlExporter = new OPMLExporter(feedCategoryDAO, feedSubscriptionDAO); // Feed fetching/parsing - HttpGetter httpGetter = new HttpGetter(applicationPropertiesService); + HttpGetter httpGetter = new HttpGetter(config); FeedParser feedParser = new FeedParser(); FaviconFetcher faviconFetcher = new FaviconFetcher(httpGetter); FeedFetcher feedFetcher = new FeedFetcher(feedParser, httpGetter); @@ -215,7 +213,7 @@ public class CommaFeedApplication extends Application { new FeedREST(feedSubscriptionDAO, feedCategoryDAO, feedEntryStatusDAO, faviconFetcher, feedFetcher, feedEntryService, feedSubscriptionService, queues, opmlImporter, opmlExporter, cacheService, config)); environment.jersey().register(new PubSubHubbubCallbackREST(feedDAO, feedParser, queues, config, metrics)); - environment.jersey().register(new ServerREST(httpGetter, config, applicationPropertiesService)); + environment.jersey().register(new ServerREST(httpGetter, config)); environment.jersey().register( new UserREST(userDAO, userRoleDAO, userSettingsDAO, userService, encryptionService, mailService, config)); diff --git a/src/main/java/com/commafeed/CommaFeedConfiguration.java b/src/main/java/com/commafeed/CommaFeedConfiguration.java index bdbd6acc..9c5175a1 100644 --- a/src/main/java/com/commafeed/CommaFeedConfiguration.java +++ b/src/main/java/com/commafeed/CommaFeedConfiguration.java @@ -4,6 +4,7 @@ import io.dropwizard.Configuration; import io.dropwizard.db.DataSourceFactory; import java.util.Date; +import java.util.ResourceBundle; import javax.validation.Valid; import javax.validation.constraints.Min; @@ -23,6 +24,12 @@ public class CommaFeedConfiguration extends Configuration { NOOP, REDIS } + private ResourceBundle bundle; + + public CommaFeedConfiguration() { + bundle = ResourceBundle.getBundle("application"); + } + @Valid @NotNull @JsonProperty("database") @@ -33,6 +40,14 @@ public class CommaFeedConfiguration extends Configuration { @JsonProperty("app") private ApplicationSettings applicationSettings; + public String getVersion() { + return bundle.getString("version"); + } + + public String getGitCommit() { + return bundle.getString("git.commit"); + } + @Getter public static class ApplicationSettings { @JsonProperty diff --git a/src/main/java/com/commafeed/backend/HttpGetter.java b/src/main/java/com/commafeed/backend/HttpGetter.java index 83466c13..43be6157 100644 --- a/src/main/java/com/commafeed/backend/HttpGetter.java +++ b/src/main/java/com/commafeed/backend/HttpGetter.java @@ -44,7 +44,7 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; -import com.commafeed.backend.service.ApplicationPropertiesService; +import com.commafeed.CommaFeedConfiguration; /** * Smart HTTP getter: handles gzip, ssl, last modified and etag headers @@ -95,8 +95,8 @@ public class HttpGetter { private final String userAgent; - public HttpGetter(ApplicationPropertiesService applicationPropertiesService) { - this.userAgent = String.format("CommaFeed/%s (https://www.commafeed.com)", applicationPropertiesService.getVersion()); + public HttpGetter(CommaFeedConfiguration config) { + this.userAgent = String.format("CommaFeed/%s (https://www.commafeed.com)", config.getVersion()); } public HttpResult getBinary(String url, int timeout) throws ClientProtocolException, IOException, NotModifiedException { diff --git a/src/main/java/com/commafeed/backend/service/ApplicationPropertiesService.java b/src/main/java/com/commafeed/backend/service/ApplicationPropertiesService.java deleted file mode 100644 index fdcfc6c9..00000000 --- a/src/main/java/com/commafeed/backend/service/ApplicationPropertiesService.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.commafeed.backend.service; - -import java.util.ResourceBundle; - -public class ApplicationPropertiesService { - - private ResourceBundle bundle; - - public ApplicationPropertiesService() { - bundle = ResourceBundle.getBundle("application"); - } - - public String getVersion() { - return bundle.getString("version"); - } - - public String getGitCommit() { - return bundle.getString("git.commit"); - } -} diff --git a/src/main/java/com/commafeed/frontend/resource/ServerREST.java b/src/main/java/com/commafeed/frontend/resource/ServerREST.java index ce171124..537d9b9f 100644 --- a/src/main/java/com/commafeed/frontend/resource/ServerREST.java +++ b/src/main/java/com/commafeed/frontend/resource/ServerREST.java @@ -20,7 +20,6 @@ import com.commafeed.backend.HttpGetter; import com.commafeed.backend.HttpGetter.HttpResult; import com.commafeed.backend.feed.FeedUtils; import com.commafeed.backend.model.User; -import com.commafeed.backend.service.ApplicationPropertiesService; import com.commafeed.frontend.auth.SecurityCheck; import com.commafeed.frontend.model.ServerInfo; import com.wordnik.swagger.annotations.Api; @@ -35,7 +34,6 @@ public class ServerREST { private final HttpGetter httpGetter; private final CommaFeedConfiguration config; - private final ApplicationPropertiesService applicationPropertiesService; @Path("/get") @GET @@ -44,8 +42,8 @@ public class ServerREST { public Response get() { ServerInfo infos = new ServerInfo(); infos.setAnnouncement(config.getApplicationSettings().getAnnouncement()); - infos.setVersion(applicationPropertiesService.getVersion()); - infos.setGitCommit(applicationPropertiesService.getGitCommit()); + infos.setVersion(config.getVersion()); + infos.setGitCommit(config.getGitCommit()); infos.setAllowRegistrations(config.getApplicationSettings().isAllowRegistrations()); infos.setGoogleAnalyticsCode(config.getApplicationSettings().getGoogleAnalyticsTrackingCode()); infos.setSmtpEnabled(StringUtils.isNotBlank(config.getApplicationSettings().getSmtpHost()));