use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class ApiMgtDAO method getVhostGatewayEnvironments.
/**
* Returns a list of vhosts belongs to the gateway environments
*
* @param connection DB connection
* @param envId Environment id.
* @return list of vhosts belongs to the gateway environments.
*/
private List<VHost> getVhostGatewayEnvironments(Connection connection, Integer envId) throws APIManagementException {
List<VHost> vhosts = new ArrayList<>();
try (PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_ENVIRONMENT_VHOSTS_BY_ID_SQL)) {
prepStmt.setInt(1, envId);
try (ResultSet rs = prepStmt.executeQuery()) {
while (rs.next()) {
String host = rs.getString("HOST");
String httpContext = rs.getString("HTTP_CONTEXT");
Integer httpPort = rs.getInt("HTTP_PORT");
Integer httpsPort = rs.getInt("HTTPS_PORT");
Integer wsPort = rs.getInt("WS_PORT");
Integer wssPort = rs.getInt("WSS_PORT");
VHost vhost = new VHost();
vhost.setHost(host);
vhost.setHttpContext(httpContext == null ? "" : httpContext);
vhost.setHttpPort(httpPort);
vhost.setHttpsPort(httpsPort);
vhost.setWsPort(wsPort);
vhost.setWssPort(wssPort);
vhosts.add(vhost);
}
}
} catch (SQLException e) {
handleException("Failed to get gateway environments list of VHost: ", e);
}
return vhosts;
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class ApiMgtDAO method getDeployedAPIRevisionByApiUUID.
/**
* Get DeployedAPIRevision details by providing ApiUUID
*
* @return List<DeployedAPIRevision> object
* @throws APIManagementException if an error occurs while retrieving revision deployment mapping details
*/
public List<DeployedAPIRevision> getDeployedAPIRevisionByApiUUID(String apiUUID) throws APIManagementException {
List<DeployedAPIRevision> deployedAPIRevisionList = new ArrayList<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(SQLConstants.APIRevisionSqlConstants.GET_DEPLOYED_REVISION_BY_API_UUID)) {
statement.setString(1, apiUUID);
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
DeployedAPIRevision deployedAPIRevision = new DeployedAPIRevision();
String environmentName = rs.getString("NAME");
String vhost = rs.getString("VHOST");
deployedAPIRevision.setDeployment(environmentName);
deployedAPIRevision.setVhost(VHostUtils.resolveIfNullToDefaultVhost(environmentName, vhost));
deployedAPIRevision.setRevisionUUID(rs.getString("REVISION_UUID"));
deployedAPIRevision.setDeployedTime(rs.getString("DEPLOYED_TIME"));
deployedAPIRevisionList.add(deployedAPIRevision);
}
}
} catch (SQLException e) {
handleException("Failed to get deployed API Revision details for api uuid: " + apiUUID, e);
}
return deployedAPIRevisionList;
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method deployedAPIRevision.
public Response deployedAPIRevision(List<DeployedAPIRevisionDTO> deployedAPIRevisionDTOList, MessageContext messageContext) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
List<String> revisionUUIDs = new ArrayList<>();
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
for (DeployedAPIRevisionDTO deployedAPIRevisionDTO : deployedAPIRevisionDTOList) {
// get revision uuid
String revisionUUID = apiProvider.getAPIRevisionUUID(Integer.toString(deployedAPIRevisionDTO.getRevisionId()), deployedAPIRevisionDTO.getApiId());
if (revisionUUID == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(null).build();
}
if (!revisionUUIDs.contains(revisionUUID)) {
revisionUUIDs.add(revisionUUID);
Map<String, Environment> environments = APIUtil.getEnvironments(tenantDomain);
List<DeployedAPIRevision> deployedAPIRevisions = new ArrayList<>();
for (DeployedEnvInfoDTO deployedEnvInfoDTO : deployedAPIRevisionDTO.getEnvInfo()) {
DeployedAPIRevision deployedAPIRevision = new DeployedAPIRevision();
deployedAPIRevision.setRevisionUUID(revisionUUID);
String environment = deployedEnvInfoDTO.getName();
if (environments.get(environment) == null) {
RestApiUtil.handleBadRequest("Gateway environment not found: " + environment, log);
}
deployedAPIRevision.setDeployment(environment);
deployedAPIRevision.setVhost(deployedEnvInfoDTO.getVhost());
if (StringUtils.isEmpty(deployedEnvInfoDTO.getVhost())) {
RestApiUtil.handleBadRequest("Required field 'vhost' not found in deployment", log);
}
deployedAPIRevisions.add(deployedAPIRevision);
}
apiProvider.addDeployedAPIRevision(deployedAPIRevisionDTO.getApiId(), revisionUUID, deployedAPIRevisions);
}
}
return Response.ok().build();
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class APIConsumerImpl method getHostWithSchemeMappingForEnvironment.
/**
* Get host names with transport scheme mapping from Gateway Environments in api-manager.xml or from the tenant
* custom url config in registry.
*
* @param apiTenantDomain Tenant domain
* @param environmentName Environment name
* @return Host name to transport scheme mapping
* @throws APIManagementException if an error occurs when getting host names with schemes
*/
private Map<String, String> getHostWithSchemeMappingForEnvironment(API api, String apiTenantDomain, String environmentName) throws APIManagementException {
Map<String, String> domains = getTenantDomainMappings(apiTenantDomain, APIConstants.API_DOMAIN_MAPPINGS_GATEWAY);
Map<String, String> hostsWithSchemes = new HashMap<>();
String organization = api.getOrganization();
if (!domains.isEmpty()) {
String customUrl = domains.get(APIConstants.CUSTOM_URL);
if (customUrl.startsWith(APIConstants.HTTP_PROTOCOL_URL_PREFIX)) {
hostsWithSchemes.put(APIConstants.HTTP_PROTOCOL, customUrl);
} else {
hostsWithSchemes.put(APIConstants.HTTPS_PROTOCOL, customUrl);
}
} else {
Map<String, Environment> allEnvironments = APIUtil.getEnvironments(organization);
Environment environment = allEnvironments.get(environmentName);
if (environment == null) {
handleResourceNotFoundException("Could not find provided environment '" + environmentName + "'");
}
List<APIRevisionDeployment> deploymentList = getAPIRevisionDeploymentListOfAPI(api.getUuid());
String host = "";
for (APIRevisionDeployment deployment : deploymentList) {
if (!deployment.isDisplayOnDevportal()) {
continue;
}
if (StringUtils.equals(deployment.getDeployment(), environmentName)) {
host = deployment.getVhost();
}
}
if (StringUtils.isEmpty(host)) {
// returns empty server urls
hostsWithSchemes.put(APIConstants.HTTP_PROTOCOL, "");
return hostsWithSchemes;
}
VHost vhost = VHostUtils.getVhostFromEnvironment(environment, host);
if (StringUtils.containsIgnoreCase(api.getTransports(), APIConstants.HTTP_PROTOCOL)) {
hostsWithSchemes.put(APIConstants.HTTP_PROTOCOL, vhost.getHttpUrl());
}
if (StringUtils.containsIgnoreCase(api.getTransports(), APIConstants.HTTPS_PROTOCOL)) {
hostsWithSchemes.put(APIConstants.HTTPS_PROTOCOL, vhost.getHttpsUrl());
}
}
return hostsWithSchemes;
}
use of org.wso2.carbon.apimgt.api.model.VHost in project carbon-apimgt by wso2.
the class EnvironmentMappingUtil method fromVHostDtoToVHost.
/**
* Convert VHostDTO to VHost
*
* @param vhostDTO VHostDTO
* @return VHostDTO
*/
public static VHost fromVHostDtoToVHost(VHostDTO vhostDTO) {
VHost vhost = new VHost();
vhost.setHost(vhostDTO.getHost());
vhost.setHttpContext(vhostDTO.getHttpContext());
vhost.setHttpPort(vhostDTO.getHttpPort());
vhost.setHttpsPort(vhostDTO.getHttpsPort());
vhost.setWsPort(vhostDTO.getWsPort());
vhost.setWssPort(vhostDTO.getWssPort());
return vhost;
}
Aggregations