use of org.wso2.carbon.apimgt.api.doc.model.APIDefinition in project carbon-apimgt by wso2.
the class TemplateBuilderUtil method retrieveGatewayAPIDto.
public static GatewayAPIDTO retrieveGatewayAPIDto(API api, Environment environment, String tenantDomain, APIDTO apidto, String extractedFolderPath, APIDefinitionValidationResponse apiDefinitionValidationResponse) throws APIManagementException, XMLStreamException, APITemplateException, CertificateManagementException {
if (apiDefinitionValidationResponse.isValid()) {
APIDefinition parser = apiDefinitionValidationResponse.getParser();
String definition = apiDefinitionValidationResponse.getJsonContent();
if (parser != null) {
Set<URITemplate> uriTemplates = parser.getURITemplates(definition);
for (URITemplate uriTemplate : uriTemplates) {
for (URITemplate template : api.getUriTemplates()) {
if (template.getHTTPVerb().equalsIgnoreCase(uriTemplate.getHTTPVerb()) && template.getUriTemplate().equals(uriTemplate.getUriTemplate())) {
template.setMediationScript(uriTemplate.getMediationScript());
template.setMediationScripts(uriTemplate.getHTTPVerb(), uriTemplate.getMediationScript());
template.setAmznResourceName(uriTemplate.getAmznResourceName());
template.setAmznResourceTimeout(uriTemplate.getAmznResourceTimeout());
break;
}
}
}
}
}
return retrieveGatewayAPIDto(api, environment, tenantDomain, apidto, extractedFolderPath);
}
use of org.wso2.carbon.apimgt.api.doc.model.APIDefinition in project carbon-apimgt by wso2.
the class RestApiUtil method getAdminAPIAppResourceMapping.
/**
* This is static method to return URI Templates map of API Admin REST API.
* This content need to load only one time and keep it in memory as content will not change
* during runtime.
*
* @return URITemplate set associated with API Manager Admin REST API
*/
public static Set<URITemplate> getAdminAPIAppResourceMapping(String version) {
API api = new API(new APIIdentifier(RestApiConstants.REST_API_PROVIDER, RestApiConstants.REST_API_ADMIN_CONTEXT, RestApiConstants.REST_API_ADMIN_VERSION_0));
if (adminAPIResourceMappings != null) {
return adminAPIResourceMappings;
} else {
try {
String definition;
if (RestApiConstants.REST_API_ADMIN_VERSION_0.equals(version)) {
definition = IOUtils.toString(RestApiUtil.class.getResourceAsStream("/admin-api.json"), "UTF-8");
} else {
definition = IOUtils.toString(RestApiUtil.class.getResourceAsStream("/admin-api.yaml"), "UTF-8");
}
APIDefinition oasParser = OASParserUtil.getOASParser(definition);
// Get URL templates from swagger content we created
adminAPIResourceMappings = oasParser.getURITemplates(definition);
} catch (APIManagementException e) {
log.error("Error while reading resource mappings for API: " + api.getId().getApiName(), e);
} catch (IOException e) {
log.error("Error while reading the swagger definition for API: " + api.getId().getApiName(), e);
}
return adminAPIResourceMappings;
}
}
use of org.wso2.carbon.apimgt.api.doc.model.APIDefinition in project carbon-apimgt by wso2.
the class SolaceAdminApis method registerAPI.
/**
* Register API in Solace using AsyncAPI Definition
*
* @param organization name of the Organization
* @param title name of the Solace API
* @param apiDefinition Async definition of the Solace API
* @return CloseableHttpResponse of the PUT call
*/
public CloseableHttpResponse registerAPI(String organization, String title, String apiDefinition) {
URL serviceEndpointURL = new URL(baseUrl);
HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
HttpPut httpPut = new HttpPut(baseUrl + "/" + organization + "/apis/" + title);
httpPut.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
httpPut.setHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
JsonNode jsonNodeTree;
String jsonAsYaml = null;
// convert json to yaml
try {
jsonNodeTree = new ObjectMapper().readTree(apiDefinition);
jsonAsYaml = new YAMLMapper().writeValueAsString(jsonNodeTree);
} catch (JsonProcessingException e) {
log.error(e.getMessage());
}
// add definition to request body
if (jsonAsYaml != null) {
StringEntity params = null;
try {
params = new StringEntity(jsonAsYaml);
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage());
}
httpPut.setEntity(params);
try {
return APIUtil.executeHTTPRequest(httpPut, httpClient);
} catch (IOException | APIManagementException e) {
log.error(e.getMessage());
}
}
return null;
}
use of org.wso2.carbon.apimgt.api.doc.model.APIDefinition in project carbon-apimgt by wso2.
the class SettingsMappingUtil method GetScopeList.
private List<String> GetScopeList() throws APIManagementException {
String definition = null;
try {
definition = IOUtils.toString(RestApiUtil.class.getResourceAsStream("/devportal-api.yaml"), "UTF-8");
} catch (IOException e) {
log.error("Error while reading the swagger definition", e);
}
APIDefinition oasParser = OASParserUtil.getOASParser(definition);
Set<Scope> scopeSet = oasParser.getScopes(definition);
List<String> scopeList = new ArrayList<>();
for (Scope entry : scopeSet) {
scopeList.add(entry.getKey());
}
return scopeList;
}
use of org.wso2.carbon.apimgt.api.doc.model.APIDefinition in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method generateSOAPAPIDefinition.
/**
* Add soap parameters to the default soap api resource.
*
* @param apiDefinition The API definition string.
* @return Modified api definition.
*/
private String generateSOAPAPIDefinition(String apiDefinition) throws APIManagementException {
JSONParser jsonParser = new JSONParser();
JSONObject apiJson;
JSONObject paths;
try {
apiJson = (JSONObject) jsonParser.parse(apiDefinition);
paths = (JSONObject) jsonParser.parse(RestApiPublisherUtils.getSOAPOperation());
apiJson.replace("paths", paths);
return apiJson.toJSONString();
} catch (ParseException e) {
throw new APIManagementException("Error while parsing the api definition.", e);
}
}
Aggregations