diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml index 9c196630b9d..7e5a1f9536e 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/test/resources/sample.xml @@ -17,63 +17,61 @@ ~ specific language governing permissions and limitations ~ under the License. --> - - sample + - - - - jdbc/SampleDM_DB - - + + en_US + 1.0.0 + This is license text + - - SAMPLE_DEVICE - - SAMPLE_DEVICE_ID - - column1 - column2 - - - en_US - 1.0.0 - This is license text - - - - - FEATURE_CODE_1 - feature name 1 - description - - - FEATURE_CODE_2 - feature name 2 - description - - - + + + jdbc/SampleDM_DB + + + + SAMPLE_DEVICE_ID + + column1 + column2 + +
+
+
+ + + + + abc + 5.0.0 + this is a feature + + place_holder + place_holder + place_holder + + + false -
+ + + true + + + sample.mqtt.adapter + tcp://localhost:1883 + admin + https://localhost:9443/dynamic-client-web/register + 0 + + true + + + - - - MQTT - true - - - sample.mqtt.adapter - tcp://localhost:1883 - admin - https://localhost:9443/dynamic-client-web/register - 0 - - true - -
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml new file mode 100644 index 00000000000..780f3b6b3e6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml @@ -0,0 +1,107 @@ + + + + + + + + device-mgt + org.wso2.carbon.devicemgt + 1.2.6-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.url.printer + bundle + WSO2 Carbon - Device Management url printer + WSO2 Carbon - Device Management url printer + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + maven-compiler-plugin + + 1.7 + 1.7 + + 2.3.2 + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + IoT Server Impl Bundle + org.wso2.carbon.device.mgt.iot.url.printer.internal + + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + org.apache.axis2.*;version="${axis2.osgi.version.range}", + org.wso2.carbon.core, + org.wso2.carbon.utils.*, + + + !org.wso2.carbon.device.mgt.iot.url.printer.internal, + org.wso2.carbon.device.mgt.iot.url.printer.*;version="${project.version}" + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.wso2.carbon + org.wso2.carbon.core + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.apache.axis2.wso2 + axis2 + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/URLPrinterStartupHandler.java b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/URLPrinterStartupHandler.java new file mode 100644 index 00000000000..757ff87d10d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/URLPrinterStartupHandler.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.url.printer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.device.mgt.url.printer.internal.UrlPrinterDataHolder; +import org.wso2.carbon.utils.CarbonUtils; +import org.wso2.carbon.utils.ConfigurationContextService; +import org.wso2.carbon.utils.NetworkUtils; + +public class URLPrinterStartupHandler implements ServerStartupObserver { + private static final Log log = LogFactory.getLog(URLPrinterStartupHandler.class); + + @Override + public void completingServerStartup() { + } + + @Override + public void completedServerStartup() { + log.info("IoT Console URL : " + this.getServerUrl()); + } + + private String getServerUrl() { + // Hostname + String hostName = "localhost"; + try { + hostName = NetworkUtils.getMgtHostName(); + } catch (Exception ignored) { + } + // HTTPS port + String mgtConsoleTransport = CarbonUtils.getManagementTransport(); + ConfigurationContextService configContextService = + UrlPrinterDataHolder.getInstance().getConfigurationContextService(); + int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport); + int httpsProxyPort = + CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(), mgtConsoleTransport); + if (httpsProxyPort > 0) { + port = httpsProxyPort; + } + return "https://" + hostName + ":" + port + "/devicemgt"; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/internal/UrlPrinterDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/internal/UrlPrinterDataHolder.java new file mode 100644 index 00000000000..1cf178b061b --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/internal/UrlPrinterDataHolder.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.mgt.url.printer.internal; + +import org.wso2.carbon.utils.ConfigurationContextService; + +public class UrlPrinterDataHolder { + + private ConfigurationContextService configurationContextService; + private static UrlPrinterDataHolder thisInstance = new UrlPrinterDataHolder(); + + private UrlPrinterDataHolder() {} + + public static UrlPrinterDataHolder getInstance() { + return thisInstance; + } + + public ConfigurationContextService getConfigurationContextService() { + return configurationContextService; + } + + public void setConfigurationContextService(ConfigurationContextService configurationContextService) { + this.configurationContextService = configurationContextService; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/internal/UrlPrinterServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/internal/UrlPrinterServiceComponent.java new file mode 100644 index 00000000000..b9b629f6466 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/src/main/java/org/wso2/carbon/device/mgt/url/printer/internal/UrlPrinterServiceComponent.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.url.printer.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.device.mgt.url.printer.URLPrinterStartupHandler; +import org.wso2.carbon.utils.ConfigurationContextService; + +/** + * @scr.component name="UrlPrinterServiceComponent" + * immediate="true" + * @scr.reference name="config.context.service" + * interface="org.wso2.carbon.utils.ConfigurationContextService" + * cardinality="0..1" + * policy="dynamic" + * bind="setConfigurationContextService" + * unbind="unsetConfigurationContextService" + */ +public class UrlPrinterServiceComponent { + + private static final Log log = LogFactory.getLog(UrlPrinterServiceComponent.class); + + protected void activate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("Activating Url printer Service Component"); + } + try { + BundleContext bundleContext = ctx.getBundleContext(); + bundleContext.registerService(ServerStartupObserver.class.getName(), new URLPrinterStartupHandler(), null); + if (log.isDebugEnabled()) { + log.debug("Url printer Service Component has been successfully activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Url printer Service Component", e); + } + } + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("De-activating Url printer Service Component"); + } + } + + protected void setConfigurationContextService(ConfigurationContextService configurationContextService) { + if (log.isDebugEnabled()) { + log.debug("Setting ConfigurationContextService"); + } + + UrlPrinterDataHolder.getInstance().setConfigurationContextService(configurationContextService); + + } + + protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) { + if (log.isDebugEnabled()) { + log.debug("Un-setting ConfigurationContextService"); + } + UrlPrinterDataHolder.getInstance().setConfigurationContextService(null); + } +} diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index d5952b7e653..e5f293950eb 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -40,6 +40,7 @@ org.wso2.carbon.device.mgt.analytics.dashboard org.wso2.carbon.device.mgt.api org.wso2.carbon.device.mgt.analytics.data.publisher + org.wso2.carbon.device.mgt.url.printer diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 8d634bf3e5a..00723dd85a8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -40,6 +40,10 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.url.printer + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common diff --git a/pom.xml b/pom.xml index 8b6a9f8d4b1..707bf23ea87 100644 --- a/pom.xml +++ b/pom.xml @@ -168,6 +168,11 @@ org.wso2.carbon.device.mgt.extensions ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.url.printer + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt org.wso2.carbon.certificate.mgt.core