use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class EnvironmentsApiServiceImpl method environmentsGet.
/**
* Get list of gateway environments from config api-manager.xml and dynamic environments (from DB)
*
* @param messageContext message context
* @return created environment
* @throws APIManagementException if failed to get list
*/
public Response environmentsGet(MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
List<Environment> envList = apiAdmin.getAllEnvironments(organization);
EnvironmentListDTO envListDTO = EnvironmentMappingUtil.fromEnvListToEnvListDTO(envList);
return Response.ok().entity(envListDTO).build();
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class EnvironmentsApiServiceImpl method environmentsEnvironmentIdPut.
/**
* Update gateway environment
*
* @param environmentId environment ID
* @param body environment to be updated
* @param messageContext message context
* @return updated environment
* @throws APIManagementException if failed to update
*/
public Response environmentsEnvironmentIdPut(String environmentId, EnvironmentDTO body, MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
body.setId(environmentId);
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Environment env = EnvironmentMappingUtil.fromEnvDtoToEnv(body);
apiAdmin.updateEnvironment(organization, env);
URI location = null;
try {
location = new URI(RestApiConstants.RESOURCE_PATH_ENVIRONMENT + "/" + environmentId);
} catch (URISyntaxException e) {
String errorMessage = "Error while updating Environment : " + environmentId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return Response.ok(location).entity(body).build();
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class ApiMgtDAO method getAllEnvironments.
/**
* Returns the Environments List for the TenantId.
*
* @param tenantDomain The tenant domain.
* @return List of Environments.
*/
public List<Environment> getAllEnvironments(String tenantDomain) throws APIManagementException {
List<Environment> envList = new ArrayList<>();
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_ENVIRONMENT_BY_ORGANIZATION_SQL)) {
prepStmt.setString(1, tenantDomain);
try (ResultSet rs = prepStmt.executeQuery()) {
while (rs.next()) {
Integer id = rs.getInt("ID");
String uuid = rs.getString("UUID");
String name = rs.getString("NAME");
String displayName = rs.getString("DISPLAY_NAME");
String description = rs.getString("DESCRIPTION");
String provider = rs.getString("PROVIDER");
Environment env = new Environment();
env.setId(id);
env.setUuid(uuid);
env.setName(name);
env.setDisplayName(displayName);
env.setDescription(description);
env.setProvider(provider);
env.setVhosts(getVhostGatewayEnvironments(connection, id));
envList.add(env);
}
}
} catch (SQLException e) {
handleException("Failed to get Environments in tenant domain: " + tenantDomain, e);
}
return envList;
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class WSDL11ProcessorImpl method updateEndpointsOfSingleWSDL.
/**
* Update the endpoint information of the provided WSDL definition when an API and the environment details are
* provided
*
* @param api API
* @param environmentName name of the gateway environment
* @param environmentType type of the gateway environment
* @param wsdlDefinition WSDL 1.1 definition
* @throws APIMgtWSDLException when error occurred while updating the endpoints
*/
private void updateEndpointsOfSingleWSDL(API api, String environmentName, String environmentType, Definition wsdlDefinition) throws APIMgtWSDLException {
Map serviceMap = wsdlDefinition.getAllServices();
URL addressURI;
String organization = api.getOrganization();
for (Object entry : serviceMap.entrySet()) {
Map.Entry svcEntry = (Map.Entry) entry;
Service svc = (Service) svcEntry.getValue();
Map portMap = svc.getPorts();
for (Object o : portMap.entrySet()) {
Map.Entry portEntry = (Map.Entry) o;
Port port = (Port) portEntry.getValue();
List<ExtensibilityElement> extensibilityElementList = port.getExtensibilityElements();
String endpointTransport;
for (ExtensibilityElement extensibilityElement : extensibilityElementList) {
try {
addressURI = new URL(getAddressUrl(extensibilityElement));
endpointTransport = determineURLTransport(addressURI.getProtocol(), api.getTransports());
if (log.isDebugEnabled()) {
log.debug("Address URI for the port:" + port.getName() + " is " + addressURI.toString());
}
} catch (MalformedURLException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while getting the wsdl address location [" + getAddressUrl(extensibilityElement) + "]");
}
endpointTransport = determineURLTransport("https", api.getTransports());
// This string to URL conversion done in order to identify URL transport eg - http or https.
// Here if there is a conversion failure , consider "https" as default protocol
}
try {
setAddressUrl(extensibilityElement, endpointTransport, api.getContext(), environmentName, environmentType, organization);
} catch (APIManagementException e) {
throw new APIMgtWSDLException("Error while setting gateway access URLs in the WSDL", e);
}
}
}
}
}
use of org.wso2.carbon.apimgt.api.model.Environment in project carbon-apimgt by wso2.
the class WSDL20ProcessorImpl method updateEndpointsOfSingleWSDL.
/**
* Update the endpoint information of the provided WSDL definition when an API and the environment details are
* provided
*
* @param api API
* @param environmentName name of the gateway environment
* @param environmentType type of the gateway environment
* @param wsdlDescription WSDL 2.0 definition
* @throws APIMgtWSDLException when error occurred while updating the endpoints
*/
private void updateEndpointsOfSingleWSDL(API api, String environmentName, String environmentType, Description wsdlDescription) throws APIMgtWSDLException {
Service[] serviceMap = wsdlDescription.getServices();
String organization = api.getOrganization();
try {
for (Service svc : serviceMap) {
Endpoint[] portMap = svc.getEndpoints();
for (Endpoint endpoint : portMap) {
EndpointElement element = endpoint.toElement();
String endpointTransport = determineURLTransport(endpoint.getAddress().getScheme(), api.getTransports());
setAddressUrl(element, new URI(APIUtil.getGatewayEndpoint(endpointTransport, environmentName, environmentType, organization) + api.getContext()));
}
}
} catch (URISyntaxException | APIManagementException e) {
throw new APIMgtWSDLException("Error while setting gateway access URLs in the WSDL", e);
}
}
Aggregations