{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/esb-connectors/pulls/comments/46647490","id":46647490,"diff_hunk":"@@ -0,0 +1,201 @@\n+/*\n+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.\n+ * \n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ * \n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ * \n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.wso2.carbon.inbound.feedep;\n+\n+import org.apache.abdera.Abdera;\n+import org.apache.abdera.factory.Factory;\n+import org.apache.abdera.filter.ListParseFilter;\n+import org.apache.abdera.model.Document;\n+import org.apache.abdera.model.Entry;\n+import org.apache.abdera.model.Feed;\n+import org.apache.abdera.parser.Parser;\n+import org.apache.abdera.parser.ParserOptions;\n+import org.apache.abdera.util.Constants;\n+import org.apache.abdera.util.filter.WhiteListParseFilter;\n+import org.apache.axiom.om.OMElement;\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.net.URL;\n+import java.text.DateFormat;\n+import java.text.ParseException;\n+import java.text.SimpleDateFormat;\n+import java.util.Date;\n+import java.util.Iterator;\n+import java.util.Locale;\n+\n+/**\n+ * ConsumeFeed uses to feeds from given Backend\n+ */\n+public class ConsumeFeed {\n+    private static final Log log = LogFactory.getLog(ConsumeFeed.class.getName());\n+    private long scanInterval;\n+    private long scanIntervalDefined;\n+    private long lastRanTime;\n+    private String host;\n+    private String feedType;\n+    private Feed feed = null;\n+    private java.util.Date lastUpdated;\n+    private RssInject rssInject;\n+    private FeedRegistryHandler feedRegistryHandler;\n+    private String pathName;\n+    private String dateFormat;\n+    private DateFormat format;\n+    private Parser parser;\n+    private ParserOptions opts;\n+\n+    public ConsumeFeed(RssInject rssInject, long scanInterval, String host, String feedType,\n+                       FeedRegistryHandler feedRegistryHandler, String name, String dateFormat) {\n+        this.host = host;\n+        this.feedType = feedType;\n+        this.scanInterval = scanInterval;\n+        this.rssInject = rssInject;\n+        this.feedRegistryHandler = feedRegistryHandler;\n+        this.pathName = name;\n+        this.dateFormat = dateFormat;\n+        this.scanIntervalDefined = scanInterval;\n+        format = new SimpleDateFormat(FeedEPConstant.RSS_FEED_DATE_FORMAT, Locale.ENGLISH);\n+        parser = Abdera.getNewParser();\n+        //set filter\n+        opts = parser.getDefaultParserOptions();\n+        ListParseFilter filter = new WhiteListParseFilter();\n+        if (feedType.equalsIgnoreCase(FeedEPConstant.FEED_TYPE_RSS)) {\n+            filter.add(FeedEPConstant.FEED_RSS);\n+            filter.add(FeedEPConstant.FEED_CHANNEL);\n+            filter.add(FeedEPConstant.FEED_ITEM);\n+            filter.add(FeedEPConstant.FEED_TITLE);\n+            filter.add(FeedEPConstant.FEED_GUID);\n+            filter.add(FeedEPConstant.FEED_PUBDATE);\n+            filter.add(FeedEPConstant.FEED_LINK);\n+        } else if (feedType.equalsIgnoreCase(FeedEPConstant.FEED_TYPE_ATOM)) {\n+            filter.add(Constants.FEED);\n+            filter.add(Constants.ENTRY);\n+            filter.add(Constants.TITLE);\n+            filter.add(Constants.ID);\n+            filter.add(Constants.UPDATED);\n+            filter.add(Constants.LINK);\n+            filter.add(Constants.AUTHOR);\n+        }\n+        opts.setParseFilter(filter);\n+    }\n+\n+    //check time interval\n+    public void execute() {\n+        try {\n+            long currentTime = (new Date()).getTime();\n+            if (((lastRanTime + scanInterval) <= currentTime)) {\n+                lastRanTime = currentTime;\n+                if (log.isDebugEnabled()) {\n+                    log.debug(\"lastRanTime \" + lastRanTime);\n+                }\n+                consume();\n+            } else if (log.isDebugEnabled()) {\n+                log.debug(\"Skip cycle since concurrent rate is higher than the scan interval : Feed Inbound EP \" + pathName);\n+            } else if (scanInterval < 999999999) {","path":"feed/feed-inbound/feed-inbound-1.0.0/atom_rss_feed_1.0.0/src/main/java/org/wso2/carbon/inbound/feedep/ConsumeFeed.java","position":110,"original_position":110,"commit_id":"fbaeb0bfde1ba0f360d080702c44e998c0a27ff3","original_commit_id":"fbaeb0bfde1ba0f360d080702c44e998c0a27ff3","user":{"login":"malakasilva","id":6091878,"avatar_url":"https://avatars.githubusercontent.com/u/6091878?v=3","gravatar_id":"","url":"https://api.github.com/users/malakasilva","html_url":"https://github.com/malakasilva","followers_url":"https://api.github.com/users/malakasilva/followers","following_url":"https://api.github.com/users/malakasilva/following{/other_user}","gists_url":"https://api.github.com/users/malakasilva/gists{/gist_id}","starred_url":"https://api.github.com/users/malakasilva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malakasilva/subscriptions","organizations_url":"https://api.github.com/users/malakasilva/orgs","repos_url":"https://api.github.com/users/malakasilva/repos","events_url":"https://api.github.com/users/malakasilva/events{/privacy}","received_events_url":"https://api.github.com/users/malakasilva/received_events","type":"User","site_admin":false},"body":"I guess we don't need it. Can you explain why do we need this logic?","created_at":"2015-12-04T04:09:01Z","updated_at":"2015-12-04T04:09:01Z","html_url":"https://github.com/wso2/esb-connectors/pull/434#discussion_r46647490","pull_request_url":"https://api.github.com/repos/wso2/esb-connectors/pulls/434","_links":{"self":{"href":"https://api.github.com/repos/wso2/esb-connectors/pulls/comments/46647490"},"html":{"href":"https://github.com/wso2/esb-connectors/pull/434#discussion_r46647490"},"pull_request":{"href":"https://api.github.com/repos/wso2/esb-connectors/pulls/434"}}},"pull_request":{"url":"https://api.github.com/repos/wso2/esb-connectors/pulls/434","id":52374990,"html_url":"https://github.com/wso2/esb-connectors/pull/434","diff_url":"https://github.com/wso2/esb-connectors/pull/434.diff","patch_url":"https://github.com/wso2/esb-connectors/pull/434.patch","issue_url":"https://api.github.com/repos/wso2/esb-connectors/issues/434","number":434,"state":"open","locked":false,"title":"Feed Inbound","user":{"login":"hmrajas","id":1703634,"avatar_url":"https://avatars.githubusercontent.com/u/1703634?v=3","gravatar_id":"","url":"https://api.github.com/users/hmrajas","html_url":"https://github.com/hmrajas","followers_url":"https://api.github.com/users/hmrajas/followers","following_url":"https://api.github.com/users/hmrajas/following{/other_user}","gists_url":"https://api.github.com/users/hmrajas/gists{/gist_id}","starred_url":"https://api.github.com/users/hmrajas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmrajas/subscriptions","organizations_url":"https://api.github.com/users/hmrajas/orgs","repos_url":"https://api.github.com/users/hmrajas/repos","events_url":"https://api.github.com/users/hmrajas/events{/privacy}","received_events_url":"https://api.github.com/users/hmrajas/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-02T10:04:30Z","updated_at":"2015-12-04T04:09:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b03f73af17b5a1a80325b1346f191e15bd9ef151","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2/esb-connectors/pulls/434/commits","review_comments_url":"https://api.github.com/repos/wso2/esb-connectors/pulls/434/comments","review_comment_url":"https://api.github.com/repos/wso2/esb-connectors/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/esb-connectors/issues/434/comments","statuses_url":"https://api.github.com/repos/wso2/esb-connectors/statuses/fbaeb0bfde1ba0f360d080702c44e998c0a27ff3","head":{"label":"hmrajas:feedinbound","ref":"feedinbound","sha":"fbaeb0bfde1ba0f360d080702c44e998c0a27ff3","user":{"login":"hmrajas","id":1703634,"avatar_url":"https://avatars.githubusercontent.com/u/1703634?v=3","gravatar_id":"","url":"https://api.github.com/users/hmrajas","html_url":"https://github.com/hmrajas","followers_url":"https://api.github.com/users/hmrajas/followers","following_url":"https://api.github.com/users/hmrajas/following{/other_user}","gists_url":"https://api.github.com/users/hmrajas/gists{/gist_id}","starred_url":"https://api.github.com/users/hmrajas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmrajas/subscriptions","organizations_url":"https://api.github.com/users/hmrajas/orgs","repos_url":"https://api.github.com/users/hmrajas/repos","events_url":"https://api.github.com/users/hmrajas/events{/privacy}","received_events_url":"https://api.github.com/users/hmrajas/received_events","type":"User","site_admin":false},"repo":{"id":47239016,"name":"esb-connectors","full_name":"hmrajas/esb-connectors","owner":{"login":"hmrajas","id":1703634,"avatar_url":"https://avatars.githubusercontent.com/u/1703634?v=3","gravatar_id":"","url":"https://api.github.com/users/hmrajas","html_url":"https://github.com/hmrajas","followers_url":"https://api.github.com/users/hmrajas/followers","following_url":"https://api.github.com/users/hmrajas/following{/other_user}","gists_url":"https://api.github.com/users/hmrajas/gists{/gist_id}","starred_url":"https://api.github.com/users/hmrajas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmrajas/subscriptions","organizations_url":"https://api.github.com/users/hmrajas/orgs","repos_url":"https://api.github.com/users/hmrajas/repos","events_url":"https://api.github.com/users/hmrajas/events{/privacy}","received_events_url":"https://api.github.com/users/hmrajas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hmrajas/esb-connectors","description":"","fork":true,"url":"https://api.github.com/repos/hmrajas/esb-connectors","forks_url":"https://api.github.com/repos/hmrajas/esb-connectors/forks","keys_url":"https://api.github.com/repos/hmrajas/esb-connectors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hmrajas/esb-connectors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hmrajas/esb-connectors/teams","hooks_url":"https://api.github.com/repos/hmrajas/esb-connectors/hooks","issue_events_url":"https://api.github.com/repos/hmrajas/esb-connectors/issues/events{/number}","events_url":"https://api.github.com/repos/hmrajas/esb-connectors/events","assignees_url":"https://api.github.com/repos/hmrajas/esb-connectors/assignees{/user}","branches_url":"https://api.github.com/repos/hmrajas/esb-connectors/branches{/branch}","tags_url":"https://api.github.com/repos/hmrajas/esb-connectors/tags","blobs_url":"https://api.github.com/repos/hmrajas/esb-connectors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hmrajas/esb-connectors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hmrajas/esb-connectors/git/refs{/sha}","trees_url":"https://api.github.com/repos/hmrajas/esb-connectors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hmrajas/esb-connectors/statuses/{sha}","languages_url":"https://api.github.com/repos/hmrajas/esb-connectors/languages","stargazers_url":"https://api.github.com/repos/hmrajas/esb-connectors/stargazers","contributors_url":"https://api.github.com/repos/hmrajas/esb-connectors/contributors","subscribers_url":"https://api.github.com/repos/hmrajas/esb-connectors/subscribers","subscription_url":"https://api.github.com/repos/hmrajas/esb-connectors/subscription","commits_url":"https://api.github.com/repos/hmrajas/esb-connectors/commits{/sha}","git_commits_url":"https://api.github.com/repos/hmrajas/esb-connectors/git/commits{/sha}","comments_url":"https://api.github.com/repos/hmrajas/esb-connectors/comments{/number}","issue_comment_url":"https://api.github.com/repos/hmrajas/esb-connectors/issues/comments{/number}","contents_url":"https://api.github.com/repos/hmrajas/esb-connectors/contents/{+path}","compare_url":"https://api.github.com/repos/hmrajas/esb-connectors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hmrajas/esb-connectors/merges","archive_url":"https://api.github.com/repos/hmrajas/esb-connectors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hmrajas/esb-connectors/downloads","issues_url":"https://api.github.com/repos/hmrajas/esb-connectors/issues{/number}","pulls_url":"https://api.github.com/repos/hmrajas/esb-connectors/pulls{/number}","milestones_url":"https://api.github.com/repos/hmrajas/esb-connectors/milestones{/number}","notifications_url":"https://api.github.com/repos/hmrajas/esb-connectors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hmrajas/esb-connectors/labels{/name}","releases_url":"https://api.github.com/repos/hmrajas/esb-connectors/releases{/id}","created_at":"2015-12-02T05:24:25Z","updated_at":"2015-12-02T05:25:24Z","pushed_at":"2015-12-03T15:14:26Z","git_url":"git://github.com/hmrajas/esb-connectors.git","ssh_url":"git@github.com:hmrajas/esb-connectors.git","clone_url":"https://github.com/hmrajas/esb-connectors.git","svn_url":"https://github.com/hmrajas/esb-connectors","homepage":null,"size":169438,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"wso2:master","ref":"master","sha":"5ae0de4f547c4bede5ac65edc19a64db7d56d3e6","user":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":14882706,"name":"esb-connectors","full_name":"wso2/esb-connectors","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/esb-connectors","description":"","fork":false,"url":"https://api.github.com/repos/wso2/esb-connectors","forks_url":"https://api.github.com/repos/wso2/esb-connectors/forks","keys_url":"https://api.github.com/repos/wso2/esb-connectors/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/esb-connectors/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/esb-connectors/teams","hooks_url":"https://api.github.com/repos/wso2/esb-connectors/hooks","issue_events_url":"https://api.github.com/repos/wso2/esb-connectors/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/esb-connectors/events","assignees_url":"https://api.github.com/repos/wso2/esb-connectors/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/esb-connectors/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/esb-connectors/tags","blobs_url":"https://api.github.com/repos/wso2/esb-connectors/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/esb-connectors/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/esb-connectors/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/esb-connectors/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/esb-connectors/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/esb-connectors/languages","stargazers_url":"https://api.github.com/repos/wso2/esb-connectors/stargazers","contributors_url":"https://api.github.com/repos/wso2/esb-connectors/contributors","subscribers_url":"https://api.github.com/repos/wso2/esb-connectors/subscribers","subscription_url":"https://api.github.com/repos/wso2/esb-connectors/subscription","commits_url":"https://api.github.com/repos/wso2/esb-connectors/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/esb-connectors/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/esb-connectors/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/esb-connectors/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/esb-connectors/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/esb-connectors/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/esb-connectors/merges","archive_url":"https://api.github.com/repos/wso2/esb-connectors/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/esb-connectors/downloads","issues_url":"https://api.github.com/repos/wso2/esb-connectors/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/esb-connectors/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/esb-connectors/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/esb-connectors/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/esb-connectors/labels{/name}","releases_url":"https://api.github.com/repos/wso2/esb-connectors/releases{/id}","created_at":"2013-12-03T03:43:53Z","updated_at":"2015-11-11T09:01:00Z","pushed_at":"2015-12-03T11:43:56Z","git_url":"git://github.com/wso2/esb-connectors.git","ssh_url":"git@github.com:wso2/esb-connectors.git","clone_url":"https://github.com/wso2/esb-connectors.git","svn_url":"https://github.com/wso2/esb-connectors","homepage":null,"size":224405,"stargazers_count":24,"watchers_count":24,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":180,"mirror_url":null,"open_issues_count":50,"forks":180,"open_issues":50,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/esb-connectors/pulls/434"},"html":{"href":"https://github.com/wso2/esb-connectors/pull/434"},"issue":{"href":"https://api.github.com/repos/wso2/esb-connectors/issues/434"},"comments":{"href":"https://api.github.com/repos/wso2/esb-connectors/issues/434/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/esb-connectors/pulls/434/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/esb-connectors/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/esb-connectors/pulls/434/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/esb-connectors/statuses/fbaeb0bfde1ba0f360d080702c44e998c0a27ff3"}}}}