diff --git a/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/pom.xml new file mode 100644 index 0000000000..fd1639b76f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -0,0 +1,89 @@ + + + + + device-mgt + org.wso2.carbon.devicemgt + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.apimgt.webapp.publisher + 0.9.2-SNAPSHOT + bundle + WSO2 Carbon - API Management Webapp Publisher + WSO2 Carbon - API Management Webapp Publisher + http://wso2.org + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.testng + testng + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.api + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.impl + + + org.wso2.tomcat + tomcat + + + org.wso2.tomcat + tomcat-servlet-api + + + + + + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + API Management Webapp Publisher + org.wso2.carbon.apimgt.webapp.publisher.internal + + !org.wso2.carbon.apimgt.webapp.publisher.internal, + org.wso2.carbon.apimgt.webapp.publisher.* + + + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + javax.servlet, + javax.xml.bind.annotation, + org.apache.catalina, + org.apache.catalina.core, + org.wso2.carbon.apimgt.api, + org.wso2.carbon.apimgt.api.model, + org.wso2.carbon.apimgt.impl + + + + + + + + \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIConfig.java b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIConfig.java similarity index 92% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIConfig.java rename to components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIConfig.java index 61a549ced7..4d5c661105 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIConfig.java +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIConfig.java @@ -16,12 +16,11 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.core.api.mgt; +package org.wso2.carbon.apimgt.webapp.publisher; 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; @@ -55,11 +54,11 @@ public class APIConfig { private APIProvider provider; private boolean isSecured; - public void init() throws DeviceManagementException { + public void init() throws APIManagementException { try { this.provider = APIManagerFactory.getInstance().getAPIProvider(this.getOwner()); } catch (APIManagementException e) { - throw new DeviceManagementException("Error occurred while initializing API provider", e); + throw new APIManagementException("Error occurred while initializing API provider", e); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherService.java b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherService.java rename to components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java index 77e961470e..32cb28f38d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherService.java +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.core.api.mgt; +package org.wso2.carbon.apimgt.webapp.publisher; import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.model.API; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherServiceImpl.java b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java similarity index 93% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherServiceImpl.java rename to components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index e5e09fe4a8..47757b4cf8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/APIPublisherServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.core.api.mgt; +package org.wso2.carbon.apimgt.webapp.publisher; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,8 +54,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { "'. Thus, the API config is updated"); } } else { - log.error("API provider configured for the given API configuration is null. Thus, the API is not " + - "published"); + throw new APIManagementException("API provider configured for the given API configuration is null. " + + "Thus, the API is not published"); } } diff --git a/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java new file mode 100644 index 0000000000..9776159a61 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java @@ -0,0 +1,98 @@ +/* + * 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.apimgt.webapp.publisher; + +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 java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +public class APIPublisherUtil { + + enum HTTPMethod { + GET, POST, DELETE, PUT, OPTIONS + } + + private static List httpMethods; + + static { + httpMethods = new ArrayList(); + httpMethods.add(HTTPMethod.GET); + httpMethods.add(HTTPMethod.POST); + httpMethods.add(HTTPMethod.DELETE); + httpMethods.add(HTTPMethod.PUT); + httpMethods.add(HTTPMethod.OPTIONS); + } + + public static API getAPI(APIConfig config) throws APIManagementException { + APIProvider provider = config.getProvider(); + APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion()); + + API api = new API(id); + api.setApiOwner(config.getOwner()); + api.setContext(config.getContext()); + api.setUrl(config.getEndpoint()); + api.setUriTemplates( + getURITemplates(config.getEndpoint(), APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN)); + api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY); + api.addAvailableTiers(provider.getTiers()); + api.setEndpointSecured(true); + api.setStatus(APIStatus.PUBLISHED); + api.setTransports(config.getTransports()); + + return api; + } + + private static Set getURITemplates(String endpoint, String authType) { + Set uriTemplates = new LinkedHashSet(); + 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; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java new file mode 100644 index 0000000000..41dd3de7ef --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java @@ -0,0 +1,44 @@ +/* + * 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.apimgt.webapp.publisher.internal; + +import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService; + +public class APIPublisherDataHolder { + + private APIPublisherService apiPublisherService; + + private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder(); + + private APIPublisherDataHolder() { + } + + public static APIPublisherDataHolder getInstance() { + return thisInstance; + } + + public APIPublisherService getApiPublisherService() { + return apiPublisherService; + } + + public void setApiPublisherService(APIPublisherService apiPublisherService) { + this.apiPublisherService = apiPublisherService; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java new file mode 100644 index 0000000000..97fe5d11e8 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/internal/APIPublisherServiceComponent.java @@ -0,0 +1,77 @@ +/* + * 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.apimgt.webapp.publisher.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; +import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService; +import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherServiceImpl; + +public class APIPublisherServiceComponent { + + private static Log log = LogFactory.getLog(APIPublisherServiceComponent.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + try { + if (log.isDebugEnabled()) { + log.debug("Initializing device management core bundle"); + } + + /* Registering declarative service instances exposed by DeviceManagementServiceComponent */ + this.registerServices(componentContext); + + if (log.isDebugEnabled()) { + log.debug("Device management core bundle has been successfully initialized"); + } + } catch (Throwable e) { + log.error("Error occurred while initializing device management core bundle", e); + } + } + + @SuppressWarnings("unused") + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + private void registerServices(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("Registering OSGi service DeviceManagementProviderServiceImpl"); + } + /* Registering Device Management Service */ + BundleContext bundleContext = componentContext.getBundleContext(); + + APIPublisherService publisher = new APIPublisherServiceImpl(); + APIPublisherDataHolder.getInstance().setApiPublisherService(publisher); + bundleContext.registerService(APIPublisherService.class, publisher, null); + + } + + protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) { + //do nothing + } + + protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService service) { + //do nothing + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/lifecycle/listener/APIPublisherLifecycleListener.java b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java similarity index 71% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/lifecycle/listener/APIPublisherLifecycleListener.java rename to components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java index c856c8a7a0..4284c9a5a5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/lifecycle/listener/APIPublisherLifecycleListener.java +++ b/components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java @@ -16,7 +16,7 @@ * under the License. * */ -package org.wso2.carbon.device.mgt.core.api.mgt.lifecycle.listener; +package org.wso2.carbon.apimgt.webapp.publisher.lifecycle.listener; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; @@ -25,9 +25,9 @@ import org.apache.catalina.core.StandardContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.api.model.API; -import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig; -import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; -import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.apimgt.webapp.publisher.APIConfig; +import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil; +import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; import javax.servlet.ServletContext; @@ -36,13 +36,14 @@ public class APIPublisherLifecycleListener implements LifecycleListener { private static final String API_CONFIG_DEFAULT_VERSION = "1.0.0"; - private static final String PARAM_MANAGE_API_NAME = "managed-api-name"; - private static final String PARAM_MANAGE_API_VERSION = "managed-api-version"; - private static final String PARAM_MANAGE_API_CONTEXT = "managed-api-context"; - private static final String PARAM_MANAGE_API_ENDPOINT = "managed-api-endpoint"; - private static final String PARAM_MANAGE_API_OWNER = "managed-api-owner"; - private static final String PARAM_MANAGE_API_TRANSPORTS = "managed-api-transports"; - private static final String PARAM_MANAGE_API_IS_SECURED = "managed-api-isSecured"; + private static final String PARAM_MANAGED_API_ENABLED = "managed-api-enabled"; + private static final String PARAM_MANAGED_API_NAME = "managed-api-name"; + private static final String PARAM_MANAGED_API_VERSION = "managed-api-version"; + private static final String PARAM_MANAGED_API_CONTEXT = "managed-api-context"; + private static final String PARAM_MANAGED_API_ENDPOINT = "managed-api-endpoint"; + private static final String PARAM_MANAGED_API_OWNER = "managed-api-owner"; + private static final String PARAM_MANAGED_API_TRANSPORTS = "managed-api-transports"; + private static final String PARAM_MANAGED_API_IS_SECURED = "managed-api-isSecured"; private static final Log log = LogFactory.getLog(APIPublisherLifecycleListener.class); @@ -52,15 +53,15 @@ public class APIPublisherLifecycleListener implements LifecycleListener { StandardContext context = (StandardContext) lifecycleEvent.getLifecycle(); ServletContext servletContext = context.getServletContext(); - String param = servletContext.getInitParameter("managed-api-enabled"); - boolean isManagedApi = (param != null && !"".equals(param)) && Boolean.parseBoolean(param); + String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED); + boolean isManagedApi = (param != null && param.isEmpty()) && Boolean.parseBoolean(param); if (isManagedApi) { APIConfig apiConfig = this.buildApiConfig(servletContext); try { apiConfig.init(); - API api = DeviceManagerUtil.getAPI(apiConfig); - DeviceManagementDataHolder.getInstance().getApiPublisherService().publishAPI(api); + API api = APIPublisherUtil.getAPI(apiConfig); + APIPublisherDataHolder.getInstance().getApiPublisherService().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 */ @@ -74,8 +75,8 @@ public class APIPublisherLifecycleListener implements LifecycleListener { private APIConfig buildApiConfig(ServletContext servletContext) { APIConfig apiConfig = new APIConfig(); - String name = servletContext.getInitParameter(PARAM_MANAGE_API_NAME); - if (name == null || "".equals(name)) { + String name = servletContext.getInitParameter(PARAM_MANAGED_API_NAME); + if (name == null || name.isEmpty()) { if (log.isDebugEnabled()) { log.debug("'managed-api-name' attribute is not configured. Therefore, using the default, " + "which is the name of the web application"); @@ -84,8 +85,8 @@ public class APIPublisherLifecycleListener implements LifecycleListener { } apiConfig.setName(name); - String version = servletContext.getInitParameter(PARAM_MANAGE_API_VERSION); - if (version == null || "".equals(version)) { + String version = servletContext.getInitParameter(PARAM_MANAGED_API_VERSION); + if (version == null || version.isEmpty()) { if (log.isDebugEnabled()) { log.debug("'managed-api-version' attribute is not configured. Therefore, using the " + "default, which is '1.0.0'"); @@ -94,8 +95,8 @@ public class APIPublisherLifecycleListener implements LifecycleListener { } apiConfig.setVersion(version); - String context = servletContext.getInitParameter(PARAM_MANAGE_API_CONTEXT); - if (context == null || "".equals(context)) { + String context = servletContext.getInitParameter(PARAM_MANAGED_API_CONTEXT); + if (context == null || context.isEmpty()) { if (log.isDebugEnabled()) { log.debug("'managed-api-context' attribute is not configured. Therefore, using the default, " + "which is the original context assigned to the web application"); @@ -104,29 +105,29 @@ public class APIPublisherLifecycleListener implements LifecycleListener { } apiConfig.setContext(context); - String endpoint = servletContext.getInitParameter(PARAM_MANAGE_API_ENDPOINT); - if (endpoint == null || "".equals(endpoint)) { + String endpoint = servletContext.getInitParameter(PARAM_MANAGED_API_ENDPOINT); + if (endpoint == null || endpoint.isEmpty()) { if (log.isDebugEnabled()) { log.debug("'managed-api-endpoint' attribute is not configured"); } } apiConfig.setEndpoint(endpoint); - String owner = servletContext.getInitParameter(PARAM_MANAGE_API_OWNER); - if (owner == null || "".equals(owner)) { + String owner = servletContext.getInitParameter(PARAM_MANAGED_API_OWNER); + if (owner == null || owner.isEmpty()) { if (log.isDebugEnabled()) { log.debug("'managed-api-owner' attribute is not configured"); } } apiConfig.setOwner(owner); - String isSecuredParam = servletContext.getInitParameter(PARAM_MANAGE_API_IS_SECURED); + String isSecuredParam = servletContext.getInitParameter(PARAM_MANAGED_API_IS_SECURED); boolean isSecured = - (isSecuredParam != null && !"".equals(isSecuredParam)) && Boolean.parseBoolean(isSecuredParam); + (isSecuredParam != null && !isSecuredParam.isEmpty()) && Boolean.parseBoolean(isSecuredParam); apiConfig.setSecured(isSecured); - String transports = servletContext.getInitParameter(PARAM_MANAGE_API_TRANSPORTS); - if (transports == null || "".equals(transports)) { + String transports = servletContext.getInitParameter(PARAM_MANAGED_API_TRANSPORTS); + if (transports == null || transports.isEmpty()) { if (log.isDebugEnabled()) { log.debug("'managed-api-transports' attribute is not configured. Therefore using the defaults, " + "which are 'http' and 'https'"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 1de4ce1c0f..6194adc77d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -17,7 +17,8 @@ ~ under the License. --> - + org.wso2.carbon.devicemgt device-mgt @@ -69,23 +70,13 @@ org.wso2.carbon.device.mgt.common.*, org.wso2.carbon.user.api, org.wso2.carbon.user.core.*, - org.wso2.carbon.registry.core, - org.wso2.carbon.registry.core.exceptions, org.wso2.carbon.registry.core.service, - org.wso2.carbon.registry.core.session, org.w3c.dom, - org.wso2.carbon.governance.api.exception, - org.wso2.carbon.governance.api.generic, - org.wso2.carbon.governance.api.generic.dataobjects, - org.wso2.carbon.apimgt.api, - org.wso2.carbon.apimgt.api.model, - org.wso2.carbon.apimgt.impl, org.wso2.carbon.identity.oauth.stub, org.wso2.carbon.identity.oauth.stub.dto, org.wso2.carbon.ndatasource.core, - org.apache.catalina, - org.apache.catalina.core, - javax.servlet + org.wso2.carbon.apimgt.impl, + org.wso2.carbon.ndatasource.core !org.wso2.carbon.device.mgt.core.internal, @@ -100,9 +91,9 @@ maven-surefire-plugin 2.18 - - file:src/test/resources/log4j.properties - + + file:src/test/resources/log4j.properties + src/test/resources/testng.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/ApplicationManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java similarity index 96% rename from components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/ApplicationManagementProviderService.java rename to components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java index 2002818504..085dadac47 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/ApplicationManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.wso2.carbon.device.mgt.core.api.mgt; +package org.wso2.carbon.device.mgt.core.app.mgt; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.app.mgt.Application; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index e4f648035a..e83c0c9a97 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -29,19 +29,16 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; -import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; -import org.wso2.carbon.device.mgt.core.api.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.oauth.ServiceAuthenticator; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; import org.wso2.carbon.device.mgt.core.dao.*; import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener; -import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException; import org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub; import org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 3533ea96c4..5dc73850f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -22,7 +22,6 @@ package org.wso2.carbon.device.mgt.core.internal; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; -import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; @@ -39,7 +38,6 @@ public class DeviceManagementDataHolder { private LicenseManager licenseManager; private RegistryService registryService; private LicenseConfig licenseConfig; - private APIPublisherService apiPublisherService; private ApplicationManager appManager; private AppManagementConfig appManagerConfig; private OperationManager operationManager; @@ -106,14 +104,6 @@ public class DeviceManagementDataHolder { this.licenseConfig = licenseConfig; } - public APIPublisherService getApiPublisherService() { - return apiPublisherService; - } - - public void setApiPublisherService(APIPublisherService apiPublisherService) { - this.apiPublisherService = apiPublisherService; - } - public ApplicationManager getAppManager() { return appManager; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index d6443f193c..84ff9553f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -25,24 +25,18 @@ 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.app.mgt.ApplicationManagementException; -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.LicenseManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; -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.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager; 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.datasource.DataSourceConfig; -import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; @@ -175,10 +169,6 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider); bundleContext.registerService(DeviceManagementProviderService.class.getName(), deviceManagementProvider, null); - APIPublisherService publisher = new APIPublisherServiceImpl(); - DeviceManagementDataHolder.getInstance().setApiPublisherService(publisher); - bundleContext.registerService(APIPublisherService.class, publisher, null); - /* Registering App Management service */ try { AppManagementConfigurationManager.getInstance().initConfig(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index dc895d8581..ac64d714a2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -20,18 +20,9 @@ package org.wso2.carbon.device.mgt.core.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; -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.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; @@ -44,27 +35,15 @@ import javax.sql.DataSource; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; -import java.util.*; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; public final class DeviceManagerUtil { private static final Log log = LogFactory.getLog(DeviceManagerUtil.class); - enum HTTPMethod { - GET, POST, DELETE, PUT, OPTIONS - } - - private static List httpMethods; - - static { - httpMethods = new ArrayList(); - 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 { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); @@ -168,52 +147,4 @@ public final class DeviceManagerUtil { return ctx.getTenantId(); } - public static API getAPI(APIConfig config) throws APIManagementException { - APIProvider provider = config.getProvider(); - APIIdentifier id = new APIIdentifier(config.getOwner(), config.getName(), config.getVersion()); - - API api = new API(id); - api.setApiOwner(config.getOwner()); - api.setContext(config.getContext()); - api.setUrl(config.getEndpoint()); - api.setUriTemplates( - getURITemplates(config.getEndpoint(), APIConstants.AUTH_APPLICATION_OR_USER_LEVEL_TOKEN)); - api.setVisibility(APIConstants.API_GLOBAL_VISIBILITY); - api.addAvailableTiers(provider.getTiers()); - api.setEndpointSecured(true); - api.setStatus(APIStatus.PUBLISHED); - api.setTransports(config.getTransports()); - - return api; - } - - private static Set getURITemplates(String endpoint, String authType) { - Set uriTemplates = new LinkedHashSet(); - 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; - } - - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java index 132f73cb17..ad607d74cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderServiceTest.java @@ -27,8 +27,6 @@ import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; -import org.wso2.carbon.device.mgt.core.api.mgt.ApplicationManagementProviderService; -import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.common.TestDataHolder; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml index 1eee2b18eb..cf107283b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/testng.xml @@ -24,17 +24,17 @@ - - - - - + + + + + - - + + \ No newline at end of file diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index 057e6af154..daaa8bda23 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -38,6 +38,7 @@ org.wso2.carbon.device.mgt.core org.wso2.carbon.device.mgt.common org.wso2.carbon.device.mgt.extensions + org.wso2.carbon.apimgt.webapp.publisher diff --git a/features/device-mgt/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/device-mgt/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml new file mode 100644 index 0000000000..b05b330b16 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -0,0 +1,91 @@ + + + + org.wso2.carbon.devicemgt + device-mgt-feature + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.apimgt.webapp.publisher.feature + pom + 0.9.2-SNAPSHOT + WSO2 Carbon - API Management Webapp Publisher Feature + http://wso2.org + This feature contains an implementation of a Tomcat lifecycle listener, which takes care of publishing + JAX-RS web applications as 'Managed APIs' + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.webapp.publisher + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.apimgt.webapp.publisher + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + org.wso2.carbon.devicemgt:org.wso2.carbon.apimgt.webapp.publisher:${carbon.device.mgt.version} + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + + + + + + + \ No newline at end of file diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index c1e36a3fe0..b929026903 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -37,6 +37,7 @@ org.wso2.carbon.device.mgt.server.feature org.wso2.carbon.device.mgt.extensions.feature + org.wso2.carbon.apimgt.webapp.publisher.feature diff --git a/pom.xml b/pom.xml index 16a015fe08..dee3c94941 100644 --- a/pom.xml +++ b/pom.xml @@ -157,9 +157,9 @@ ${carbon.device.mgt.version} - org.wso2.carbon.identity - org.wso2.carbon.identity.oauth.stub - ${carbon.identity.version} + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.webapp.publisher + ${carbon.device.mgt.version} @@ -837,6 +837,11 @@ org.wso2.carbon.identity.core ${carbon.identity.version} + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth.stub + ${carbon.identity.version} +