Search in sources :

Example 1 with AsyncProtocolEndpoint

use of org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint in project carbon-apimgt by wso2.

the class SolaceEnvironmentImpl method getExternalEndpointURLs.

/**
 * Get endpoint URLs of the Solace environment
 *
 * @return List of protocol endpoint URLs map of Solace
 */
@Override
public List<AsyncProtocolEndpoint> getExternalEndpointURLs(Environment environment) {
    SolaceAdminApis solaceAdminApis = new SolaceAdminApis(environment.getServerURL(), environment.getUserName(), environment.getPassword(), environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_DEV_NAME));
    HttpResponse response = solaceAdminApis.environmentGET(environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION), environment.getName());
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        String responseString = null;
        try {
            responseString = EntityUtils.toString(response.getEntity());
        } catch (IOException e) {
            log.error(e.getMessage());
        }
        JSONObject jsonObject = new JSONObject(responseString);
        if (jsonObject.has("messagingProtocols")) {
            JSONArray protocols = jsonObject.getJSONArray("messagingProtocols");
            List<AsyncProtocolEndpoint> asyncProtocolEndpoints = new ArrayList<>();
            for (int i = 0; i < protocols.length(); i++) {
                JSONObject protocolDetails = protocols.getJSONObject(i);
                String protocolName = protocolDetails.getJSONObject("protocol").getString("name");
                String endpointURI = protocolDetails.getString("uri");
                AsyncProtocolEndpoint asyncProtocolEndpoint = new AsyncProtocolEndpoint();
                asyncProtocolEndpoint.setProtocol(protocolName);
                asyncProtocolEndpoint.setProtocolUrl(endpointURI);
                asyncProtocolEndpoints.add(asyncProtocolEndpoint);
            }
            return asyncProtocolEndpoints;
        }
    }
    return null;
}
Also used : SolaceAdminApis(org.wso2.carbon.apimgt.solace.SolaceAdminApis) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) AsyncProtocolEndpoint(org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint) AsyncProtocolEndpoint(org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint)

Example 2 with AsyncProtocolEndpoint

use of org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvironmentToDTO.

/**
 * Converts an Environment object into EnvironmentDTO.
 *
 * @param environment Environment object
 * @return EnvironmentDTO object corresponding to the given Environment object
 */
public static EnvironmentDTO fromEnvironmentToDTO(Environment environment) {
    EnvironmentDTO environmentDTO = new EnvironmentDTO();
    environmentDTO.setId(environment.getUuid());
    environmentDTO.setName(environment.getName());
    environmentDTO.setDisplayName(environment.getDisplayName());
    environmentDTO.setType(environment.getType());
    environmentDTO.setServerUrl(environment.getServerURL());
    environmentDTO.setShowInApiConsole(environment.isShowInConsole());
    environmentDTO.setProvider(environment.getProvider());
    environmentDTO.setVhosts(environment.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostToVHostDTO).collect(Collectors.toList()));
    environmentDTO.setAdditionalProperties(fromAdditionalPropertiesToAdditionalPropertiesDTO(environment.getAdditionalProperties()));
    ExternalEnvironment parser = APIUtil.getExternalEnvironment(environment.getProvider());
    if (parser != null) {
        List<GatewayEnvironmentProtocolURIDTO> endpointsList = new ArrayList<>();
        List<AsyncProtocolEndpoint> endpointUrlsList = parser.getExternalEndpointURLs(environment);
        if (endpointUrlsList != null || endpointUrlsList.size() > 0) {
            for (AsyncProtocolEndpoint asyncProtocolEndpoint : endpointUrlsList) {
                GatewayEnvironmentProtocolURIDTO gatewayEnvironmentProtocolURIDTO = new GatewayEnvironmentProtocolURIDTO();
                gatewayEnvironmentProtocolURIDTO.setProtocol(asyncProtocolEndpoint.getProtocol());
                gatewayEnvironmentProtocolURIDTO.setEndpointURI(asyncProtocolEndpoint.getProtocolUrl());
                endpointsList.add(gatewayEnvironmentProtocolURIDTO);
            }
            environmentDTO.setEndpointURIs(endpointsList);
        }
    }
    return environmentDTO;
}
Also used : EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO) ArrayList(java.util.ArrayList) GatewayEnvironmentProtocolURIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GatewayEnvironmentProtocolURIDTO) ExternalEnvironment(org.wso2.carbon.apimgt.impl.ExternalEnvironment) AsyncProtocolEndpoint(org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint)

Aggregations

ArrayList (java.util.ArrayList)2 AsyncProtocolEndpoint (org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint)2 IOException (java.io.IOException)1 HttpResponse (org.apache.http.HttpResponse)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 ExternalEnvironment (org.wso2.carbon.apimgt.impl.ExternalEnvironment)1 EnvironmentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO)1 GatewayEnvironmentProtocolURIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GatewayEnvironmentProtocolURIDTO)1 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)1