From 4334994b36e82fa96d24a14f5af01bd1aa9f689f Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 2 Sep 2015 20:25:52 +0530 Subject: [PATCH] Fixing issues encountered in APIPublisher implementation --- .../internal/APIPublisherServiceComponent.java | 1 - .../listener/APIPublisherLifecycleListener.java | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java index 97fe5d11e8..3e42caf5a0 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java @@ -63,7 +63,6 @@ public class APIPublisherServiceComponent { APIPublisherService publisher = new APIPublisherServiceImpl(); APIPublisherDataHolder.getInstance().setApiPublisherService(publisher); bundleContext.registerService(APIPublisherService.class, publisher, null); - } protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java index 4284c9a5a5..020925f165 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java @@ -26,6 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.api.model.API; import org.wso2.carbon.apimgt.webapp.publisher.APIConfig; +import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService; import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil; import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; @@ -54,14 +55,19 @@ public class APIPublisherLifecycleListener implements LifecycleListener { ServletContext servletContext = context.getServletContext(); String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED); - boolean isManagedApi = (param != null && param.isEmpty()) && Boolean.parseBoolean(param); + boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param); if (isManagedApi) { APIConfig apiConfig = this.buildApiConfig(servletContext); try { apiConfig.init(); API api = APIPublisherUtil.getAPI(apiConfig); - APIPublisherDataHolder.getInstance().getApiPublisherService().publishAPI(api); + APIPublisherService apiPublisherService = + APIPublisherDataHolder.getInstance().getApiPublisherService(); + if (apiPublisherService == null) { + throw new IllegalStateException("API Publisher service is not initialized properly"); + } + apiPublisherService.publishAPI(api); } catch (Throwable e) { /* Throwable is caught as none of the RuntimeExceptions that can potentially occur at this point does not seem to be logged anywhere else within the framework */