Fixing API publishing related issues

revert-70aa11f8
prabathabey 10 years ago
parent 2b26ad08c2
commit 5d02746a5e

@ -18,7 +18,10 @@
*/
package org.wso2.carbon.device.mgt.core.api.mgt;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@ -51,8 +54,12 @@ public class APIConfig {
private String transports;
private APIProvider provider;
public void init(APIProvider provider) {
this.provider = provider;
public void init() throws DeviceManagementException {
try {
this.provider = APIManagerFactory.getInstance().getAPIProvider(this.getOwner());
} catch (APIManagementException e) {
throw new DeviceManagementException("Error occurred while initializing API provider", e);
}
}
@XmlTransient

@ -42,10 +42,15 @@ public class APIPublisherServiceImpl implements APIPublisherService {
log.debug("Publishing API '" + api.getId() + "'");
}
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(api.getApiOwner());
provider.addAPI(api);
if (log.isDebugEnabled()) {
log.debug("Successfully published API '" + api.getId() + "' with the context '" +
api.getContext() + "'");
if (provider != null) {
provider.addAPI(api);
if (log.isDebugEnabled()) {
log.debug("Successfully published API '" + api.getId() + "' with the context '" +
api.getContext() + "'");
}
} else {
log.error("API provider configured for the given API configuration is null. Thus, the API is not " +
"published");
}
}

@ -60,14 +60,21 @@ public class APIRegistrationStartupObserver implements ServerStartupObserver {
List<APIConfig> apiConfigs = APIPublisherConfig.getInstance().getApiConfigs();
for (APIConfig apiConfig : apiConfigs) {
try {
/* API Config is initialized at this point in order to avoid OSGi declarative services which
the APIManagerComponent depend on, are deployed and initialized before invoking methods in
APIManagerFactory */
apiConfig.init();
API api = DeviceManagerUtil.getAPI(apiConfig);
DeviceManagementDataHolder.getInstance().getApiPublisherService().publishAPI(api);
log.info("Successfully published API '" + apiConfig.getName() + "' with the context '" +
apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'");
} catch (APIManagementException e) {
log.error("Error occurred while publishing API '" + apiConfig.getName() + "' with the context '" +
apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'");
} 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 */
log.error("Error occurred while publishing API '" + apiConfig.getName() + "' with the context '" +
apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'", e);
}
}
if (log.isDebugEnabled()) {

Loading…
Cancel
Save