forked from community/device-mgt-core
Removing API publisher lifecycle listener implementation out of device.mgt.core and making it a separate module
parent
bfa1ea1875
commit
1a6526fc77
@ -0,0 +1,89 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>device-mgt</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - API Management Webapp Publisher</name>
|
||||||
|
<description>WSO2 Carbon - API Management Webapp Publisher</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.osgi</groupId>
|
||||||
|
<artifactId>org.eclipse.osgi</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.osgi</groupId>
|
||||||
|
<artifactId>org.eclipse.osgi.services</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testng</groupId>
|
||||||
|
<artifactId>testng</artifactId>
|
||||||
|
</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>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.tomcat</groupId>
|
||||||
|
<artifactId>tomcat</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>1.4.0</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>API Management Webapp Publisher</Bundle-Description>
|
||||||
|
<Private-Package>org.wso2.carbon.apimgt.webapp.publisher.internal</Private-Package>
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.apimgt.webapp.publisher.internal,
|
||||||
|
org.wso2.carbon.apimgt.webapp.publisher.*
|
||||||
|
</Export-Package>
|
||||||
|
<Import-Package>
|
||||||
|
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
|
||||||
|
</Import-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -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<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 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<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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/lifecycle/listener/APIPublisherLifecycleListener.java → components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java
59
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/lifecycle/listener/APIPublisherLifecycleListener.java → components/device-mgt/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java
2
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/ApplicationManagementProviderService.java → components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java
2
components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/api/mgt/ApplicationManagementProviderService.java → components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagementProviderService.java
@ -0,0 +1,91 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>device-mgt-feature</artifactId>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.webapp.publisher.feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - API Management Webapp Publisher Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
<description>This feature contains an implementation of a Tomcat lifecycle listener, which takes care of publishing
|
||||||
|
JAX-RS web applications as 'Managed APIs'
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.apimgt.webapp.publisher</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>src/main/resources</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>build.properties</include>
|
||||||
|
<include>p2.inf</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.wso2.maven</groupId>
|
||||||
|
<artifactId>carbon-p2-plugin</artifactId>
|
||||||
|
<version>${carbon.p2.plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>p2-feature-generation</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>p2-feature-gen</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<id>org.wso2.carbon.apimgt.webapp.publisher</id>
|
||||||
|
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||||
|
<adviceFile>
|
||||||
|
<properties>
|
||||||
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
|
</properties>
|
||||||
|
</adviceFile>
|
||||||
|
<bundles>
|
||||||
|
<bundleDef>
|
||||||
|
org.wso2.carbon.devicemgt:org.wso2.carbon.apimgt.webapp.publisher:${carbon.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
</bundles>
|
||||||
|
<importFeatures>
|
||||||
|
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||||
|
</importFeatures>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
Loading…
Reference in new issue