Search in sources :

Example 11 with Environment

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();
}
Also used : EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 12 with Environment

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();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 13 with Environment

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Environment(org.wso2.carbon.apimgt.api.model.Environment) PreparedStatement(java.sql.PreparedStatement)

Example 14 with Environment

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);
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Port(javax.wsdl.Port) Service(javax.wsdl.Service) URL(java.net.URL) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with Environment

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);
    }
}
Also used : Endpoint(org.apache.woden.wsdl20.Endpoint) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) Service(org.apache.woden.wsdl20.Service) URISyntaxException(java.net.URISyntaxException) EndpointElement(org.apache.woden.wsdl20.xml.EndpointElement) URI(java.net.URI)

Aggregations

Environment (org.wso2.carbon.apimgt.api.model.Environment)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 ArrayList (java.util.ArrayList)38 HashMap (java.util.HashMap)28 API (org.wso2.carbon.apimgt.api.model.API)22 IOException (java.io.IOException)21 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)19 Map (java.util.Map)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)13 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)12 JsonObject (com.google.gson.JsonObject)11 Gson (com.google.gson.Gson)10 PreparedStatement (java.sql.PreparedStatement)10 SQLException (java.sql.SQLException)10 HashSet (java.util.HashSet)10 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)10 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)10 JSONObject (org.json.simple.JSONObject)9 Test (org.junit.Test)9 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)9