use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIDefaultVersionURLsDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIRevisionToEndpoints.
private static APIEndpointURLsDTO fromAPIRevisionToEndpoints(APIDTO apidto, Environment environment, String host, String customGatewayUrl, String tenantDomain) throws APIManagementException {
// Deployed VHost
VHost vHost;
String context = apidto.getContext();
if (StringUtils.isEmpty(customGatewayUrl)) {
vHost = VHostUtils.getVhostFromEnvironment(environment, host);
} else {
if (!StringUtils.contains(customGatewayUrl, "://")) {
customGatewayUrl = APIConstants.HTTPS_PROTOCOL_URL_PREFIX + customGatewayUrl;
}
vHost = VHost.fromEndpointUrls(new String[] { customGatewayUrl });
context = context.replace("/t/" + tenantDomain, "");
}
APIEndpointURLsDTO apiEndpointURLsDTO = new APIEndpointURLsDTO();
apiEndpointURLsDTO.setEnvironmentName(environment.getName());
apiEndpointURLsDTO.setEnvironmentDisplayName(environment.getDisplayName());
apiEndpointURLsDTO.setEnvironmentType(environment.getType());
APIURLsDTO apiurLsDTO = new APIURLsDTO();
boolean isWs = StringUtils.equalsIgnoreCase("WS", apidto.getType());
boolean isGQLSubscription = StringUtils.equalsIgnoreCase(APIConstants.GRAPHQL_API, apidto.getType()) && isGraphQLSubscriptionsAvailable(apidto);
if (!isWs) {
if (apidto.getTransport().contains(APIConstants.HTTP_PROTOCOL)) {
apiurLsDTO.setHttp(vHost.getHttpUrl() + context);
}
if (apidto.getTransport().contains(APIConstants.HTTPS_PROTOCOL)) {
apiurLsDTO.setHttps(vHost.getHttpsUrl() + context);
}
}
if (isWs || isGQLSubscription) {
apiurLsDTO.setWs(vHost.getWsUrl() + context);
apiurLsDTO.setWss(vHost.getWssUrl() + context);
}
apiEndpointURLsDTO.setUrLs(apiurLsDTO);
APIDefaultVersionURLsDTO apiDefaultVersionURLsDTO = new APIDefaultVersionURLsDTO();
if (apidto.isIsDefaultVersion() != null && apidto.isIsDefaultVersion()) {
String defaultContext = context.replaceAll("/" + apidto.getVersion() + "$", "");
if (!isWs) {
if (apidto.getTransport().contains(APIConstants.HTTP_PROTOCOL)) {
apiDefaultVersionURLsDTO.setHttp(vHost.getHttpUrl() + defaultContext);
}
if (apidto.getTransport().contains(APIConstants.HTTPS_PROTOCOL)) {
apiDefaultVersionURLsDTO.setHttps(vHost.getHttpsUrl() + defaultContext);
}
}
if (isWs || isGQLSubscription) {
apiDefaultVersionURLsDTO.setWs(vHost.getWsUrl() + defaultContext);
apiDefaultVersionURLsDTO.setWss(vHost.getWssUrl() + defaultContext);
}
}
apiEndpointURLsDTO.setDefaultVersionURLs(apiDefaultVersionURLsDTO);
return apiEndpointURLsDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIDefaultVersionURLsDTO in project carbon-apimgt by wso2.
the class APIUtils method extractEndpointURLs.
/**
* Extracts the API environment details with access url for each endpoint
*
* @param api API object
* @param tenantDomain Tenant domain of the API
* @return the API environment details
* @throws APIManagementException error while extracting the information
*/
public static List<APIEndpointURLsDTO> extractEndpointURLs(API api, String tenantDomain) throws APIManagementException {
List<APIEndpointURLsDTO> apiEndpointsList = new ArrayList<>();
String organization = api.getOrganization();
Map<String, Environment> environments = APIUtil.getEnvironments(organization);
Set<String> environmentsPublishedByAPI = new HashSet<>(api.getEnvironments());
environmentsPublishedByAPI.remove("none");
Set<String> apiTransports = new HashSet<>(Arrays.asList(api.getTransports().split(",")));
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
for (String environmentName : environmentsPublishedByAPI) {
Environment environment = environments.get(environmentName);
if (environment != null) {
APIURLsDTO apiURLsDTO = new APIURLsDTO();
APIDefaultVersionURLsDTO apiDefaultVersionURLsDTO = new APIDefaultVersionURLsDTO();
String[] gwEndpoints = null;
if ("WS".equalsIgnoreCase(api.getType())) {
gwEndpoints = environment.getWebsocketGatewayEndpoint().split(",");
} else {
gwEndpoints = environment.getApiGatewayEndpoint().split(",");
}
Map<String, String> domains = new HashMap<>();
if (tenantDomain != null) {
domains = apiConsumer.getTenantDomainMappings(tenantDomain, APIConstants.API_DOMAIN_MAPPINGS_GATEWAY);
}
String customGatewayUrl = null;
if (domains != null) {
customGatewayUrl = domains.get(APIConstants.CUSTOM_URL);
}
for (String gwEndpoint : gwEndpoints) {
StringBuilder endpointBuilder = new StringBuilder(gwEndpoint);
if (customGatewayUrl != null) {
int index = endpointBuilder.indexOf("//");
endpointBuilder.replace(index + 2, endpointBuilder.length(), customGatewayUrl);
endpointBuilder.append(api.getContext().replace("/t/" + tenantDomain, ""));
} else {
endpointBuilder.append(api.getContext());
}
if (gwEndpoint.contains("http:") && apiTransports.contains("http")) {
apiURLsDTO.setHttp(endpointBuilder.toString());
} else if (gwEndpoint.contains("https:") && apiTransports.contains("https")) {
apiURLsDTO.setHttps(endpointBuilder.toString());
} else if (gwEndpoint.contains("ws:")) {
apiURLsDTO.setWs(endpointBuilder.toString());
} else if (gwEndpoint.contains("wss:")) {
apiURLsDTO.setWss(endpointBuilder.toString());
}
if (api.isDefaultVersion()) {
int index = endpointBuilder.lastIndexOf(api.getId().getVersion());
endpointBuilder.replace(index, endpointBuilder.length(), "");
if (gwEndpoint.contains("http:") && apiTransports.contains("http")) {
apiDefaultVersionURLsDTO.setHttp(endpointBuilder.toString());
} else if (gwEndpoint.contains("https:") && apiTransports.contains("https")) {
apiDefaultVersionURLsDTO.setHttps(endpointBuilder.toString());
} else if (gwEndpoint.contains("ws:")) {
apiDefaultVersionURLsDTO.setWs(endpointBuilder.toString());
} else if (gwEndpoint.contains("wss:")) {
apiDefaultVersionURLsDTO.setWss(endpointBuilder.toString());
}
}
}
APIEndpointURLsDTO apiEndpointURLsDTO = new APIEndpointURLsDTO();
apiEndpointURLsDTO.setDefaultVersionURLs(apiDefaultVersionURLsDTO);
apiEndpointURLsDTO.setUrLs(apiURLsDTO);
apiEndpointURLsDTO.setEnvironmentName(environment.getName());
apiEndpointURLsDTO.setEnvironmentType(environment.getType());
apiEndpointsList.add(apiEndpointURLsDTO);
}
}
return apiEndpointsList;
}
Aggregations