{"action":"created","comment":{"url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/comments/52743320","id":52743320,"diff_hunk":"@@ -0,0 +1,130 @@\n+/*\n+ * Copyright (c) 2014, 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.device.mgt.iot.common.transport.mqtt;\n+\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+import org.eclipse.paho.client.mqttv3.*;\n+import org.wso2.carbon.device.mgt.iot.common.controlqueue.ControlQueueConnector;\n+import org.wso2.carbon.device.mgt.iot.common.exception.DeviceControllerException;\n+\n+import java.io.File;\n+import java.util.HashMap;\n+\n+import static java.nio.charset.StandardCharsets.UTF_8;\n+\n+/**\n+ * The Class MqttControlPublisher. It is an implementation of the interface\n+ * ControlQueueConnector.\n+ * This implementation supports publishing of control signals received to an\n+ * MQTT end-point.\n+ * The configuration settings for the MQTT end-point are read from the\n+ * 'devicecloud-config.xml' file of the project.\n+ * This is done using the class 'DeviceCloudConfigManager.java' which loads\n+ * the settings from the default xml org.wso2.carbon.device.mgt.iot.common.devicecloud.org.wso2.carbon.device.mgt.iot.common.config.server.configs\n+ * file -\n+ * /resources/conf/device-controls/devicecloud-config.xml\n+ */\n+public class MqttPublisher implements MqttCallback {\n+\n+\tprivate static final Log log = LogFactory.getLog(MqttPublisher.class);\n+\n+\tprivate String mqttEndpoint;\n+\tprivate String mqttUsername;\n+\tprivate String mqttPassword;\n+\tprivate boolean mqttEnabled = false;\n+\n+\tpublic MqttPublisher() {\n+\t}\n+\n+\tpublic void initControlQueue() throws DeviceControllerException {\n+\t\tmqttEndpoint = MqttConfig.getInstance().getMqttQueueEndpoint();\n+\t\tmqttUsername = MqttConfig.getInstance().getMqttQueueUsername();\n+\t\tmqttPassword = MqttConfig.getInstance().getMqttQueuePassword();\n+\t\tmqttEnabled = MqttConfig.getInstance().isEnabled();\n+\t}\n+\n+\tpublic void publish(String publishClientId, String publishTopic, byte[] payload)\n+\t\t\tthrows DeviceControllerException {\n+\n+\t\tif (mqttEnabled) {\n+\t\t\tMqttClient client;\n+\t\t\tMqttConnectOptions options;\n+\n+\t\t\tif (publishClientId.length() > 24) {\n+\t\t\t\tString errorString =\n+\t\t\t\t\t\t\"No of characters '\" + publishClientId.length() + \"' for ClientID: '\" + publishClientId +\n+\t\t\t\t\t\t\t\t\"' is invalid (should be less than 24, hence please provide a \" +\n+\t\t\t\t\t\t\t\t\"simple \" +\n+\n+\n+\t\t\t\t\t\t\t\t\"'owner' tag)\";\n+\t\t\t\tlog.error(errorString);","path":"components/iotserver-mgt/org.wso2.carbon.device.mgt.iot.common/src/main/java/org/wso2/carbon/device/mgt/iot/common/transport/mqtt/MqttPublisher.java","position":76,"original_position":76,"commit_id":"4e714b67f085999cb1a35c77cf8c0b76b8e9ca33","original_commit_id":"4e714b67f085999cb1a35c77cf8c0b76b8e9ca33","user":{"login":"prabathabey","id":6664125,"avatar_url":"https://avatars.githubusercontent.com/u/6664125?v=3","gravatar_id":"","url":"https://api.github.com/users/prabathabey","html_url":"https://github.com/prabathabey","followers_url":"https://api.github.com/users/prabathabey/followers","following_url":"https://api.github.com/users/prabathabey/following{/other_user}","gists_url":"https://api.github.com/users/prabathabey/gists{/gist_id}","starred_url":"https://api.github.com/users/prabathabey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prabathabey/subscriptions","organizations_url":"https://api.github.com/users/prabathabey/orgs","repos_url":"https://api.github.com/users/prabathabey/repos","events_url":"https://api.github.com/users/prabathabey/events{/privacy}","received_events_url":"https://api.github.com/users/prabathabey/received_events","type":"User","site_admin":false},"body":"Log and throw is generally considered an anti-pattern. If not extremely necessary, get rid of it.","created_at":"2016-02-12T13:56:33Z","updated_at":"2016-02-12T13:56:33Z","html_url":"https://github.com/wso2-incubator/iot-server-extensions/pull/14#discussion_r52743320","pull_request_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/comments/52743320"},"html":{"href":"https://github.com/wso2-incubator/iot-server-extensions/pull/14#discussion_r52743320"},"pull_request":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14","id":47382355,"html_url":"https://github.com/wso2-incubator/iot-server-extensions/pull/14","diff_url":"https://github.com/wso2-incubator/iot-server-extensions/pull/14.diff","patch_url":"https://github.com/wso2-incubator/iot-server-extensions/pull/14.patch","issue_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/issues/14","number":14,"state":"closed","locked":false,"title":"adding policy manager jax-rs service and mqtt transport","user":{"login":"rasika90","id":1448489,"avatar_url":"https://avatars.githubusercontent.com/u/1448489?v=3","gravatar_id":"","url":"https://api.github.com/users/rasika90","html_url":"https://github.com/rasika90","followers_url":"https://api.github.com/users/rasika90/followers","following_url":"https://api.github.com/users/rasika90/following{/other_user}","gists_url":"https://api.github.com/users/rasika90/gists{/gist_id}","starred_url":"https://api.github.com/users/rasika90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasika90/subscriptions","organizations_url":"https://api.github.com/users/rasika90/orgs","repos_url":"https://api.github.com/users/rasika90/repos","events_url":"https://api.github.com/users/rasika90/events{/privacy}","received_events_url":"https://api.github.com/users/rasika90/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-12T02:46:54Z","updated_at":"2016-02-12T13:56:33Z","closed_at":"2015-10-12T02:51:35Z","merged_at":"2015-10-12T02:51:35Z","merge_commit_sha":"1f68ac286cc221a4a60576b0b182e96cb346c75d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14/commits","review_comments_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14/comments","review_comment_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/issues/14/comments","statuses_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/statuses/4e714b67f085999cb1a35c77cf8c0b76b8e9ca33","head":{"label":"rasika90:build-pack","ref":"build-pack","sha":"4e714b67f085999cb1a35c77cf8c0b76b8e9ca33","user":{"login":"rasika90","id":1448489,"avatar_url":"https://avatars.githubusercontent.com/u/1448489?v=3","gravatar_id":"","url":"https://api.github.com/users/rasika90","html_url":"https://github.com/rasika90","followers_url":"https://api.github.com/users/rasika90/followers","following_url":"https://api.github.com/users/rasika90/following{/other_user}","gists_url":"https://api.github.com/users/rasika90/gists{/gist_id}","starred_url":"https://api.github.com/users/rasika90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasika90/subscriptions","organizations_url":"https://api.github.com/users/rasika90/orgs","repos_url":"https://api.github.com/users/rasika90/repos","events_url":"https://api.github.com/users/rasika90/events{/privacy}","received_events_url":"https://api.github.com/users/rasika90/received_events","type":"User","site_admin":false},"repo":{"id":43116054,"name":"iot-server-extensions","full_name":"rasika90/iot-server-extensions","owner":{"login":"rasika90","id":1448489,"avatar_url":"https://avatars.githubusercontent.com/u/1448489?v=3","gravatar_id":"","url":"https://api.github.com/users/rasika90","html_url":"https://github.com/rasika90","followers_url":"https://api.github.com/users/rasika90/followers","following_url":"https://api.github.com/users/rasika90/following{/other_user}","gists_url":"https://api.github.com/users/rasika90/gists{/gist_id}","starred_url":"https://api.github.com/users/rasika90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasika90/subscriptions","organizations_url":"https://api.github.com/users/rasika90/orgs","repos_url":"https://api.github.com/users/rasika90/repos","events_url":"https://api.github.com/users/rasika90/events{/privacy}","received_events_url":"https://api.github.com/users/rasika90/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rasika90/iot-server-extensions","description":"","fork":true,"url":"https://api.github.com/repos/rasika90/iot-server-extensions","forks_url":"https://api.github.com/repos/rasika90/iot-server-extensions/forks","keys_url":"https://api.github.com/repos/rasika90/iot-server-extensions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rasika90/iot-server-extensions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rasika90/iot-server-extensions/teams","hooks_url":"https://api.github.com/repos/rasika90/iot-server-extensions/hooks","issue_events_url":"https://api.github.com/repos/rasika90/iot-server-extensions/issues/events{/number}","events_url":"https://api.github.com/repos/rasika90/iot-server-extensions/events","assignees_url":"https://api.github.com/repos/rasika90/iot-server-extensions/assignees{/user}","branches_url":"https://api.github.com/repos/rasika90/iot-server-extensions/branches{/branch}","tags_url":"https://api.github.com/repos/rasika90/iot-server-extensions/tags","blobs_url":"https://api.github.com/repos/rasika90/iot-server-extensions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rasika90/iot-server-extensions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rasika90/iot-server-extensions/git/refs{/sha}","trees_url":"https://api.github.com/repos/rasika90/iot-server-extensions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rasika90/iot-server-extensions/statuses/{sha}","languages_url":"https://api.github.com/repos/rasika90/iot-server-extensions/languages","stargazers_url":"https://api.github.com/repos/rasika90/iot-server-extensions/stargazers","contributors_url":"https://api.github.com/repos/rasika90/iot-server-extensions/contributors","subscribers_url":"https://api.github.com/repos/rasika90/iot-server-extensions/subscribers","subscription_url":"https://api.github.com/repos/rasika90/iot-server-extensions/subscription","commits_url":"https://api.github.com/repos/rasika90/iot-server-extensions/commits{/sha}","git_commits_url":"https://api.github.com/repos/rasika90/iot-server-extensions/git/commits{/sha}","comments_url":"https://api.github.com/repos/rasika90/iot-server-extensions/comments{/number}","issue_comment_url":"https://api.github.com/repos/rasika90/iot-server-extensions/issues/comments{/number}","contents_url":"https://api.github.com/repos/rasika90/iot-server-extensions/contents/{+path}","compare_url":"https://api.github.com/repos/rasika90/iot-server-extensions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rasika90/iot-server-extensions/merges","archive_url":"https://api.github.com/repos/rasika90/iot-server-extensions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rasika90/iot-server-extensions/downloads","issues_url":"https://api.github.com/repos/rasika90/iot-server-extensions/issues{/number}","pulls_url":"https://api.github.com/repos/rasika90/iot-server-extensions/pulls{/number}","milestones_url":"https://api.github.com/repos/rasika90/iot-server-extensions/milestones{/number}","notifications_url":"https://api.github.com/repos/rasika90/iot-server-extensions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rasika90/iot-server-extensions/labels{/name}","releases_url":"https://api.github.com/repos/rasika90/iot-server-extensions/releases{/id}","deployments_url":"https://api.github.com/repos/rasika90/iot-server-extensions/deployments","created_at":"2015-09-25T07:25:20Z","updated_at":"2015-10-10T02:09:56Z","pushed_at":"2015-11-03T05:43:40Z","git_url":"git://github.com/rasika90/iot-server-extensions.git","ssh_url":"git@github.com:rasika90/iot-server-extensions.git","clone_url":"https://github.com/rasika90/iot-server-extensions.git","svn_url":"https://github.com/rasika90/iot-server-extensions","homepage":null,"size":3750,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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-incubator:build-pack","ref":"build-pack","sha":"5f150866cb39f6a54b2f2fe678af462550437634","user":{"login":"wso2-incubator","id":6744733,"avatar_url":"https://avatars.githubusercontent.com/u/6744733?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2-incubator","html_url":"https://github.com/wso2-incubator","followers_url":"https://api.github.com/users/wso2-incubator/followers","following_url":"https://api.github.com/users/wso2-incubator/following{/other_user}","gists_url":"https://api.github.com/users/wso2-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2-incubator/subscriptions","organizations_url":"https://api.github.com/users/wso2-incubator/orgs","repos_url":"https://api.github.com/users/wso2-incubator/repos","events_url":"https://api.github.com/users/wso2-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/wso2-incubator/received_events","type":"Organization","site_admin":false},"repo":{"id":33305761,"name":"iot-server-extensions","full_name":"wso2-incubator/iot-server-extensions","owner":{"login":"wso2-incubator","id":6744733,"avatar_url":"https://avatars.githubusercontent.com/u/6744733?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2-incubator","html_url":"https://github.com/wso2-incubator","followers_url":"https://api.github.com/users/wso2-incubator/followers","following_url":"https://api.github.com/users/wso2-incubator/following{/other_user}","gists_url":"https://api.github.com/users/wso2-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2-incubator/subscriptions","organizations_url":"https://api.github.com/users/wso2-incubator/orgs","repos_url":"https://api.github.com/users/wso2-incubator/repos","events_url":"https://api.github.com/users/wso2-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/wso2-incubator/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2-incubator/iot-server-extensions","description":"","fork":false,"url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions","forks_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/forks","keys_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/teams","hooks_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/hooks","issue_events_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/issues/events{/number}","events_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/events","assignees_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/assignees{/user}","branches_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/branches{/branch}","tags_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/tags","blobs_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/languages","stargazers_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/stargazers","contributors_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/contributors","subscribers_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/subscribers","subscription_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/subscription","commits_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/contents/{+path}","compare_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/merges","archive_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/downloads","issues_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/issues{/number}","pulls_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/labels{/name}","releases_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/releases{/id}","deployments_url":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/deployments","created_at":"2015-04-02T11:40:34Z","updated_at":"2015-10-09T21:21:40Z","pushed_at":"2015-11-06T06:47:02Z","git_url":"git://github.com/wso2-incubator/iot-server-extensions.git","ssh_url":"git@github.com:wso2-incubator/iot-server-extensions.git","clone_url":"https://github.com/wso2-incubator/iot-server-extensions.git","svn_url":"https://github.com/wso2-incubator/iot-server-extensions","homepage":null,"size":4275,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":0,"forks":8,"open_issues":0,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14"},"html":{"href":"https://github.com/wso2-incubator/iot-server-extensions/pull/14"},"issue":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/issues/14"},"comments":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/wso2-incubator/iot-server-extensions/statuses/4e714b67f085999cb1a35c77cf8c0b76b8e9ca33"}}}}