use of org.wso2.carbon.apimgt.impl.APIClientGenerationManager in project carbon-apimgt by wso2.
the class SdkGenApiServiceImpl method sdkGenLanguagesGet.
/**
* Rest API implementation to get the supported sdk languages
*/
@Override
public Response sdkGenLanguagesGet(MessageContext messageContext) {
APIClientGenerationManager apiClientGenerationManager = new APIClientGenerationManager();
String supportedLanguages = apiClientGenerationManager.getSupportedSDKLanguages();
if (StringUtils.isNotEmpty(supportedLanguages)) {
// Split the string with ',' and add them to a list.
List<String> lanuagesList = Arrays.stream(supportedLanguages.split(",")).collect(Collectors.toList());
return Response.ok().entity(lanuagesList).build();
}
String message = "Could not find the supported sdk languages";
RestApiUtil.handleInternalServerError(message, log);
return null;
}
use of org.wso2.carbon.apimgt.impl.APIClientGenerationManager in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdSdksLanguageGet.
/**
* Rest api implementation to downloading the client sdk for given api in given sdk language.
*
* @param apiId : The id of the api.
* @param language : Preferred sdk language.
* @param messageContext : messageContext
* @return : The sdk as a zip archive.
*/
@Override
public Response apisApiIdSdksLanguageGet(String apiId, String language, String xWSO2Tenant, MessageContext messageContext) throws APIManagementException {
if (StringUtils.isEmpty(apiId) || StringUtils.isEmpty(language)) {
String message = "Error generating the SDK. API id or language should not be empty";
RestApiUtil.handleBadRequest(message, log);
}
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIDTO api = getAPIByAPIId(apiId, organization);
APIClientGenerationManager apiClientGenerationManager = new APIClientGenerationManager();
Map<String, String> sdkArtifacts;
String swaggerDefinition = api.getApiDefinition();
if (api != null) {
try {
sdkArtifacts = apiClientGenerationManager.generateSDK(language, api.getName(), api.getVersion(), swaggerDefinition);
// Create the sdk response.
File sdkFile = new File(sdkArtifacts.get("zipFilePath"));
return Response.ok(sdkFile, MediaType.APPLICATION_OCTET_STREAM_TYPE).header("Content-Disposition", "attachment; filename=\"" + sdkArtifacts.get("zipFileName") + "\"").build();
} catch (APIClientGenerationException e) {
String message = "Error generating client sdk for api: " + api.getName() + " for language: " + language;
RestApiUtil.handleInternalServerError(message, e, log);
}
}
String message = "Could not find an API for ID " + apiId;
RestApiUtil.handleResourceNotFoundError(message, log);
return null;
}
Aggregations