mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing API publishing related issues
This commit is contained in:
parent
2b26ad08c2
commit
5d02746a5e
@ -18,7 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.mgt.core.api.mgt;
|
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.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.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
@ -51,8 +54,12 @@ public class APIConfig {
|
|||||||
private String transports;
|
private String transports;
|
||||||
private APIProvider provider;
|
private APIProvider provider;
|
||||||
|
|
||||||
public void init(APIProvider provider) {
|
public void init() throws DeviceManagementException {
|
||||||
this.provider = provider;
|
try {
|
||||||
|
this.provider = APIManagerFactory.getInstance().getAPIProvider(this.getOwner());
|
||||||
|
} catch (APIManagementException e) {
|
||||||
|
throw new DeviceManagementException("Error occurred while initializing API provider", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlTransient
|
@XmlTransient
|
||||||
|
|||||||
@ -42,10 +42,15 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
log.debug("Publishing API '" + api.getId() + "'");
|
log.debug("Publishing API '" + api.getId() + "'");
|
||||||
}
|
}
|
||||||
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(api.getApiOwner());
|
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(api.getApiOwner());
|
||||||
provider.addAPI(api);
|
if (provider != null) {
|
||||||
if (log.isDebugEnabled()) {
|
provider.addAPI(api);
|
||||||
log.debug("Successfully published API '" + api.getId() + "' with the context '" +
|
if (log.isDebugEnabled()) {
|
||||||
api.getContext() + "'");
|
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();
|
List<APIConfig> apiConfigs = APIPublisherConfig.getInstance().getApiConfigs();
|
||||||
for (APIConfig apiConfig : apiConfigs) {
|
for (APIConfig apiConfig : apiConfigs) {
|
||||||
try {
|
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);
|
API api = DeviceManagerUtil.getAPI(apiConfig);
|
||||||
DeviceManagementDataHolder.getInstance().getApiPublisherService().publishAPI(api);
|
DeviceManagementDataHolder.getInstance().getApiPublisherService().publishAPI(api);
|
||||||
|
|
||||||
log.info("Successfully published API '" + apiConfig.getName() + "' with the context '" +
|
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() + "'");
|
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()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user