use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.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.impl.gatewayartifactsynchronizer.environmentspecificproperty.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);
}
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class ApiMgtDAO method getEnvironment.
/**
* Returns the Environment for the uuid in the tenant domain.
*
* @param tenantDomain the tenant domain to look environment
* @param uuid UUID of the environment
* @return Gateway environment with given UUID
*/
public Environment getEnvironment(String tenantDomain, String uuid) throws APIManagementException {
Environment env = null;
try (Connection connection = APIMgtDBUtil.getConnection();
PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_ENVIRONMENT_BY_ORGANIZATION_AND_UUID_SQL)) {
prepStmt.setString(1, tenantDomain);
prepStmt.setString(2, uuid);
try (ResultSet rs = prepStmt.executeQuery()) {
if (rs.next()) {
Integer id = rs.getInt("ID");
String name = rs.getString("NAME");
String displayName = rs.getString("DISPLAY_NAME");
String description = rs.getString("DESCRIPTION");
String provider = rs.getString("PROVIDER");
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));
}
}
} catch (SQLException e) {
handleException("Failed to get Environment in tenant domain:" + tenantDomain, e);
}
return env;
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class GatewayArtifactsMgtDAO method retrieveGatewayArtifacts.
public List<APIRuntimeArtifactDto> retrieveGatewayArtifacts(String tenantDomain) throws APIManagementException {
String query = SQLConstants.RETRIEVE_ARTIFACTS;
List<APIRuntimeArtifactDto> apiRuntimeArtifactDtoList = new ArrayList<>();
try (Connection connection = GatewayArtifactsMgtDBUtil.getArtifactSynchronizerConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query)) {
preparedStatement.setString(1, tenantDomain);
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String apiId = resultSet.getString("API_ID");
String label = resultSet.getString("LABEL");
try {
APIRuntimeArtifactDto apiRuntimeArtifactDto = new APIRuntimeArtifactDto();
apiRuntimeArtifactDto.setTenantDomain(resultSet.getString("TENANT_DOMAIN"));
apiRuntimeArtifactDto.setApiId(apiId);
String resolvedVhost = VHostUtils.resolveIfNullToDefaultVhost(label, resultSet.getString("VHOST"));
apiRuntimeArtifactDto.setLabel(label);
apiRuntimeArtifactDto.setVhost(resolvedVhost);
apiRuntimeArtifactDto.setName(resultSet.getString("API_NAME"));
apiRuntimeArtifactDto.setVersion(resultSet.getString("API_VERSION"));
apiRuntimeArtifactDto.setProvider(resultSet.getString("API_PROVIDER"));
apiRuntimeArtifactDto.setRevision(resultSet.getString("REVISION_ID"));
apiRuntimeArtifactDto.setType(resultSet.getString("API_TYPE"));
apiRuntimeArtifactDto.setContext(resultSet.getString("CONTEXT"));
InputStream artifact = resultSet.getBinaryStream("ARTIFACT");
if (artifact != null) {
byte[] artifactByte = APIMgtDBUtil.getBytesFromInputStream(artifact);
try (InputStream newArtifact = new ByteArrayInputStream(artifactByte)) {
apiRuntimeArtifactDto.setArtifact(newArtifact);
}
}
apiRuntimeArtifactDto.setFile(true);
apiRuntimeArtifactDtoList.add(apiRuntimeArtifactDto);
} catch (APIManagementException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Error resolving vhost while retrieving runtime artifact for API %s, " + "gateway environment \"%s\", tenant: \"%s\"." + "Skipping runtime artifact for the API.", apiId, label, tenantDomain), e);
} catch (IOException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Error occurred retrieving input stream from byte array of " + "API: %s, gateway environment \"%s\", tenant: \"%s\".", apiId, label, tenantDomain), e);
} catch (SQLException e) {
// handle exception inside the loop and continue with other API artifacts
log.error(String.format("Failed to retrieve Gateway Artifact of API: %s, " + "gateway environment \"%s\", tenant: \"%s\".", apiId, label, tenantDomain), e);
}
}
}
} catch (SQLException e) {
handleException("Failed to retrieve Gateway Artifacts.", e);
}
return apiRuntimeArtifactDtoList;
}
use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.environmentspecificproperty.Environment in project carbon-apimgt by wso2.
the class EnvironmentSpecificAPIPropertyDAO method getMGEnvironmentSpecificAPIPropertiesOfAPIs.
/**
* Getting the api configs related MGs
*
* @param apiUuidS
* @return
* @throws APIManagementException
*/
private Map<String, Map<String, Environment>> getMGEnvironmentSpecificAPIPropertiesOfAPIs(List<String> apiUuidS) throws APIManagementException {
final String query = EnvironmentSpecificAPIPropertyConstants.GET_ENVIRONMENT_SPECIFIC_API_PROPERTIES_BY_APIS_SQL.replaceAll("_API_ID_LIST_", String.join(",", Collections.nCopies(apiUuidS.size(), "?")));
Map<String, Map<String, Environment>> apiEnvironmentMap = new HashMap<>();
try (Connection conn = APIMgtDBUtil.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
int index = 1;
for (String apiId : apiUuidS) {
preparedStatement.setString(index++, apiId);
}
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
String envId = resultSet.getString(1);
String envName = resultSet.getString(2);
String apiId = resultSet.getString(3);
JsonObject jsonConfig = null;
try (InputStream propertyConfigBlob = resultSet.getBinaryStream(4)) {
if (propertyConfigBlob != null) {
String apiJsonConfig = APIMgtDBUtil.getStringFromInputStream(propertyConfigBlob);
jsonConfig = new Gson().fromJson(apiJsonConfig, JsonObject.class);
}
}
Map<String, Environment> environmentMap;
Environment environment;
if (apiEnvironmentMap.containsKey(apiId)) {
environmentMap = apiEnvironmentMap.get(apiId);
} else {
environmentMap = new HashMap<>();
apiEnvironmentMap.put(apiId, environmentMap);
}
environment = new Environment();
environment.setEnvId(envId);
environment.setEnvName(envName);
environment.setConfigs(jsonConfig);
environmentMap.put(envName, environment);
}
}
} catch (SQLException | IOException e) {
handleException("Error occurred when getting MG environment specific api properties", e);
}
return apiEnvironmentMap;
}
Aggregations