|
|
|
@ -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 */
|
|
|
|
|