Fixing API Manager related issues

merge-requests/1/head
prabathabey 10 years ago
parent 2b3ee5e4f2
commit da34270a61

@ -24,8 +24,11 @@ import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider; import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
import org.wso2.carbon.apimgt.impl.APIManagerFactory; import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.apimgt.impl.utils.APIMgtDBUtil;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
import org.wso2.carbon.device.mgt.mobile.MobileDeviceManagementStartupObserver;
import org.wso2.carbon.device.mgt.mobile.config.APIConfig; import org.wso2.carbon.device.mgt.mobile.config.APIConfig;
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager;
import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig;
@ -55,134 +58,101 @@ import java.util.List;
*/ */
public class MobileDeviceManagementServiceComponent { public class MobileDeviceManagementServiceComponent {
private ServiceRegistration androidServiceRegRef; private ServiceRegistration androidServiceRegRef;
private ServiceRegistration iOSServiceRegRef; private ServiceRegistration iOSServiceRegRef;
private ServiceRegistration windowsServiceRegRef; private ServiceRegistration windowsServiceRegRef;
private ServiceRegistration serverStartupObserverRef;
private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class);
protected void activate(ComponentContext ctx) { protected void activate(ComponentContext ctx) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Activating Mobile Device Management Service Component"); log.debug("Activating Mobile Device Management Service Component");
} }
try { try {
BundleContext bundleContext = ctx.getBundleContext(); BundleContext bundleContext = ctx.getBundleContext();
/* Initialize the datasource configuration */ /* Initialize the datasource configuration */
MobileDeviceConfigurationManager.getInstance().initConfig(); MobileDeviceConfigurationManager.getInstance().initConfig();
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
.getMobileDeviceManagementConfig(); .getMobileDeviceManagementConfig();
MobileDataSourceConfig dsConfig = MobileDataSourceConfig dsConfig =
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig); MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
MobileDeviceManagementDAOFactory.init(); MobileDeviceManagementDAOFactory.init();
String setupOption = System.getProperty("setup"); String setupOption = System.getProperty("setup");
if (setupOption != null) { if (setupOption != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
"-Dsetup is enabled. Mobile Device management repository schema initialization is about " + "-Dsetup is enabled. Mobile Device management repository schema initialization is about " +
"to begin"); "to begin");
} }
try { try {
MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema( MobileDeviceManagementDAOUtil.setupMobileDeviceManagementSchema(
MobileDeviceManagementDAOFactory.getDataSource()); MobileDeviceManagementDAOFactory.getDataSource());
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error( log.error("Exception occurred while initializing mobile device management database schema", e);
"Exception occurred while initializing mobile device management database schema", }
e); }
}
} androidServiceRegRef =
bundleContext.registerService(DeviceManagerService.class.getName(),
androidServiceRegRef = new AndroidDeviceManagerService(), null);
bundleContext.registerService(DeviceManagerService.class.getName(), iOSServiceRegRef =
new AndroidDeviceManagerService(), null); bundleContext.registerService(DeviceManagerService.class.getName(),
iOSServiceRegRef = new IOSDeviceManagerService(), null);
bundleContext.registerService(DeviceManagerService.class.getName(), windowsServiceRegRef =
new IOSDeviceManagerService(), null); bundleContext.registerService(DeviceManagerService.class.getName(),
windowsServiceRegRef = new WindowsDeviceManagerService(), null);
bundleContext.registerService(DeviceManagerService.class.getName(),
new WindowsDeviceManagerService(), null); serverStartupObserverRef = bundleContext.registerService(ServerStartupObserver.class,
new MobileDeviceManagementStartupObserver(), null);
/* Initialize all API configurations with corresponding API Providers */ if (log.isDebugEnabled()) {
this.initAPIConfigs(); log.debug("Mobile Device Management Service Component has been successfully activated");
/* Publish all mobile device management related JAX-RS services as APIs */ }
this.publishAPIs(); } catch (Throwable e) {
log.error("Error occurred while activating Mobile Device Management Service Component", e);
if (log.isDebugEnabled()) { }
log.debug( }
"Mobile Device Management Service Component has been successfully activated");
} protected void deactivate(ComponentContext ctx) {
} catch (Throwable e) { if (log.isDebugEnabled()) {
log.error("Error occurred while activating Mobile Device Management Service Component", log.debug("De-activating Mobile Device Management Service Component");
e); }
} try {
} androidServiceRegRef.unregister();
iOSServiceRegRef.unregister();
protected void deactivate(ComponentContext ctx) { windowsServiceRegRef.unregister();
if (log.isDebugEnabled()) { serverStartupObserverRef.unregister();
log.debug("De-activating Mobile Device Management Service Component");
}
try {
BundleContext bundleContext = ctx.getBundleContext();
androidServiceRegRef.unregister();
iOSServiceRegRef.unregister();
windowsServiceRegRef.unregister();
/* Removing all APIs published upon start-up for mobile device management related JAX-RS /* Removing all APIs published upon start-up for mobile device management related JAX-RS
services */ services */
this.removeAPIs(); this.removeAPIs();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug(
"Mobile Device Management Service Component has been successfully de-activated"); "Mobile Device Management Service Component has been successfully de-activated");
} }
} catch (Throwable e) { } catch (Throwable e) {
log.error("Error occurred while de-activating Mobile Device Management bundle", e); log.error("Error occurred while de-activating Mobile Device Management bundle", e);
} }
} }
private void initAPIConfigs() throws DeviceManagementException { private void removeAPIs() throws DeviceManagementException {
List<APIConfig> apiConfigs = List<APIConfig> apiConfigs =
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig(). MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs(); getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) { for (APIConfig apiConfig : apiConfigs) {
try { DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
APIProvider provider = }
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner()); }
apiConfig.init(provider);
} catch (APIManagementException e) { protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
throw new DeviceManagementException( //do nothing
"Error occurred while initializing API Config '" + }
apiConfig.getName() + "'", e);
} protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) {
} //do nothing
} }
private void publishAPIs() throws DeviceManagementException {
List<APIConfig> apiConfigs =
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
}
}
private void removeAPIs() throws DeviceManagementException {
List<APIConfig> apiConfigs =
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
getApiPublisherConfig().getAPIs();
for (APIConfig apiConfig : apiConfigs) {
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
}
}
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
//do nothing
}
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) {
//do nothing
}
} }

@ -1,5 +1,5 @@
product.name=WSO2 Mobile Device Manager product.name=WSO2 Mobile Device Manager
product.version=1.0.0-SNAPSHOT product.version=2.0.0-SNAPSHOT
product.key=MDM product.key=MDM
hotdeployment=true hotdeployment=true
hotupdate=true hotupdate=true

Loading…
Cancel
Save