Moving API registration bits to device.mgt.core

revert-70aa11f8
prabathabey 10 years ago
parent fc80514d74
commit c40af0de7a

@ -75,7 +75,10 @@
org.w3c.dom, org.w3c.dom,
org.wso2.carbon.governance.api.exception, org.wso2.carbon.governance.api.exception,
org.wso2.carbon.governance.api.generic, org.wso2.carbon.governance.api.generic,
org.wso2.carbon.governance.api.generic.dataobjects org.wso2.carbon.governance.api.generic.dataobjects,
org.wso2.carbon.apimgt.api,
org.wso2.carbon.apimgt.api.model,
org.wso2.carbon.apimgt.impl
</Import-Package> </Import-Package>
<Export-Package> <Export-Package>
!org.wso2.carbon.device.mgt.core.internal, !org.wso2.carbon.device.mgt.core.internal,
@ -176,6 +179,14 @@
<groupId>org.apache.ws.commons.axiom.wso2</groupId> <groupId>org.apache.ws.commons.axiom.wso2</groupId>
<artifactId>axiom</artifactId> <artifactId>axiom</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.api</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -0,0 +1,99 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.api.mgt;
import org.wso2.carbon.apimgt.api.APIProvider;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
public class APIConfig {
private String name;
private String owner;
private String context;
private String endpoint;
private String version;
private String transports;
private APIProvider provider;
public void init(APIProvider provider) {
this.provider = provider;
}
@XmlTransient
public APIProvider getProvider() {
return provider;
}
@XmlElement(name = "Name", nillable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement(name = "Owner", nillable = false)
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
@XmlElement(name = "Context", nillable = false)
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
@XmlElement(name = "Endpoint", nillable = false)
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
@XmlElement(name = "Version", nillable = false)
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
@XmlElement(name = "Transports", nillable = false)
public String getTransports() {
return transports;
}
public void setTransports(String transports) {
this.transports = transports;
}
}

@ -0,0 +1,35 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.api.mgt;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import java.util.List;
public interface APIPublisherService {
void publishAPI(API api) throws APIManagementException;
void removeAPI(APIIdentifier id) throws APIManagementException;
void publishAPIs(List<API> apis) throws APIManagementException;
}

@ -0,0 +1,73 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.api.mgt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import java.util.List;
public class APIPublisherServiceImpl implements APIPublisherService {
private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class);
@Override
public void publishAPI(API api) throws APIManagementException {
if (log.isDebugEnabled()) {
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() + "'");
}
}
@Override
public void removeAPI(APIIdentifier id) throws APIManagementException {
if (log.isDebugEnabled()) {
log.debug("Removing API '" + id.getApiName() + "'");
}
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(id.getProviderName());
provider.deleteAPI(id);
if (log.isDebugEnabled()) {
log.debug("API '" + id.getApiName() + "' has been successfully removed");
}
}
@Override
public void publishAPIs(List<API> apis) throws APIManagementException {
if (log.isDebugEnabled()) {
log.debug("Publishing a batch of APIs");
}
for (API api : apis) {
this.publishAPI(api);
}
if (log.isDebugEnabled()) {
log.debug("Successfully published the batch of APIs");
}
}
}

@ -0,0 +1,84 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.api.mgt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.core.ServerStartupObserver;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.api.mgt.config.APIPublisherConfig;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.List;
public class APIRegistrationStartupObserver implements ServerStartupObserver {
private static final Log log = LogFactory.getLog(APIRegistrationStartupObserver.class);
@Override
public void completingServerStartup() {
}
@Override
public void completedServerStartup() {
try {
this.initAPIConfigs();
/* Publish all mobile device management related JAX-RS services as APIs */
this.publishAPIs();
} catch (DeviceManagementException e) {
log.error("Error occurred while publishing Mobile Device Management related APIs", e);
}
}
private void initAPIConfigs() throws DeviceManagementException {
if (log.isDebugEnabled()) {
log.debug("Initializing Mobile Device Management related APIs");
}
List<APIConfig> apiConfigs = APIPublisherConfig.getInstance().getApiConfigs();
for (APIConfig apiConfig : apiConfigs) {
try {
APIProvider provider =
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
apiConfig.init(provider);
} catch (APIManagementException e) {
throw new DeviceManagementException("Error occurred while initializing API Config '" +
apiConfig.getName() + "'", e);
}
}
}
private void publishAPIs() throws DeviceManagementException {
if (log.isDebugEnabled()) {
log.debug("Publishing Mobile Device Management related APIs");
}
List<APIConfig> apiConfigs = APIPublisherConfig.getInstance().getApiConfigs();
for (APIConfig apiConfig : apiConfigs) {
DeviceManagerUtil.publishAPI(apiConfig);
if (log.isDebugEnabled()) {
log.debug("Successfully published API '" + apiConfig.getName() + "' with the context '" +
apiConfig.getContext() + "' and version '" + apiConfig.getVersion() + "'");
}
}
}
}

@ -0,0 +1,88 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.core.api.mgt.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.File;
import java.util.List;
@XmlRootElement(name = "APIPublisherConfig")
public class APIPublisherConfig {
private List<APIConfig> apiConfigs;
private static APIPublisherConfig config;
private static final Log log = LogFactory.getLog(APIPublisherConfig.class);
private static final String USER_DEFINED_API_CONFIG_PATH =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "user-api-publisher-config.xml";
private static final Object LOCK = new Object();
public static APIPublisherConfig getInstance() {
if (config == null) {
synchronized (LOCK) {
try {
init();
} catch (DeviceManagementException e) {
log.error("Error occurred while initializing API Publisher Config", e);
}
}
}
return config;
}
@XmlElementWrapper(name = "APIs", required = true)
@XmlElement(name = "API", required = true)
public List<APIConfig> getApiConfigs() {
return apiConfigs;
}
public void setApiConfig(List<APIConfig> apiConfigs) {
this.apiConfigs = apiConfigs;
}
private static void init() throws DeviceManagementException {
try {
File publisherConfig = new File(APIPublisherConfig.USER_DEFINED_API_CONFIG_PATH);
Document doc = DeviceManagerUtil.convertToDocument(publisherConfig);
/* Un-marshaling Device Management configuration */
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
config = (APIPublisherConfig) unmarshaller.unmarshal(doc);
} catch (JAXBException e) {
throw new DeviceManagementException("Error occurred while un-marshalling API Publisher Config", e);
}
}
}

@ -58,7 +58,6 @@ public class DeviceConfigurationManager {
public synchronized void initConfig() throws DeviceManagementException { public synchronized void initConfig() throws DeviceManagementException {
//catch generic exception.if any exception occurs wrap and throw DeviceManagementException
try { try {
File deviceMgtConfig = new File(deviceMgtConfigXMLPath); File deviceMgtConfig = new File(deviceMgtConfigXMLPath);
Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig); Document doc = DeviceManagerUtil.convertToDocument(deviceMgtConfig);
@ -67,8 +66,8 @@ public class DeviceConfigurationManager {
JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class); JAXBContext cdmContext = JAXBContext.newInstance(DeviceManagementConfig.class);
Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc); this.currentDeviceConfig = (DeviceManagementConfig) unmarshaller.unmarshal(doc);
} catch (JAXBException jaxbEx) { } catch (JAXBException e) {
throw new DeviceManagementException("Error occurred while initializing Data Source config", jaxbEx); throw new DeviceManagementException("Error occurred while initializing Data Source config", e);
} }
try { try {
@ -79,9 +78,8 @@ public class DeviceConfigurationManager {
JAXBContext notificationContext = JAXBContext.newInstance(NotificationMessagesConfig.class); JAXBContext notificationContext = JAXBContext.newInstance(NotificationMessagesConfig.class);
Unmarshaller unmarshaller = notificationContext.createUnmarshaller(); Unmarshaller unmarshaller = notificationContext.createUnmarshaller();
this.notificationMessagesConfig = (NotificationMessagesConfig) unmarshaller.unmarshal(doc); this.notificationMessagesConfig = (NotificationMessagesConfig) unmarshaller.unmarshal(doc);
}catch(JAXBException jaxbEx){ } catch(JAXBException e){
throw new DeviceManagementException("Error occurred while initializing Notification settings config", throw new DeviceManagementException("Error occurred while initializing Notification settings config", e);
jaxbEx);
} }
} }

@ -20,6 +20,7 @@
package org.wso2.carbon.device.mgt.core.internal; package org.wso2.carbon.device.mgt.core.internal;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import org.wso2.carbon.registry.core.service.RegistryService; import org.wso2.carbon.registry.core.service.RegistryService;
@ -34,6 +35,7 @@ public class DeviceManagementDataHolder {
private LicenseManager licenseManager; private LicenseManager licenseManager;
private RegistryService registryService; private RegistryService registryService;
private LicenseConfig licenseConfig; private LicenseConfig licenseConfig;
private APIPublisherService apiPublisherService;
private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder();
@ -96,4 +98,12 @@ public class DeviceManagementDataHolder {
this.licenseConfig = licenseConfig; this.licenseConfig = licenseConfig;
} }
public APIPublisherService getApiPublisherService() {
return apiPublisherService;
}
public void setApiPublisherService(APIPublisherService apiPublisherService) {
this.apiPublisherService = apiPublisherService;
}
} }

@ -21,6 +21,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
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.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
@ -29,6 +31,9 @@ import org.wso2.carbon.device.mgt.common.spi.DeviceManager;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService;
import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl;
import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
@ -63,6 +68,12 @@ import org.wso2.carbon.user.core.service.RealmService;
* policy="dynamic" * policy="dynamic"
* bind="setRegistryService" * bind="setRegistryService"
* unbind="unsetRegistryService" * unbind="unsetRegistryService"
* @scr.reference name="api.manager.config.service"
* interface="org.wso2.carbon.apimgt.impl.APIManagerConfigurationService"
* cardinality="1..1"
* policy="dynamic"
* bind="setAPIManagerConfigurationService"
* unbind="unsetAPIManagerConfigurationService"
*/ */
public class DeviceManagementServiceComponent { public class DeviceManagementServiceComponent {
@ -129,6 +140,12 @@ public class DeviceManagementServiceComponent {
BundleContext bundleContext = componentContext.getBundleContext(); BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(DeviceManagementService.class.getName(), bundleContext.registerService(DeviceManagementService.class.getName(),
new DeviceManagementServiceImpl(), null); new DeviceManagementServiceImpl(), null);
APIPublisherService publisher = new APIPublisherServiceImpl();
DeviceManagementDataHolder.getInstance().setApiPublisherService(publisher);
bundleContext.registerService(APIPublisherService.class, publisher, null);
bundleContext.registerService(ServerStartupObserver.class, new APIRegistrationStartupObserver(), null);
} }
private void setupDeviceManagementSchema(DataSourceConfig config) private void setupDeviceManagementSchema(DataSourceConfig config)
@ -246,4 +263,12 @@ public class DeviceManagementServiceComponent {
return pluginRepository; return pluginRepository;
} }
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
//do nothing
}
protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) {
//do nothing
}
} }

@ -20,9 +20,17 @@ package org.wso2.carbon.device.mgt.core.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.APIProvider;
import org.wso2.carbon.apimgt.api.model.API;
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
import org.wso2.carbon.apimgt.api.model.APIStatus;
import org.wso2.carbon.apimgt.api.model.URITemplate;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
@ -35,15 +43,27 @@ import javax.sql.DataSource;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.*;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
public final class DeviceManagerUtil { public final class DeviceManagerUtil {
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class); private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
enum HTTPMethod {
GET, POST, DELETE, PUT, OPTIONS
}
private static List<HTTPMethod> httpMethods;
static {
httpMethods = new ArrayList<HTTPMethod>();
httpMethods.add(HTTPMethod.GET);
httpMethods.add(HTTPMethod.POST);
httpMethods.add(HTTPMethod.DELETE);
httpMethods.add(HTTPMethod.PUT);
httpMethods.add(HTTPMethod.OPTIONS);
}
public static Document convertToDocument(File file) throws DeviceManagementException { public static Document convertToDocument(File file) throws DeviceManagementException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true); factory.setNamespaceAware(true);
@ -147,4 +167,63 @@ public final class DeviceManagerUtil {
return ctx.getTenantId(); return ctx.getTenantId();
} }
public static void publishAPI(APIConfig config) throws DeviceManagementException {
APIProvider provider = config.getProvider();
APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion());
API api = new API(id);
try {
api.setContext(config.getContext());
api.setUrl(config.getVersion());
api.setUriTemplates(getURITemplates(config.getEndpoint(),
APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN));
api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY);
api.addAvailableTiers(provider.getTiers());
api.setEndpointSecured(false);
api.setStatus(APIStatus.PUBLISHED);
api.setTransports(config.getTransports());
provider.addAPI(api);
} catch (APIManagementException e) {
throw new DeviceManagementException("Error occurred while registering the API", e);
}
}
public static void removeAPI(APIConfig config) throws DeviceManagementException {
try {
APIProvider provider = config.getProvider();
APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion());
provider.deleteAPI(id);
} catch (APIManagementException e) {
throw new DeviceManagementException("Error occurred while removing API", e);
}
}
private static Set<URITemplate> getURITemplates(String endpoint, String authType) {
Set<URITemplate> uriTemplates = new LinkedHashSet<URITemplate>();
if (APIConstants.AUTH_NO_AUTHENTICATION.equals(authType)) {
for (HTTPMethod method : httpMethods) {
URITemplate template = new URITemplate();
template.setAuthType(APIConstants.AUTH_NO_AUTHENTICATION);
template.setHTTPVerb(method.toString());
template.setResourceURI(endpoint);
template.setUriTemplate("/*");
uriTemplates.add(template);
}
} else {
for (HTTPMethod method : httpMethods) {
URITemplate template = new URITemplate();
if (HTTPMethod.OPTIONS.equals(method)) {
template.setAuthType(APIConstants.AUTH_NO_AUTHENTICATION);
} else {
template.setAuthType(APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN);
}
template.setHTTPVerb(method.toString());
template.setResourceURI(endpoint);
template.setUriTemplate("/*");
uriTemplates.add(template);
}
}
return uriTemplates;
}
} }

@ -109,6 +109,7 @@
<importFeatures> <importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef> <importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
<importFeatureDef>org.wso2.carbon.governance.metadata:${carbon.governance.version}</importFeatureDef> <importFeatureDef>org.wso2.carbon.governance.metadata:${carbon.governance.version}</importFeatureDef>
<importFeatureDef>org.wso2.carbon.apimgt.core:${carbon.api.mgt.version}</importFeatureDef>
</importFeatures> </importFeatures>
</configuration> </configuration>
</execution> </execution>

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="ISO-8859-1"?>
<!-- <!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ ~

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ you may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<APIPublisherConfig>
<APIs>
<API>
<Name>appmanager</Name>
<Owner>admin</Owner>
<Context>enrollment</Context>
<Version>1.0.0</Version>
<Endpoint>http://localhost:9763/</Endpoint>
<Transports>http,https</Transports>
</API>
</APIs>
</APIPublisherConfig>

@ -2,5 +2,6 @@ instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/cdm-config.xml,target:${installFolder}/../../conf/cdm-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/notification-messages.xml,target:${installFolder}/../../conf/notification-messages.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/notification-messages.xml,target:${installFolder}/../../conf/notification-messages.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/conf/user-api-publisher-config.xml,target:${installFolder}/../../conf/etc/user-api-publisher-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.server_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\

@ -416,6 +416,135 @@
<version>${carbon.commons.version}</version> <version>${carbon.commons.version}</version>
</dependency> </dependency>
<!-- API Management dependencies -->
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.api</artifactId>
<version>${carbon.api.mgt.version}</version>
<exclusions>
<exclusion>
<groupId>com.googlecode.json-simple.wso2</groupId>
<artifactId>json-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wso2.carbon.apimgt</groupId>
<artifactId>org.wso2.carbon.apimgt.impl</artifactId>
<version>${carbon.api.mgt.version}</version>
<exclusions>
<exclusion>
<groupId>org.wso2.carbon.mediation</groupId>
<artifactId>org.wso2.carbon.mediation.initializer</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.woden.wso2</groupId>
<artifactId>woden</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.core</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon.governance</groupId>
<artifactId>org.wso2.carbon.governance.api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.ws.client</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.identity.oauth</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.apimgt.keymgt.client</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.rest.api.stub</artifactId>
</exclusion>
<exclusion>
<groupId>org.json.wso2</groupId>
<artifactId>json</artifactId>
</exclusion>
<exclusion>
<groupId>com.h2database.wso2</groupId>
<artifactId>h2-database-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.apimgt.handlers.security.stub</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.user.mgt.stub</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.um.ws.api</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.mediation.dependency.mgt</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.mediation.registry</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.event.core</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.sequences.stub</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.mediation.security.stub</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.registry.indexing</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.apimgt.keymgt.stub</artifactId>
</exclusion>
<exclusion>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.securevault</artifactId>
</exclusion>
<exclusion>
<groupId>com.googlecode.json-simple.wso2</groupId>
<artifactId>json-simple</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.bsf</groupId>
<artifactId>bsf-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- End of API Management dependencies -->
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -660,6 +789,9 @@
<carbon.device.mgt.version>0.9.2-SNAPSHOT</carbon.device.mgt.version> <carbon.device.mgt.version>0.9.2-SNAPSHOT</carbon.device.mgt.version>
<carbon.commons.version>4.3.6</carbon.commons.version> <carbon.commons.version>4.3.6</carbon.commons.version>
<!-- API Management -->
<carbon.api.mgt.version>1.3.1</carbon.api.mgt.version>
</properties> </properties>
</project> </project>

Loading…
Cancel
Save