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;
}
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;
}
Aggregations