mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
5bcc020b3e
@ -47,11 +47,31 @@
|
|||||||
<groupId>org.wso2.tomcat</groupId>
|
<groupId>org.wso2.tomcat</groupId>
|
||||||
<artifactId>tomcat-servlet-api</artifactId>
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.felix</groupId>
|
<groupId>org.apache.felix</groupId>
|
||||||
<artifactId>maven-bundle-plugin</artifactId>
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
@ -78,7 +98,10 @@
|
|||||||
org.apache.catalina.core,
|
org.apache.catalina.core,
|
||||||
org.wso2.carbon.apimgt.api,
|
org.wso2.carbon.apimgt.api,
|
||||||
org.wso2.carbon.apimgt.api.model,
|
org.wso2.carbon.apimgt.api.model,
|
||||||
org.wso2.carbon.apimgt.impl
|
org.wso2.carbon.apimgt.impl,
|
||||||
|
org.apache.axis2.*;version="${axis2.osgi.version.range}",
|
||||||
|
org.wso2.carbon.core,
|
||||||
|
org.wso2.carbon.utils
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -25,6 +25,10 @@ import org.wso2.carbon.apimgt.api.model.APIIdentifier;
|
|||||||
import org.wso2.carbon.apimgt.api.model.APIStatus;
|
import org.wso2.carbon.apimgt.api.model.APIStatus;
|
||||||
import org.wso2.carbon.apimgt.api.model.URITemplate;
|
import org.wso2.carbon.apimgt.api.model.URITemplate;
|
||||||
import org.wso2.carbon.apimgt.impl.APIConstants;
|
import org.wso2.carbon.apimgt.impl.APIConstants;
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
import org.wso2.carbon.utils.NetworkUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@ -95,4 +99,29 @@ public class APIPublisherUtil {
|
|||||||
return uriTemplates;
|
return uriTemplates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getServerBaseUrl() {
|
||||||
|
// Hostname
|
||||||
|
String hostName = "localhost";
|
||||||
|
try {
|
||||||
|
hostName = NetworkUtils.getMgtHostName();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
// HTTPS port
|
||||||
|
String mgtConsoleTransport = CarbonUtils.getManagementTransport();
|
||||||
|
ConfigurationContextService configContextService =
|
||||||
|
APIPublisherDataHolder.getInstance().getConfigurationContextService();
|
||||||
|
int port = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport);
|
||||||
|
int httpsProxyPort =
|
||||||
|
CarbonUtils.getTransportProxyPort(configContextService.getServerConfigContext(),
|
||||||
|
mgtConsoleTransport);
|
||||||
|
if (httpsProxyPort > 0) {
|
||||||
|
port = httpsProxyPort;
|
||||||
|
}
|
||||||
|
return "https://" + hostName + ":" + port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getApiEndpointUrl(String context) {
|
||||||
|
return getServerBaseUrl() + context;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,10 +19,12 @@
|
|||||||
package org.wso2.carbon.apimgt.webapp.publisher.internal;
|
package org.wso2.carbon.apimgt.webapp.publisher.internal;
|
||||||
|
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
|
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
|
||||||
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
public class APIPublisherDataHolder {
|
public class APIPublisherDataHolder {
|
||||||
|
|
||||||
private APIPublisherService apiPublisherService;
|
private APIPublisherService apiPublisherService;
|
||||||
|
private ConfigurationContextService configurationContextService;
|
||||||
|
|
||||||
private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder();
|
private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder();
|
||||||
|
|
||||||
@ -41,4 +43,12 @@ public class APIPublisherDataHolder {
|
|||||||
this.apiPublisherService = apiPublisherService;
|
this.apiPublisherService = apiPublisherService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||||
|
this.configurationContextService = configurationContextService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationContextService getConfigurationContextService() {
|
||||||
|
return configurationContextService;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,12 +25,21 @@ import org.osgi.service.component.ComponentContext;
|
|||||||
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
|
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherServiceImpl;
|
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherServiceImpl;
|
||||||
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.apimgt.webapp.publisher" immediate="true"
|
||||||
|
* @scr.reference name="config.context.service"
|
||||||
|
* interface="org.wso2.carbon.utils.ConfigurationContextService"
|
||||||
|
* cardinality="0..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setConfigurationContextService"
|
||||||
|
* unbind="unsetConfigurationContextService"
|
||||||
|
*/
|
||||||
public class APIPublisherServiceComponent {
|
public class APIPublisherServiceComponent {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(APIPublisherServiceComponent.class);
|
private static Log log = LogFactory.getLog(APIPublisherServiceComponent.class);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
protected void activate(ComponentContext componentContext) {
|
protected void activate(ComponentContext componentContext) {
|
||||||
try {
|
try {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
@ -48,7 +57,6 @@ public class APIPublisherServiceComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
protected void deactivate(ComponentContext componentContext) {
|
protected void deactivate(ComponentContext componentContext) {
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
@ -63,7 +71,6 @@ public class APIPublisherServiceComponent {
|
|||||||
APIPublisherService publisher = new APIPublisherServiceImpl();
|
APIPublisherService publisher = new APIPublisherServiceImpl();
|
||||||
APIPublisherDataHolder.getInstance().setApiPublisherService(publisher);
|
APIPublisherDataHolder.getInstance().setApiPublisherService(publisher);
|
||||||
bundleContext.registerService(APIPublisherService.class, publisher, null);
|
bundleContext.registerService(APIPublisherService.class, publisher, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
protected void setAPIManagerConfigurationService(APIManagerConfigurationService service) {
|
||||||
@ -74,4 +81,18 @@ public class APIPublisherServiceComponent {
|
|||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Setting ConfigurationContextService");
|
||||||
|
}
|
||||||
|
APIPublisherDataHolder.getInstance().setConfigurationContextService(configurationContextService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Un-setting ConfigurationContextService");
|
||||||
|
}
|
||||||
|
APIPublisherDataHolder.getInstance().setConfigurationContextService(null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.apimgt.api.model.API;
|
import org.wso2.carbon.apimgt.api.model.API;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.APIConfig;
|
import org.wso2.carbon.apimgt.webapp.publisher.APIConfig;
|
||||||
|
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherService;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil;
|
import org.wso2.carbon.apimgt.webapp.publisher.APIPublisherUtil;
|
||||||
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||||
|
|
||||||
@ -53,15 +54,21 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
|
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
|
||||||
ServletContext servletContext = context.getServletContext();
|
ServletContext servletContext = context.getServletContext();
|
||||||
|
|
||||||
|
|
||||||
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
|
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
|
||||||
boolean isManagedApi = (param != null && param.isEmpty()) && Boolean.parseBoolean(param);
|
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
|
||||||
|
|
||||||
if (isManagedApi) {
|
if (isManagedApi) {
|
||||||
APIConfig apiConfig = this.buildApiConfig(servletContext);
|
APIConfig apiConfig = this.buildApiConfig(servletContext);
|
||||||
try {
|
try {
|
||||||
apiConfig.init();
|
apiConfig.init();
|
||||||
API api = APIPublisherUtil.getAPI(apiConfig);
|
API api = APIPublisherUtil.getAPI(apiConfig);
|
||||||
APIPublisherDataHolder.getInstance().getApiPublisherService().publishAPI(api);
|
APIPublisherService apiPublisherService =
|
||||||
|
APIPublisherDataHolder.getInstance().getApiPublisherService();
|
||||||
|
if (apiPublisherService == null) {
|
||||||
|
throw new IllegalStateException("API Publisher service is not initialized properly");
|
||||||
|
}
|
||||||
|
apiPublisherService.publishAPI(api);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
/* Throwable is caught as none of the RuntimeExceptions that can potentially occur at this point
|
/* 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 */
|
does not seem to be logged anywhere else within the framework */
|
||||||
@ -110,6 +117,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("'managed-api-endpoint' attribute is not configured");
|
log.debug("'managed-api-endpoint' attribute is not configured");
|
||||||
}
|
}
|
||||||
|
endpoint = APIPublisherUtil.getApiEndpointUrl(context);
|
||||||
}
|
}
|
||||||
apiConfig.setEndpoint(endpoint);
|
apiConfig.setEndpoint(endpoint);
|
||||||
|
|
||||||
@ -122,17 +130,25 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
apiConfig.setOwner(owner);
|
apiConfig.setOwner(owner);
|
||||||
|
|
||||||
String isSecuredParam = servletContext.getInitParameter(PARAM_MANAGED_API_IS_SECURED);
|
String isSecuredParam = servletContext.getInitParameter(PARAM_MANAGED_API_IS_SECURED);
|
||||||
boolean isSecured =
|
boolean isSecured;
|
||||||
(isSecuredParam != null && !isSecuredParam.isEmpty()) && Boolean.parseBoolean(isSecuredParam);
|
if (isSecuredParam == null || isSecuredParam.isEmpty()) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("'managed-api-isSecured' attribute is not configured. Therefore, using the default, " +
|
||||||
|
"which is 'true'");
|
||||||
|
}
|
||||||
|
isSecured = false;
|
||||||
|
} else {
|
||||||
|
isSecured = Boolean.parseBoolean(isSecuredParam);
|
||||||
|
}
|
||||||
apiConfig.setSecured(isSecured);
|
apiConfig.setSecured(isSecured);
|
||||||
|
|
||||||
String transports = servletContext.getInitParameter(PARAM_MANAGED_API_TRANSPORTS);
|
String transports = servletContext.getInitParameter(PARAM_MANAGED_API_TRANSPORTS);
|
||||||
if (transports == null || transports.isEmpty()) {
|
if (transports == null || transports.isEmpty()) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("'managed-api-transports' attribute is not configured. Therefore using the defaults, " +
|
log.debug("'managed-api-transports' attribute is not configured. Therefore using the default, " +
|
||||||
"which are 'http' and 'https'");
|
"which is 'https'");
|
||||||
}
|
}
|
||||||
transports = "http,https";
|
transports = "https";
|
||||||
}
|
}
|
||||||
apiConfig.setTransports(transports);
|
apiConfig.setTransports(transports);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user