From e8b6cd1830b1ed8e927fc40d4e88ac8fbd0dea4a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Tue, 28 Jul 2015 18:28:48 +0530 Subject: [PATCH] Adding URL Printer startup handler implementation to devicemgt-plugins --- .../pom.xml | 84 +++++++++++++++++++ .../url/printer/URLPrinterStartupHandler.java | 64 ++++++++++++++ .../internal/URLPrinterDataHolder.java | 42 ++++++++++ ...PrinterStartupHandlerServiceComponent.java | 73 ++++++++++++++++ components/device-mgt/pom.xml | 1 + .../pom.xml | 11 ++- pom.xml | 15 +++- 7 files changed, 285 insertions(+), 5 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterDataHolder.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterStartupHandlerServiceComponent.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml new file mode 100644 index 0000000000..af83029f12 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/pom.xml @@ -0,0 +1,84 @@ + + + + device-mgt + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.mobile.url.printer + 1.9.2-SNAPSHOT + bundle + WSO2 Carbon - Startup Handler That Prints MDM End-User Web-App URL + WSO2 Carbon - Startup Handler That Prints MDM End-User Web-App URL + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.mobile.device.mgt.version} + Bundle Containing The Startup Handler That Prints MDM End-User Web-App URL + org.wso2.carbon.device.mgt.mobile.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.mobile.url.printer.internal, + org.wso2.carbon.device.mgt.mobile.url.printer, + + + + + + + + + + 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 + + + + \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java new file mode 100644 index 0000000000..ab9d41b14c --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java @@ -0,0 +1,64 @@ +/* + * 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.mobile.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.mobile.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("EMM Console URL : " + this.getEmmUrl()); + } + + private String getEmmUrl() { + // 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 + "/mdm"; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterDataHolder.java new file mode 100644 index 0000000000..0dd8a459d0 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/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.mobile.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.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterStartupHandlerServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterStartupHandlerServiceComponent.java new file mode 100644 index 0000000000..88a2b2daea --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/internal/URLPrinterStartupHandlerServiceComponent.java @@ -0,0 +1,73 @@ +/* + * 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.mobile.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.mobile.url.printer.URLPrinterStartupHandler; +import org.wso2.carbon.utils.ConfigurationContextService; + +/** + * @scr.component name="org.wso2.carbon.device.mgt.mobile.url.printer.URLPrinterStartupHandlerServiceComponent" + * 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 URLPrinterStartupHandlerServiceComponent { + + private static final Log log = LogFactory.getLog(URLPrinterStartupHandlerServiceComponent.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + try { + BundleContext bundleContext = componentContext.getBundleContext(); + /* Registering URL printer start-up handler */ + bundleContext.registerService(ServerStartupObserver.class, new URLPrinterStartupHandler(), null); + } catch (Throwable e) { + log.error("Error occurred while activating URL printer server start-up handler service component", e); + } + } + + @SuppressWarnings("unused") + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + 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 e447bf442f..c70760561f 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -36,6 +36,7 @@ org.wso2.carbon.device.mgt.mobile.impl + org.wso2.carbon.device.mgt.mobile.url.printer diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml index 6341425bfb..92c9564374 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.mobile.feature/pom.xml @@ -30,7 +30,7 @@ org.wso2.carbon.device.mgt.mobile.feature pom 1.9.2-SNAPSHOT - WSO2 Carbon - Mobile Implementation of Device Management + WSO2 Carbon - Mobile Device Management Feature http://wso2.org This feature contains the core bundles required for Mobile Device Management functionality @@ -44,6 +44,10 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.mobile.url.printer + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.server.feature @@ -104,9 +108,8 @@ - - org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.impl:${carbon.mobile.device.mgt.version} - + org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.impl:${carbon.mobile.device.mgt.version} + org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.mobile.url.printer:${carbon.mobile.device.mgt.version} org.wso2.carbon.core.server:${carbon.kernel.version} diff --git a/pom.xml b/pom.xml index 64d4955f36..b5a35ee11d 100644 --- a/pom.xml +++ b/pom.xml @@ -248,6 +248,11 @@ org.wso2.carbon.device.mgt.mobile.impl ${carbon.mobile.device.mgt.version} + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.mobile.url.printer + ${carbon.mobile.device.mgt.version} + @@ -501,7 +506,11 @@ - + + org.apache.axis2.wso2 + axis2 + ${axis2.orbit.version} + @@ -513,6 +522,10 @@ 1.5.4 + + [1.6.1.wso2v11, 1.7.0) + 1.6.1.wso2v11 + 1.3